2 #ifndef XGUI_DocumentDataModel_H
3 #define XGUI_DocumentDataModel_H
6 #include <ModuleBase_Definitions.h>
7 #include <ModelAPI_ResultPart.h>
9 #include <Events_Listener.h>
11 #include <QAbstractItemModel>
14 class ModelAPI_Document;
16 class XGUI_TopDataModel;
18 /**\class XGUI_DocumentDataModel
20 * \brief This is a proxy data model for Object Browser (QTreeView).
21 * It contains several sub-models for generation of each sub-part of data tree.
23 class XGUI_EXPORT XGUI_DocumentDataModel : public QAbstractItemModel, public Events_Listener
29 XGUI_DocumentDataModel(QObject* theParent);
30 virtual ~XGUI_DocumentDataModel();
32 // Event Listener method
33 virtual void processEvent(const Events_Message* theMessage);
36 virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
37 virtual QVariant headerData(int theSection, Qt::Orientation theOrient,
38 int theRole = Qt::DisplayRole) const;
40 virtual int rowCount(const QModelIndex& theParent = QModelIndex()) const;
41 virtual int columnCount(const QModelIndex& theParent = QModelIndex()) const;
43 virtual QModelIndex index(int theRow, int theColumn,
44 const QModelIndex &parent = QModelIndex()) const;
46 virtual QModelIndex parent(const QModelIndex& theIndex) const;
48 virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
50 bool insertRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
52 bool removeRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
54 Qt::ItemFlags flags(const QModelIndex& theIndex) const;
56 //! Returns an object by the given Model index.
57 //! Returns 0 if the given index is not index of an object
58 ObjectPtr object(const QModelIndex& theIndex) const;
60 QModelIndex objectIndex(const ObjectPtr theObject) const;
62 //! Returns QModelIndex which corresponds to the given part
63 //! If the object is not found then index is not valid
64 QModelIndex partIndex(const ResultPartPtr& thePart) const;
66 //! Activates a part data model if the index is a Part node index.
67 //! Returns true if active part changed.
68 bool activatedIndex(const QModelIndex& theIndex);
70 //! Retrurns active part
71 ResultPartPtr activePart() const;
73 //! Retrurns QModelIndex of active part
74 QModelIndex activePartIndex() const { return myActivePartIndex; }
76 //! Deactivates a Part
77 void deactivatePart();
79 void rebuildDataTree();
83 enum {PartsFolder, HistoryNode};
86 //! Converts QModelIndex of this model to QModelIndex of a one of sub-models.
87 QModelIndex* toSourceModelIndex(const QModelIndex& theProxy) const;
89 //! Finds a pointer on QModelIndex which is equal to the given one
90 QModelIndex* findModelIndex(const QModelIndex& theIndex) const;
92 //! Returns pointer on QModelIndex which is equal to the given one.
93 QModelIndex* getModelIndex(const QModelIndex& theIndex) const;
95 //! Deletes all saved pointers on QModelIndex objects.
96 void clearModelIndexes();
98 //! Removes sub-model on removing a part object. Also it removes QModelIndex-es which refer to this model
99 void removeSubModel(int theModelId);
101 //! Returns true if the given model is a one of sub-models (of both types)
102 bool isSubModel(const QAbstractItemModel* theModel) const;
104 //! Returns true if the given model is a one of sub-models of Part type
105 bool isPartSubModel(const QAbstractItemModel* theModel) const;
107 //! Returns Parts Folder node
108 QModelIndex partFolderNode() const;
110 int historyOffset() const;
113 //! Data model of top part of data tree (not parts object)
114 XGUI_TopDataModel* myModel;
116 //! Data models for Parts data tree representation (one data model per a one part)
117 QList<XGUI_PartModel*> myPartModels;
119 //! Active part in part editing mode
120 XGUI_PartModel* myActivePart;
122 QModelIndex myActivePartIndex;
124 //! List of saved QModelIndexes created by sub-models
125 QList<QModelIndex*> myIndexes;