1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_ModelWidget.h
4 // Created: 25 Apr 2014
5 // Author: Natalia ERMOLAEVA
7 #ifndef MODULEBASE_MODELWIDGET_H
8 #define MODULEBASE_MODELWIDGET_H
10 #include <ModuleBase.h>
11 #include <ModuleBase_ViewerPrs.h>
13 #include <ModelAPI_Feature.h>
19 class Config_WidgetAPI;
22 /**\class ModuleBase_ModelWidget
23 * \brief An abstract custom widget class. This class realization is assumed to create some controls.
24 * The controls values modification should send signal about values change.
26 * Common interface for widgets in the property panel.
27 * Every widget are able to save/restore data from the model and/or to contain other widgets.
30 class MODULEBASE_EXPORT ModuleBase_ModelWidget : public QObject
35 /// \theParent the parent object
36 /// \theData the widget configuation. The attribute of the model widget is obtained from
37 ModuleBase_ModelWidget(QWidget* theParent, const Config_WidgetAPI* theData,
38 const std::string& theParentId);
40 virtual ~ModuleBase_ModelWidget()
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 /// Returns true, if default value of the widget should be computed
50 /// on operation's execute, like radius for circle's constraint (can not be zero)
51 bool isComputedDefault() { return myIsComputedDefault; }
53 /// Returns true, if default value of the widget is defined in the XML and it is not the
55 /// \return the boolean result
56 bool isValueDefault() { return myIsValueDefault; }
58 /// Defines if it is supposed that the widget should interact with the viewer.
59 virtual bool isViewerSelector() { return false; }
61 /// Defines if it is supported to set the value in this widget
62 /// By default it returns true
63 virtual bool canSetValue() const { return true; };
65 /// Set the given wrapped value to the current widget
66 /// This value should be processed in the widget according to the needs
67 /// \param theValue the wrapped widget value
68 virtual bool setSelection(ModuleBase_ViewerPrs theValue)
73 /// Saves the internal parameters to the given feature
74 /// \param theObject a model feature to be changed
75 virtual bool storeValue() const = 0;
77 virtual bool restoreValue() = 0;
79 /// Set focus to the first control of the current widget. The focus policy of the control is checked.
80 /// If the widget has the NonFocus focus policy, it is skipped.
81 /// \return the state whether the widget can accept the focus
82 virtual bool focusTo();
84 /// The methiod called when widget is activated
85 virtual void activate() {}
87 /// The methiod called when widget is deactivated
88 virtual void deactivate() {}
90 /// Returns the internal parent wiget control, that can be shown anywhere
91 /// \returns the widget
92 virtual QWidget* getControl() const = 0;
94 /// Returns list of widget controls
95 /// \return a control list
96 virtual QList<QWidget*> getControls() const = 0;
99 /// FocusIn events processing
100 virtual bool eventFilter(QObject* theObject, QEvent *theEvent);
103 void enableFocusProcessing();
105 void setHighlighted(bool isHighlighted);
107 /// Returns the attribute name
108 /// \returns the string value
109 std::string attributeID() const
111 return myAttributeID;
114 /// Returns the parent of the attribute
115 /// \returns the string value
116 std::string parentID() const
121 FeaturePtr feature() const
126 void setFeature(const FeaturePtr& theFeature)
128 myFeature = theFeature;
131 /// Editing mode depends on mode of current operation. This value is defined by it.
132 void setEditingMode(bool isEditing) { myIsEditing = isEditing; }
133 bool isEditingMode() const { return myIsEditing; }
136 /// The signal about widget values changed
137 void valuesChanged();
138 /// The signal about key release on the control, that corresponds to the attribute
139 /// \param theAttributeName a name of the attribute
140 /// \param theEvent key release event
141 void keyReleased(QKeyEvent* theEvent);
142 /// The signal about the widget is get focus
143 /// \param theWidget the model base widget
144 void focusInWidget(ModuleBase_ModelWidget* theWidget);
145 /// The signal about the widget is lost focus
146 /// \param theWidget the model base widget
147 void focusOutWidget(ModuleBase_ModelWidget* theWidget);
150 /// Returns the attribute name
151 /// \returns the string value
152 void setAttributeID(const std::string& theAttribute)
154 myAttributeID = theAttribute;
157 void updateObject(ObjectPtr theObj) const;
158 void moveObject(ObjectPtr theObj) const;
161 std::string myAttributeID; /// the attribute name of the model feature
162 std::string myParentId; /// name of parent
163 FeaturePtr myFeature;
165 bool myIsComputedDefault; /// Value should be computed on execute,
166 /// like radius for circle's constraint (can not be zero)
168 bool myIsValueDefault; /// the default value is defined in the XML for this attribute