Salome HOME
Temporary comment (somehow inform the user about the scale of the view: line lenght...
[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_AttributeString.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::placeWidget(QWidget* theWidget)
88 {
89   if (!theWidget) {
90 #ifdef _DEBUG
91     std::cout << "ModuleBase_PageGroupBox::placePageWidget: can not cast page" << std::endl;
92 #endif
93     return;
94   }
95   const int kCol = 0;
96   const int kRow = myMainLayout->count();
97   myMainLayout->addWidget(theWidget, kRow, kCol);
98   myMainLayout->setRowStretch(kRow, 0);
99 }
100
101 QLayout* ModuleBase_WidgetCheckGroupBox::pageLayout()
102 {
103   return myMainLayout;
104 }
105
106 bool ModuleBase_WidgetCheckGroupBox::storeValueCustom()
107 {
108   DataPtr aData = myFeature->data();
109   AttributeStringPtr aStringAttr = aData->string(attributeID());
110   aStringAttr->setValue(myGroupBox->isChecked() ? attributeID() : "");
111
112   updateObject(myFeature);
113
114   return true;
115 }
116
117 bool ModuleBase_WidgetCheckGroupBox::restoreValueCustom()
118 {
119   DataPtr aData = myFeature->data();
120   AttributeStringPtr aStringAttr = aData->string(attributeID());
121
122   bool isBlocked = myGroupBox->blockSignals(true);
123   myGroupBox->setChecked(!aStringAttr->value().empty());
124   myGroupBox->blockSignals(isBlocked);
125
126   return true;
127 }