25 #include "itkCommand.h"
30 : QAbstractListModel(parent), m_NodePredicate(nullptr),
m_DataStorage(nullptr), m_BlockEvents(false)
44 if (m_DataStorage == dataStorage)
50 if (m_DataStorage !=
nullptr)
60 m_DataStorage->RemoveObserver(m_DataStorageDeleteObserverTag);
61 m_DataStorageDeleteObserverTag = 0;
64 m_DataStorage = dataStorage;
66 if (m_DataStorage !=
nullptr)
80 m_DataStorageDeleteObserverTag = m_DataStorage->AddObserver(itk::DeleteEvent(), deleteCommand);
89 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
94 if (role == Qt::DisplayRole && index.isValid())
96 const mitk::DataNode *node = std::get<NODE>(m_NodesAndObserverTags.at(index.row()));
97 return QVariant(QString::fromStdString(node->
GetName()));
107 return QVariant(tr(
"Nodes"));
112 return m_NodesAndObserverTags.size();
117 auto size = m_NodesAndObserverTags.size();
118 std::vector<mitk::DataNode *> result(size);
119 for (
int i = 0; i < size; ++i)
121 result[i] = std::get<NODE>(m_NodesAndObserverTags[i]);
128 return m_DataStorage;
133 m_NodePredicate = pred;
137 QAbstractListModel::beginResetModel();
139 QAbstractListModel::endResetModel();
144 return m_NodePredicate;
151 if (m_DataStorage !=
nullptr)
153 if (m_NodePredicate !=
nullptr)
155 modelNodes = m_DataStorage->
GetSubset(m_NodePredicate);
159 modelNodes = m_DataStorage->
GetAll();
166 if (modelNodes !=
nullptr)
168 for (
auto &node : *modelNodes)
177 if (m_DataStorage !=
nullptr)
183 unsigned long nodeObserverTag = node->AddObserver(itk::ModifiedEvent(), nodeModifiedCommand);
186 unsigned long dataObserverTag = 0;
188 if (node->
GetData() !=
nullptr)
192 dataObserverTag = node->
GetData()->AddObserver(itk::ModifiedEvent(), dataModifiedCommand);
195 m_NodesAndObserverTags.push_back(std::make_tuple(node, nodeObserverTag, dataObserverTag));
201 for (
auto &iter : m_NodesAndObserverTags)
203 auto node = std::get<NODE>(iter);
206 node->RemoveObserver(std::get<NODE_OBSERVER>(iter));
207 if (node->GetData() !=
nullptr)
209 node->GetData()->RemoveObserver(std::get<DATA_OBSERVER>(iter));
213 m_NodesAndObserverTags.clear();
218 for (
auto iter = m_NodesAndObserverTags.begin(); iter != m_NodesAndObserverTags.end(); ++iter)
220 if (std::get<NODE>(*iter) == node)
222 node->RemoveObserver(std::get<NODE_OBSERVER>(*iter));
223 if (node->
GetData() !=
nullptr)
225 node->
GetData()->RemoveObserver(std::get<DATA_OBSERVER>(*iter));
227 m_NodesAndObserverTags.erase(iter);
238 m_BlockEvents =
true;
242 if (m_NodePredicate && !m_NodePredicate->CheckNode(node))
247 int newIndex = m_NodesAndObserverTags.size();
248 beginInsertRows(QModelIndex(), newIndex, newIndex);
253 m_BlockEvents =
false;
262 m_BlockEvents =
true;
265 for (
auto iter = m_NodesAndObserverTags.begin(); iter != m_NodesAndObserverTags.end(); ++iter, ++row)
267 if (std::get<NODE>(*iter) == node)
270 beginRemoveRows(QModelIndex(), row, row);
278 m_BlockEvents =
false;
289 QModelIndex changedIndex =
getIndex(modifiedNode);
290 if (changedIndex.isValid())
292 emit dataChanged(changedIndex, changedIndex);
315 return std::get<NODE>(m_NodesAndObserverTags.at(index.row()));
326 for (
auto iter = m_NodesAndObserverTags.begin(); iter != m_NodesAndObserverTags.end(); ++iter, ++row)
328 if (std::get<NODE>(*iter) == node)
333 return QModelIndex();
void RemoveListener(const AbstractDelegate &delegate) const
void AddListener(const AbstractDelegate &delegate) const
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Implements QAbstractListModel.
void reset()
Resets the whole model. Get all nodes matching the predicate from the data storage.
Data management class that handles 'was created by' relations.
itk::SmartPointer< Self > Pointer
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Implements QAbstractListModel.
mitk::NodePredicateBase * GetPredicate() const
Get the filter predicate in use.
virtual void OnDataStorageDeleted(const itk::Object *caller, const itk::EventObject &event)
bool GetName(std::string &nodeName, const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="name") const
Convenience access method for accessing the name of an object (instance of StringProperty with proper...
QModelIndex getIndex(const mitk::DataNode *node) const
Return the model index of the given node.
void SetPredicate(mitk::NodePredicateBase *pred)
Change the filter predicate.
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
virtual ~QmitkDataStorageListModel()
void SetDataStorage(mitk::DataStorage::Pointer dataStorage)
Change the data storage to represent.
itk::SmartPointer< const Self > ConstPointer
mitk::DataStorage * GetDataStorage() const
Get the represented data storage.
virtual void OnDataNodeModified(const itk::Object *caller, const itk::EventObject &event)
void AddNodeToInternalList(mitk::DataNode *node)
Internal helper: adds given node to end of list.
virtual SetOfObjects::ConstPointer GetAll() const =0
returns a set of all data objects that are stored in the data storage
mitk::DataStorage::Pointer m_DataStorage
Qt::ItemFlags flags(const QModelIndex &index) const override
Implements QAbstractListModel.
SetOfObjects::ConstPointer GetSubset(const NodePredicateBase *condition) const
returns a set of data objects that meet the given condition(s)
QmitkDataStorageListModel(mitk::DataStorage *dataStorage=nullptr, mitk::NodePredicateBase::Pointer pred=nullptr, QObject *parent=nullptr)
void RemoveNodeFromInternalList(mitk::DataNode *node)
Internal helper: remove given node.
virtual void OnDataStorageNodeAdded(const mitk::DataNode *node)
DataStorageEvent AddNodeEvent
AddEvent is emitted whenever a new node has been added to the DataStorage.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Implements QAbstractListModel.
DataStorageEvent RemoveNodeEvent
RemoveEvent is emitted directly before a node is removed from the DataStorage.
mitk::DataNode::Pointer getNode(const QModelIndex &index) const
Return the node for given model index.
virtual void OnDataStorageNodeRemoved(const mitk::DataNode *node)
Interface for evaluation conditions used in the DataStorage class GetSubset() method.
void ClearInternalNodeList()
Internal helper: Clear complete model list.
Class for nodes of the DataTree.
virtual void OnDataModified(const itk::Object *caller, const itk::EventObject &event)
std::vector< mitk::DataNode * > GetDataNodes() const
Get all current data nodes.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.