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