Salome HOME
Update just modified part tree in object browser
[modules/shaper.git] / src / XGUI / XGUI_DocumentDataModel.h
1
2 #ifndef XGUI_DocumentDataModel_H
3 #define XGUI_DocumentDataModel_H
4
5 #include "XGUI_Constants.h"
6
7 #include <QAbstractItemModel>
8 #include <Event_Listener.h>
9
10 #include <QList>
11
12 class ModelAPI_Document;
13 class XGUI_PartModel;
14 class XGUI_TopDataModel;
15
16 /**\class XGUI_DocumentDataModel
17  * \ingroup GUI
18  * \brief This is a proxy data model for Object Browser (QTreeView).
19  * It contains several sub-models for generation of each sub-part of data tree.
20  */
21 class XGUI_DocumentDataModel : public QAbstractItemModel, public Event_Listener
22 {
23   Q_OBJECT
24 public:
25
26
27   XGUI_DocumentDataModel(QObject* theParent);
28   virtual ~XGUI_DocumentDataModel();
29
30   // Event Listener method
31   virtual void processEvent(const Event_Message* theMessage);
32
33
34   virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
35   virtual QVariant headerData(int theSection, Qt::Orientation theOrient,
36                               int theRole = Qt::DisplayRole) const;
37
38   virtual int rowCount(const QModelIndex& theParent = QModelIndex()) const;
39   virtual int columnCount(const QModelIndex& theParent = QModelIndex()) const;
40
41   virtual QModelIndex index(int theRow, int theColumn, 
42                             const QModelIndex &parent = QModelIndex()) const;
43
44   virtual QModelIndex parent(const QModelIndex& theIndex) const;
45
46   virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
47
48   //! Returns Feature object by the given Model index.
49   //! Returns 0 if the given index is not index of a feature
50   FeaturePtr feature(const QModelIndex& theIndex) const;
51
52 private:
53
54   //! Converts QModelIndex of this model to QModelIndex of a one of sub-models.
55   QModelIndex toSourceModel(const QModelIndex& theProxy) const;
56
57   //! Finds a pointer on QModelIndex which is equal to the given one
58   QModelIndex* findModelIndex(const QModelIndex& theIndex) const;
59
60   //! Returns pointer on QModelIndex which is equal to the given one.
61   QModelIndex* getModelIndex(const QModelIndex& theIndex) const;
62
63   //! Deletes all saved pointers on QModelIndex objects.
64   void clearModelIndexes();
65
66   //! Document
67   std::shared_ptr<ModelAPI_Document> myDocument;
68
69   //! Data model of top part of data tree (not parts object)
70   XGUI_TopDataModel* myModel;
71
72   //! Data models for Parts data tree representation (one data model per a one part)
73   QList<XGUI_PartModel*> myPartModels;
74
75   //! List of saved QModelIndexes created by sub-models
76   QList<QModelIndex*> myIndexes;
77 };
78
79 #endif