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 ModuleBase_WidgetValue;
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, const std::string& theParentId);
37 virtual ~ModuleBase_ModelWidget() {};
39 /// Set the given wrapped value to the current widget
40 /// This value should be processed in the widget according to the needs
41 /// \param theValue the wrapped widget value
42 virtual bool setValue(ModuleBase_WidgetValue* theValue) { return false; };
44 /// Returns the state whether the attribute of the feature is initialized
45 /// \param theObject a model feature to be checked
46 /// \return the boolean result
47 bool isInitialized(ObjectPtr theObject) const;
49 /// Saves the internal parameters to the given feature
50 /// \param theObject a model feature to be changed
51 virtual bool storeValue() const = 0;
53 virtual bool restoreValue() = 0;
55 /// Set focus to the first control of the current widget. The focus policy of the control is checked.
56 /// If the widget has the NonFocus focus policy, it is skipped.
57 /// \return the state whether the widget can accept the focus
58 virtual bool focusTo();
60 /// Returns list of widget controls
61 /// \return a control list
62 virtual QList<QWidget*> getControls() const = 0;
64 /// Returns whether the control has a default value
65 /// \return a boolean value
66 bool hasDefaultValue() const { return myHasDefaultValue; }
68 /// Returns the attribute name
69 /// \returns the string value
70 std::string attributeID() const { return myAttributeID; }
72 /// Returns the parent of the attribute
73 /// \returns the string value
74 std::string parentID() const { return myParentId; }
76 FeaturePtr feature() const { return myFeature;}
77 void setFeature(const FeaturePtr& theFeature) { myFeature = theFeature; }
80 /// The signal about widget values changed
82 /// The signal about key release on the control, that corresponds to the attribute
83 /// \param theAttributeName a name of the attribute
84 /// \param theEvent key release event
85 void keyReleased(const std::string& theAttributeName, QKeyEvent* theEvent);
86 /// The signal about the widget is lost focus
87 /// \param theWidget the model base widget
88 void focusOutWidget(ModuleBase_ModelWidget* theWidget);
91 /// Returns the attribute name
92 /// \returns the string value
93 void setAttributeID(const std::string& theAttribute) { myAttributeID = theAttribute; }
95 void updateObject(ObjectPtr theObj) const;
97 bool myHasDefaultValue; /// the boolean state whether the control has a default value
100 std::string myAttributeID; /// the attribute name of the model feature
101 std::string myParentId; /// name of parent
102 FeaturePtr myFeature;