Salome HOME
Result attributes validators created
[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 ModelAPI_Feature;
18 class ModuleBase_WidgetValue;
19 class QKeyEvent;
20
21 /**\class ModuleBase_ModelWidget
22  * \brief An abstract custom widget class. This class realization is assumed to create some controls.
23  * The controls values modification should send signal about values change.
24  *
25  * Common interface for widgets in the property panel.
26  * Every widget are able to save/restore data from the model and/or to contain other widgets.
27  *
28  */
29 class MODULEBASE_EXPORT ModuleBase_ModelWidget : public QObject
30 {
31   Q_OBJECT
32 public:
33   /// Constructor
34   /// \theParent the parent object
35   /// \theData the widget configuation. The attribute of the model widget is obtained from
36   ModuleBase_ModelWidget(QObject* theParent, const Config_WidgetAPI* theData, const std::string& theParentId);
37   /// Destructor
38   virtual ~ModuleBase_ModelWidget() {};
39
40   /// Set the given wrapped value to the current widget
41   /// This value should be processed in the widget according to the needs
42   /// \param theValue the wrapped widget value
43   virtual bool setValue(ModuleBase_WidgetValue* theValue) { return false; };
44
45   /// Returns the state whether the attribute of the feature is initialized
46   /// \param theObject a model feature to be checked
47   /// \return the boolean result
48   bool isInitialized(ObjectPtr theObject) const;
49
50   /// Saves the internal parameters to the given feature
51   /// \param theObject a model feature to be changed
52   virtual bool storeValue(ObjectPtr theObject) const = 0;
53
54   virtual bool restoreValue(ObjectPtr theObject) = 0;
55
56   /// Set focus to the first control of the current widget. The focus policy of the control is checked.
57   /// If the widget has the NonFocus focus policy, it is skipped.
58   /// \return the state whether the widget can accept the focus
59   virtual bool focusTo();
60
61   /// Returns list of widget controls
62   /// \return a control list
63   virtual QList<QWidget*> getControls() const = 0;
64
65   /// Returns whether the control has a default value
66   /// \return a boolean value
67   bool hasDefaultValue() const { return myHasDefaultValue; }
68
69   /// Returns the attribute name
70   /// \returns the string value
71   std::string attributeID() const { return myAttributeID; }
72
73   /// Returns the parent of the attribute
74   /// \returns the string value
75   std::string parentID() const { return myParentId; }
76
77 signals:
78   /// The signal about widget values changed
79   void valuesChanged();
80   /// The signal about key release on the control, that corresponds to the attribute
81   /// \param theAttributeName a name of the attribute
82   /// \param theEvent key release event
83   void keyReleased(const std::string& theAttributeName, QKeyEvent* theEvent);
84   /// The signal about the widget is lost focus
85   /// \param theWidget the model base widget
86   void focusOutWidget(ModuleBase_ModelWidget* theWidget);
87
88 protected:
89   /// Returns the attribute name
90   /// \returns the string value
91   void setAttributeID(const std::string& theAttribute) { myAttributeID = theAttribute; }
92
93   bool myHasDefaultValue; /// the boolean state whether the control has a default value
94
95 private:
96   std::string myAttributeID; /// the attribute name of the model feature
97   std::string myParentId;    /// name of parent
98 };
99
100 #endif