1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef ModuleBase_WidgetOptionalBox_H_
21 #define ModuleBase_WidgetOptionalBox_H_
23 #include <ModuleBase.h>
24 #include <ModuleBase_PageBase.h>
25 #include <ModuleBase_ModelWidget.h>
36 * Implements a model widget for switch as a container widget. It can be defined in XML with "toolbox" keyword
38 class MODULEBASE_EXPORT ModuleBase_WidgetOptionalBox : public ModuleBase_ModelWidget,
39 public ModuleBase_PageBase
43 enum OptionType {CheckBox, GroupBox};
46 /// \param theParent the parent object
47 /// \param theData the widget configuration. The attribute of the model widget is obtained from
48 ModuleBase_WidgetOptionalBox(QWidget* theParent, const Config_WidgetAPI* theData);
49 virtual ~ModuleBase_WidgetOptionalBox();
51 /// Defines if it is supported to set the value in this widget
52 /// \return false because this is an info widget
53 virtual bool canAcceptFocus() const { return false; };
55 /// Methods to be redefined from ModuleBase_PageBase: start
56 /// Cast the page to regular QWidget
57 virtual QWidget* pageWidget();
58 /// Methods to be redefined from ModuleBase_PageBase: end
60 /// Methods to be redefined from ModuleBase_ModelWidget: start
61 /// Returns list of widget controls
62 /// \return a control list
63 virtual QList<QWidget*> getControls() const;
64 /// Methods to be redefined from ModuleBase_ModelWidget: end
67 // store value to the model
71 /// Methods to be redefined from ModuleBase_PageBase: start
72 /// Adds the given widget to page's layout
73 virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget);
74 /// Adds the given page to page's layout
75 virtual void placeWidget(QWidget* theWidget);
76 /// Returns page's layout (QGridLayout)
77 virtual QLayout* pageLayout();
78 /// Adds a stretch to page's layout
79 virtual void addPageStretch();
80 /// Methods to be redefined from ModuleBase_PageBase: end
83 /// Methods to be redefined from ModuleBase_ModelWidget: start
84 /// Saves the internal parameters to the given feature
85 /// \return True in success
86 virtual bool storeValueCustom();
87 /// Restore value from attribute data to the widget's control
88 virtual bool restoreValueCustom();
89 /// Methods to be redefined from ModuleBase_ModelWidget: end
92 /// Sets whether Check box or Group box is used currently
93 /// \param theType a type of the control
94 void setOptionType(const OptionType& theType);
96 /// Returns true if the model widget is set into the check box frame
97 /// \return boolean value
98 bool isCheckBoxFilled() const;
100 /// Creates controls for the given type if it was not perfomed yet
101 /// \param theType a type to create whether check box or group box controls
102 void createControl(const OptionType& theType);
104 /// Returns true if control is checked
105 /// \return boolean value
106 bool getCurrentValue() const;
108 /// Returns true if control is checked
109 /// \param theValue a new value to fill the control state
110 void setCurrentValue(const bool& theValue);
112 /// Makes model widget controls either disabled(for check box mode) or hidden(for group box mode)
113 void updateControlsVisibility();
115 bool toEnableWidgets() const;
118 std::string myToolTip; ///< tool tip defined in XML
119 std::string myGroupTitle; ///< a title for group box
121 OptionType myOptionType; ///< current option state
122 QVBoxLayout* myMainLayout; ///< the main layout
123 // controls to fill check box frame
124 QWidget* myCheckBoxFrame; ///< frame with check box, to be hidden when group box is used
125 QCheckBox* myCheckBox; ///< control used if only one model widget is placed inside
126 QHBoxLayout* myCheckBoxLayout; ///< layout of check box frame
127 ModuleBase_ModelWidget* myCheckBoxWidget; /// model widget, placed in the check box frame
128 // controls to fill group box frame
129 QGroupBox* myGroupBox; ///< control used if more than model widget is placed inside
130 QGridLayout* myGroupBoxLayout; ///< page's layout
132 QWidget* myCheckGroup;
133 QCheckBox* myCheckGroupBtn;
134 QWidget* myCheckContent;
135 QVBoxLayout* myCheckGroupLayout;
138 bool myEnableOnCheck;
141 #endif /* ModuleBase_WidgetOptionalBox_H_ */