Salome HOME
SketchShapePlugin: checked group box/multi editor controls, which highlight the paren...
[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                                                                const std::string& theParentId)
23 : ModuleBase_ModelWidget(theParent, theData, theParentId),
24   ModuleBase_PageBase()
25 {
26   QString aToolTip = QString::fromStdString(theData->widgetTooltip());
27   bool isChecked = theData->getBooleanAttribute(ATTR_DEFAULT, false);
28
29   QVBoxLayout* aMainLayout = new QVBoxLayout(this);
30   ModuleBase_Tools::zeroMargins(aMainLayout);
31   myGroupBox = new QGroupBox(this);
32   myGroupBox->setCheckable(true);
33   myGroupBox->setToolTip(aToolTip);
34   myGroupBox->setChecked(isChecked);
35
36   myMainLayout = new QGridLayout(myGroupBox);
37   ModuleBase_Tools::adjustMargins(myMainLayout);
38   myGroupBox->setLayout(myMainLayout);
39
40   // default vertical size policy is preferred
41   aMainLayout->addWidget(myGroupBox);
42   connect(myGroupBox, SIGNAL(clicked(bool)), this, SLOT(onPageClicked()));
43 }
44
45 ModuleBase_WidgetCheckGroupBox::~ModuleBase_WidgetCheckGroupBox()
46 {
47 }
48
49 void ModuleBase_WidgetCheckGroupBox::setTitle(const QString& theTitle)
50 {
51   myGroupBox->setTitle(theTitle);
52 }
53
54 QWidget* ModuleBase_WidgetCheckGroupBox::pageWidget()
55 {
56   return myGroupBox;
57 }
58
59 QList<QWidget*> ModuleBase_WidgetCheckGroupBox::getControls() const
60 {
61   QList<QWidget*> aControls;
62   aControls.append(myGroupBox);
63
64   return aControls;
65 }
66
67 void ModuleBase_WidgetCheckGroupBox::onPageClicked()
68 {
69   storeValue();
70 }
71
72 void ModuleBase_WidgetCheckGroupBox::addPageStretch()
73 {
74 }
75
76 void ModuleBase_WidgetCheckGroupBox::placeModelWidget(ModuleBase_ModelWidget* theWidget)
77 {
78   const int kCol = 0;
79   const int kRow = myMainLayout->count();
80   // it seems, that the align on left is not necessary here, but leads to widgets, which are
81   // not extended on full width of the parent page. The case is grouped widgets in
82   // the sketch translation operation
83   myMainLayout->addWidget(theWidget, kRow, kCol, Qt::AlignTop);// | Qt::AlignLeft);
84   myMainLayout->setRowStretch(kRow, 0);
85
86 }
87
88 void ModuleBase_WidgetCheckGroupBox::placePageWidget(ModuleBase_PageBase* theWidget)
89 {
90   QWidget* aWidget = dynamic_cast<QWidget*>(theWidget);
91   if (!aWidget) {
92 #ifdef _DEBUG
93     std::cout << "ModuleBase_PageGroupBox::placePageWidget: can not cast page" << std::endl;
94 #endif
95     return;
96   }
97   const int kCol = 0;
98   const int kRow = myMainLayout->count();
99   myMainLayout->addWidget(aWidget, kRow, kCol);
100   myMainLayout->setRowStretch(kRow, 0);
101 }
102
103 QLayout* ModuleBase_WidgetCheckGroupBox::pageLayout()
104 {
105   return myMainLayout;
106 }
107
108 bool ModuleBase_WidgetCheckGroupBox::storeValueCustom() const
109 {
110   DataPtr aData = myFeature->data();
111   std::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(attributeID());
112   aBool->setValue(myGroupBox->isChecked());
113   updateObject(myFeature);
114
115   return true;
116 }
117
118 bool ModuleBase_WidgetCheckGroupBox::restoreValueCustom()
119 {
120   DataPtr aData = myFeature->data();
121   std::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(attributeID());
122
123   bool isBlocked = myGroupBox->blockSignals(true);
124   myGroupBox->setChecked(aRef->value());
125   myGroupBox->blockSignals(isBlocked);
126
127   return true;
128 }