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(QWidget* theParent, const Config_WidgetAPI* theData,
36 const std::string& theParentId);
38 virtual ~ModuleBase_ModelWidget()
42 /// Returns the state whether the attribute of the feature is initialized
43 /// \param theObject a model feature to be checked
44 /// \return the boolean result
45 bool isInitialized(ObjectPtr theObject) const;
47 /// Returns true, if default value of the widget should be computed
48 /// on operation's execute, like radius for circle's constraint (can not be zero)
49 bool isComputedDefault() { return myIsComputedDefault; }
51 /// Defines if it is supposed that the widget should interact with the viewer.
52 virtual bool isViewerSelector() { return false; }
54 /// Set the given wrapped value to the current widget
55 /// This value should be processed in the widget according to the needs
56 /// \param theValue the wrapped widget value
57 virtual bool setValue(ModuleBase_WidgetValue* theValue)
62 /// Saves the internal parameters to the given feature
63 /// \param theObject a model feature to be changed
64 virtual bool storeValue() const = 0;
66 virtual bool restoreValue() = 0;
68 /// Set focus to the first control of the current widget. The focus policy of the control is checked.
69 /// If the widget has the NonFocus focus policy, it is skipped.
70 /// \return the state whether the widget can accept the focus
71 virtual bool focusTo();
73 /// Returns the internal parent wiget control, that can be shown anywhere
74 /// \returns the widget
75 virtual QWidget* getControl() const = 0;
77 /// Returns list of widget controls
78 /// \return a control list
79 virtual QList<QWidget*> getControls() const = 0;
82 /// FocusIn events processing
83 virtual bool eventFilter(QObject* theObject, QEvent *theEvent);
86 void enableFocusProcessing();
88 void setHighlighted(bool isHighlighted);
90 /// Returns the attribute name
91 /// \returns the string value
92 std::string attributeID() const
97 /// Returns the parent of the attribute
98 /// \returns the string value
99 std::string parentID() const
104 FeaturePtr feature() const
109 void setFeature(const FeaturePtr& theFeature)
111 myFeature = theFeature;
115 /// The signal about widget values changed
116 void valuesChanged();
117 /// The signal about key release on the control, that corresponds to the attribute
118 /// \param theAttributeName a name of the attribute
119 /// \param theEvent key release event
120 void keyReleased(QKeyEvent* theEvent);
121 /// The signal about the widget is get focus
122 /// \param theWidget the model base widget
123 void focusInWidget(ModuleBase_ModelWidget* theWidget);
124 /// The signal about the widget is lost focus
125 /// \param theWidget the model base widget
126 void focusOutWidget(ModuleBase_ModelWidget* theWidget);
129 /// Returns the attribute name
130 /// \returns the string value
131 void setAttributeID(const std::string& theAttribute)
133 myAttributeID = theAttribute;
136 void updateObject(ObjectPtr theObj) const;
139 std::string myAttributeID; /// the attribute name of the model feature
140 std::string myParentId; /// name of parent
141 FeaturePtr myFeature;
143 bool myIsComputedDefault; /// Value should be computed on execute,
144 /// like radius for circle's constraint (can not be zero)