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;
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.
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.
28 class MODULEBASE_EXPORT ModuleBase_ModelWidget : public QObject
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);
37 virtual ~ModuleBase_ModelWidget() {};
39 /// Returns the state whether the attribute of the feature is initialized
40 /// \param theFeature a model feature to be checked
41 /// \return the boolean result
42 bool isInitialized(FeaturePtr theFeature) const;
44 /// Saves the internal parameters to the given feature
45 /// \param theFeature a model feature to be changed
46 virtual bool storeValue(FeaturePtr theFeature) const = 0;
48 virtual bool restoreValue(FeaturePtr theFeature) = 0;
50 /// Returns whether the widget can accept focus, or if it corresponds to the given attribute
51 /// \param theAttribute name
52 bool canFocusTo(const std::string& theAttributeName) const;
54 /// Set focus to the first control of the current widget. The focus policy of the control is checked.
55 /// If the widget has the NonFocus focus policy, it is skipped.
56 virtual void focusTo();
58 /// Returns list of widget controls
59 /// \return a control list
60 virtual QList<QWidget*> getControls() const = 0;
62 /// Returns whether the control has a default value
63 /// \return a boolean value
64 bool hasDefaultValue() const { return myHasDefaultValue; }
66 /// Returns the attribute name
67 /// \returns the string value
68 std::string attributeID() const;
71 /// The signal about widget values changed
73 /// The signal about key release on the control, that corresponds to the attribute
74 /// \param theAttributeName a name of the attribute
75 /// \param theEvent key release event
76 void keyReleased(const std::string& theAttributeName, QKeyEvent* theEvent);
77 /// The signal about the widget is lost focus
78 /// \param theWidget the model base widget
79 void focusOutWidget(ModuleBase_ModelWidget* theWidget);
82 /// Returns the attribute name
83 /// \returns the string value
84 void setAttributeID(const std::string& theAttribute) { myAttributeID = theAttribute; }
86 bool myHasDefaultValue; /// the boolean state whether the control has a default value
89 std::string myAttributeID; /// the attribute name of the model feature