1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef ModuleBase_WidgetOptionalBox_H_
22 #define ModuleBase_WidgetOptionalBox_H_
24 #include <ModuleBase.h>
25 #include <ModuleBase_PageBase.h>
26 #include <ModuleBase_ModelWidget.h>
37 * Implements a model widget for switch as a container widget. It can be defined in XML with "toolbox" keyword
39 class MODULEBASE_EXPORT ModuleBase_WidgetOptionalBox : public ModuleBase_ModelWidget,
40 public ModuleBase_PageBase
44 enum OptionType {CheckBox, GroupBox};
47 /// \param theParent the parent object
48 /// \param theData the widget configuration. The attribute of the model widget is obtained from
49 ModuleBase_WidgetOptionalBox(QWidget* theParent, const Config_WidgetAPI* theData);
50 virtual ~ModuleBase_WidgetOptionalBox();
52 /// Defines if it is supported to set the value in this widget
53 /// \return false because this is an info widget
54 virtual bool canAcceptFocus() const { return false; };
56 /// Methods to be redefined from ModuleBase_PageBase: start
57 /// Cast the page to regular QWidget
58 virtual QWidget* pageWidget();
59 /// Methods to be redefined from ModuleBase_PageBase: end
61 /// Methods to be redefined from ModuleBase_ModelWidget: start
62 /// Returns list of widget controls
63 /// \return a control list
64 virtual QList<QWidget*> getControls() const;
65 /// Methods to be redefined from ModuleBase_ModelWidget: end
68 // store value to the model
72 /// Methods to be redefined from ModuleBase_PageBase: start
73 /// Adds the given widget to page's layout
74 virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget);
75 /// Adds the given page to page's layout
76 virtual void placeWidget(QWidget* theWidget);
77 /// Returns page's layout (QGridLayout)
78 virtual QLayout* pageLayout();
79 /// Adds a stretch to page's layout
80 virtual void addPageStretch();
81 /// Methods to be redefined from ModuleBase_PageBase: end
84 /// Methods to be redefined from ModuleBase_ModelWidget: start
85 /// Saves the internal parameters to the given feature
86 /// \return True in success
87 virtual bool storeValueCustom();
88 /// Restore value from attribute data to the widget's control
89 virtual bool restoreValueCustom();
90 /// Methods to be redefined from ModuleBase_ModelWidget: end
93 /// Sets whether Check box or Group box is used currently
94 /// \param theType a type of the control
95 void setOptionType(const OptionType& theType);
97 /// Returns true if the model widget is set into the check box frame
98 /// \return boolean value
99 bool isCheckBoxFilled() const;
101 /// Creates controls for the given type if it was not perfomed yet
102 /// \param theType a type to create whether check box or group box controls
103 void createControl(const OptionType& theType);
105 /// Returns true if control is checked
106 /// \return boolean value
107 bool getCurrentValue() const;
109 /// Returns true if control is checked
110 /// \param theValue a new value to fill the control state
111 void setCurrentValue(const bool& theValue);
113 /// Makes model widget controls either disabled(for check box mode) or hidden(for group box mode)
114 void updateControlsVisibility();
117 std::string myToolTip; ///< tool tip defined in XML
118 std::string myGroupTitle; ///< a title for group box
120 OptionType myOptionType; ///< current option state
121 QVBoxLayout* myMainLayout; ///< the main layout
122 // controls to fill check box frame
123 QFrame* myCheckBoxFrame; ///< frame with check box, to be hidden when group box is used
124 QCheckBox* myCheckBox; ///< control used if only one model widget is placed inside
125 QHBoxLayout* myCheckBoxLayout; ///< layout of check box frame
126 ModuleBase_ModelWidget* myCheckBoxWidget; /// model widget, placed in the check box frame
127 // controls to fill group box frame
128 QGroupBox* myGroupBox; ///< control used if more than model widget is placed inside
129 QGridLayout* myGroupBoxLayout; ///< page's layout
132 #endif /* ModuleBase_WidgetOptionalBox_H_ */