]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_ModelWidget.h
Salome HOME
Issue #144 If an operation has valid feature after initialization by preselection...
[modules/shaper.git] / src / ModuleBase / ModuleBase_ModelWidget.h
1 // File:        ModuleBase_ModelWidget.h
2 // Created:     25 Apr 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #ifndef MODULEBASE_MODELWIDGET_H
6 #define MODULEBASE_MODELWIDGET_H
7
8 #include <ModuleBase.h>
9
10 #include <ModelAPI_Feature.h>
11
12 #include <QObject>
13
14 #include <boost/shared_ptr.hpp>
15
16 class Config_WidgetAPI;
17 class ModuleBase_WidgetValue;
18 class QKeyEvent;
19
20 /**\class ModuleBase_ModelWidget
21  * \brief An abstract custom widget class. This class realization is assumed to create some controls.
22  * The controls values modification should send signal about values change.
23  *
24  * Common interface for widgets in the property panel.
25  * Every widget are able to save/restore data from the model and/or to contain other widgets.
26  *
27  */
28 class MODULEBASE_EXPORT ModuleBase_ModelWidget : public QObject
29 {
30 Q_OBJECT
31  public:
32   /// Constructor
33   /// \theParent the parent object
34   /// \theData the widget configuation. The attribute of the model widget is obtained from
35   ModuleBase_ModelWidget(QObject* theParent, const Config_WidgetAPI* theData,
36                          const std::string& theParentId);
37   /// Destructor
38   virtual ~ModuleBase_ModelWidget()
39   {
40   }
41
42   /// Set the given wrapped value to the current widget
43   /// This value should be processed in the widget according to the needs
44   /// \param theValue the wrapped widget value
45   virtual bool setValue(ModuleBase_WidgetValue* theValue)
46   {
47     return false;
48   }
49
50   /// Returns the state whether the attribute of the feature is initialized
51   /// \param theObject a model feature to be checked
52   /// \return the boolean result
53   bool isInitialized(ObjectPtr theObject) const;
54
55   /// Returns true, if default value of the widget should be computed
56   /// on operation's execute, like radius for circle's constraint (can not be zero)
57   bool isComputedDefault() { return myIsComputedDefault; }
58
59   /// Returns false for non-obligatory widgets which are
60   /// valid even if they are not initialized
61   bool isObligatory() { return myIsObligatory; }
62
63   /// Saves the internal parameters to the given feature
64   /// \param theObject a model feature to be changed
65   virtual bool storeValue() const = 0;
66
67   virtual bool restoreValue() = 0;
68
69   void enableFocusProcessing();
70   /// Set focus to the first control of the current widget. The focus policy of the control is checked.
71   /// If the widget has the NonFocus focus policy, it is skipped.
72   /// \return the state whether the widget can accept the focus
73   virtual bool focusTo();
74
75   /// Returns list of widget controls
76   /// \return a control list
77   virtual QList<QWidget*> getControls() const = 0;
78
79   /// FocusIn events processing
80   virtual bool eventFilter(QObject* theObject, QEvent *theEvent);
81
82   /// Returns the attribute name
83   /// \returns the string value
84   std::string attributeID() const
85   {
86     return myAttributeID;
87   }
88
89   /// Returns the parent of the attribute
90   /// \returns the string value
91   std::string parentID() const
92   {
93     return myParentId;
94   }
95
96   FeaturePtr feature() const
97   {
98     return myFeature;
99   }
100   void setFeature(const FeaturePtr& theFeature)
101   {
102     myFeature = theFeature;
103   }
104
105   /// Defines if it is supposed that the widget should interact with the viewer.
106   virtual bool isViewerSelector() { return false; }
107
108 signals:
109   /// The signal about widget values changed
110   void valuesChanged();
111   /// The signal about key release on the control, that corresponds to the attribute
112   /// \param theAttributeName a name of the attribute
113   /// \param theEvent key release event
114   void keyReleased(QKeyEvent* theEvent);
115   /// The signal about the widget is get focus
116   /// \param theWidget the model base widget
117   void focusInWidget(ModuleBase_ModelWidget* theWidget);
118   /// The signal about the widget is lost focus
119   /// \param theWidget the model base widget
120   void focusOutWidget(ModuleBase_ModelWidget* theWidget);
121
122  protected:
123   /// Returns the attribute name
124   /// \returns the string value
125   void setAttributeID(const std::string& theAttribute)
126   {
127     myAttributeID = theAttribute;
128   }
129
130   void updateObject(ObjectPtr theObj) const;
131
132  private:
133   /// Let the widget process FocusIn events
134   void enableFocusProcessing(QWidget* theWidget);
135
136  protected:
137   std::string myAttributeID; /// the attribute name of the model feature
138   std::string myParentId;    /// name of parent
139   FeaturePtr myFeature;
140
141     bool myIsComputedDefault; /// Value should be computed on execute,
142                               /// like radius for circle's constraint (can not be zero)
143     bool myIsObligatory;      /// Non-obligatory widget is valid even if it is not initialized
144
145  private:
146    /// Contains a list of widgets that may accept focus
147    QList<QWidget*> myFocusInWidgets;
148 };
149
150 #endif