7 #include "guiQt/editor/Code.hpp" 9 #include <fwCom/Signal.hpp> 10 #include <fwCom/Signal.hxx> 12 #include <fwCore/base.hpp> 14 #include <fwData/String.hpp> 16 #include <fwGuiQt/container/QtContainer.hpp> 17 #include <fwGuiQt/highlighter/CppHighlighter.hpp> 18 #include <fwGuiQt/highlighter/PythonHighlighter.hpp> 20 #include <fwServices/macros.hpp> 22 #include <QHBoxLayout> 34 const std::string Code::s_PYTHON =
"Python";
35 const std::string Code::s_CPP =
"Cpp";
37 static const ::fwServices::IService::KeyType s_STRING_INOUT =
"string";
59 ::fwGuiQt::container::QtContainer::sptr qtContainer = ::fwGuiQt::container::QtContainer::dynamicCast(
60 this->getContainer() );
62 ::fwData::String::sptr stringObj = this->getInOut< ::fwData::String >(s_STRING_INOUT);
64 QHBoxLayout* layout =
new QHBoxLayout();
65 m_valueCtrl =
new QTextEdit( );
66 layout->addWidget( m_valueCtrl, 1);
68 if(m_language == s_PYTHON )
70 m_highlighter = new ::fwGuiQt::highlighter::PythonHighlighter(m_valueCtrl->document());
72 else if(m_language == s_CPP )
74 m_highlighter = new ::fwGuiQt::highlighter::CppHighlighter(m_valueCtrl->document());
78 OSLM_WARN(
"Language "<<m_language<<
" not yet supported.");
81 qtContainer->setLayout( layout );
83 QObject::connect(m_valueCtrl, SIGNAL(textChanged()),
this, SLOT(
onModifyValue()));
93 QObject::disconnect(m_valueCtrl, SIGNAL(textChanged()),
this, SLOT(
onModifyValue()));
104 std::vector < ConfigurationType > vectConfig =
m_configuration->find(
"config");
105 if(!vectConfig.empty())
107 std::vector < ConfigurationType > vectLanguage = vectConfig.at(0)->find(
"language");
108 if(!vectLanguage.empty())
110 ConfigurationType configLanguage = vectLanguage.at(0);
111 SLM_ASSERT(
"missing 'name' attribute in language tag", configLanguage->hasAttribute(
"name"));
112 m_language = configLanguage->getAttributeValue(
"name");
121 ::fwData::String::sptr stringObj = this->getInOut< ::fwData::String >(s_STRING_INOUT);
122 SLM_ASSERT(
"The given string object is null", stringObj);
124 m_valueCtrl->setText(QString::fromStdString(stringObj->value()));
125 OSLM_TRACE(stringObj->getID() <<
" updated value : " << stringObj->value());
139 _sstream <<
"String Editor";
146 QString value = m_valueCtrl->toPlainText();
147 ::fwData::String::sptr stringObj = this->getInOut< ::fwData::String >(s_STRING_INOUT);
148 ::fwData::String::sptr oldValue;
151 std::string strValue = value.toStdString();
152 stringObj->value() = strValue;
154 if ( oldValue->value() != stringObj->value() )
156 OSLM_TRACE( stringObj->getID() <<
" modified");
This class is a helper to define the connections of a service and its data.
virtual void swapping() override
Update the value from the String object.
void onModifyValue()
This method is called when the value change.
Class allowing to block a Connection.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
This service displays a code editor and works on a fwData::String.
Defines the service interface managing the editor service for object.
virtual void updating() override
Update the value from the String object.
GUIQT_API Code() noexcept
Constructor. Do nothing.
FWGUI_API void destroy()
Stops sub-views and toobar services. Destroys view, sub-views and toolbar containers.
#define OSLM_TRACE(message)
virtual void starting() override
Install the layout.
virtual void info(std::ostream &_sstream) override
Overrides.
virtual GUIQT_API ~Code() noexcept
Destructor. Do nothing.
UpdateSlotType::sptr m_slotUpdate
Slot to call update method.
virtual void stopping() override
Destroy the layout.
#define OSLM_WARN(message)
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
static FWDATA_API::fwData::Object::sptr copy(const ::fwData::Object::csptr &source)
return a copy of the source. if source is a null pointer, return a null pointer.
::fwRuntime::ConfigurationElement::sptr m_configuration
Configuration element used to configure service internal state using a generic XML like structure TOD...
FWGUI_API void create()
Creates view, sub-views and toolbar containers. Manages sub-views and toobar services.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
virtual GUIQT_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
The namespace guiQt contains the basic services to build the application IHM with Qt...
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
This class contains an std::string value.
virtual void configuring() override
Parses the configuration.
FWGUI_API void initialize()
Initialize managers.