1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_WidgetValidator.h
4 // Created: 12 Mar 2015
5 // Author: Natalia ERMOLAEVA
8 #ifndef ModuleBase_WidgetValidator_H_
9 #define ModuleBase_WidgetValidator_H_
11 #include <ModuleBase.h>
16 class ModelAPI_Attribute;
18 class ModuleBase_ModelWidget;
19 class ModuleBase_IWorkshop;
20 class ModuleBase_ViewerPrs;
21 class ModuleBase_WidgetSelectorStore;
25 * Implementation of widget with validators and filters processing.
27 class MODULEBASE_EXPORT ModuleBase_WidgetValidator
31 /// \param theModelWidget the model widget to be validated
32 /// \param theWorkshop the current workshop
33 ModuleBase_WidgetValidator(ModuleBase_ModelWidget* theModelWidget,
34 ModuleBase_IWorkshop* theWorkshop);
35 virtual ~ModuleBase_WidgetValidator();
37 /// Returns true if the validation is activated
38 bool isInValidate() const { return myIsInValidate; }
40 /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating,
41 /// next, the attribute's validating. It trying on the give selection to current attribute by
42 /// setting the value inside and calling validators. After this, the previous attribute value is
43 /// restored.The valid/invalid value is cashed.
44 /// \param theValue a selected presentation in the view
45 /// \return a boolean value
46 virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
48 /// It obtains selection filters from the workshop and activates them in the active viewer
49 /// \param toActivate a flag about activation or deactivation the filters
50 /// \return true if the selection filter of the widget is activated in viewer context
51 bool activateFilters(const bool toActivate);
53 /// Creates a backup of the current values of the attribute
54 /// It should be realized in the specific widget because of different
55 /// parameters of the current attribute
56 /// \param theAttribute an attribute to be stored
57 virtual void storeAttributeValue(const std::shared_ptr<ModelAPI_Attribute>& theAttribute);
59 /// Creates a backup of the current values of the attribute
60 /// It should be realized in the specific widget because of different
61 /// parameters of the current attribute
62 /// \param theAttribute an attribute to be restored
63 /// \param theValid a boolean flag, if restore happens for valid parameters
64 virtual void restoreAttributeValue(const std::shared_ptr<ModelAPI_Attribute>& theAttribute,
67 /// Checks the current attibute in all attribute validators
68 /// \param theAttribute an attribute to be validated
69 /// \return true if all validators return that the attribute is valid
70 bool isValidAttribute(const std::shared_ptr<ModelAPI_Attribute>& theAttribute) const;
73 /// Returns true if the workshop validator filter has been already activated
74 /// \return boolean value
75 bool isFilterActivated() const;
77 //! Clear all validated cash in the widget
78 void clearValidatedCash();
80 /// Gets the validity state of the presentation in an internal map.
81 /// Returns true if the valid state of value is stored
82 /// \param theValue a viewer presentation
83 /// \param theValid a valid state
84 bool getValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, bool& theValid);
86 /// Store the validity state of the presentation in an internal map
87 /// \param theValue a viewer presentation
88 /// \param theValid a valid state
89 void storeValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, const bool theValid);
92 bool myIsInValidate; ///< cashed if the value is processed in validation
93 /// Reference to workshop
94 ModuleBase_ModelWidget* myModelWidget; ///< the current widget to be validated
95 ModuleBase_IWorkshop* myWorkshop; ///< the active workshop
96 ModuleBase_WidgetSelectorStore* myAttributeStore; //< store/restore attribute values
98 /// cash of valid selection presentations
99 QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs;
101 /// cash of invalid selection presentations
102 QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs;
105 #endif /* ModuleBase_WidgetValidator_H_ */