From 74eb35164d4241a3dd3280badbc2fe2fd99990f2 Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 12 Jul 2016 15:51:29 +0300 Subject: [PATCH] #1658 New widget supporting nested option buttons --- .../ModuleBase_WidgetCheckGroupBox.cpp | 24 ++++++++++++++++++- .../ModuleBase_WidgetCheckGroupBox.h | 5 ++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.cpp b/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.cpp index 05b0fc43f..a2bf7d60e 100755 --- a/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.cpp +++ b/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.cpp @@ -24,16 +24,18 @@ ModuleBase_WidgetCheckGroupBox::ModuleBase_WidgetCheckGroupBox(QWidget* theParen { QString aToolTip = QString::fromStdString(theData->widgetTooltip()); bool isChecked = theData->getBooleanAttribute(ATTR_DEFAULT, false); + setDefaultValue(isChecked ? "true" : "false"); QVBoxLayout* aMainLayout = new QVBoxLayout(this); ModuleBase_Tools::zeroMargins(aMainLayout); + aMainLayout->setMargin(2); myGroupBox = new QGroupBox(this); myGroupBox->setCheckable(true); myGroupBox->setToolTip(aToolTip); myGroupBox->setChecked(isChecked); myMainLayout = new QGridLayout(myGroupBox); - ModuleBase_Tools::adjustMargins(myMainLayout); + ModuleBase_Tools::zeroMargins(myMainLayout); myGroupBox->setLayout(myMainLayout); // default vertical size policy is preferred @@ -66,6 +68,7 @@ QList ModuleBase_WidgetCheckGroupBox::getControls() const void ModuleBase_WidgetCheckGroupBox::onPageClicked() { storeValue(); + updatePagesVisibility(); } void ModuleBase_WidgetCheckGroupBox::addPageStretch() @@ -82,6 +85,7 @@ void ModuleBase_WidgetCheckGroupBox::placeModelWidget(ModuleBase_ModelWidget* th myMainLayout->addWidget(theWidget, kRow, kCol, Qt::AlignTop);// | Qt::AlignLeft); myMainLayout->setRowStretch(kRow, 0); + theWidget->setVisible(myGroupBox->isChecked()); } void ModuleBase_WidgetCheckGroupBox::placeWidget(QWidget* theWidget) @@ -121,7 +125,25 @@ bool ModuleBase_WidgetCheckGroupBox::restoreValueCustom() bool isBlocked = myGroupBox->blockSignals(true); myGroupBox->setChecked(!aStringAttr->value().empty()); + updatePagesVisibility(); myGroupBox->blockSignals(isBlocked); return true; } + +void ModuleBase_WidgetCheckGroupBox::updatePagesVisibility() +{ + bool aVisible = myGroupBox->isChecked(); + + if (aVisible) + ModuleBase_Tools::zeroMargins(myMainLayout); + else + ModuleBase_Tools::adjustMargins(myMainLayout); + + int aNbSubControls = myMainLayout->count(); + for (int i = 0; i < aNbSubControls; i++) { + QWidget* aWidget = myMainLayout->itemAt(i)->widget(); + if (aWidget) + aWidget->setVisible(aVisible); + } +} diff --git a/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.h b/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.h index 4e0dd3983..5cf821eef 100755 --- a/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.h +++ b/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.h @@ -73,6 +73,11 @@ protected: virtual bool restoreValueCustom(); /// Methods to be redefined from ModuleBase_ModelWidget: end +private: + /// Makes the children page of the group box visible if the checked state is on + /// otherwise, make the sub-pages is not visible. + void updatePagesVisibility(); + private: QGroupBox* myGroupBox; QGridLayout* myMainLayout; ///< page's layout -- 2.39.2