Salome HOME
db9719b807f4d3351301edee79b6920eeb5cffee
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetValidator.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_WidgetValidator.h
4 // Created:     12 Mar 2015
5 // Author:      Natalia ERMOLAEVA
6
7
8 #ifndef ModuleBase_WidgetValidator_H_
9 #define ModuleBase_WidgetValidator_H_
10
11 #include <ModuleBase.h>
12
13 #include <QList>
14 #include <memory>
15
16 class ModuleBase_ModelWidget;
17 class ModuleBase_IWorkshop;
18 class ModuleBase_ViewerPrs;
19
20 /**
21 * \ingroup GUI
22 * Implementation of widget with validators and filters processing.
23 */
24 class MODULEBASE_EXPORT ModuleBase_WidgetValidator
25 {
26  public:
27   /// Constructor
28   /// \param theModelWidget the model widget to be validated
29   /// \param theWorkshop the current workshop
30   ModuleBase_WidgetValidator(ModuleBase_ModelWidget* theModelWidget,
31                              ModuleBase_IWorkshop* theWorkshop);
32   virtual ~ModuleBase_WidgetValidator();
33
34   /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating,
35   /// next, the attribute's validating. It trying on the give selection to current attribute by
36   /// setting the value inside and calling validators. After this, the previous attribute value is
37   /// restored.The valid/invalid value is cashed.
38   /// \param theValue a selected presentation in the view
39   /// \return a boolean value
40   virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
41
42   /// It obtains selection filters from the workshop and activates them in the active viewer
43   /// \param toActivate a flag about activation or deactivation the filters
44   /// \return true if the selection filter of the widget is activated in viewer context
45   bool activateFilters(const bool toActivate);
46
47 private:
48   /// Returns true if the workshop validator filter has been already activated
49   /// \return boolean value
50   bool isFilterActivated() const;
51
52   //! Clear all validated cash in the widget
53   void clearValidatedCash();
54
55   /// Gets the validity state of the presentation in an internal map. Returns true if the valid state of value is stored
56   /// \param theValue a viewer presentation
57   /// \param theValid a valid state
58   bool getValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, bool& theValid);
59
60   /// Store the validity state of the presentation in an internal map
61   /// \param theValue a viewer presentation
62   /// \param theValid a valid state
63   void storeValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, const bool theValid);
64
65 protected:
66   /// Reference to workshop
67   ModuleBase_ModelWidget* myModelWidget; ///< the current widget to be validated
68   ModuleBase_IWorkshop* myWorkshop; ///< the active workshop
69
70   QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs; ///< cash of valid selection presentations
71   QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs; ///< cash of invalid selection presentations
72 };
73
74 #endif /* ModuleBase_WidgetValidator_H_ */