2 #ifndef XGUI_DocumentDataModel_H
3 #define XGUI_DocumentDataModel_H
6 #include "XGUI_Constants.h"
8 #include <QAbstractItemModel>
9 #include <Events_Listener.h>
13 class ModelAPI_Document;
15 class XGUI_TopDataModel;
17 /**\class XGUI_DocumentDataModel
19 * \brief This is a proxy data model for Object Browser (QTreeView).
20 * It contains several sub-models for generation of each sub-part of data tree.
22 class XGUI_EXPORT XGUI_DocumentDataModel : public QAbstractItemModel, public Events_Listener
28 XGUI_DocumentDataModel(QObject* theParent);
29 virtual ~XGUI_DocumentDataModel();
31 // Event Listener method
32 virtual void processEvent(const Events_Message* theMessage);
35 virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
36 virtual QVariant headerData(int theSection, Qt::Orientation theOrient,
37 int theRole = Qt::DisplayRole) const;
39 virtual int rowCount(const QModelIndex& theParent = QModelIndex()) const;
40 virtual int columnCount(const QModelIndex& theParent = QModelIndex()) const;
42 virtual QModelIndex index(int theRow, int theColumn,
43 const QModelIndex &parent = QModelIndex()) const;
45 virtual QModelIndex parent(const QModelIndex& theIndex) const;
47 virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
49 bool insertRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
51 bool removeRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
53 Qt::ItemFlags flags(const QModelIndex& theIndex) const;
55 //! Returns Feature object by the given Model index.
56 //! Returns 0 if the given index is not index of a feature
57 FeaturePtr feature(const QModelIndex& theIndex) const;
59 //! Returns QModelIndex which corresponds to the given feature if this is a part
60 //! If the feature is not found then index is not valid
61 QModelIndex partIndex(const FeaturePtr& theFeature) const;
63 //! Activates a part data model if the index is a Part node index.
64 //! Returns true if active part changed.
65 bool activatedIndex(const QModelIndex& theIndex);
67 FeaturePtr activePart() const;
69 QModelIndex activePartIndex() const { return myActivePartIndex; }
71 //! Deactivates a Part
72 void deactivatePart();
76 enum {PartsFolder, HistoryNode};
79 //! Converts QModelIndex of this model to QModelIndex of a one of sub-models.
80 QModelIndex* toSourceModelIndex(const QModelIndex& theProxy) const;
82 //! Finds a pointer on QModelIndex which is equal to the given one
83 QModelIndex* findModelIndex(const QModelIndex& theIndex) const;
85 //! Returns pointer on QModelIndex which is equal to the given one.
86 QModelIndex* getModelIndex(const QModelIndex& theIndex) const;
88 //! Deletes all saved pointers on QModelIndex objects.
89 void clearModelIndexes();
91 //! Removes sub-model on removing a part object. Also it removes QModelIndex-es which refer to this model
92 void removeSubModel(int theModelId);
94 //! Returns true if the given model is a one of sub-models (of both types)
95 bool isSubModel(const QAbstractItemModel* theModel) const;
97 //! Returns true if the given model is a one of sub-models of Part type
98 bool isPartSubModel(const QAbstractItemModel* theModel) const;
100 //! Returns Parts Folder node
101 QModelIndex partFolderNode() const;
103 int historyOffset() const;
107 boost::shared_ptr<ModelAPI_Document> myDocument;
109 //! Data model of top part of data tree (not parts object)
110 XGUI_TopDataModel* myModel;
112 //! Data models for Parts data tree representation (one data model per a one part)
113 QList<XGUI_PartModel*> myPartModels;
115 //! Active part in part editing mode
116 XGUI_PartModel* myActivePart;
118 QModelIndex myActivePartIndex;
120 //! List of saved QModelIndexes created by sub-models
121 QList<QModelIndex*> myIndexes;