1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: ModuleBase_WidgetCheckGroupBox.cpp
4 // Created: 13 Dec 2015
5 // Author: Natalia ERMOLAEVA
7 #include <ModuleBase_WidgetCheckGroupBox.h>
8 #include <ModelAPI_AttributeBoolean.h>
10 #include <Config_WidgetAPI.h>
11 #include <Config_Keywords.h>
15 #include <QGridLayout>
16 #include <QVBoxLayout>
20 ModuleBase_WidgetCheckGroupBox::ModuleBase_WidgetCheckGroupBox(QWidget* theParent,
21 const Config_WidgetAPI* theData,
22 const std::string& theParentId)
23 : ModuleBase_ModelWidget(theParent, theData, theParentId),
26 QString aToolTip = QString::fromStdString(theData->widgetTooltip());
27 bool isChecked = theData->getBooleanAttribute(ATTR_DEFAULT, false);
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);
36 myMainLayout = new QGridLayout(myGroupBox);
37 ModuleBase_Tools::adjustMargins(myMainLayout);
38 myGroupBox->setLayout(myMainLayout);
40 // default vertical size policy is preferred
41 aMainLayout->addWidget(myGroupBox);
42 connect(myGroupBox, SIGNAL(clicked(bool)), this, SLOT(onPageClicked()));
45 ModuleBase_WidgetCheckGroupBox::~ModuleBase_WidgetCheckGroupBox()
49 void ModuleBase_WidgetCheckGroupBox::setTitle(const QString& theTitle)
51 myGroupBox->setTitle(theTitle);
54 QWidget* ModuleBase_WidgetCheckGroupBox::pageWidget()
59 QList<QWidget*> ModuleBase_WidgetCheckGroupBox::getControls() const
61 QList<QWidget*> aControls;
62 aControls.append(myGroupBox);
67 void ModuleBase_WidgetCheckGroupBox::onPageClicked()
72 void ModuleBase_WidgetCheckGroupBox::addPageStretch()
76 void ModuleBase_WidgetCheckGroupBox::placeModelWidget(ModuleBase_ModelWidget* theWidget)
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);
88 void ModuleBase_WidgetCheckGroupBox::placePageWidget(ModuleBase_PageBase* theWidget)
90 QWidget* aWidget = dynamic_cast<QWidget*>(theWidget);
93 std::cout << "ModuleBase_PageGroupBox::placePageWidget: can not cast page" << std::endl;
98 const int kRow = myMainLayout->count();
99 myMainLayout->addWidget(aWidget, kRow, kCol);
100 myMainLayout->setRowStretch(kRow, 0);
103 QLayout* ModuleBase_WidgetCheckGroupBox::pageLayout()
108 bool ModuleBase_WidgetCheckGroupBox::storeValueCustom() const
110 DataPtr aData = myFeature->data();
111 std::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(attributeID());
112 aBool->setValue(myGroupBox->isChecked());
113 updateObject(myFeature);
118 bool ModuleBase_WidgetCheckGroupBox::restoreValueCustom()
120 DataPtr aData = myFeature->data();
121 std::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(attributeID());
123 bool isBlocked = myGroupBox->blockSignals(true);
124 myGroupBox->setChecked(aRef->value());
125 myGroupBox->blockSignals(isBlocked);