1 // File: ModuleBase_ModelWidget.h
2 // Created: 25 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #ifndef ModuleBase_ModelWidget_H
6 #define ModuleBase_ModelWidget_H
8 #include <ModuleBase.h>
10 #include <ModelAPI_Feature.h>
14 #include <boost/shared_ptr.hpp>
16 class Config_WidgetAPI;
17 class ModelAPI_Feature;
18 class ModuleBase_WidgetValue;
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.
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.
29 class MODULEBASE_EXPORT ModuleBase_ModelWidget : public QObject
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);
38 virtual ~ModuleBase_ModelWidget() {};
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; };
45 /// Returns the state whether the attribute of the feature is initialized
46 /// \param theFeature a model feature to be checked
47 /// \return the boolean result
48 bool isInitialized(FeaturePtr theFeature) const;
50 /// Saves the internal parameters to the given feature
51 /// \param theFeature a model feature to be changed
52 virtual bool storeValue(FeaturePtr theFeature) const = 0;
54 virtual bool restoreValue(FeaturePtr theFeature) = 0;
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();
61 /// Returns list of widget controls
62 /// \return a control list
63 virtual QList<QWidget*> getControls() const = 0;
65 /// Returns whether the control has a default value
66 /// \return a boolean value
67 bool hasDefaultValue() const { return myHasDefaultValue; }
69 /// Returns the attribute name
70 /// \returns the string value
71 std::string attributeID() const;
74 /// The signal about widget values changed
76 /// The signal about key release on the control, that corresponds to the attribute
77 /// \param theAttributeName a name of the attribute
78 /// \param theEvent key release event
79 void keyReleased(const std::string& theAttributeName, QKeyEvent* theEvent);
80 /// The signal about the widget is lost focus
81 /// \param theWidget the model base widget
82 void focusOutWidget(ModuleBase_ModelWidget* theWidget);
85 /// Returns the attribute name
86 /// \returns the string value
87 void setAttributeID(const std::string& theAttribute) { myAttributeID = theAttribute; }
89 bool myHasDefaultValue; /// the boolean state whether the control has a default value
92 std::string myAttributeID; /// the attribute name of the model feature