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