Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef QMITKDATASTORAGETREEMODEL_H_
00020 #define QMITKDATASTORAGETREEMODEL_H_
00021
00022 #include <mitkDataStorage.h>
00023 #include <mitkNodePredicateBase.h>
00024 #include <mitkWeakPointer.h>
00025
00026 #include <QAbstractListModel>
00027
00028 #include "QmitkEnums.h"
00029 #include "QmitkCustomVariants.h"
00030
00031 #include <vector>
00032 #include <string>
00033 #include <QList>
00034
00035 class QMITK_EXPORT QmitkDataStorageTreeModel : public QAbstractItemModel
00036 {
00037
00038 public:
00039 static const std::string COLUMN_NAME;
00040 static const std::string COLUMN_TYPE;
00041 static const std::string COLUMN_VISIBILITY;
00042
00043
00044 public:
00045 QmitkDataStorageTreeModel(mitk::DataStorage* _DataStorage
00046 , bool _PlaceNewNodesOnTop=false
00047 , QObject* parent = 0);
00048 ~QmitkDataStorageTreeModel();
00049
00050
00051 public:
00056 mitk::DataNode::Pointer GetNode(const QModelIndex &index) const;
00060 virtual std::vector<mitk::DataNode*> GetNodeSet() const;
00064 const mitk::DataStorage::Pointer GetDataStorage() const;
00068 void SetPlaceNewNodesOnTop(bool _PlaceNewNodesOnTop);
00069
00070
00071
00072 Qt::ItemFlags flags(const QModelIndex& index) const;
00073 QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const;
00074 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
00075 int rowCount ( const QModelIndex & parent = QModelIndex() ) const;
00076 int columnCount ( const QModelIndex & parent = QModelIndex() ) const;
00077
00082 QModelIndex index ( int row, int column, const QModelIndex & parent = QModelIndex() ) const;
00083 QModelIndex parent ( const QModelIndex & index ) const;
00084
00085 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
00086 bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
00087 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
00088 Qt::DropActions supportedDropActions() const;
00089 QMimeData * mimeData(const QModelIndexList & indexes) const;
00090
00091
00092
00093
00094 public:
00098 void SetDataStorage(mitk::DataStorage* _DataStorage);
00102 void SetDataStorageDeleted(const itk::Object* _DataStorage);
00107 virtual void AddNode(const mitk::DataNode* node);
00111 virtual void RemoveNode(const mitk::DataNode* node);
00115 virtual void SetNodeModified(const mitk::DataNode* node);
00116
00120 QModelIndex GetIndex(const mitk::DataNode*) const;
00121
00122
00123 protected:
00127 class TreeItem
00128 {
00129 public:
00133 TreeItem(mitk::DataNode* _DataNode, TreeItem* _Parent=0);
00138 virtual ~TreeItem();
00142 int IndexOfChild(const TreeItem* item) const;
00146 TreeItem* GetChild(int index) const;
00150 TreeItem* Find( const mitk::DataNode* _DataNode) const;
00154 int GetChildCount() const;
00158 int GetIndex() const;
00162 TreeItem* GetParent() const;
00166 mitk::DataNode::Pointer GetDataNode() const;
00170 std::vector<TreeItem*> GetChildren() const;
00171
00175 void AddChild( TreeItem* item);
00179 void RemoveChild( TreeItem* item);
00184 void InsertChild( TreeItem* item, int index=-1 );
00186 void SetParent(TreeItem* _Parent);
00190 void Delete();
00191 protected:
00192 TreeItem* m_Parent;
00193 std::vector<TreeItem*> m_Children;
00194 mitk::DataNode::Pointer m_DataNode;
00195 };
00199 void AdjustLayerProperty();
00203 TreeItem* TreeItemFromIndex(const QModelIndex &index) const;
00207 QModelIndex IndexFromTreeItem(TreeItem*) const;
00211 mitk::DataNode* GetParentNode(const mitk::DataNode* node) const;
00215 void TreeToVector(TreeItem* parent, std::vector<TreeItem*>& vec) const;
00219 void TreeToNodeSet(TreeItem* parent, std::vector<mitk::DataNode*>& vec) const;
00220
00221 protected:
00222 mitk::WeakPointer<mitk::DataStorage> m_DataStorage;
00223 mitk::NodePredicateBase::Pointer m_Predicate;
00224 bool m_PlaceNewNodesOnTop;
00225 TreeItem* m_Root;
00226 };
00227
00228 #endif