Salome HOME
912a1985897e122e89031fe58070c12dea1246da
[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. 
56   /// Returns true if the valid state of value is stored
57   /// \param theValue a viewer presentation
58   /// \param theValid a valid state
59   bool getValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, bool& theValid);
60
61   /// Store the validity state of the presentation in an internal map
62   /// \param theValue a viewer presentation
63   /// \param theValid a valid state
64   void storeValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, const bool theValid);
65
66 protected:
67   /// Reference to workshop
68   ModuleBase_ModelWidget* myModelWidget; ///< the current widget to be validated
69   ModuleBase_IWorkshop* myWorkshop; ///< the active workshop
70
71   /// cash of valid selection presentations
72   QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs; 
73   
74   /// cash of invalid selection presentations
75   QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs; 
76 };
77
78 #endif /* ModuleBase_WidgetValidator_H_ */