SHAPER 9.16.0
ModuleBase_ModelWidget.h
1// Copyright (C) 2014-2026 CEA, EDF
2//
3// This library is free software; you can redistribute it and/or
4// modify it under the terms of the GNU Lesser General Public
5// License as published by the Free Software Foundation; either
6// version 2.1 of the License, or (at your option) any later version.
7//
8// This library is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11// Lesser General Public License for more details.
12//
13// You should have received a copy of the GNU Lesser General Public
14// License along with this library; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19
20#ifndef MODULEBASE_MODELWIDGET_H
21#define MODULEBASE_MODELWIDGET_H
22
23#include <ModuleBase.h>
24#include <ModuleBase_ActionType.h>
25#include <ModuleBase_Definitions.h>
26#include <ModuleBase_OperationFeature.h>
27#include <ModuleBase_ActionInfo.h>
28#include <ModuleBase_ActionParameter.h>
29#include <ModelAPI_Feature.h>
30
31#include <SelectMgr_ListOfFilter.hxx>
32
33#include <QWidget>
34
35#include <memory>
36
37#ifdef _MSC_VER
38#pragma warning(disable: 4100)
39#endif
40
47class QKeyEvent;
48
59class MODULEBASE_EXPORT ModuleBase_ModelWidget : public QWidget
60{
61Q_OBJECT
62 public:
64 enum ValueState { Stored,
67 Reset };
68
69 enum EnableState { On,
72 DefinedInPreferences };
73
78 ModuleBase_ModelWidget(QWidget* theParent, const Config_WidgetAPI* theData);
81
85 bool reset();
86
90 bool isInitialized(ObjectPtr theObject) const;
91
95 virtual void selectionModes(int& theModuleSelectionModes, QIntList& theModes);
96
100 virtual void selectionFilters(QIntList& theModuleSelectionFilters,
101 SelectMgr_ListOfFilter& theSelectionFilters);
102
105 bool isComputedDefault() const { return myIsComputedDefault; }
106
110 std::string getDefaultValue() const { return myDefaultValue; }
111
114 bool isInternal() const { return myIsInternal; }
115
119 bool isObligatory() const { return myIsObligatory; }
120
125 virtual bool isValueEnabled() const;
126
129 bool isUseReset() const { return myUseReset; }
130
133 std::string isModifiedInEdit() const { return myIsModifiedInEdit; }
134
137 ValueState getValueState() const { return myState; }
138
140 void processValueState();
141
144 Events_InfoMessage getValueStateError() const;
145
147 virtual bool isViewerSelector() { return false; }
148
151 virtual bool canAcceptFocus() const { return true; };
152
157 virtual QString getError(const bool theValueStateChecked = true) const;
158
163 virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
164 const bool theToValidate)
165 {
166 return false;
167 }
168
171 virtual void getHighlighted(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues) {};
172
176 virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue)
177 { return true; }
178
180 ModuleBase_WidgetValidator* widgetValidator() { return myWidgetValidator.get(); }
181
185 bool restoreValue();
186
189 bool storeValue();
190
195 virtual bool focusTo();
196
198 virtual void selectContent() {}
199
201 void activate();
202
204 virtual void deactivate();
205
207 virtual void updateAfterDeactivation() {}
209 virtual void updateAfterActivation() {}
210
212 virtual bool needToBeActivated() { return false; }
213
216 virtual QList<QWidget*> getControls() const = 0;
217
221 QWidget* getControlAcceptingFocus(const bool isFirst);
222
224 virtual bool eventFilter(QObject* theObject, QEvent *theEvent);
225
228 virtual void enableFocusProcessing();
229
231 virtual void setHighlighted(bool isHighlighted);
232
235 std::string attributeID() const
236 {
237 return myAttributeID;
238 }
239
241 FeaturePtr feature() const
242 {
243 return myFeature;
244 }
245
247 virtual std::string context() const {
248 bool isAppendAttr = true;
249 std::string aContext = myFeatureId;
250 if(!aContext.empty() && !myAttributeID.empty()) {
251 // workaround for ModelAPI_Filter's attributes:
252 // do not keep attribute name, because it may be changed
253 // if the same filter is selected twice or more.
254 if (myAttributeID.find(aContext + "__") != std::string::npos)
255 isAppendAttr = false;
256 else
257 aContext += ":";
258 }
259 if (isAppendAttr)
260 aContext += myAttributeID;
261
262 return aContext;
263 }
264
269 virtual void setFeature(const FeaturePtr& theFeature, const bool theToStoreValue = false,
270 const bool isUpdateFlushed = true);
271
273 virtual void setEditingMode(bool isEditing) { myIsEditing = isEditing; }
274
276 bool isEditingMode() const { return myIsEditing; }
277
281 virtual bool canProcessAction(ModuleBase_ActionType theActionType, bool& isActionEnabled);
282
284 virtual bool processAction(ModuleBase_ActionType theActionType,
285 const ActionParamPtr& theParam = ActionParamPtr());
286
289 virtual QList<ActionInfo> actionsList(ModuleBase_ActionType theActionType) const
290 { return QList<ActionInfo>(); }
291
294 void updateObject(ObjectPtr theObj);
295
297 virtual QString translate(const std::string& theStr) const;
298
300 void emitFocusInWidget() { emit focusInWidget(this); }
301
306 static ModuleBase_ModelWidget* findModelWidget(ModuleBase_IPropertyPanel* theProp,
307 QWidget* theWidget);
308
311 virtual bool usesAttribute() const { return true; }
312
315 virtual void onFeatureAccepted() {}
316
318 virtual bool isInformative() const { return true; }
319
322 virtual void showInformativePage() {}
323
325 virtual bool isModified() const { return false; }
326
327 virtual void setReadOnly(bool isReadOnly) { setEnabled(!isReadOnly); }
328
329 virtual bool isReadOnly() const { return !isEnabled(); }
330
332 bool canUseExternalParts() const { return myUseExternalParts; }
333
334signals:
343
348
352 void keyReleased(QObject* theObject, QKeyEvent* theEvent);
353
356 void enterClicked(QObject* theObject);
357
361
365
367 void valueStateChanged(int theState);
368
371
372protected:
375 void setDefaultValue(const std::string& theValue);
378 void setAttributeID(const std::string& theAttribute)
379 {
380 myAttributeID = theAttribute;
381 }
382
387 ValueState setValueState(const ValueState& theState);
388
392 bool blockValueState(const bool theBlocked);
393
396 virtual void initializeValueByActivate();
397
400 virtual bool storeValueCustom() = 0;
401
403 virtual bool restoreValueCustom() = 0;
404
407 virtual bool resetCustom() { return false; };
408
410 virtual void activateCustom() {};
411
413 virtual bool processEnter();
414
416 virtual bool processEscape();
417
419 virtual bool processDelete();
420
422 virtual bool processSelection();
423
424 protected slots:
426 void onWidgetValuesChanged();
427
429 void onWidgetValuesModified();
430
431 protected:
433 std::unique_ptr<ModuleBase_WidgetValidator> myWidgetValidator;
434
436 std::string myAttributeID;
437
439 FeaturePtr myFeature;
440
442 std::string myFeatureId;
443
447
450
453
454private:
456 bool myIsEditing;
457
459 bool myIsComputedDefault;
460
462 std::string myDefaultValue;
463
465 bool myIsInternal;
466
467 // an XML state, the value is not stored into model if the widget is in edit mode
468 std::string myIsModifiedInEdit;
469
471 bool myUseReset;
473 bool myIsValueStateBlocked;
475 bool myFlushUpdateBlocked;
476
477 bool myUpdateVisualAttributes;
478
480 bool myUseExternalParts;
481};
482
483#endif
Provides low-level API for WidgetFactory for reading xml definitions of widgets.
Definition: Config_WidgetAPI.h:46
An event message for sending a string message which has to be translated.
Definition: Events_InfoMessage.h:35
A class for Property panel object definition.
Definition: ModuleBase_IPropertyPanel.h:35
Class which provides access to Workshop object services.
Definition: ModuleBase_IWorkshop.h:48
An abstract custom widget class.
Definition: ModuleBase_ModelWidget.h:60
EnableState
the value is reset
Definition: ModuleBase_ModelWidget.h:69
@ Off
the widget value is always enabled
Definition: ModuleBase_ModelWidget.h:70
void valuesModified()
The signal about widget values modified.
virtual void activateCustom()
The method called when widget is activated.
Definition: ModuleBase_ModelWidget.h:410
void beforeValuesRestored()
The signal about widget values are to be restored.
bool isEditingMode() const
Definition: ModuleBase_ModelWidget.h:276
virtual void showInformativePage()
If widgets has several panels then this method has to show a page which contains information for curr...
Definition: ModuleBase_ModelWidget.h:322
bool myIsObligatory
Flag which shows whether current widget is obligatory The non-obligatory widgets should not accept th...
Definition: ModuleBase_ModelWidget.h:446
virtual bool isValidSelectionCustom(const std::shared_ptr< ModuleBase_ViewerPrs > &theValue)
Checks if the selection presentation is valid in widget.
Definition: ModuleBase_ModelWidget.h:176
void emitFocusInWidget()
Emit focus in widget to set this control as active in property panel.
Definition: ModuleBase_ModelWidget.h:300
virtual void setEditingMode(bool isEditing)
Editing mode depends on mode of current operation. This value is defined by it.
Definition: ModuleBase_ModelWidget.h:273
virtual QList< QWidget * > getControls() const =0
Returns list of widget controls.
void afterValuesRestored()
The signal about widget values are to be restored.
ValueState myState
The widget value state.
Definition: ModuleBase_ModelWidget.h:452
void afterValuesChanged()
The signal about widget values are to be changed.
void valueStateChanged(int theState)
The signal about value state modification.
bool canUseExternalParts() const
Returns true if the widget should have access to external parts.
Definition: ModuleBase_ModelWidget.h:332
void enterClicked(QObject *theObject)
The signal is emitted if the enter is clicked in the control of the widget.
std::unique_ptr< ModuleBase_WidgetValidator > myWidgetValidator
own validator, by default it is zero
Definition: ModuleBase_ModelWidget.h:433
virtual void updateAfterDeactivation()
Opportunity to do something after the active widget of the property panel changed.
Definition: ModuleBase_ModelWidget.h:207
std::string myAttributeID
The attribute name of the model feature.
Definition: ModuleBase_ModelWidget.h:436
ValueState
State of the widget.
Definition: ModuleBase_ModelWidget.h:64
@ ModifiedInPP
modification is finished and applied to the model
Definition: ModuleBase_ModelWidget.h:65
@ ModifiedInViewer
modification has not been finished and set to the model yet
Definition: ModuleBase_ModelWidget.h:66
virtual QList< ActionInfo > actionsList(ModuleBase_ActionType theActionType) const
Returns list of accessible actions for Undo/Redo commands.
Definition: ModuleBase_ModelWidget.h:289
virtual std::string context() const
Definition: ModuleBase_ModelWidget.h:247
virtual bool isModified() const
Returns True if data of its attribute was modified.
Definition: ModuleBase_ModelWidget.h:325
std::string attributeID() const
Returns the attribute name.
Definition: ModuleBase_ModelWidget.h:235
void beforeValuesChanged()
The signal about widget values are to be changed.
void setAttributeID(const std::string &theAttribute)
Set the attribute name.
Definition: ModuleBase_ModelWidget.h:378
virtual bool isInformative() const
Returns True in case if the widget contains useful information for inspection tool.
Definition: ModuleBase_ModelWidget.h:318
bool isComputedDefault() const
Returns true, if default value of the widget should be computed on operation's execute,...
Definition: ModuleBase_ModelWidget.h:105
ValueState getValueState() const
Returns this widget value state.
Definition: ModuleBase_ModelWidget.h:137
std::string myFeatureId
A feature ID.
Definition: ModuleBase_ModelWidget.h:442
virtual bool canAcceptFocus() const
Defines if it is supported to set the value in this widget By default it returns true.
Definition: ModuleBase_ModelWidget.h:151
virtual void selectContent()
Select the internal content if it can be selected. It is empty in the default realization.
Definition: ModuleBase_ModelWidget.h:198
virtual void getHighlighted(QList< std::shared_ptr< ModuleBase_ViewerPrs > > &theValues)
Returns values which should be highlighted when the whidget is active.
Definition: ModuleBase_ModelWidget.h:171
bool isObligatory() const
Returns true, if the obligatory value of the widget is not defined in the XML or has true value.
Definition: ModuleBase_ModelWidget.h:119
virtual bool storeValueCustom()=0
Saves the internal parameters to the given feature.
virtual bool restoreValueCustom()=0
Restore value from attribute data to the widget's control.
bool isUseReset() const
Returns this parameter value in the xml file.
Definition: ModuleBase_ModelWidget.h:129
ModuleBase_WidgetValidator * widgetValidator()
Returns widget validator, by default it is NULL. To be created in a child if necessary.
Definition: ModuleBase_ModelWidget.h:180
void focusInWidget(ModuleBase_ModelWidget *theWidget)
The signal about the widget is get focus.
virtual bool isViewerSelector()
Defines if it is supposed that the widget should interact with the viewer.
Definition: ModuleBase_ModelWidget.h:147
virtual bool usesAttribute() const
Returns True if the widget uses feature attribute.
Definition: ModuleBase_ModelWidget.h:311
virtual bool needToBeActivated()
The method called if widget should be activated always.
Definition: ModuleBase_ModelWidget.h:212
std::string getDefaultValue() const
Returns true, if default value of the widget is defined in the XML and it is not the computed value.
Definition: ModuleBase_ModelWidget.h:110
virtual void onFeatureAccepted()
It is called when user press Ok or OkPlus buttons in the parent property panel By default this slot d...
Definition: ModuleBase_ModelWidget.h:315
EnableState myIsValueEnabled
Flag about value of the control is enabled (can be modified)
Definition: ModuleBase_ModelWidget.h:449
bool isInternal() const
Returns true, if widget is internal.
Definition: ModuleBase_ModelWidget.h:114
virtual bool setSelection(QList< std::shared_ptr< ModuleBase_ViewerPrs > > &theValues, const bool theToValidate)
Set the given wrapped value to the current widget This value should be processed in the widget accord...
Definition: ModuleBase_ModelWidget.h:163
void objectUpdated()
The signal is emitted after flush of updates singal for the widget.
virtual bool resetCustom()
Fills the widget with default values.
Definition: ModuleBase_ModelWidget.h:407
void focusOutWidget(ModuleBase_ModelWidget *theWidget)
The signal about the widget is lost focus.
virtual void updateAfterActivation()
Opportunity to do something after the active widget of the property panel changed.
Definition: ModuleBase_ModelWidget.h:209
FeaturePtr feature() const
Definition: ModuleBase_ModelWidget.h:241
FeaturePtr myFeature
A feature which is processing by active operation.
Definition: ModuleBase_ModelWidget.h:439
void keyReleased(QObject *theObject, QKeyEvent *theEvent)
The signal about key release on the control, that corresponds to the attribute.
void valuesChanged()
The signal about widget values changed.
std::string isModifiedInEdit() const
Returns this parameter value in the xml file.
Definition: ModuleBase_ModelWidget.h:133
Presentation.
Definition: ModuleBase_ViewerPrs.h:37
Implementation of widget with validators and filters processing.
Definition: ModuleBase_WidgetValidator.h:44