Salome HOME
0f2cd543f8f3424cd0fe73b05652a039c3d11227
[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 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   /// Destructor
37   virtual ~ModuleBase_ModelWidget() {};
38
39   /// Saves the internal parameters to the given feature
40   /// \param theFeature a model feature to be changed
41   virtual bool storeValue(FeaturePtr theFeature) const = 0;
42
43   virtual bool restoreValue(FeaturePtr theFeature) = 0;
44
45   /// Returns whether the widget can accept focus, or if it corresponds to the given attribute
46   /// \param theAttribute name
47   bool canFocusTo(const std::string& theAttributeName) const;
48
49   /// Set focus to the first control of the current widget. The focus policy of the control is checked.
50   /// If the widget has the NonFocus focus policy, it is skipped.
51   virtual void focusTo();
52
53   /// Returns list of widget controls
54   /// \return a control list
55   virtual QList<QWidget*> getControls() const = 0;
56
57   /// Returns whether the control has a default value
58   /// \return a boolean value
59   bool hasDefaultValue() const { return myHasDefaultValue; }
60
61 signals:
62   /// The signal about widget values changed
63   void valuesChanged();
64   /// The signal about key release on the control, that corresponds to the attribute
65   /// \param theAttributeName a name of the attribute
66   /// \param theEvent key release event
67   void keyReleased(const std::string& theAttributeName, QKeyEvent* theEvent);
68
69 protected:
70   /// Returns the attribute name
71   /// \returns the string value
72   std::string attributeID() const;
73
74   /// Sets the has default value state to the widget
75   /// \param theHasDefaultValue the boolean value
76   void setHasDefaultValue(const bool& theHasDefaultValue);
77
78 private:
79   bool myHasDefaultValue; /// the boolean state whether the control has a default value
80   std::string myAttributeID; /// the attribute name of the model feature
81 };
82
83 #endif