Salome HOME
Issue #23: current document management
[modules/shaper.git] / src / XGUI / XGUI_DocumentDataModel.h
1
2 #ifndef XGUI_DocumentDataModel_H
3 #define XGUI_DocumentDataModel_H
4
5 #include "XGUI.h"
6 #include "XGUI_Constants.h"
7
8 #include <QAbstractItemModel>
9 #include <Events_Listener.h>
10
11 #include <QList>
12
13 class ModelAPI_Document;
14 class XGUI_PartModel;
15 class XGUI_TopDataModel;
16
17 /**\class XGUI_DocumentDataModel
18  * \ingroup GUI
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.
21  */
22 class XGUI_EXPORT XGUI_DocumentDataModel : public QAbstractItemModel, public Events_Listener
23 {
24   Q_OBJECT
25 public:
26
27
28   XGUI_DocumentDataModel(QObject* theParent);
29   virtual ~XGUI_DocumentDataModel();
30
31   // Event Listener method
32   virtual void processEvent(const Events_Message* theMessage);
33
34
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;
38
39   virtual int rowCount(const QModelIndex& theParent = QModelIndex()) const;
40   virtual int columnCount(const QModelIndex& theParent = QModelIndex()) const;
41
42   virtual QModelIndex index(int theRow, int theColumn, 
43                             const QModelIndex &parent = QModelIndex()) const;
44
45   virtual QModelIndex parent(const QModelIndex& theIndex) const;
46
47   virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
48
49   bool insertRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
50
51   bool removeRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
52
53   //! Returns Feature object by the given Model index.
54   //! Returns 0 if the given index is not index of a feature
55   FeaturePtr feature(const QModelIndex& theIndex) const;
56
57   //! Activates a part data model if the index is a Part node index. 
58   //! Returns true if active part changed.
59   bool activatedIndex(const QModelIndex& theIndex);
60
61   FeaturePtr activePart() const;
62
63 private:
64
65   enum {PartsFolder, HistoryNode};
66
67
68   //! Converts QModelIndex of this model to QModelIndex of a one of sub-models.
69   QModelIndex* toSourceModelIndex(const QModelIndex& theProxy) const;
70
71   //! Finds a pointer on QModelIndex which is equal to the given one
72   QModelIndex* findModelIndex(const QModelIndex& theIndex) const;
73
74   //! Returns pointer on QModelIndex which is equal to the given one.
75   QModelIndex* getModelIndex(const QModelIndex& theIndex) const;
76
77   //! Deletes all saved pointers on QModelIndex objects.
78   void clearModelIndexes();
79
80   //! Removes sub-model on removing a part object. Also it removes QModelIndex-es which refer to this model
81   void removeSubModel(int theModelId);
82
83   //! Returns true if the given model is a one of sub-models (of both types)
84   bool isSubModel(const QAbstractItemModel* theModel) const;
85
86   //! Returns true if the given model is a one of sub-models of Part type
87   bool isPartSubModel(const QAbstractItemModel* theModel) const;
88
89   //! Returns Parts Folder node
90   QModelIndex partFolderNode() const;
91
92   int historyOffset() const;
93
94
95   //! Document
96   boost::shared_ptr<ModelAPI_Document> myDocument;
97
98   //! Data model of top part of data tree (not parts object)
99   XGUI_TopDataModel* myModel;
100
101   //! Data models for Parts data tree representation (one data model per a one part)
102   QList<XGUI_PartModel*> myPartModels;
103
104   //! Active part in part editing mode
105   XGUI_PartModel* myActivePart;
106
107   //! List of saved QModelIndexes created by sub-models
108   QList<QModelIndex*> myIndexes;
109
110 };
111
112 #endif