Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkDataStorageListModel Class Reference

#include <QmitkDataStorageListModel.h>

Inheritance diagram for QmitkDataStorageListModel:
Collaboration diagram for QmitkDataStorageListModel:

Public Member Functions

 QmitkDataStorageListModel (mitk::DataStorage *dataStorage=nullptr, mitk::NodePredicateBase::Pointer pred=nullptr, QObject *parent=nullptr)
 
virtual ~QmitkDataStorageListModel ()
 
void SetDataStorage (mitk::DataStorage::Pointer dataStorage)
 Change the data storage to represent. More...
 
mitk::DataStorageGetDataStorage () const
 Get the represented data storage. More...
 
void SetPredicate (mitk::NodePredicateBase *pred)
 Change the filter predicate. More...
 
mitk::NodePredicateBaseGetPredicate () const
 Get the filter predicate in use. More...
 
std::vector< mitk::DataNode * > GetDataNodes () const
 Get all current data nodes. More...
 
mitk::DataNode::Pointer getNode (const QModelIndex &index) const
 Return the node for given model index. More...
 
QModelIndex getIndex (const mitk::DataNode *node) const
 Return the model index of the given node. More...
 
Qt::ItemFlags flags (const QModelIndex &index) const override
 Implements QAbstractListModel. More...
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 Implements QAbstractListModel. More...
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
 Implements QAbstractListModel. More...
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 Implements QAbstractListModel. More...
 
virtual void OnDataStorageNodeAdded (const mitk::DataNode *node)
 
virtual void OnDataStorageNodeRemoved (const mitk::DataNode *node)
 
virtual void OnDataNodeModified (const itk::Object *caller, const itk::EventObject &event)
 
virtual void OnDataModified (const itk::Object *caller, const itk::EventObject &event)
 
virtual void OnDataStorageDeleted (const itk::Object *caller, const itk::EventObject &event)
 

Protected Member Functions

void reset ()
 Resets the whole model. Get all nodes matching the predicate from the data storage. More...
 
void AddNodeToInternalList (mitk::DataNode *node)
 Internal helper: adds given node to end of list. More...
 
void RemoveNodeFromInternalList (mitk::DataNode *node)
 Internal helper: remove given node. More...
 
void ClearInternalNodeList ()
 Internal helper: Clear complete model list. More...
 

Detailed Description

Qt list model for the (optionally filtered) nodes in a DataStorage.

Given a data storage instance, this model will observe the storage for its list of nodes and keep the provided Qt model up to date. When given a NodePredicateBase instance, the Qt model will only contain nodes that satisfy the predicate. This is useful to display lists of a certain data type only, for example.

Developer notes:

  • class should be reviewed by somebody who knows well Qt models
  • The OnSomethingModifedAddedRemoved() methods are declared virtual. They are required to be executed on event reception, though! They should not be virtual.
  • Is there any valid use case for sub-classing? Declare class final?
  • Is GetDataNodes needed? DataStorage or Qt model would yield the same result.

Definition at line 45 of file QmitkDataStorageListModel.h.

Constructor & Destructor Documentation

QmitkDataStorageListModel::QmitkDataStorageListModel ( mitk::DataStorage dataStorage = nullptr,
mitk::NodePredicateBase::Pointer  pred = nullptr,
QObject *  parent = nullptr 
)
Parameters
dataStoragethe data storage to represent
predicatethe optional predicate to filter filters
parentthe Qt parent of this Qt object

Definition at line 27 of file QmitkDataStorageListModel.cpp.

References SetDataStorage(), and SetPredicate().

QmitkDataStorageListModel::~QmitkDataStorageListModel ( )
virtual

Definition at line 36 of file QmitkDataStorageListModel.cpp.

References SetDataStorage().

Member Function Documentation

void QmitkDataStorageListModel::AddNodeToInternalList ( mitk::DataNode node)
protected

Internal helper: adds given node to end of list.

Definition at line 175 of file QmitkDataStorageListModel.cpp.

References mitk::DataNode::GetData(), mitk::New(), OnDataModified(), and OnDataNodeModified().

Referenced by OnDataStorageNodeAdded(), and reset().

void QmitkDataStorageListModel::ClearInternalNodeList ( )
protected

Internal helper: Clear complete model list.

Definition at line 199 of file QmitkDataStorageListModel.cpp.

Referenced by reset().

QVariant QmitkDataStorageListModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
override

Implements QAbstractListModel.

Definition at line 92 of file QmitkDataStorageListModel.cpp.

