Salome HOME
Merge branch 'master' of salome:modules/shaper
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetFeatureSelector.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_WidgetFeatureSelector.h
4 // Created:     5 Sep 2016
5 // Author:      Natalia Ermolaeva
6
7 #ifndef ModuleBase_WidgetFeatureSelector_H
8 #define ModuleBase_WidgetFeatureSelector_H
9
10 #include "ModuleBase.h"
11 #include "ModuleBase_WidgetSelector.h"
12
13 class Config_WidgetAPI;
14 class QWidget;
15 class QLabel;
16 class QLineEdit;
17
18 /**
19 * \ingroup GUI
20 * Implementation of widget for feature selection.
21 * This type of widget can be defined in XML file with 'feature_selector' keyword.
22 * For example:
23 * \code
24 *   <feature_selector id="main_object" 
25 *    label="Main object" 
26 *    tooltip="Select an object solid"
27 *  />
28 * \endcode
29 * It can use following parameters:
30 * - id - name of object attribute
31 * - label - content of widget's label
32 * - tooltip - the witget's tooltip text
33 */
34 class MODULEBASE_EXPORT ModuleBase_WidgetFeatureSelector : public ModuleBase_WidgetValidated
35 {
36 Q_OBJECT
37  public:
38
39   /// Constructor
40   /// \param theParent the parent object
41   /// \param theWorkshop instance of workshop interface
42   /// \param theData the widget configuation. The attribute of the model widget is obtained from
43   ModuleBase_WidgetFeatureSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
44                                    const Config_WidgetAPI* theData);
45
46   virtual ~ModuleBase_WidgetFeatureSelector();
47
48   /// Set the given wrapped value to the current widget
49   /// This value should be processed in the widget according to the needs
50   /// The method is called by the current operation to process the operation preselection.
51   /// It is redefined to check the value validity and if it is, fill the attribute with by value
52   /// \param theValues the wrapped selection values
53   /// \param theToValidate a flag on validation of the values
54   virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
55                             const bool theToValidate);
56
57   /// Returns list of widget controls
58   /// \return a control list
59   virtual QList<QWidget*> getControls() const;
60
61   /// Fills the attribute with the value of the selected owner
62   /// \param thePrs a selected owner
63   virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
64
65   /// The method called when widget is deactivated
66   virtual void deactivate();
67
68 protected:
69   /// The method called when widget is activated
70   virtual void activateCustom();
71
72   /// Saves the internal parameters to the given feature
73   /// \return True in success
74   virtual bool storeValueCustom();
75
76   virtual bool restoreValueCustom();
77
78   /// Computes and updates name of selected object in the widget
79   virtual void updateSelectionName();
80
81   // Update focus after the attribute value change
82   virtual void updateFocus();
83
84   /// Checks whether all active viewer filters validate the presentation
85   /// \param thePrs a selected presentation in the view
86   /// \return a boolean value
87   virtual bool isValidInFilters(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
88
89   /// Emits model changed info, updates the current control by selection change
90   /// \param theDone a state whether the selection is set
91   virtual void updateOnSelectionChanged(const bool theDone);
92
93 protected slots:
94   /// Called on selection changed event
95   virtual void onSelectionChanged();
96
97   //----------- Class members -------------
98 protected:
99   /// Label of the widget
100   QLabel* myLabel;
101
102   /// Input control of the widget
103   QLineEdit* myTextLine;
104 };
105
106 #endif