Salome HOME
c203579420b29a78e13f0c0d7e907d9678e348ab
[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 ModelAPI_Feature;
17 class QKeyEvent;
18
19 /**\class ModuleBase_ModelWidget
20  * \brief An abstract custom widget class. This class realization is assumed to create some controls.
21  * The controls values modification should send signal about values change.
22  *
23  * Common interface for widgets in the property panel.
24  * Every widget are able to save/restore data from the model and/or to contain other widgets.
25  *
26  */
27 class MODULEBASE_EXPORT ModuleBase_ModelWidget : public QObject
28 {
29   Q_OBJECT
30 public:
31   /// Constructor
32   /// \theParent the parent object
33   ModuleBase_ModelWidget(QObject* theParent) :QObject(theParent) {};
34   /// Destructor
35   virtual ~ModuleBase_ModelWidget() {};
36
37   /// Saves the internal parameters to the given feature
38   /// \param theFeature a model feature to be changed
39   virtual bool storeValue(FeaturePtr theFeature) const = 0;
40
41   virtual bool restoreValue(FeaturePtr theFeature) = 0;
42
43   /// Returns whether the widget can accept focus, or if it corresponds to the given attribute
44   /// \param theAttribute name
45   virtual bool canFocusTo(const std::string& theAttributeName) const { return false; }
46
47   /// Set focus to the current widget if it corresponds to the given attribute
48   virtual void focusTo() {}
49
50   /// Returns list of widget controls
51   /// \return a control list
52   virtual QList<QWidget*> getControls() const = 0;
53
54 signals:
55   /// The signal about widget values changed
56   void valuesChanged();
57   /// The signal about key release on the control, that corresponds to the attribute
58   /// \param theAttributeName a name of the attribute
59   /// \param theEvent key release event
60   void keyReleased(const std::string& theAttributeName, QKeyEvent* theEvent);
61 };
62
63 #endif