7 #include "activities/editor/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 <fwGuiQt/container/QtContainer.hpp> 27 #include <fwMedData/ActivitySeries.hpp> 29 #include <fwRuntime/Bundle.hpp> 30 #include <fwRuntime/Convert.hpp> 31 #include <fwRuntime/operations.hpp> 33 #include <fwServices/macros.hpp> 35 #include <boost/foreach.hpp> 37 #include <QGridLayout> 41 #include <QPushButton> 42 #include <QScrollArea> 43 #include <QVBoxLayout> 58 const ::fwCom::Signals::SignalKeyType SCreateActivity::s_ACTIVITY_ID_SELECTED_SIG =
"activityIDSelected";
59 const ::fwCom::Signals::SignalKeyType SCreateActivity::s_LOAD_REQUESTED_SIG =
"loadRequested";
63 SCreateActivity::SCreateActivity() noexcept
65 newSignal< ActivityIDSelectedSignalType >(s_ACTIVITY_ID_SELECTED_SIG);
66 newSignal< LoadRequestedSignalType >(s_LOAD_REQUESTED_SIG);
71 SCreateActivity::~SCreateActivity() noexcept
77 void SCreateActivity::configuring()
81 const auto cfg = this->getConfigTree();
83 if(cfg.count(
"filter") == 1 )
85 const ::fwServices::IService::ConfigType& configFilter = cfg.get_child(
"filter");
86 SLM_ASSERT(
"A maximum of 1 <mode> tag is allowed", configFilter.count(
"mode") < 2);
88 const std::string mode = configFilter.get< std::string >(
"mode");
89 SLM_ASSERT(
"'" + mode +
"' value for <mode> tag isn't valid. Allowed values are : 'include', 'exclude'.",
90 mode ==
"include" || mode ==
"exclude");
93 BOOST_FOREACH(
const ConfigType::value_type& v, configFilter.equal_range(
"id") )
95 m_keys.push_back(v.second.get<std::string>(
""));
98 SLM_ASSERT(
"A maximum of 1 <filter> tag is allowed", cfg.count(
"filter") < 2);
103 void SCreateActivity::starting()
107 fwGuiQt::container::QtContainer::sptr qtContainer = fwGuiQt::container::QtContainer::dynamicCast(getContainer());
109 QGroupBox* groupBox =
new QGroupBox(tr(
"Activities") );
111 QScrollArea* scrollArea =
new QScrollArea();
112 scrollArea->setWidget(groupBox);
113 scrollArea->setWidgetResizable(
true);
115 QVBoxLayout* mainLayout =
new QVBoxLayout();
116 mainLayout->addWidget(scrollArea);
118 m_buttonGroup =
new QButtonGroup(groupBox);
121 m_activitiesInfo = this->getEnabledActivities(infos);
125 infoLoad.title =
"Load activity";
126 infoLoad.icon = ::fwRuntime::getBundleResourceFilePath(
"media",
"icons/LoadActivity.svg").string();
127 infoLoad.description =
"Load a previously saved activity.";
129 m_activitiesInfo.insert(m_activitiesInfo.begin(), infoLoad);
131 size_t indexButton = 0;
132 size_t numCols =
static_cast<size_t>(std::ceil(std::sqrt(static_cast<float>(m_activitiesInfo.size()))));
133 int numRows =
static_cast<int>(std::floor(std::sqrt(static_cast<float>(m_activitiesInfo.size()))));
134 numCols = numCols + numCols + 1;
136 QWidget*
const container = qtContainer->getQtContainer();
137 container->setObjectName(
"activities");
138 std::string styleGrid(
"QGridLayout#activities {" 141 container->setStyleSheet(QString::fromUtf8(styleGrid.c_str()));
143 QGridLayout* activitiesLayout =
new QGridLayout();
144 activitiesLayout->setRowMinimumHeight(0, 5);
145 activitiesLayout->setRowStretch(0, 2);
146 groupBox->setLayout(activitiesLayout);
149 font.setPointSize(12);
152 std::string style(
"QPushButton#activityButton {" 160 for(const ::fwActivities::registry::ActivityInfo& info : m_activitiesInfo)
162 QPushButton* button =
new QPushButton(QIcon(info.icon.c_str()), QString::fromStdString(
" " + info.title));
163 button->setToolTip(QString::fromStdString(info.description));
164 button->setIconSize(QSize(80, 80));
165 button->setObjectName(
"activityButton");
166 button->setFont(font);
168 button->setStyleSheet(QString::fromUtf8(style.c_str()));
169 m_buttonGroup->addButton(button, static_cast<int>(indexButton));
171 QLabel* label =
new QLabel(QString::fromStdString(info.description));
172 label->setWordWrap(
true);
174 activitiesLayout->setColumnMinimumWidth(j, 10);
175 activitiesLayout->setColumnStretch(j, 5);
176 activitiesLayout->addWidget(button, i, j + 1);
178 activitiesLayout->addWidget(label, i + 1, j + 1);
180 if(j == static_cast<int>(numCols) - 1 )
182 activitiesLayout->setColumnMinimumWidth(j, 10);
183 activitiesLayout->setColumnStretch(j, 5);
188 activitiesLayout->setRowMinimumHeight(i + 2, 5);
189 activitiesLayout->setRowStretch(i + 2, 1);
194 activitiesLayout->setRowMinimumHeight(numRows * 3, 5);
195 activitiesLayout->setRowStretch(numRows * 3, 2);
197 qtContainer->setLayout(mainLayout);
199 this->connect(m_buttonGroup, SIGNAL(buttonClicked(
int)), SLOT(onClicked(
int)));
204 void SCreateActivity::stopping()
212 void SCreateActivity::updating()
218 void SCreateActivity::onClicked(
int id)
222 auto sig = this->signal<LoadRequestedSignalType>(s_LOAD_REQUESTED_SIG);
227 auto sig = this->signal<ActivityIDSelectedSignalType>(s_ACTIVITY_ID_SELECTED_SIG);
228 sig->asyncEmit(m_activitiesInfo[ static_cast<size_t>(
id)].
id);
234 SCreateActivity::ActivityInfoContainer SCreateActivity::getEnabledActivities(
const ActivityInfoContainer& infos)
236 ActivityInfoContainer configs;
238 if(m_filterMode ==
"include" || m_filterMode ==
"exclude")
240 const bool isIncludeMode = m_filterMode ==
"include";
242 for(ActivityInfoContainer::const_iterator iter = infos.begin(); iter != infos.end(); ++iter)
244 KeysType::iterator keyIt = std::find(m_keys.begin(), m_keys.end(), iter->id);
246 if(keyIt != m_keys.end() && isIncludeMode)
248 configs.push_back(*iter);
250 else if(keyIt == m_keys.end() && !isIncludeMode)
252 configs.push_back(*iter);
Holds Activities configuration.
Defines the service interface managing the editor service for object.
static FWACTIVITIES_API Activities::sptr getDefault()
Return the default global instance of Activities.
This editor launchs an activity according to the given configuration.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
The namespace activities contains helpers and services allowing to launch activities.
FWGUI_API void create()
Creates view, sub-views and toolbar containers. Manages sub-views and toobar services.
FWGUI_API void initialize()
Initialize managers.