7 #include "activities/action/SCreateActivity.hpp" 9 #include <fwActivities/IBuilder.hpp> 10 #include <fwActivities/IValidator.hpp> 12 #include <fwCom/Signal.hpp> 13 #include <fwCom/Signal.hxx> 14 #include <fwCom/Slot.hpp> 15 #include <fwCom/Slots.hpp> 16 #include <fwCom/Slots.hxx> 18 #include <fwData/Composite.hpp> 19 #include <fwData/String.hpp> 20 #include <fwData/Vector.hpp> 22 #include <fwGui/dialog/MessageDialog.hpp> 23 #include <fwGui/dialog/SelectorDialog.hpp> 25 #include <fwMedData/ActivitySeries.hpp> 27 #include <fwRuntime/Bundle.hpp> 28 #include <fwRuntime/Convert.hpp> 29 #include <fwRuntime/operations.hpp> 31 #include <fwServices/macros.hpp> 33 #include <boost/foreach.hpp> 35 #include <QApplication> 37 #include <QHBoxLayout> 38 #include <QListWidget> 39 #include <QPushButton> 40 #include <QStandardItemModel> 41 #include <QVBoxLayout> 56 const ::fwCom::Signals::SignalKeyType SCreateActivity::s_ACTIVITY_ID_SELECTED_SIG =
"activityIDSelected";
57 const ::fwCom::Signals::SignalKeyType SCreateActivity::s_ACTIVITY_SELECTED_SIG =
"activitySelected";
61 SCreateActivity::SCreateActivity() noexcept
63 m_sigActivityIDSelected = newSignal< ActivityIDSelectedSignalType >(s_ACTIVITY_ID_SELECTED_SIG);
64 m_sigActivitySelected = newSignal< ActivitySelectedSignalType >(s_ACTIVITY_SELECTED_SIG);
69 SCreateActivity::~SCreateActivity() noexcept
75 void SCreateActivity::starting()
77 this->actionServiceStarting();
82 void SCreateActivity::stopping()
84 this->actionServiceStopping();
89 void SCreateActivity::configuring()
92 typedef ::fwServices::IService::ConfigType ConfigType;
94 const ::fwServices::IService::ConfigType srvconfig = this->getConfigTree();
96 if(srvconfig.count(
"filter") == 1 )
98 const ::fwServices::IService::ConfigType& configFilter = srvconfig.get_child(
"filter");
99 SLM_ASSERT(
"A maximum of 1 <mode> tag is allowed", configFilter.count(
"mode") < 2);
101 const std::string mode = configFilter.get< std::string >(
"mode");
102 SLM_ASSERT(
"'" + mode +
"' value for <mode> tag isn't valid. Allowed values are : 'include', 'exclude'.",
103 mode ==
"include" || mode ==
"exclude");
106 BOOST_FOREACH(
const ConfigType::value_type& v, configFilter.equal_range(
"id") )
108 m_keys.push_back(v.second.get<std::string>(
""));
111 SLM_ASSERT(
"A maximum of 1 <filter> tag is allowed", srvconfig.count(
"filter") < 2);
118 QWidget* parent = qApp->activeWindow();
120 QDialog* dialog =
new QDialog(parent);
121 dialog->setWindowTitle(QString::fromStdString(
"Choose an activity"));
122 dialog->resize(600, 400);
124 QStandardItemModel* model =
new QStandardItemModel(dialog);
125 for( const ::fwActivities::registry::ActivityInfo& info : infos)
128 if(info.title.empty())
134 text = info.title + (info.description.empty() ?
"" :
"\n" + info.description);
137 QStandardItem* item =
new QStandardItem(QIcon(info.icon.c_str()), QString::fromStdString(text));
138 item->setData(QVariant::fromValue(info));
139 item->setEditable(
false);
140 model->appendRow(item);
143 QListView* selectionList =
new QListView();
144 selectionList->setIconSize(QSize(40, 40));
145 selectionList->setUniformItemSizes(
true);
146 selectionList->setModel(model);
148 QModelIndex index = model->index( 0, 0 );
149 if ( index.isValid() )
151 selectionList->selectionModel()->select( index, QItemSelectionModel::Select );
154 QPushButton* okButton =
new QPushButton(
"Ok");
155 QPushButton* cancelButton =
new QPushButton(
"Cancel");
157 QHBoxLayout* hLayout =
new QHBoxLayout();
158 hLayout->addWidget(okButton);
159 hLayout->addWidget(cancelButton);
161 QVBoxLayout* vLayout =
new QVBoxLayout();
162 vLayout->addWidget(selectionList);
163 vLayout->addLayout(hLayout);
165 dialog->setLayout(vLayout);
166 QObject::connect(okButton, SIGNAL(clicked()), dialog, SLOT(accept()));
167 QObject::connect(cancelButton, SIGNAL(clicked()), dialog, SLOT(reject()));
168 QObject::connect(selectionList, SIGNAL(doubleClicked(
const QModelIndex&)), dialog, SLOT(accept()));
173 QModelIndex currentIndex = selectionList->selectionModel()->currentIndex();
174 QStandardItem* item = model->itemFromIndex( currentIndex );
175 QVariant var = item->data();
184 SCreateActivity::ActivityInfoContainer SCreateActivity::getEnabledActivities(
const ActivityInfoContainer& infos)
186 ActivityInfoContainer configs;
188 if(m_filterMode ==
"include" || m_filterMode ==
"exclude")
190 const bool isIncludeMode = m_filterMode ==
"include";
192 for(
auto info : infos)
194 KeysType::iterator keyIt = std::find(m_keys.begin(), m_keys.end(), info.id);
196 if(keyIt != m_keys.end() && isIncludeMode)
198 configs.push_back(info);
200 else if(keyIt == m_keys.end() && !isIncludeMode)
202 configs.push_back(info);
216 void SCreateActivity::updating()
219 infos = this->getEnabledActivities(infos);
224 if((m_keys.size() == 1 && m_filterMode ==
"include") || (infos.size() == 1))
230 info = this->show( infos );
233 if( !info.id.empty() )
235 m_sigActivityIDSelected->asyncEmit(info.id);
241 "No available activity for the current selection.",
242 ::fwGui::dialog::MessageDialog::WARNING);
Holds Activities configuration.
static FWGUI_API IMessageDialog::Buttons showMessageDialog(const std::string &title, const std::string &message,::fwGui::dialog::IMessageDialog::Icons icon=INFO)
static FWACTIVITIES_API Activities::sptr getDefault()
Return the default global instance of Activities.
Defines the service interface managing the menu items.
This class defines a vector of objects.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
FWGUI_API void initialize()
Initialize the action.
The namespace activities contains helpers and services allowing to launch activities.
This action launchs an activity according to the given configuration.