From 641b2ce08d63ddb605f5d0343a5395d05a62bcb9 Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 20 Sep 2018 13:56:35 +0300 Subject: [PATCH] Issue #2643: Extend optional box with possibility to work without frame. Avoid using of Close and Tangency at the same moment. --- src/BuildPlugin/BuildPlugin_Interpolation.cpp | 2 +- src/BuildPlugin/interpolation_widget.xml | 38 ++--- .../ModuleBase_WidgetOptionalBox.cpp | 139 +++++++++++++----- src/ModuleBase/ModuleBase_WidgetOptionalBox.h | 12 +- 4 files changed, 137 insertions(+), 54 deletions(-) diff --git a/src/BuildPlugin/BuildPlugin_Interpolation.cpp b/src/BuildPlugin/BuildPlugin_Interpolation.cpp index bc651c9d6..4af802725 100644 --- a/src/BuildPlugin/BuildPlugin_Interpolation.cpp +++ b/src/BuildPlugin/BuildPlugin_Interpolation.cpp @@ -86,7 +86,7 @@ void BuildPlugin_Interpolation::execute() bool isToReorder = boolean(REORDER_ID())->value(); // Get use tangents flag value - bool isToUseTangents = !string(USE_TANGENTS_ID())->value().empty(); + bool isToUseTangents = isClosed? false : (!string(USE_TANGENTS_ID())->value().empty()); // Get tangent for start and end points GeomDirPtr aDirStart, aDirEnd; diff --git a/src/BuildPlugin/interpolation_widget.xml b/src/BuildPlugin/interpolation_widget.xml index e5d6071ad..eb8e3e138 100644 --- a/src/BuildPlugin/interpolation_widget.xml +++ b/src/BuildPlugin/interpolation_widget.xml @@ -27,25 +27,27 @@ email : webmaster.salome@opencascade.com - - - - - - - - + + + + + + + + + diff --git a/src/ModuleBase/ModuleBase_WidgetOptionalBox.cpp b/src/ModuleBase/ModuleBase_WidgetOptionalBox.cpp index d9d96157c..c035f02c7 100755 --- a/src/ModuleBase/ModuleBase_WidgetOptionalBox.cpp +++ b/src/ModuleBase/ModuleBase_WidgetOptionalBox.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -42,11 +43,19 @@ ModuleBase_WidgetOptionalBox::ModuleBase_WidgetOptionalBox(QWidget* theParent, myCheckBoxLayout(0), myCheckBoxWidget(0), myGroupBox(0), - myGroupBoxLayout(0) + myGroupBoxLayout(0), + myCheckGroup(0), + myCheckGroupLayout(0), + myCheckContent(0), + myCheckGroupBtn(0), + myEnableOnCheck(true) { myToolTip = theData->widgetTooltip(); myGroupTitle = theData->getProperty(CONTAINER_PAGE_NAME); + myHaveFrame = theData->getBooleanAttribute("has_frame", true); + myEnableOnCheck = theData->getBooleanAttribute("enable_on_check", true); + bool isChecked = theData->getBooleanAttribute(ATTR_DEFAULT, false); setDefaultValue(isChecked ? "true" : "false"); @@ -60,14 +69,19 @@ ModuleBase_WidgetOptionalBox::~ModuleBase_WidgetOptionalBox() QWidget* ModuleBase_WidgetOptionalBox::pageWidget() { - return myOptionType == GroupBox ? myGroupBox : (QWidget*)myCheckBoxFrame; + return myOptionType == GroupBox ? (myGroupBox? myGroupBox : myCheckGroup) : + (QWidget*)myCheckBoxFrame; } QList ModuleBase_WidgetOptionalBox::getControls() const { QList aControls; - if (myOptionType == GroupBox) - aControls.append(myGroupBox); + if (myOptionType == GroupBox) { + if (myGroupBox) + aControls.append(myGroupBox); + else + aControls.append(myCheckGroup); + } else aControls.append(myCheckBoxFrame); @@ -129,10 +143,15 @@ void ModuleBase_WidgetOptionalBox::placeWidget(QWidget* theWidget) #endif return; } - const int kCol = 0; - const int kRow = myGroupBoxLayout->count(); - myGroupBoxLayout->addWidget(theWidget, kRow, kCol); - myGroupBoxLayout->setRowStretch(kRow, 0); + if (myGroupBoxLayout) { + const int kCol = 0; + const int kRow = myGroupBoxLayout->count(); + myGroupBoxLayout->addWidget(theWidget, kRow, kCol); + myGroupBoxLayout->setRowStretch(kRow, 0); + } + else { + myCheckGroupLayout->addWidget(theWidget); + } } QLayout* ModuleBase_WidgetOptionalBox::pageLayout() @@ -144,20 +163,38 @@ void ModuleBase_WidgetOptionalBox::createControl(const OptionType& theType) { if (theType == GroupBox && !myGroupBox) { // group box: more than one model widget is inside - myGroupBox = new QGroupBox(this); - myGroupBox->setTitle(translate(myGroupTitle)); - myGroupBox->setVisible(false); - myGroupBox->setCheckable(true); - myGroupBox->setChecked(getDefaultValue() == "true"); - myGroupBox->setToolTip(translate(myToolTip)); - - myGroupBoxLayout = new QGridLayout(myGroupBox); - ModuleBase_Tools::zeroMargins(myGroupBoxLayout); - myGroupBox->setLayout(myGroupBoxLayout); - - // default vertical size policy is preferred - myMainLayout->addWidget(myGroupBox); - connect(myGroupBox, SIGNAL(clicked(bool)), this, SLOT(onPageClicked())); + if (myHaveFrame) { + myGroupBox = new QGroupBox(this); + myGroupBox->setTitle(translate(myGroupTitle)); + myGroupBox->setVisible(false); + myGroupBox->setCheckable(true); + myGroupBox->setChecked(getDefaultValue() == "true"); + myGroupBox->setToolTip(translate(myToolTip)); + + myGroupBoxLayout = new QGridLayout(myGroupBox); + ModuleBase_Tools::zeroMargins(myGroupBoxLayout); + myGroupBox->setLayout(myGroupBoxLayout); + + // default vertical size policy is preferred + myMainLayout->addWidget(myGroupBox); + connect(myGroupBox, SIGNAL(clicked(bool)), this, SLOT(onPageClicked())); + } + else { + myCheckGroup = new QWidget(this); + QVBoxLayout* aLayout = new QVBoxLayout(myCheckGroup); + ModuleBase_Tools::zeroMargins(aLayout); + + myCheckGroupBtn = new QCheckBox(translate(myGroupTitle), myCheckGroup); + aLayout->addWidget(myCheckGroupBtn); + + myCheckContent = new QWidget(myCheckGroup); + myCheckGroupLayout = new QVBoxLayout(myCheckContent); + ModuleBase_Tools::zeroMargins(myCheckGroupLayout); + aLayout->addWidget(myCheckContent); + + myMainLayout->addWidget(myCheckGroup); + connect(myCheckGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onPageClicked())); + } } else if (theType == CheckBox && !myCheckBoxFrame) { myCheckBoxFrame = new QFrame(this); @@ -177,7 +214,12 @@ bool ModuleBase_WidgetOptionalBox::storeValueCustom() { DataPtr aData = myFeature->data(); AttributeStringPtr aStringAttr = aData->string(attributeID()); - aStringAttr->setValue(getCurrentValue() ? attributeID() : ""); + if (aStringAttr.get()) + aStringAttr->setValue(getCurrentValue() ? attributeID() : ""); + else { + AttributeBooleanPtr aBoolAtr = aData->boolean(attributeID()); + aBoolAtr->setValue(getCurrentValue()); + } updateObject(myFeature); @@ -188,8 +230,12 @@ bool ModuleBase_WidgetOptionalBox::restoreValueCustom() { DataPtr aData = myFeature->data(); AttributeStringPtr aStringAttr = aData->string(attributeID()); - setCurrentValue(!aStringAttr->value().empty()); - + if (aStringAttr.get()) + setCurrentValue(!aStringAttr->value().empty()); + else { + AttributeBooleanPtr aBoolAtr = aData->boolean(attributeID()); + setCurrentValue(aBoolAtr->value()); + } return true; } @@ -203,6 +249,8 @@ void ModuleBase_WidgetOptionalBox::setOptionType( myCheckBoxFrame->setVisible(!isGroupBox); if (myGroupBox) myGroupBox->setVisible(isGroupBox); + else if (myCheckContent) + myCheckGroup->setVisible(isGroupBox); } bool ModuleBase_WidgetOptionalBox::isCheckBoxFilled() const @@ -213,16 +261,24 @@ bool ModuleBase_WidgetOptionalBox::isCheckBoxFilled() const bool ModuleBase_WidgetOptionalBox::getCurrentValue() const { bool isGroupBox = myOptionType == GroupBox; - return isGroupBox ? myGroupBox->isChecked() : myCheckBox->isChecked(); + return isGroupBox ? (myGroupBox? myGroupBox->isChecked() : myCheckGroupBtn->isChecked()) : + myCheckBox->isChecked(); } void ModuleBase_WidgetOptionalBox::setCurrentValue(const bool& theValue) { bool isGroupBox = myOptionType == GroupBox; if (isGroupBox) { - bool isBlocked = myGroupBox->blockSignals(true); - myGroupBox->setChecked(theValue); - myGroupBox->blockSignals(isBlocked); + if (myGroupBox) { + bool isBlocked = myGroupBox->blockSignals(true); + myGroupBox->setChecked(theValue); + myGroupBox->blockSignals(isBlocked); + } + else { + bool isBlocked = myCheckGroupBtn->blockSignals(true); + myCheckGroupBtn->setChecked(theValue); + myCheckGroupBtn->blockSignals(isBlocked); + } } else { bool isBlocked = myCheckBox->blockSignals(true); @@ -235,18 +291,33 @@ void ModuleBase_WidgetOptionalBox::setCurrentValue(const bool& theValue) void ModuleBase_WidgetOptionalBox::updateControlsVisibility() { if (myOptionType == GroupBox) { - bool aChecked = myGroupBox->isChecked(); + bool aChecked = toEnableWidgets(); ModuleBase_Tools::adjustMargins(myGroupBoxLayout); - int aNbSubControls = myGroupBoxLayout->count(); + QLayout* aLayout = myGroupBoxLayout ? myGroupBoxLayout : (QLayout*)myCheckGroupLayout; + + int aNbSubControls = aLayout->count(); for (int i = 0; i < aNbSubControls; i++) { - QWidget* aWidget = myGroupBoxLayout->itemAt(i)->widget(); + QWidget* aWidget = aLayout->itemAt(i)->widget(); if (aWidget) aWidget->setEnabled(aChecked); } } else { - bool aChecked = myCheckBox->isChecked(); - myCheckBoxWidget->setEnabled(aChecked); + myCheckBoxWidget->setEnabled(toEnableWidgets()); } } + +bool ModuleBase_WidgetOptionalBox::toEnableWidgets() const +{ + bool aChecked; + if (myOptionType == GroupBox) + aChecked = myGroupBox ? myGroupBox->isChecked() : myCheckGroupBtn->isChecked(); + else + aChecked = myCheckBox->isChecked(); + + if (myEnableOnCheck) + return aChecked; + else + return !aChecked; +} diff --git a/src/ModuleBase/ModuleBase_WidgetOptionalBox.h b/src/ModuleBase/ModuleBase_WidgetOptionalBox.h index 6a04e8033..b2d9fb8a0 100755 --- a/src/ModuleBase/ModuleBase_WidgetOptionalBox.h +++ b/src/ModuleBase/ModuleBase_WidgetOptionalBox.h @@ -113,6 +113,8 @@ private: /// Makes model widget controls either disabled(for check box mode) or hidden(for group box mode) void updateControlsVisibility(); + bool toEnableWidgets() const; + private: std::string myToolTip; ///< tool tip defined in XML std::string myGroupTitle; ///< a title for group box @@ -120,13 +122,21 @@ private: OptionType myOptionType; ///< current option state QVBoxLayout* myMainLayout; ///< the main layout // controls to fill check box frame - QFrame* myCheckBoxFrame; ///< frame with check box, to be hidden when group box is used + QWidget* myCheckBoxFrame; ///< frame with check box, to be hidden when group box is used QCheckBox* myCheckBox; ///< control used if only one model widget is placed inside QHBoxLayout* myCheckBoxLayout; ///< layout of check box frame ModuleBase_ModelWidget* myCheckBoxWidget; /// model widget, placed in the check box frame // controls to fill group box frame QGroupBox* myGroupBox; ///< control used if more than model widget is placed inside QGridLayout* myGroupBoxLayout; ///< page's layout + + QWidget* myCheckGroup; + QCheckBox* myCheckGroupBtn; + QWidget* myCheckContent; + QVBoxLayout* myCheckGroupLayout; + + bool myHaveFrame; + bool myEnableOnCheck; }; #endif /* ModuleBase_WidgetOptionalBox_H_ */ -- 2.39.2