]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetCheckGroupBox.cpp
Salome HOME
df32f5b53ea8c09dff7a8d6a24d11c7975443fa2
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetCheckGroupBox.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        ModuleBase_WidgetCheckGroupBox.cpp
4 // Created:     13 Dec 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #include <ModuleBase_WidgetCheckGroupBox.h>
8 #include <ModelAPI_AttributeBoolean.h>
9
10 #include <Config_WidgetAPI.h>
11 #include <Config_Keywords.h>
12
13 #include <QWidget>
14 #include <QGroupBox>
15 #include <QGridLayout>
16 #include <QVBoxLayout>
17
18 #include <QList>
19
20 ModuleBase_WidgetCheckGroupBox::ModuleBase_WidgetCheckGroupBox(QWidget* theParent,
21                                                                const Config_WidgetAPI* theData)
22 : ModuleBase_ModelWidget(theParent, theData),
23   ModuleBase_PageBase()
24 {
25   QString aToolTip = QString::fromStdString(theData->widgetTooltip());
26   bool isChecked = theData->getBooleanAttribute(ATTR_DEFAULT, false);
27
28   QVBoxLayout* aMainLayout = new QVBoxLayout(this);
29   ModuleBase_Tools::zeroMargins(aMainLayout);
30   myGroupBox = new QGroupBox(this);
31   myGroupBox->setCheckable(true);
32   myGroupBox->setToolTip(aToolTip);
33   myGroupBox->setChecked(isChecked);
34
35   myMainLayout = new QGridLayout(myGroupBox);
36   ModuleBase_Tools::adjustMargins(myMainLayout);
37   myGroupBox->setLayout(myMainLayout);
38
39   // default vertical size policy is preferred
40   aMainLayout->addWidget(myGroupBox);
41   connect(myGroupBox, SIGNAL(clicked(bool)), this, SLOT(onPageClicked()));
42 }
43
44 ModuleBase_WidgetCheckGroupBox::~ModuleBase_WidgetCheckGroupBox()
45 {
46 }
47
48 void ModuleBase_WidgetCheckGroupBox::setTitle(const QString& theTitle)
49 {
50   myGroupBox->setTitle(theTitle);
51 }
52
53 QWidget* ModuleBase_WidgetCheckGroupBox::pageWidget()
54 {
55   return myGroupBox;
56 }
57
58 QList<QWidget*> ModuleBase_WidgetCheckGroupBox::getControls() const
59 {
60   QList<QWidget*> aControls;
61   aControls.append(myGroupBox);
62
63   return aControls;
64 }
65
66 void ModuleBase_WidgetCheckGroupBox::onPageClicked()
67 {
68   storeValue();
69 }
70
71 void ModuleBase_WidgetCheckGroupBox::addPageStretch()
72 {
73 }
74
75 void ModuleBase_WidgetCheckGroupBox::placeModelWidget(ModuleBase_ModelWidget* theWidget)
76 {
77   const int kCol = 0;
78   const int kRow = myMainLayout->count();
79   // it seems, that the align on left is not necessary here, but leads to widgets, which are
80   // not extended on full width of the parent page. The case is grouped widgets in
81   // the sketch translation operation
82   myMainLayout->addWidget(theWidget, kRow, kCol, Qt::AlignTop);// | Qt::AlignLeft);
83   myMainLayout->setRowStretch(kRow, 0);
84
85 }
86
87 void ModuleBase_WidgetCheckGroupBox::placePageWidget(ModuleBase_PageBase* theWidget)
88 {
89   QWidget* aWidget = dynamic_cast<QWidget*>(theWidget);
90   if (!aWidget) {
91 #ifdef _DEBUG
92     std::cout << "ModuleBase_PageGroupBox::placePageWidget: can not cast page" << std::endl;
93 #endif
94     return;
95   }
96   const int kCol = 0;
97   const int kRow = myMainLayout->count();
98   myMainLayout->addWidget(aWidget, kRow, kCol);
99   myMainLayout->setRowStretch(kRow, 0);
100 }
101
102 QLayout* ModuleBase_WidgetCheckGroupBox::pageLayout()
103 {
104   return myMainLayout;
105 }
106
107 bool ModuleBase_WidgetCheckGroupBox::storeValueCustom() const
108 {
109   DataPtr aData = myFeature->data();
110   std::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(attributeID());
111   aBool->setValue(myGroupBox->isChecked());
112   updateObject(myFeature);
113
114   return true;
115 }
116
117 bool ModuleBase_WidgetCheckGroupBox::restoreValueCustom()
118 {
119   DataPtr aData = myFeature->data();
120   std::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(attributeID());
121
122   bool isBlocked = myGroupBox->blockSignals(true);
123   myGroupBox->setChecked(aRef->value());
124   myGroupBox->blockSignals(isBlocked);
125
126   return true;
127 }