Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetFeature.h
1 // File:        ModuleBase_WidgetFeature.h
2 // Created:     25 Apr 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #ifndef ModuleBase_WidgetFeature_H
6 #define ModuleBase_WidgetFeature_H
7
8 #include <ModuleBase.h>
9 #include "ModuleBase_ModelWidget.h"
10
11 #include <QObject>
12 #include <QStringList>
13
14 class ModuleBase_WidgetValue;
15 class ModelAPI_Feature;
16 class QWidget;
17 class QLabel;
18 class QLineEdit;
19 class QToolButton;
20
21 /**\class ModuleBase_WidgetFeature
22  * \ingroup GUI
23  * \brief Custom widget. An abstract class to be redefined to fill with some GUI controls
24  */
25 class MODULEBASE_EXPORT ModuleBase_WidgetFeature : public ModuleBase_ModelWidget
26 {
27 Q_OBJECT
28  public:
29   /// Constructor
30   /// \theParent the parent object
31   /// \theParent the parent object
32   /// \theData the widget configuation. The attribute of the model widget is obtained from
33   ModuleBase_WidgetFeature(QWidget* theParent, const Config_WidgetAPI* theData,
34                            const std::string& theParentId);
35   /// Destructor
36   virtual ~ModuleBase_WidgetFeature();
37
38   /// Set the given wrapped value to the current widget
39   /// This value should be processed in the widget according to the needs
40   /// \param theValue the wrapped widget value
41   virtual bool setValue(ModuleBase_WidgetValue* theValue);
42
43   /// Saves the internal parameters to the given feature
44   /// \param theFeature a model feature to be changed
45   virtual bool storeValue() const;
46
47   virtual bool restoreValue();
48
49   /// Returns the internal parent wiget control, that can be shown anywhere
50   /// \returns the widget
51   QWidget* getControl() const;
52
53   /// Returns list of widget controls
54   /// \return a control list
55   virtual QList<QWidget*> getControls() const;
56   /// Defines if it is supposed that the widget should interact with the viewer.
57   virtual bool isViewerSelector() { return true; }
58
59  protected:
60   /// Fill the widget values by given point
61   /// \param thePoint the point
62   /// \return the boolean result of the feature set
63   bool setObject(const ObjectPtr& theObject, bool theSendEvent = true);
64
65   /// Returns current widget feature
66   /// \return the feature
67   const ObjectPtr object() const
68   {
69     return myObject;
70   }
71
72   /// Returns the widget editor
73   /// \return the editor
74   QLineEdit* editor() const
75   {
76     return myEditor;
77   }
78
79   /// Returns the possible feature kinds
80   /// \return the list of kinds
81   const QStringList& featureKinds() const
82   {
83     return myObjectKinds;
84   }
85
86  protected:
87   ObjectPtr myObject;  ///< the current widget feature
88   QStringList myObjectKinds;  ///< the kinds of possible features
89
90  private:
91   QWidget* myContainer;  /// the parent top control
92   QLabel* myLabel;  /// the editor information label
93   QLineEdit* myEditor;  ///< the feature editor to visualize the feature name
94 };
95
96 #endif