Salome HOME
Better management of errors.
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetOptionalBox.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        ModuleBase_WidgetOptionalBox.h
4 // Created:     13 Dec 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #ifndef ModuleBase_WidgetOptionalBox_H_
8 #define ModuleBase_WidgetOptionalBox_H_
9
10 #include <ModuleBase.h>
11 #include <ModuleBase_PageBase.h>
12 #include <ModuleBase_ModelWidget.h>
13
14 class QGroupBox;
15 class QFrame;
16 class QCheckBox;
17 class QVBoxLayout;
18 class QHBoxLayout;
19 class QGridLayout;
20
21 /**
22 * \ingroup GUI
23 * Implements a model widget for switch as a container widget. It can be defined in XML with "toolbox" keyword
24 */
25 class MODULEBASE_EXPORT ModuleBase_WidgetOptionalBox : public ModuleBase_ModelWidget,
26                                                          public ModuleBase_PageBase
27 {
28   Q_OBJECT
29
30   enum OptionType {CheckBox, GroupBox};
31 public:
32   /// Constructor
33   /// \param theParent the parent object
34   /// \param theData the widget configuration. The attribute of the model widget is obtained from
35   ModuleBase_WidgetOptionalBox(QWidget* theParent, const Config_WidgetAPI* theData);
36   virtual ~ModuleBase_WidgetOptionalBox();
37
38   /// Defines if it is supported to set the value in this widget
39   /// \return false because this is an info widget
40   virtual bool canAcceptFocus() const { return false; };
41
42   /// Methods to be redefined from ModuleBase_PageBase: start
43   /// Cast the page to regular QWidget
44   virtual QWidget* pageWidget();
45   /// Methods to be redefined from ModuleBase_PageBase: end
46
47   /// Methods to be redefined from ModuleBase_ModelWidget: start
48   /// Returns list of widget controls
49   /// \return a control list
50   virtual QList<QWidget*> getControls() const;
51   /// Methods to be redefined from ModuleBase_ModelWidget: end
52
53 protected slots:
54   // store value to the model
55   void onPageClicked();
56
57 protected:
58   /// Methods to be redefined from ModuleBase_PageBase: start
59   /// Adds the given widget to page's layout
60   virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget);
61   /// Adds the given page to page's layout
62   virtual void placeWidget(QWidget* theWidget);
63   /// Returns page's layout (QGridLayout)
64   virtual QLayout* pageLayout();
65   /// Adds a stretch to page's layout
66   virtual void addPageStretch();
67   /// Methods to be redefined from ModuleBase_PageBase: end
68
69
70   /// Methods to be redefined from ModuleBase_ModelWidget: start
71   /// Saves the internal parameters to the given feature
72   /// \return True in success
73   virtual bool storeValueCustom();
74   /// Restore value from attribute data to the widget's control
75   virtual bool restoreValueCustom();
76   /// Methods to be redefined from ModuleBase_ModelWidget: end
77
78 private:
79   /// Sets whether Check box or Group box is used currently
80   /// \param theType a type of the control
81   void setOptionType(const OptionType& theType);
82
83   /// Returns true if the model widget is set into the check box frame
84   /// \return boolean value
85   bool isCheckBoxFilled() const;
86
87   /// Creates controls for the given type if it was not perfomed yet
88   /// \param theType a type to create whether check box or group box controls
89   void createControl(const OptionType& theType);
90
91   /// Returns true if control is checked
92   /// \return boolean value
93   bool getCurrentValue() const;
94
95   /// Returns true if control is checked
96   /// \param theValue a new value to fill the control state
97   void setCurrentValue(const bool& theValue);
98
99   /// Makes model widget controls either disabled(for check box mode) or hidden(for group box mode)
100   void updateControlsVisibility();
101
102 private:
103   std::string myToolTip; ///< tool tip defined in XML
104   std::string myGroupTitle; ///< a title for group box
105
106   OptionType myOptionType; ///< current option state
107   QVBoxLayout* myMainLayout; ///< the main layout
108   // controls to fill check box frame
109   QFrame* myCheckBoxFrame; ///< frame with check box, to be hidden when group box is used
110   QCheckBox* myCheckBox; ///< control used if only one model widget is placed inside
111   QHBoxLayout* myCheckBoxLayout; ///< layout of check box frame
112   ModuleBase_ModelWidget* myCheckBoxWidget; /// model widget, placed in the check box frame
113   // controls to fill group box frame
114   QGroupBox* myGroupBox; ///< control used if more than model widget is placed inside
115   QGridLayout* myGroupBoxLayout; ///< page's layout
116 };
117
118 #endif /* ModuleBase_WidgetOptionalBox_H_ */