]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_ModelWidget.h
Salome HOME
Sources formated according to the codeing standards
[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
43   /// Set the given wrapped value to the current widget
44   /// This value should be processed in the widget according to the needs
45   /// \param theValue the wrapped widget value
46   virtual bool setValue(ModuleBase_WidgetValue* theValue)
47   {
48     return false;
49   }
50   ;
51
52   /// Returns the state whether the attribute of the feature is initialized
53   /// \param theObject a model feature to be checked
54   /// \return the boolean result
55   bool isInitialized(ObjectPtr theObject) const;
56
57   /// Saves the internal parameters to the given feature
58   /// \param theObject a model feature to be changed
59   virtual bool storeValue() const = 0;
60
61   virtual bool restoreValue() = 0;
62
63   /// Set focus to the first control of the current widget. The focus policy of the control is checked.
64   /// If the widget has the NonFocus focus policy, it is skipped.
65   /// \return the state whether the widget can accept the focus
66   virtual bool focusTo();
67
68   /// Returns list of widget controls
69   /// \return a control list
70   virtual QList<QWidget*> getControls() const = 0;
71
72   /// Returns whether the control has a default value
73   /// \return a boolean value
74   bool hasDefaultValue() const
75   {
76     return myHasDefaultValue;
77   }
78
79   /// Returns the attribute name
80   /// \returns the string value
81   std::string attributeID() const
82   {
83     return myAttributeID;
84   }
85
86   /// Returns the parent of the attribute
87   /// \returns the string value
88   std::string parentID() const
89   {
90     return myParentId;
91   }
92
93   FeaturePtr feature() const
94   {
95     return myFeature;
96   }
97   void setFeature(const FeaturePtr& theFeature)
98   {
99     myFeature = theFeature;
100   }
101
102 signals:
103   /// The signal about widget values changed
104   void valuesChanged();
105   /// The signal about key release on the control, that corresponds to the attribute
106   /// \param theAttributeName a name of the attribute
107   /// \param theEvent key release event
108   void keyReleased(const std::string& theAttributeName, QKeyEvent* theEvent);
109   /// The signal about the widget is lost focus
110   /// \param theWidget the model base widget
111   void focusOutWidget(ModuleBase_ModelWidget* theWidget);
112
113  protected:
114   /// Returns the attribute name
115   /// \returns the string value
116   void setAttributeID(const std::string& theAttribute)
117   {
118     myAttributeID = theAttribute;
119   }
120
121   void updateObject(ObjectPtr theObj) const;
122
123   bool myHasDefaultValue;  /// the boolean state whether the control has a default value
124
125   std::string myAttributeID;  /// the attribute name of the model feature
126   std::string myParentId;    /// name of parent
127   FeaturePtr myFeature;
128 };
129
130 #endif