7 #include "guiQt/editor/DynamicView.hpp" 9 #include <fwCom/Slot.hpp> 10 #include <fwCom/Slot.hxx> 11 #include <fwCom/Slots.hpp> 12 #include <fwCom/Slots.hxx> 14 #include <fwCore/base.hpp> 16 #include <fwData/Boolean.hpp> 17 #include <fwData/Composite.hpp> 18 #include <fwData/String.hpp> 20 #include <fwDataCamp/getObject.hpp> 22 #include <fwGui/dialog/MessageDialog.hpp> 23 #include <fwGui/GuiRegistry.hpp> 25 #include <fwRuntime/ConfigurationElement.hpp> 26 #include <fwRuntime/operations.hpp> 28 #include <fwServices/macros.hpp> 29 #include <fwServices/registry/AppConfig.hpp> 31 #include <boost/foreach.hpp> 42 static const ::fwCom::Slots::SlotKeyType s_CREATE_TAB_SLOT =
"createTab";
46 AppConfig::AppConfig(
const ConfigType& config) :
47 id(config.get<
std::string>(
"<xmlattr>.id")),
48 title(config.get<
std::string>(
"<xmlattr>.title"))
50 std::string closableStr = config.get_optional<std::string>(
"<xmlattr>.closable").get_value_or(
"true");
51 closable = (closableStr ==
"true");
53 tabInfo = config.get_optional<std::string>(
"<xmlattr>.tabinfo").get_value_or(
"");
55 if(config.count(
"parameters") == 1 )
57 const ConfigType& configParameters = config.get_child(
"parameters");
58 BOOST_FOREACH(
const ConfigType::value_type& v, configParameters.equal_range(
"parameter") )
60 ParameterType parameter( v.second );
61 parameters.push_back( parameter );
64 OSLM_ASSERT(
"At most 1 <parameters> tag is allowed", config.count(
"parameters") < 2);
69 DynamicView::DynamicView() noexcept
71 m_dynamicConfigStartStop =
false;
73 newSlot(s_CREATE_TAB_SLOT, &DynamicView::createTab,
this);
78 DynamicView::~DynamicView() noexcept
84 void DynamicView::starting()
86 FW_DEPRECATED_MSG(
"The service '::guiQt::editor::DynamicView' is deprecated, use '::guiQt::editor::SDynamicView' " 91 ::fwGuiQt::container::QtContainer::sptr parentContainer
92 = ::fwGuiQt::container::QtContainer::dynamicCast( this->getContainer() );
94 m_tabWidget =
new QTabWidget();
95 m_tabWidget->setTabsClosable(
true );
96 m_tabWidget->setDocumentMode(
true );
97 m_tabWidget->setMovable(
true );
99 QObject::connect(m_tabWidget, SIGNAL(tabCloseRequested(
int)),
this, SLOT(closeTabSignal(
int)));
100 QObject::connect(m_tabWidget, SIGNAL(currentChanged(
int)),
this, SLOT(changedTab(
int)));
102 QBoxLayout* layout =
new QBoxLayout(QBoxLayout::TopToBottom);
103 layout->addWidget( m_tabWidget );
105 parentContainer->setLayout(layout);
109 if(!m_appConfig.id.empty())
112 this->launchTab(info);
118 void DynamicView::stopping()
121 while(m_tabWidget->count())
123 this->closeTab(0,
true);
125 m_tabWidget->clear();
133 void DynamicView::configuring()
137 if(this->getConfigTree().count(
"config") > 0)
139 SLM_ASSERT(
"There must be one (and only one) <config/> element.",
140 this->getConfigTree().count(
"config") == 1 );
141 const ::fwServices::IService::ConfigType srvconfig = this->getConfigTree();
142 const ::fwServices::IService::ConfigType& config = srvconfig.get_child(
"config");
144 const std::string dynamicConfig =
145 config.get_optional<std::string>(
"<xmlattr>.dynamicConfigStartStop").get_value_or(
"false");
146 m_dynamicConfigStartStop = (dynamicConfig ==
"true");
148 if(config.count(
"appConfig") == 1 )
150 const ::fwServices::IService::ConfigType& appConfig = config.get_child(
"appConfig");
153 OSLM_ASSERT(
"At most 1 <appConfig> tag is allowed", config.count(
"appConfig") < 2);
162 info.tabID =
"TABID_" + this->getID();
164 if(appConfig.tabInfo.empty())
166 info.title = appConfig.title;
170 info.title = appConfig.tabInfo;
172 info.viewConfigID = appConfig.id;
173 info.closable = appConfig.closable;
175 ::fwData::Object::sptr currentObj = this->getObject();
176 ReplaceMapType replaceMap;
177 for(
const AppConfig::ParametersType::value_type& param : appConfig.parameters)
179 if(!param.isSeshat())
181 replaceMap[param.replace] = param.by;
185 std::string parameterToReplace = param.by;
186 if (parameterToReplace.substr(0, 1) ==
"!")
188 parameterToReplace.replace(0, 1,
"@");
191 ::fwData::Object::sptr obj = ::fwDataCamp::getObject(currentObj, parameterToReplace);
192 OSLM_ASSERT(
"Invalid seshat path : '"<<param.by<<
"'", obj);
194 ::fwData::String::sptr stringParameter = ::fwData::String::dynamicCast(obj);
196 std::string parameterValue = obj->getID();
198 if(stringParameter && param.by.substr(0, 1) ==
"!")
200 parameterValue = stringParameter->getValue();
202 replaceMap[param.replace] = parameterValue;
205 info.replaceMap = replaceMap;
211 void DynamicView::updating()
217 void DynamicView::swapping()
234 this->launchTab(viewInfo);
241 static int count = 0;
242 if(m_tabIDList.find(info.tabID) != m_tabIDList.end() )
245 "The tab " + info.title +
" cannot be opened twice.",
246 ::fwGui::dialog::IMessageDialog::WARNING);
250 if ( m_titleToCount.find( info.title ) != m_titleToCount.end() )
252 m_titleToCount[ info.title ]++;
256 m_titleToCount[ info.title ] = 1;
259 QString finalTitle = QString(
"%1 %2").arg( info.title.c_str(),
"(%1)" ).arg( m_titleToCount[ info.title ] );
260 info.wid = QString(
"DynamicView-%1").arg(count++).toStdString();
262 ::fwGuiQt::container::QtContainer::sptr subContainer = ::fwGuiQt::container::QtContainer::New();
263 QWidget* widget =
new QWidget();
264 subContainer->setQtContainer(widget);
267 info.replaceMap[
"WID_PARENT" ] = info.wid;
269 info.replaceMap[
"GENERIC_UID"] = genericUidAdaptor;
272 helper->setConfig( info.viewConfigID, info.replaceMap );
276 if (!m_dynamicConfigStartStop)
285 catch( std::exception& e )
289 ::fwGui::dialog::IMessageDialog::CRITICAL);
293 info.container = subContainer;
294 info.helper = helper;
296 m_dynamicInfoMap[widget] = info;
297 m_tabIDList.insert(info.tabID);
299 int index = m_tabWidget->addTab(widget, finalTitle );
300 if(!info.tooltip.empty())
302 m_tabWidget->setTabToolTip(index, QString::fromStdString(info.tooltip));
304 if(!info.icon.empty())
306 m_tabWidget->setTabIcon(index, QIcon(QString::fromStdString(info.icon)) );
308 m_tabWidget->setCurrentWidget(widget);
313 void DynamicView::info( std::ostream& _sstream )
319 void DynamicView::closeTabSignal(
int index )
321 closeTab( index,
false );
326 void DynamicView::closeTab(
int index,
bool forceClose )
328 QWidget* widget = m_tabWidget->widget(index);
330 SLM_ASSERT(
"Widget is not in dynamicInfoMap", m_dynamicInfoMap.find(widget) != m_dynamicInfoMap.end());
332 if ( info.closable || forceClose )
334 m_tabIDList.erase(info.tabID);
335 if (!m_dynamicConfigStartStop)
337 info.helper->stopAndDestroy();
341 if (info.helper->isStarted())
345 info.helper->destroy();
351 m_tabWidget->removeTab(index);
355 info.container->destroyContainer();
356 info.container.reset();
357 m_dynamicInfoMap.erase(widget);
362 "The tab " + info.title +
" can not be closed.",
363 ::fwGui::dialog::IMessageDialog::INFO);
369 void DynamicView::changedTab(
int index )
371 QWidget* widget = m_tabWidget->widget(index);
373 if (m_dynamicConfigStartStop && widget != m_currentWidget)
378 oldinfo.helper->stop();
384 if (!newinfo.helper->isStarted())
386 newinfo.helper->start();
387 newinfo.helper->update();
393 m_currentWidget = widget;
const std::string & getTitle() const
Return activity title.
static FWGUI_API void unregisterWIDContainer(std::string wid)
Unregisters container associate with window ID.
const ReplaceMapType & getReplaceMap() const
Return the map of the string association to replace in config.
#define OSLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
#define SLM_TRACE_FUNC()
Trace contextual function signature.
static FWGUI_API IMessageDialog::Buttons showMessageDialog(const std::string &title, const std::string &message,::fwGui::dialog::IMessageDialog::Icons icon=INFO)
#define FW_DEPRECATED_MSG(message, version)
Use this macro when deprecating a function to warn the developer.
This editor manages tabs containing sub-configurations.
const std::string & getTabID() const
Return tab identifier.
static FWGUI_API void registerWIDContainer(std::string wid,::fwGui::container::fwContainer::sptr container)
Registers container associate with window ID.
Activity information sent by signal to launch new activities in a tab.
const std::string & getAppConfigID() const
Return appConfig identifier.
#define OSLM_ERROR(message)
const std::string & getIconPath() const
Return activity icon path.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
FWGUI_API void create()
Creates view, sub-views and toolbar containers. Manages sub-views and toobar services.
bool isClosable() const
Return if the activity can be closed.
static FWSERVICES_API std::shared_ptr< IAppConfigManager > New()
static FWSERVICES_API std::string getUniqueIdentifier(const std::string &serviceUid="")
Create an unique identifier.
const std::string & getToolTip() const
Return tooltip.
The namespace guiQt contains the basic services to build the application IHM with Qt...
Defines the service interface managing a view placed in main frame.
FWGUI_API void initialize()
Initialize managers.