7 #include "uiMedDataQt/editor/SSelector.hpp" 9 #include "uiMedDataQt/widget/Selector.hpp" 11 #include <fwCom/Signal.hpp> 12 #include <fwCom/Signal.hxx> 13 #include <fwCom/Slot.hpp> 14 #include <fwCom/Slot.hxx> 15 #include <fwCom/Slots.hpp> 16 #include <fwCom/Slots.hxx> 18 #include <fwCore/base.hpp> 20 #include <fwDataTools/helper/Vector.hpp> 22 #include <fwGui/dialog/MessageDialog.hpp> 24 #include <fwGuiQt/container/QtContainer.hpp> 26 #include <fwMedData/Series.hpp> 27 #include <fwMedData/SeriesDB.hpp> 29 #include <fwMedDataTools/helper/SeriesDB.hpp> 31 #include <fwRuntime/operations.hpp> 33 #include <fwServices/macros.hpp> 35 #include <QVBoxLayout> 50 const ::fwCom::Slots::SlotKeyType SSelector::s_ADD_SERIES_SLOT =
"addSeries";
51 const ::fwCom::Slots::SlotKeyType SSelector::s_REMOVE_SERIES_SLOT =
"removeSeries";
56 m_allowedRemove(true),
57 m_selectionMode(QAbstractItemView::ExtendedSelection),
61 m_sigSeriesDoubleClicked = SeriesDoubleClickedSignalType::New();
66 newSlot(s_ADD_SERIES_SLOT, &SSelector::addSeries,
this);
67 m_slotRemoveSeries = newSlot(s_REMOVE_SERIES_SLOT, &SSelector::removeSeries,
this);
82 _sstream << std::string(
"SSelector");
91 ::fwGuiQt::container::QtContainer::sptr qtContainer = ::fwGuiQt::container::QtContainer::dynamicCast(
92 this->getContainer() );
94 m_selectorWidget = new ::uiMedDataQt::widget::Selector();
95 m_selectorWidget->setSeriesIcons(m_seriesIcons);
96 m_selectorWidget->setSelectionMode(m_selectionMode);
97 m_selectorWidget->setAllowedRemove(m_allowedRemove);
98 m_selectorWidget->setInsertMode(m_insertMode);
100 QVBoxLayout* layout =
new QVBoxLayout();
101 layout->addWidget(m_selectorWidget);
102 qtContainer->setLayout(layout);
104 QObject::connect(m_selectorWidget, SIGNAL(selectSeries(QVector< ::fwMedData::Series::sptr >,
105 QVector< ::fwMedData::Series::sptr >)),
107 QVector< ::fwMedData::Series::sptr >)));
111 QObject::connect(m_selectorWidget, SIGNAL(doubleClicked(
const QModelIndex&)),
118 QObject::connect(m_selectorWidget, SIGNAL(removeSeries(QVector< ::fwMedData::Series::sptr >)),
119 this, SLOT(
onRemoveSeries(QVector< ::fwMedData::Series::sptr >)));
136 ::fwMedData::SeriesDB::sptr seriesDB = this->getInOut< ::fwMedData::SeriesDB >(
"seriesDB");
138 m_selectorWidget->clear();
140 for(::fwMedData::Series::sptr series : seriesDB->getContainer())
142 m_selectorWidget->addSeries(series);
152 std::vector < ::fwRuntime::ConfigurationElement::sptr > selectionModeCfg =
m_configuration->find(
"selectionMode");
153 if(!selectionModeCfg.empty())
155 const std::string& selectionMode = selectionModeCfg.front()->getValue();
157 if(!selectionMode.empty())
159 if(selectionMode ==
"single")
161 m_selectionMode = QAbstractItemView::SingleSelection;
163 else if(selectionMode ==
"extended")
165 m_selectionMode = QAbstractItemView::ExtendedSelection;
169 SLM_WARN(
"value " + selectionMode +
" is not managed for <selectionMode>");
174 std::vector < ::fwRuntime::ConfigurationElement::sptr > allowedRemoveCfg =
m_configuration->find(
"allowedRemove");
175 if(!allowedRemoveCfg.empty())
177 const std::string& allowedRemove = allowedRemoveCfg.front()->getValue();
179 if(allowedRemove ==
"yes")
181 m_allowedRemove =
true;
183 else if(allowedRemove ==
"no")
185 m_allowedRemove =
false;
189 SLM_WARN(
"value " + allowedRemove +
" is not managed for <allowedRemove>");
193 std::vector < ::fwRuntime::ConfigurationElement::sptr > insertCfg =
m_configuration->find(
"insertMode");
194 if(!insertCfg.empty())
196 const std::string& insert = insertCfg.front()->getValue();
202 else if(insert ==
"no")
204 m_insertMode =
false;
208 SLM_WARN(
"value " + insert +
" is not managed for <insertMode>");
212 std::vector < ::fwRuntime::ConfigurationElement::sptr > iconsCfg =
m_configuration->find(
"icons");
213 if (!iconsCfg.empty())
215 SLM_ASSERT(
"Only one 'config' tag is allowed for SSelector configuration", iconsCfg.size() == 1);
217 std::vector < ::fwRuntime::ConfigurationElement::sptr > cfg = iconsCfg.front()->find(
"icon");
219 for(::fwRuntime::ConfigurationElement::sptr elt : cfg)
221 const std::string series = elt->getAttributeValue(
"series");
222 SLM_ASSERT(
"'series' attribute is missing", !series.empty());
224 const std::string icon = elt->getAttributeValue(
"icon");
225 SLM_ASSERT(
"'icon' attribute is missing", !icon.empty());
227 const auto file = ::fwRuntime::getResourceFilePath(icon);
228 m_seriesIcons[series] = file.string();
236 QVector< ::fwMedData::Series::sptr > deselection)
238 ::fwData::Vector::sptr selectionVector = this->getSelection();
241 for( ::fwMedData::Series::sptr series : deselection)
243 vectorHelper.
remove(series);
246 for( ::fwMedData::Series::sptr series : selection)
248 vectorHelper.
add(series);
258 m_selectorWidget->clearSelection();
259 m_selectorWidget->setCurrentIndex(index);
261 ::fwData::Vector::sptr selectionVector = this->getSelection();
265 std::stringstream str;
266 str <<
"Selected study. TODO";
273 SLM_ASSERT(
"There must be only one object selected", selectionVector->size() == 1);
274 ::fwData::Object::sptr obj = selectionVector->front();
275 ::fwMedData::Series::sptr series = ::fwMedData::Series::dynamicCast(obj);
276 SLM_ASSERT(
"Object must be a '::fwMedData::Series'", series);
278 m_sigSeriesDoubleClicked->asyncEmit(series);
286 ::fwMedData::SeriesDB::sptr seriesDB = this->getInOut< ::fwMedData::SeriesDB >(
"seriesDB");
290 std::set< ::fwMedData::Series::sptr > seriesSet;
291 std::copy(selection.begin(), selection.end(), std::inserter(seriesSet, seriesSet.begin()));
293 for( ::fwMedData::Series::sptr series : seriesSet)
295 seriesDBHelper.remove(series);
302 seriesDBHelper.notify();
308 ::fwData::Vector::sptr SSelector::getSelection()
310 ::fwData::Vector::sptr selection = this->getInOut< ::fwData::Vector >(
"selection");
311 SLM_ASSERT(
"Object " << m_selectionId <<
" is not a '::fwData::Vector'", selection);
318 void SSelector::addSeries(::fwMedData::SeriesDB::ContainerType addedSeries)
320 for( ::fwMedData::Series::sptr series : addedSeries )
322 m_selectorWidget->addSeries(series);
328 void SSelector::removeSeries(::fwMedData::SeriesDB::ContainerType removedSeries)
330 for( ::fwMedData::Series::sptr series : removedSeries )
332 m_selectorWidget->removeSeries(series);
The namespace uiMedDataQt contains editors for medical data.
This class is a helper to define the connections of a service and its data.
virtual void info(std::ostream &_sstream) override
Write information in a stream.
void onSelectedSeries(QVector< ::fwMedData::Series::sptr > selection, QVector< ::fwMedData::Series::sptr > deselection)
Manages the selection vector according to selection/deselection.
Class allowing to block a Connection.
Defines the service interface managing the editor service for object.
static FWGUI_API IMessageDialog::Buttons showMessageDialog(const std::string &title, const std::string &message,::fwGui::dialog::IMessageDialog::Icons icon=INFO)
FWGUI_API void destroy()
Stops sub-views and toobar services. Destroys view, sub-views and toolbar containers.
void onRemoveSeries(QVector< ::fwMedData::Series::sptr > selection)
Removes series from seriesDB and notify.
static UIMEDDATAQT_APIconst::fwCom::Signals::SignalKeyType s_SERIES_DOUBLE_CLICKED_SIG
Key in m_signals map of signal m_sigSeriesDoubleClicked.
#define SLM_WARN(message)
virtual void starting() override
Installs GUI : create container and add selector.
This editor shows information about the medical data. It allows to manipulate (select, erase, ...) studies and series.
static FWMEDDATA_APIconst::fwCom::Signals::SignalKeyType s_ADDED_SERIES_SIG
Type of signal when series are added.
static FWMEDDATA_APIconst::fwCom::Signals::SignalKeyType s_REMOVED_SERIES_SIG
Type of signal when series are added.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
virtual void configuring() override
Configures the service according to the xml tags found.
::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.
virtual void stopping() override
Destroys GUI.
#define SLM_TRACE(message)
void onDoubleClick(const QModelIndex &index)
Send a 'seriesDoubleClicked' signal when the user double click on a series. This signal holds the cli...
virtual void updating() override
Fill selector with the series contained in SeriesDB.
UIMEDDATAQT_API SSelector()
Constructor.
virtual UIMEDDATAQT_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
FWGUI_API void initialize()
Initialize managers.
virtual UIMEDDATAQT_API ~SSelector() noexcept
Destructor.