Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / XGUI / XGUI_DataTreeModel.h
1 #ifndef XGUI_DataTreeModel_H
2 #define XGUI_DataTreeModel_H
3
4 #include "XGUI.h"
5 #include "XGUI_Constants.h"
6
7 #include <ModelAPI_Document.h>
8 #include <ModelAPI_Feature.h>
9 #include <ModelAPI_ResultPart.h>
10
11 #include <QAbstractItemModel>
12 #include <QColor>
13
14 /**\class XGUI_FeaturesModel
15  * \ingroup GUI
16  * \brief Abstaract class of model object which operates with features data.
17  */
18 class XGUI_EXPORT XGUI_FeaturesModel : public QAbstractItemModel
19 {
20  public:
21   XGUI_FeaturesModel(QObject* theParent)
22       : QAbstractItemModel(theParent),
23         myItemsColor(Qt::black)
24   {
25   }
26
27   //! Returns Feature object by the given Model index.
28   //! Returns 0 if the given index is not index of a feature
29   virtual ObjectPtr object(const QModelIndex& theIndex) const = 0;
30
31   //! Returns QModelIndex which corresponds to the given feature
32   //! If the feature is not found then index is not valid
33   virtual QModelIndex objectIndex(const ObjectPtr& theFeature) const = 0;
34
35   //! Returns parent index of the given feature
36   virtual QModelIndex findParent(const ObjectPtr& theObject) const = 0;
37
38   //! Returns index corresponded to the group
39   virtual QModelIndex findGroup(const std::string& theGroup) const = 0;
40
41   void setItemsColor(const QColor& theColor)
42   {
43     myItemsColor = theColor;
44   }
45
46   QColor itemsColor() const
47   {
48     return myItemsColor;
49   }
50
51  protected:
52   QColor myItemsColor;
53 };
54
55 /**\class XGUI_PartModel
56  * \ingroup GUI
57  * \brief Abstaract class of model object which operates with parts data.
58  */
59 class XGUI_PartModel : public XGUI_FeaturesModel
60 {
61  public:
62   XGUI_PartModel(QObject* theParent)
63       : XGUI_FeaturesModel(theParent)
64   {
65   }
66
67   void setPartId(int theId)
68   {
69     myId = theId;
70   }
71
72   //! Returns true if the given document is a sub-document of this tree
73   virtual bool hasDocument(const DocumentPtr& theDoc) const = 0;
74
75   //! Return a Part object
76   virtual ResultPartPtr part() const = 0;
77
78  protected:
79   //! Id of the current part object in the document
80   int myId;
81 };
82
83 #endif