1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 #ifndef XGUI_DocumentDataModel_H
4 #define XGUI_DocumentDataModel_H
7 #include <ModuleBase_Definitions.h>
8 #include <ModelAPI_ResultPart.h>
10 #include <Events_Listener.h>
12 #include <QAbstractItemModel>
15 class ModelAPI_Document;
17 class XGUI_TopDataModel;
19 /**\class XGUI_DocumentDataModel
21 * \brief This is a proxy data model for Object Browser (QTreeView).
22 * It contains several sub-models for generation of each sub-part of data tree.
24 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 std::shared_ptr<Events_Message>& theMessage);
35 virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
36 virtual QVariant headerData(int theSection, Qt::Orientation theOrient, int theRole =
37 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, const QModelIndex &parent =
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 an object by the given Model index.
56 //! Returns 0 if the given index is not index of an object
57 ObjectPtr object(const QModelIndex& theIndex) const;
59 QModelIndex objectIndex(const ObjectPtr theObject) const;
61 //! Returns QModelIndex which corresponds to the given part
62 //! If the object is not found then index is not valid
63 QModelIndex partIndex(const ResultPartPtr& thePart) const;
65 //! Activates a part data model if the index is a Part node index.
66 //! Returns true if active part changed.
67 bool activatedIndex(const QModelIndex& theIndex);
69 //! Retrurns active part
70 ResultPartPtr activePart() const;
72 //! Retrurns QModelIndex of active part
73 QModelIndex activePartIndex() const
75 return myActivePartIndex;
78 //! Deactivates a Part
79 void deactivatePart();
81 void rebuildDataTree();
83 //! Clear internal data
95 //! Converts QModelIndex of this model to QModelIndex of a one of sub-models.
96 QModelIndex* toSourceModelIndex(const QModelIndex& theProxy) const;
98 //! Finds a pointer on QModelIndex which is equal to the given one
99 QModelIndex* findModelIndex(const QModelIndex& theIndex) const;
101 //! Returns pointer on QModelIndex which is equal to the given one.
102 QModelIndex* getModelIndex(const QModelIndex& theIndex) const;
104 //! Deletes all saved pointers on QModelIndex objects.
105 void clearModelIndexes();
107 //! Deletes all saved pointers on QModelIndex objects.
108 void clearSubModels();
110 //! Removes sub-model on removing a part object. Also it removes QModelIndex-es which refer to this model
111 void removeSubModel(int theModelId);
113 //! Returns true if the given model is a one of sub-models (of both types)
114 bool isSubModel(const QAbstractItemModel* theModel) const;
116 //! Returns true if the given model is a one of sub-models of Part type
117 bool isPartSubModel(const QAbstractItemModel* theModel) const;
119 //! Returns Parts Folder node
120 QModelIndex partFolderNode() const;
122 int historyOffset() const;
124 //! Data model of top part of data tree (not parts object)
125 XGUI_TopDataModel* myModel;
127 //! Data models for Parts data tree representation (one data model per a one part)
128 QList<XGUI_PartModel*> myPartModels;
130 //! Active part in part editing mode
131 XGUI_PartModel* myActivePart;
133 QModelIndex myActivePartIndex;
135 //! List of saved QModelIndexes created by sub-models
136 QList<QModelIndex*> myIndexes;