]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_DataTreeModel.h
Salome HOME
Using mouse double click for history line change
[modules/shaper.git] / src / PartSet / PartSet_DataTreeModel.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 #ifndef PartSet_DataTreeModel_H
4 #define PartSet_DataTreeModel_H
5
6 #include "PartSet.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 PartSet_FeaturesModel
16  * \ingroup GUI
17  * \brief Abstaract class of model object which operates with features data.
18  */
19 class PARTSET_EXPORT PartSet_FeaturesModel : public QAbstractItemModel
20 {
21  public:
22    /// Constructor
23    /// \param theParent a parent object
24   PartSet_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 PartSet_PartModel
64  * \ingroup GUI
65  * \brief Abstaract class of model object which operates with parts data.
66  */
67 class PartSet_PartModel : public PartSet_FeaturesModel
68 {
69  public:
70    /// Constructor
71    /// \param theParent a parent object
72   PartSet_PartModel(QObject* theParent)
73       : PartSet_FeaturesModel(theParent), myId(-1)
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 Id of the part
85   int partId() const { return myId; }
86
87   //! Returns true if the given document is a sub-document of this tree
88   //! \param theDoc a document to check
89   virtual bool hasDocument(const DocumentPtr& theDoc) const = 0;
90
91   //! Return a Part object
92   virtual ResultPartPtr part() const = 0;
93
94  protected:
95   //! Id of the current part object in the document
96   int myId;
97 };
98
99 #endif