1 #ifndef XGUI_DocumentDataModel_H
2 #define XGUI_DocumentDataModel_H
5 #include <ModuleBase_Definitions.h>
6 #include <ModelAPI_ResultPart.h>
8 #include <Events_Listener.h>
10 #include <QAbstractItemModel>
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
27 XGUI_DocumentDataModel(QObject* theParent);
28 virtual ~XGUI_DocumentDataModel();
30 // Event Listener method
31 virtual void processEvent(const Events_Message* theMessage);
33 virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
34 virtual QVariant headerData(int theSection, Qt::Orientation theOrient, int theRole =
35 Qt::DisplayRole) const;
37 virtual int rowCount(const QModelIndex& theParent = QModelIndex()) const;
38 virtual int columnCount(const QModelIndex& theParent = QModelIndex()) const;
40 virtual QModelIndex index(int theRow, int theColumn, const QModelIndex &parent =
43 virtual QModelIndex parent(const QModelIndex& theIndex) const;
45 virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
47 bool insertRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
49 bool removeRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
51 Qt::ItemFlags flags(const QModelIndex& theIndex) const;
53 //! Returns an object by the given Model index.
54 //! Returns 0 if the given index is not index of an object
55 ObjectPtr object(const QModelIndex& theIndex) const;
57 QModelIndex objectIndex(const ObjectPtr theObject) const;
59 //! Returns QModelIndex which corresponds to the given part
60 //! If the object is not found then index is not valid
61 QModelIndex partIndex(const ResultPartPtr& thePart) 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 //! Retrurns active part
68 ResultPartPtr activePart() const;
70 //! Retrurns QModelIndex of active part
71 QModelIndex activePartIndex() const
73 return myActivePartIndex;
76 //! Deactivates a Part
77 void deactivatePart();
79 void rebuildDataTree();
89 //! Converts QModelIndex of this model to QModelIndex of a one of sub-models.
90 QModelIndex* toSourceModelIndex(const QModelIndex& theProxy) const;
92 //! Finds a pointer on QModelIndex which is equal to the given one
93 QModelIndex* findModelIndex(const QModelIndex& theIndex) const;
95 //! Returns pointer on QModelIndex which is equal to the given one.
96 QModelIndex* getModelIndex(const QModelIndex& theIndex) const;
98 //! Deletes all saved pointers on QModelIndex objects.
99 void clearModelIndexes();
101 //! Removes sub-model on removing a part object. Also it removes QModelIndex-es which refer to this model
102 void removeSubModel(int theModelId);
104 //! Returns true if the given model is a one of sub-models (of both types)
105 bool isSubModel(const QAbstractItemModel* theModel) const;
107 //! Returns true if the given model is a one of sub-models of Part type
108 bool isPartSubModel(const QAbstractItemModel* theModel) const;
110 //! Returns Parts Folder node
111 QModelIndex partFolderNode() const;
113 int historyOffset() const;
115 //! Data model of top part of data tree (not parts object)
116 XGUI_TopDataModel* myModel;
118 //! Data models for Parts data tree representation (one data model per a one part)
119 QList<XGUI_PartModel*> myPartModels;
121 //! Active part in part editing mode
122 XGUI_PartModel* myActivePart;
124 QModelIndex myActivePartIndex;
126 //! List of saved QModelIndexes created by sub-models
127 QList<QModelIndex*> myIndexes;