References mitk::DataNode::GetName().

Qt::ItemFlags QmitkDataStorageListModel::flags ( const QModelIndex &  index) const
override

Implements QAbstractListModel.

Definition at line 87 of file QmitkDataStorageListModel.cpp.

std::vector< mitk::DataNode * > QmitkDataStorageListModel::GetDataNodes ( ) const

Get all current data nodes.

Definition at line 115 of file QmitkDataStorageListModel.cpp.

mitk::DataStorage * QmitkDataStorageListModel::GetDataStorage ( ) const

Get the represented data storage.

Definition at line 126 of file QmitkDataStorageListModel.cpp.

QModelIndex QmitkDataStorageListModel::getIndex ( const mitk::DataNode node) const

Return the model index of the given node.

Definition at line 323 of file QmitkDataStorageListModel.cpp.

Referenced by OnDataNodeModified().

mitk::DataNode::Pointer QmitkDataStorageListModel::getNode ( const QModelIndex &  index) const
mitk::NodePredicateBase * QmitkDataStorageListModel::GetPredicate ( ) const

Get the filter predicate in use.

Definition at line 142 of file QmitkDataStorageListModel.cpp.

QVariant QmitkDataStorageListModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
override

Implements QAbstractListModel.

Definition at line 105 of file QmitkDataStorageListModel.cpp.

void QmitkDataStorageListModel::OnDataModified ( const itk::Object *  caller,
const itk::EventObject &  event 
)
virtual

Callback entry for observed BaseDatas' ModifiedEvent().

Emits signal dataChanged().

Definition at line 297 of file QmitkDataStorageListModel.cpp.

References OnDataNodeModified().

Referenced by AddNodeToInternalList().

void QmitkDataStorageListModel::OnDataNodeModified ( const itk::Object *  caller,
const itk::EventObject &  event 
)
virtual

Callback entry for observed DataNodes' ModifiedEvent().

Emits signal dataChanged().

Definition at line 281 of file QmitkDataStorageListModel.cpp.

References getIndex().

Referenced by AddNodeToInternalList(), and OnDataModified().

void QmitkDataStorageListModel::OnDataStorageDeleted ( const itk::Object *  caller,
const itk::EventObject &  event 
)
virtual

Callback entry for DataStorage's DeleteEvent().

Clears the model.

Definition at line 302 of file QmitkDataStorageListModel.cpp.

References SetDataStorage().

Referenced by SetDataStorage().

void QmitkDataStorageListModel::OnDataStorageNodeAdded ( const mitk::DataNode node)
virtual

Called when a DataStorage Add Event was thrown. May be reimplemented by deriving classes.

Warning
When sub-classing, call this class' method first! Otherwise the node addition will not be reflected in the Qt model!

Definition at line 233 of file QmitkDataStorageListModel.cpp.

References AddNodeToInternalList().

Referenced by SetDataStorage().

void QmitkDataStorageListModel::OnDataStorageNodeRemoved ( const mitk::DataNode node)
virtual

Called when a DataStorage Remove Event was thrown. May be reimplemented by deriving classes.

Warning
When sub-classing, call this class' method first! Otherwise the node removal will not be reflected in the Qt model!

Definition at line 257 of file QmitkDataStorageListModel.cpp.

References RemoveNodeFromInternalList().

Referenced by SetDataStorage().

void QmitkDataStorageListModel::RemoveNodeFromInternalList ( mitk::DataNode node)
protected

Internal helper: remove given node.

Definition at line 216 of file QmitkDataStorageListModel.cpp.

References mitk::DataNode::GetData().

Referenced by OnDataStorageNodeRemoved().

void QmitkDataStorageListModel::reset ( )
protected

Resets the whole model. Get all nodes matching the predicate from the data storage.

Definition at line 147 of file QmitkDataStorageListModel.cpp.

References AddNodeToInternalList(), ClearInternalNodeList(), mitk::DataStorage::GetAll(), and mitk::DataStorage::GetSubset().

Referenced by SetDataStorage(), and SetPredicate().

int QmitkDataStorageListModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
override

Implements QAbstractListModel.

Definition at line 110 of file QmitkDataStorageListModel.cpp.

void QmitkDataStorageListModel::SetPredicate ( mitk::NodePredicateBase pred)

Change the filter predicate.

Definition at line 131 of file QmitkDataStorageListModel.cpp.

References reset().

Referenced by QmitkDataStorageListModel().


The documentation for this class was generated from the following files: