Salome HOME
updated copyright message
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetFeatureSelector.h
1 // Copyright (C) 2014-2023  CEA/DEN, EDF R&D
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_WidgetFeatureSelector_H
21 #define ModuleBase_WidgetFeatureSelector_H
22
23 #include "ModuleBase.h"
24 #include "ModuleBase_WidgetSelector.h"
25
26 class Config_WidgetAPI;
27 class QWidget;
28 class QLabel;
29 class QLineEdit;
30
31 /**
32 * \ingroup GUI
33 * Implementation of widget for feature selection.
34 * This type of widget can be defined in XML file with 'feature_selector' keyword.
35 * For example:
36 * \code
37 *   <feature_selector id="main_object" 
38 *    label="Main object" 
39 *    tooltip="Select an object solid"
40 *  />
41 * \endcode
42 * It can use following parameters:
43 * - id - name of object attribute
44 * - label - content of widget's label
45 * - tooltip - the witget's tooltip text
46 */
47 class MODULEBASE_EXPORT ModuleBase_WidgetFeatureSelector : public ModuleBase_WidgetValidated
48 {
49 Q_OBJECT
50  public:
51
52   /// Constructor
53   /// \param theParent the parent object
54   /// \param theWorkshop instance of workshop interface
55   /// \param theData the widget configuation. The attribute of the model widget is obtained from
56   ModuleBase_WidgetFeatureSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
57                                    const Config_WidgetAPI* theData);
58
59   virtual ~ModuleBase_WidgetFeatureSelector();
60
61   /// Set the given wrapped value to the current widget
62   /// This value should be processed in the widget according to the needs
63   /// The method is called by the current operation to process the operation preselection.
64   /// It is redefined to check the value validity and if it is, fill the attribute with by value
65   /// \param theValues the wrapped selection values
66   /// \param theToValidate a flag on validation of the values
67   virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
68                             const bool theToValidate);
69
70   /// Fills given container with selection modes if the widget has it
71   /// \param [out] theModuleSelectionModes module additional modes, -1 means all default modes
72   /// \param theModes [out] a container of modes
73   virtual void selectionModes(int& theModuleSelectionModes, QIntList& theModes);
74
75   /// Returns list of widget controls
76   /// \return a control list
77   virtual QList<QWidget*> getControls() const;
78
79   /// Fills the attribute with the value of the selected owner
80   /// \param thePrs a selected owner
81   virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
82
83 protected:
84   /// The method called when widget is activated
85   virtual void activateCustom();
86
87   /// Saves the internal parameters to the given feature
88   /// \return True in success
89   virtual bool storeValueCustom();
90
91   virtual bool restoreValueCustom();
92
93   /// Computes and updates name of selected object in the widget
94   virtual void updateSelectionName();
95
96   // Update focus after the attribute value change
97   virtual void updateFocus();
98
99   /// Checks whether all active viewer filters validate the presentation
100   /// \param thePrs a selected presentation in the view
101   /// \return a boolean value
102   virtual bool isValidInFilters(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
103
104   /// Emits model changed info, updates the current control by selection change
105   /// \param theDone a state whether the selection is set
106   virtual void updateOnSelectionChanged(const bool theDone);
107
108 protected:
109   /// Returns true if envent is processed.
110   virtual bool processSelection();
111
112   //----------- Class members -------------
113 protected:
114   /// Label of the widget
115   QLabel* myLabel;
116
117   /// Input control of the widget
118   QLineEdit* myTextLine;
119 };
120
121 #endif