Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / XGUI / XGUI_PartDataModel.h
1
2 #ifndef XGUI_PartDataModel_H
3 #define XGUI_PartDataModel_H
4
5 #include <QAbstractItemModel>
6
7 class ModelAPI_Feature;
8 class ModelAPI_Document; 
9
10 /**\class XGUI_TopDataModel
11  * \ingroup GUI
12  * \brief This is a data model for Object Browser (QTreeView).
13  * It represents only upper part of data tree (non-parts tree items)
14  */
15 class XGUI_TopDataModel : public QAbstractItemModel
16 {
17   Q_OBJECT
18 public:
19   XGUI_TopDataModel(QObject* theParent);
20   virtual ~XGUI_TopDataModel();
21  
22   //! Set a document object
23   virtual void setDocument(const std::shared_ptr<ModelAPI_Document>& theDoc)
24   {
25     myDocument = theDoc;
26   }
27
28   // Reimplementation from QAbstractItemModel
29   virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
30   virtual QVariant headerData(int section, Qt::Orientation orientation,
31                               int role = Qt::DisplayRole) const;
32
33   virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
34   virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
35
36   virtual QModelIndex index(int theRow, int theColumn, 
37                             const QModelIndex& theParent = QModelIndex()) const;
38
39   virtual QModelIndex parent(const QModelIndex& theIndex) const;
40
41   virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
42
43 private:
44   //! Types of QModelIndexes
45   enum DataIds {
46     ParamsFolder,
47     ParamObject,
48     ConstructFolder,
49     ConstructObject
50   };
51
52   //! Document object
53   std::shared_ptr<ModelAPI_Document> myDocument;
54 };
55
56
57 /**\class XGUI_PartDataModel
58  * \ingroup GUI
59  * \brief This is a data model for Object Browser (QTreeView).
60  * It represents data tree only of a one part
61  */
62 class XGUI_PartDataModel : public QAbstractItemModel
63 {
64   Q_OBJECT
65 public:
66   XGUI_PartDataModel(QObject* theParent);
67   virtual ~XGUI_PartDataModel();
68
69   //! Set a document object and Id of a part in the document
70   virtual void setDocument(const std::shared_ptr<ModelAPI_Document>& theDoc, int theId)
71   {
72     myDocument = theDoc;
73     myId = theId;
74   }
75
76   // Reimplementation from QAbstractItemModel
77   virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
78   virtual QVariant headerData(int section, Qt::Orientation orientation,
79                               int role = Qt::DisplayRole) const;
80
81   virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
82   virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
83
84   virtual QModelIndex index(int theRow, int theColumn, 
85                             const QModelIndex& theParent = QModelIndex()) const;
86
87   virtual QModelIndex parent(const QModelIndex& theIndex) const;
88
89   virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
90
91 private: 
92   std::shared_ptr<ModelAPI_Document> featureDocument() const;
93
94   //! Types of QModelIndexes
95   enum DataIds {
96     MyRoot,
97     ParamsFolder,
98     ParamObject,
99     ConstructFolder,
100     ConstructObject
101   };
102
103   //! Document object
104   std::shared_ptr<ModelAPI_Document> myDocument;
105
106   //! Id of the current part object in the document
107   int myId;
108 };
109
110 #endif