30 #include <itkCommand.h>
36 : QAbstractTableModel(parent),
40 m_SortDescending(false)
80 if (role == Qt::DisplayRole)
82 if (orientation == Qt::Horizontal)
87 else if (section == 1)
88 headerData =
"Data Type";
89 else if (section == 2)
90 headerData =
"Visibility";
92 else if (orientation == Qt::Vertical)
95 headerData = section + 1;
104 Qt::ItemFlags
flags = QAbstractItemModel::flags(index);
107 if (index.column() == 0)
109 flags |= Qt::ItemIsEditable;
111 else if (index.column() == 2)
113 flags |= Qt::ItemIsUserCheckable;
135 if (index.isValid() && !
m_NodeSet.empty())
139 std::string nodeName = node->GetName();
140 if (nodeName.empty())
141 nodeName =
"unnamed";
144 if (index.column() == 0)
147 if (role == Qt::DisplayRole || role == Qt::EditRole)
149 data = QFile::encodeName(nodeName.c_str());
153 data = QVariant::fromValue(node);
156 else if (index.column() == 1)
161 if (role == Qt::DisplayRole)
166 else if (role == Qt::DecorationRole)
168 data = nodeDescriptor->
GetIcon();
171 else if (index.column() == 2)
174 bool visibility =
false;
176 if (node->GetVisibility(visibility,
nullptr) && role == Qt::CheckStateRole)
178 data = (visibility ? Qt::Checked : Qt::Unchecked);
246 if (node->
GetData() ==
nullptr)
260 tempProperty->AddObserver(itk::ModifiedEvent(), propertyModifiedCommand);
265 tempProperty->AddObserver(itk::ModifiedEvent(), propertyModifiedCommand);
271 m_NodeSet.push_back(const_cast<mitk::DataNode *>(node));
291 tempProperty = (*nodeIt)->GetProperty(
"visible");
297 tempProperty = (*nodeIt)->GetProperty(
"name");
303 int row = std::distance(
m_NodeSet.begin(), nodeIt);
306 this->beginRemoveRows(QModelIndex(), row, row);
324 if (modifiedProperty)
330 std::vector<mitk::DataNode *>::iterator it;
338 visibilityProperty = (*it)->GetProperty(
"visible");
339 if (modifiedProperty == visibilityProperty)
345 nameProperty = (*it)->GetProperty(
"name");
346 if (modifiedProperty == nameProperty)
355 row = std::distance(
m_NodeSet.begin(), it);
358 QModelIndex indexOfChangedProperty = index(row, column);
359 emit dataChanged(indexOfChangedProperty, indexOfChangedProperty);
368 if (index.isValid() && (role == Qt::EditRole || role == Qt::CheckStateRole))
376 if (index.column() == 0)
378 node->SetStringProperty(
"name", value.toString().toStdString().c_str());
380 else if (index.column() == 2)
382 node->SetBoolProperty(
"visible", (value.toInt() == Qt::Checked ?
true :
false));
387 emit dataChanged(index, index);
431 for (
auto it = _NodeSet->begin(); it != _NodeSet->end(); it++)
441 bool sortDescending = (order == Qt::DescendingOrder) ?
true :
false;
458 else if (column == 2)
464 QAbstractTableModel::beginResetModel();
465 QAbstractTableModel::endResetModel();
476 : m_CompareCriteria(_CompareCriteria), m_CompareOperator(_CompareOperator)
483 switch (m_CompareCriteria)
485 case CompareByClassName:
486 if (m_CompareOperator == Less)
487 return (_Left->GetData()->GetNameOfClass() < _Right->GetData()->GetNameOfClass());
489 return (_Left->GetData()->GetNameOfClass() > _Right->GetData()->GetNameOfClass());
492 case CompareByVisibility:
494 bool _LeftVisibility =
false;
495 bool _RightVisibility =
false;
496 _Left->GetVisibility(_LeftVisibility,
nullptr);
497 _Right->GetVisibility(_RightVisibility,
nullptr);
499 if (m_CompareOperator == Less)
500 return (_LeftVisibility < _RightVisibility);
502 return (_LeftVisibility > _RightVisibility);
508 if (m_CompareOperator == Less)
509 return (_Left->GetName() < _Right->GetName());
511 return (_Left->GetName() > _Right->GetName());
void RemoveListener(const AbstractDelegate &delegate) const
QmitkDataStorageTableModel(mitk::DataStorage::Pointer _DataStorage, mitk::NodePredicateBase *_Predicate=nullptr, QObject *parent=nullptr)
void AddListener(const AbstractDelegate &delegate) const
bool setData(const QModelIndex &index, const QVariant &value, int role) override
itk::SmartPointer< Self > Pointer
QmitkNodeQmitkNodeDescriptor is Decorator class for the mitk::DataNode which enhances certain mitk::D...
CompareCriteria
Specifies field of the property with which it will be sorted.
virtual QVariant data(const QModelIndex &index, int role) const override
virtual int rowCount(const QModelIndex &parent) const override
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override
virtual std::vector< mitk::DataNode * > GetNodeSet() const
bool operator()(const mitk::DataNode::Pointer &_Left, const mitk::DataNode::Pointer &_Right) const
The reimplemented compare function.
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
std::vector< mitk::DataNode * > m_NodeSet
mitk::BaseProperty * GetProperty(const char *propertyKey, const mitk::BaseRenderer *renderer=nullptr) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList of the rendere...
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder) override
Reimplemented sort function from QAbstractTableModel to enable sorting on the table.
itk::SmartPointer< const Self > ConstPointer
void SetDataStorage(mitk::DataStorage::Pointer _DataStorage)
ObjectType * GetPointer() const
virtual SetOfObjects::ConstPointer GetAll() const =0
returns a set of all data objects that are stored in the data storage
Abstract base class for properties.
mitk::DataNode::Pointer GetNode(const QModelIndex &index) const
mitk::DataStorage::Pointer m_DataStorage
SetOfObjects::ConstPointer GetSubset(const NodePredicateBase *condition) const
returns a set of data objects that meet the given condition(s)
static RenderingManager * GetInstance()
virtual QIcon GetIcon() const
virtual QString GetNameOfClass() const
DataStorageEvent AddNodeEvent
AddEvent is emitted whenever a new node has been added to the DataStorage.
mitk::WeakPointer< mitk::DataStorage > m_DataStorage
virtual void RemoveNode(const mitk::DataNode *node)
std::map< mitk::BaseProperty *, unsigned long > m_VisiblePropertyModifiedObserverTags
Maps a property to an observer tag.
A struct that inherits from std::binary_function. You can use it in std::sort algorithm for sorting t...
QmitkNodeDescriptor * GetDescriptor(const mitk::DataNode *_Node) const
DataStorageEvent RemoveNodeEvent
RemoveEvent is emitted directly before a node is removed from the DataStorage.
const mitk::DataStorage::Pointer GetDataStorage() const
std::map< mitk::BaseProperty *, unsigned long > m_NamePropertyModifiedObserverTags
Maps a property to an observer tag.
DataNodeCompareFunction(CompareCriteria _CompareCriteria=CompareByName, CompareOperator _CompareOperator=Less)
Creates a PropertyDataSetCompareFunction. A CompareCriteria and a CompareOperator must be given...
Interface for evaluation conditions used in the DataStorage class GetSubset() method.
mitk::NodePredicateBase::Pointer m_Predicate
mitk::NodePredicateBase::Pointer GetPredicate() const
virtual ~QmitkDataStorageTableModel()
virtual int columnCount(const QModelIndex &parent) const override
virtual void AddNode(const mitk::DataNode *node)
virtual void PropertyModified(const itk::Object *caller, const itk::EventObject &event)
Called when a single property was changed. The function searches through the list of nodes in this mo...
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
static QmitkNodeDescriptorManager * GetInstance()
Class for nodes of the DataTree.
void SetPredicate(mitk::NodePredicateBase *_Predicate)
CompareOperator
Specifies Ascending/descending ordering.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.