7 #include "uiMedDataQt/editor/SModelSeriesList.hpp" 9 #include <fwCom/Signal.hpp> 10 #include <fwCom/Signal.hxx> 11 #include <fwCom/Signals.hpp> 12 #include <fwCom/Slot.hpp> 13 #include <fwCom/Slot.hxx> 14 #include <fwCom/Slots.hpp> 15 #include <fwCom/Slots.hxx> 17 #include <fwCore/base.hpp> 19 #include <fwData/Boolean.hpp> 20 #include <fwData/Float.hpp> 21 #include <fwData/Integer.hpp> 22 #include <fwData/Reconstruction.hpp> 23 #include <fwData/String.hpp> 25 #include <fwDataCamp/getObject.hpp> 27 #include <fwDataTools/helper/Field.hpp> 29 #include <fwGuiQt/container/QtContainer.hpp> 31 #include <fwMedData/ModelSeries.hpp> 33 #include <fwRuntime/operations.hpp> 35 #include <fwServices/IService.hpp> 36 #include <fwServices/macros.hpp> 37 #include <fwServices/op/Get.hpp> 39 #include <fwTools/fwID.hpp> 41 #include <boost/format.hpp> 45 #include <QListWidgetItem> 47 #include <QTreeWidget> 48 #include <QTreeWidgetItem> 49 #include <QVBoxLayout> 61 virtual std::string apply(::fwData::Object::sptr obj)
63 if(obj->isA(
"::fwData::String"))
65 ::fwData::String::sptr fwValue = ::fwData::String::dynamicCast(obj);
66 return fwValue->getValue();
68 else if(obj->isA(
"::fwData::Integer"))
70 ::fwData::Integer::sptr fwValue = ::fwData::Integer::dynamicCast(obj);
71 return ::boost::lexical_cast<std::string>(fwValue->getValue());
73 else if(obj->isA(
"::fwData::Float"))
75 ::fwData::Float::sptr fwValue = ::fwData::Float::dynamicCast(obj);
76 return ::boost::lexical_cast<std::string>(fwValue->getValue());
80 SLM_WARN(obj->getClassname() +
" is not a printable object : ");
92 virtual std::string apply(::fwData::Object::sptr obj)
94 if(obj->isA(
"::fwData::Integer"))
96 ::fwData::Integer::sptr fwValue = ::fwData::Integer::dynamicCast(obj);
98 if(fwValue->getValue() > 0)
100 std::stringstream ss;
101 ::fwData::Float::sptr fwValue = ::fwData::Float::dynamicCast(obj);
102 ss << ::boost::format(
"%11.2f") % (fwValue->getValue());
107 else if(obj->isA(
"::fwData::Float"))
109 ::fwData::Float::sptr fwValue = ::fwData::Float::dynamicCast(obj);
110 if(fwValue->getValue() > 0)
112 std::stringstream ss;
113 ::fwData::Float::sptr fwValue = ::fwData::Float::dynamicCast(obj);
114 ss << ::boost::format(
"%11.2f") % (fwValue->getValue());
121 SLM_WARN(obj->getClassname() +
" is not a printable object : ");
129 const ::fwCom::Signals::SignalKeyType SModelSeriesList::s_RECONSTRUCTION_SELECTED_SIG =
"reconstructionSelected";
130 const ::fwCom::Signals::SignalKeyType SModelSeriesList::s_EMPTIED_SELECTION_SIG =
"emptiedSelection";
131 const ::fwCom::Slots::SlotKeyType SModelSeriesList::s_SHOW_RECONSTRUCTIONS_SLOT =
"showReconstructions";
133 const ::fwServices::IService::KeyType s_MODEL_SERIES_INOUT =
"modelSeries";
136 m_tree(new QTreeWidget()),
137 m_enableHideAll(true)
139 m_sigReconstructionSelected = newSignal< ReconstructionSelectedSignalType >( s_RECONSTRUCTION_SELECTED_SIG );
140 m_sigEmptiedSelection = newSignal< EmptiedSelectionSignalType >( s_EMPTIED_SELECTION_SIG );
142 newSlot(s_SHOW_RECONSTRUCTIONS_SLOT, &SModelSeriesList::showReconstructions,
this);
149 for(
auto cIt : m_displayedInfo)
161 ::fwGuiQt::container::QtContainer::sptr qtContainer
162 = ::fwGuiQt::container::QtContainer::dynamicCast(this->getContainer());
164 QVBoxLayout* layout =
new QVBoxLayout;
165 QHBoxLayout* layoutButton =
new QHBoxLayout;
166 layout->addLayout(layoutButton);
171 m_showCheckBox =
new QCheckBox( tr(
"Hide all organs"));
172 m_showCheckBox->setToolTip(tr(
"Show or hide all organs"));
173 layoutButton->addWidget( m_showCheckBox, 0 );
174 QObject::connect(m_showCheckBox, SIGNAL(stateChanged(
int)),
this, SLOT(onShowReconstructions(
int)));
176 m_checkAllButton =
new QPushButton(tr(
"Check all"));
177 layoutButton->addWidget(m_checkAllButton, 0);
178 QObject::connect( m_checkAllButton, SIGNAL(clicked()),
this, SLOT(onCheckAllCheckBox()) );
180 m_unCheckAllButton =
new QPushButton(tr(
"UnCheck all"));
181 layoutButton->addWidget(m_unCheckAllButton, 0);
182 QObject::connect( m_unCheckAllButton, SIGNAL(clicked()),
this, SLOT(onUnCheckAllCheckBox()) );
185 layout->addWidget( m_tree, 1 );
187 qtContainer->setLayout( layout );
189 QObject::connect(m_tree, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
190 this, SLOT(onCurrentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
194 QObject::connect(m_tree, SIGNAL(itemChanged(QTreeWidgetItem*,
int)),
195 this, SLOT(onCurrentItemChanged(QTreeWidgetItem*,
int)));
206 QObject::disconnect(m_showCheckBox, SIGNAL(stateChanged(
int)),
this, SLOT(onShowReconstructions(
int)));
209 QObject::disconnect(m_tree, SIGNAL(itemChanged(QTreeWidgetItem*,
int)),
210 this, SLOT(onCurrentItemChanged(QTreeWidgetItem*,
int)));
211 QObject::disconnect(m_tree, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
212 this, SLOT(onCurrentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
224 if( m_configuration->findConfigurationElement(
"enable_hide_all" ) )
226 const std::string& hide = m_configuration->findConfigurationElement(
"enable_hide_all")->getValue();
227 SLM_ASSERT(
"'enable_hide_all' attribute value must be 'true' or 'false' (found '" + hide +
"')",
228 hide ==
"true" || hide ==
"false");
229 m_enableHideAll = (hide ==
"true");
232 const ::fwRuntime::ConfigurationElement::sptr& columns = m_configuration->findConfigurationElement(
"columns" );
235 ::fwRuntime::ConfigurationElement::Container::const_iterator cIt = columns->begin();
236 m_tree->setColumnCount(static_cast<int>(columns->size()));
238 for(; cIt != columns->end(); cIt++)
242 if(!configView.first)
246 else if (configView.second == (
"positive"))
251 m_displayedInfo.insert(DisplayedInformation::value_type((*cIt)->getValue(), view));
252 header << QString::fromStdString((*cIt)->getName());
254 m_tree->setHeaderLabels(header);
262 m_tree->blockSignals(
true);
264 this->updateReconstructions();
265 this->refreshVisibility();
267 m_tree->blockSignals(
false);
280 void SModelSeriesList::updateReconstructions()
282 ::fwGuiQt::container::QtContainer::sptr qtContainer
283 = ::fwGuiQt::container::QtContainer::dynamicCast( this->getContainer() );
284 QWidget*
const container = qtContainer->getQtContainer();
286 SLM_ASSERT(
"container not instanced", container);
288 ::fwMedData::ModelSeries::sptr modelSeries = this->getInOut< ::fwMedData::ModelSeries >(s_MODEL_SERIES_INOUT);
292 modelSeries = this->getObject< ::fwMedData::ModelSeries >();
295 bool hasReconstructions = !modelSeries->getReconstructionDB().empty();
296 container->setEnabled( hasReconstructions );
298 if(hasReconstructions)
303 const bool showAllRec = modelSeries->getField(
"ShowReconstructions", ::fwData::Boolean::New(
true))->value();
304 m_showCheckBox->setCheckState(showAllRec ? Qt::Unchecked : Qt::Checked );
311 void SModelSeriesList::fillTree()
313 ::fwMedData::ModelSeries::sptr modelSeries = this->getInOut< ::fwMedData::ModelSeries >(s_MODEL_SERIES_INOUT);
317 modelSeries = this->getObject< ::fwMedData::ModelSeries >();
319 auto& reconstructions = modelSeries->getReconstructionDB();
321 if(!m_tree->selectedItems().empty())
323 m_sigEmptiedSelection->asyncEmit();
329 for(
auto const& reconstruction : reconstructions)
332 for(
auto const& cIt : m_displayedInfo)
334 ::fwData::Object::sptr obj = ::fwDataCamp::getObject(reconstruction, cIt.first);
335 OSLM_ASSERT(
"Invalid seshat path : '"<< cIt.first <<
"'", obj);
336 info << QString::fromStdString(cIt.second->apply(obj));
338 QTreeWidgetItem* item =
new QTreeWidgetItem(info);
339 item->setCheckState(0, Qt::Unchecked);
340 m_tree->addTopLevelItem(item);
341 item->setData(0, Qt::UserRole, QString::fromStdString(reconstruction->getID()));
344 for(
int i = 0; i < m_tree->topLevelItemCount(); i++)
346 m_tree->resizeColumnToContents(i);
354 SLM_ASSERT(
"Current selected item is null", current );
355 std::string
id = current->data(0, Qt::UserRole).toString().toStdString();
359 m_sigReconstructionSelected->asyncEmit(rec);
366 this->onOrganChoiceVisibility(current, column);
371 void SModelSeriesList::onOrganChoiceVisibility(QTreeWidgetItem* item,
int )
373 std::string
id = item->data(0, Qt::UserRole).toString().toStdString();
377 const bool itemIsChecked = (item->checkState(0) == Qt::Checked);
379 if (rec->getIsVisible() != itemIsChecked)
381 rec->setIsVisible(itemIsChecked);
383 ::fwData::Reconstruction::VisibilityModifiedSignalType::sptr sig;
386 sig->asyncEmit(itemIsChecked);
392 void SModelSeriesList::onShowReconstructions(
int state )
394 const bool visible =
static_cast<bool>(state);
396 m_checkAllButton->setEnabled(!visible);
397 m_unCheckAllButton->setEnabled(!visible);
398 m_tree->setEnabled(!visible);
400 ::fwMedData::ModelSeries::sptr modelSeries = this->getInOut< ::fwMedData::ModelSeries >(s_MODEL_SERIES_INOUT);
404 modelSeries = this->getObject< ::fwMedData::ModelSeries >();
408 helper.
addOrSwap(
"ShowReconstructions", ::fwData::Boolean::New(state == Qt::Unchecked));
414 void SModelSeriesList::refreshVisibility()
416 for(
int i = 0; i < m_tree->topLevelItemCount(); ++i )
418 QTreeWidgetItem* item = m_tree->topLevelItem( i );
419 std::string
id = item->data(0, Qt::UserRole).toString().toStdString();
421 item->setCheckState(0, rec->getIsVisible() ? Qt::Checked : Qt::Unchecked );
427 void SModelSeriesList::showReconstructions(
bool show)
431 m_showCheckBox->setCheckState(show ? Qt::Unchecked : Qt::Checked );
454 if (this->getInOut< ::fwMedData::ModelSeries >(s_MODEL_SERIES_INOUT))
466 void SModelSeriesList::onCheckAllCheckBox()
468 this->onCheckAllBoxes(
true);
473 void SModelSeriesList::onUnCheckAllCheckBox()
475 this->onCheckAllBoxes(
false);
480 void SModelSeriesList::onCheckAllBoxes(
bool visible )
482 for(
int i = 0; i < m_tree->topLevelItemCount(); ++i )
484 QTreeWidgetItem* item = m_tree->topLevelItem( i );
485 item->setCheckState(0, visible ? Qt::Checked : Qt::Unchecked );
#define FW_DEPRECATED_KEY(newKey, access, version)
Use this macro when deprecating a service key to warn the developer.
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 configuring() override
Configures the editor.
#define OSLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
virtual UIMEDDATAQT_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
virtual void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
#define SLM_TRACE_FUNC()
Trace contextual function signature.
Defines the service interface managing the editor service for object.
virtual void swapping() override
Swap the service from associated object to another object.
virtual UIMEDDATAQT_API ~SModelSeriesList() noexcept
Destructor. Do nothing.
std::pair< bool, std::string > AttributePair
Defines the attribute pair type.
virtual void starting() override
This method launches the IEditor::starting method.
#define SLM_WARN(message)
void onCurrentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
Slot called when new current item is setted in m_organChoice.
static FWMEDDATA_APIconst::fwCom::Signals::SignalKeyType s_RECONSTRUCTIONS_ADDED_SIG
Key in m_signals map of signal m_sigReconstructionsAdded.
virtual UIMEDDATAQT_API KeyConnectionsType getObjSrvConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
::fwCom::helper::SigSlotConnection::KeyConnectionsType KeyConnectionsType
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_VISIBILITY_MODIFIED_SIG
Key in m_signals map of signal m_sigVisibilityModified.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
Editor displaying the list of the organs in a ModelSeries.
UIMEDDATAQT_API SModelSeriesList() noexcept
Constructor. Do nothing.
virtual void stopping() override
This method launches the IEditor::stopping method.
static FWMEDDATA_APIconst::fwCom::Signals::SignalKeyType s_RECONSTRUCTIONS_REMOVED_SIG
Key in m_signals map of signal m_sigReconstructionsRemoved.