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 boost::shared_ptr<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();
81 //! Clear internal data
93 //! Converts QModelIndex of this model to QModelIndex of a one of sub-models.
94 QModelIndex* toSourceModelIndex(const QModelIndex& theProxy) const;
96 //! Finds a pointer on QModelIndex which is equal to the given one
97 QModelIndex* findModelIndex(const QModelIndex& theIndex) const;
99 //! Returns pointer on QModelIndex which is equal to the given one.
100 QModelIndex* getModelIndex(const QModelIndex& theIndex) const;
102 //! Deletes all saved pointers on QModelIndex objects.
103 void clearModelIndexes();
105 //! Deletes all saved pointers on QModelIndex objects.
106 void clearSubModels();
108 //! Removes sub-model on removing a part object. Also it removes QModelIndex-es which refer to this model
109 void removeSubModel(int theModelId);
111 //! Returns true if the given model is a one of sub-models (of both types)
112 bool isSubModel(const QAbstractItemModel* theModel) const;
114 //! Returns true if the given model is a one of sub-models of Part type
115 bool isPartSubModel(const QAbstractItemModel* theModel) const;
117 //! Returns Parts Folder node
118 QModelIndex partFolderNode() const;
120 int historyOffset() const;
122 //! Data model of top part of data tree (not parts object)
123 XGUI_TopDataModel* myModel;
125 //! Data models for Parts data tree representation (one data model per a one part)
126 QList<XGUI_PartModel*> myPartModels;
128 //! Active part in part editing mode
129 XGUI_PartModel* myActivePart;
131 QModelIndex myActivePartIndex;
133 //! List of saved QModelIndexes created by sub-models
134 QList<QModelIndex*> myIndexes;