]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_ModelWidget.h
Salome HOME
Issue #348 Validate sketch is disabled when point coordinates are set manually
[modules/shaper.git] / src / ModuleBase / ModuleBase_ModelWidget.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_ModelWidget.h
4 // Created:     25 Apr 2014
5 // Author:      Natalia ERMOLAEVA
6
7 #ifndef MODULEBASE_MODELWIDGET_H
8 #define MODULEBASE_MODELWIDGET_H
9
10 #include <ModuleBase.h>
11 #include <ModuleBase_ViewerPrs.h>
12
13 #include <ModelAPI_Feature.h>
14
15 #include <QObject>
16
17 #include <memory>
18
19 class Config_WidgetAPI;
20 class QKeyEvent;
21
22 /**\class ModuleBase_ModelWidget
23  * \brief An abstract custom widget class. This class realization is assumed to create some controls.
24  * The controls values modification should send signal about values change.
25  *
26  * Common interface for widgets in the property panel.
27  * Every widget are able to save/restore data from the model and/or to contain other widgets.
28  *
29  */
30 class MODULEBASE_EXPORT ModuleBase_ModelWidget : public QObject
31 {
32 Q_OBJECT
33  public:
34   /// Constructor
35   /// \theParent the parent object
36   /// \theData the widget configuation. The attribute of the model widget is obtained from
37   ModuleBase_ModelWidget(QWidget* theParent, const Config_WidgetAPI* theData,
38                          const std::string& theParentId);
39   /// Destructor
40   virtual ~ModuleBase_ModelWidget()
41   {
42   }
43
44   /// Returns the state whether the attribute of the feature is initialized
45   /// \param theObject a model feature to be checked
46   /// \return the boolean result
47   bool isInitialized(ObjectPtr theObject) const;
48
49   /// Returns true, if default value of the widget should be computed
50   /// on operation's execute, like radius for circle's constraint (can not be zero)
51   bool isComputedDefault() { return myIsComputedDefault; }
52
53   /// Returns true, if default value of the widget is defined in the XML and it is not the
54   /// computed value
55   /// \return the boolean result
56   bool isValueDefault() { return myIsValueDefault; }
57
58   /// Defines if it is supposed that the widget should interact with the viewer.
59   virtual bool isViewerSelector() { return false; }
60
61   /// Defines if it is supported to set the value in this widget
62   /// By default it returns true
63   virtual bool canSetValue() const { return true; };
64
65   /// Set the given wrapped value to the current widget
66   /// This value should be processed in the widget according to the needs
67   /// \param theValue the wrapped widget value
68   virtual bool setSelection(ModuleBase_ViewerPrs theValue)
69   {
70     return false;
71   }
72
73   /// Saves the internal parameters to the given feature
74   /// \param theObject a model feature to be changed
75   virtual bool storeValue() const = 0;
76
77   virtual bool restoreValue() = 0;
78
79   /// Set focus to the first control of the current widget. The focus policy of the control is checked.
80   /// If the widget has the NonFocus focus policy, it is skipped.
81   /// \return the state whether the widget can accept the focus
82   virtual bool focusTo();
83
84   /// The methiod called when widget is activated
85   virtual void activate() {}
86
87   /// The methiod called when widget is deactivated
88   virtual void deactivate() {}
89
90   /// Returns the internal parent wiget control, that can be shown anywhere
91   /// \returns the widget
92   virtual QWidget* getControl() const = 0;
93
94   /// Returns list of widget controls
95   /// \return a control list
96   virtual QList<QWidget*> getControls() const = 0;
97
98
99   /// FocusIn events processing
100   virtual bool eventFilter(QObject* theObject, QEvent *theEvent);
101
102
103   void enableFocusProcessing();
104
105   void setHighlighted(bool isHighlighted);
106
107   /// Returns the attribute name
108   /// \returns the string value
109   std::string attributeID() const
110   {
111     return myAttributeID;
112   }
113
114   /// Returns the parent of the attribute
115   /// \returns the string value
116   std::string parentID() const
117   {
118     return myParentId;
119   }
120
121   FeaturePtr feature() const
122   {
123     return myFeature;
124   }
125
126   void setFeature(const FeaturePtr& theFeature)
127   {
128     myFeature = theFeature;
129   }
130
131   /// Editing mode depends on mode of current operation. This value is defined by it.
132   void setEditingMode(bool isEditing) { myIsEditing = isEditing; }
133   bool isEditingMode() const { return myIsEditing; }
134
135 signals:
136   /// The signal about widget values changed
137   void valuesChanged();
138   /// The signal about key release on the control, that corresponds to the attribute
139   /// \param theAttributeName a name of the attribute
140   /// \param theEvent key release event
141   void keyReleased(QKeyEvent* theEvent);
142   /// The signal about the widget is get focus
143   /// \param theWidget the model base widget
144   void focusInWidget(ModuleBase_ModelWidget* theWidget);
145   /// The signal about the widget is lost focus
146   /// \param theWidget the model base widget
147   void focusOutWidget(ModuleBase_ModelWidget* theWidget);
148
149  protected:
150   /// Returns the attribute name
151   /// \returns the string value
152   void setAttributeID(const std::string& theAttribute)
153   {
154     myAttributeID = theAttribute;
155   }
156
157   void updateObject(ObjectPtr theObj) const;
158   void moveObject(ObjectPtr theObj) const;
159
160  protected:
161   std::string myAttributeID; /// the attribute name of the model feature
162   std::string myParentId;    /// name of parent
163   FeaturePtr myFeature;
164
165   bool myIsComputedDefault; /// Value should be computed on execute,
166                             /// like radius for circle's constraint (can not be zero)
167
168   bool myIsValueDefault; /// the default value is defined in the XML for this attribute
169   bool myIsEditing;
170 };
171
172 #endif