X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetChoice.cpp;h=5e5520bb6e274dfbfb2f42abcecd67c0a133de67;hb=50a8df0c6a66da8067b16155e5ae39f8f26a7ebc;hp=c259ed3247a00f3f87783b59bb5e973b5a62f654;hpb=dc7d4d86b58b81684abc9b5a2be8ec30f210c2da;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetChoice.cpp b/src/ModuleBase/ModuleBase_WidgetChoice.cpp index c259ed324..5e5520bb6 100644 --- a/src/ModuleBase/ModuleBase_WidgetChoice.cpp +++ b/src/ModuleBase/ModuleBase_WidgetChoice.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2020 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,10 +12,9 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "ModuleBase_WidgetChoice.h" @@ -32,16 +31,23 @@ #include #include #include -#include #include #include #include #include +static QMap defaultValues; + ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent, const Config_WidgetAPI* theData) -: ModuleBase_ModelWidget(theParent, theData)//, myCombo(0), myButtons(0) +: ModuleBase_ModelWidget(theParent, theData), myIsFirst(true) { + myHasValue = defaultValues.contains(myFeatureId + attributeID()); + if (myHasValue) + myDefValue = defaultValues[myFeatureId + attributeID()]; + else + myDefValue = 0; + QString aLabelText = translate(theData->widgetLabel()); QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); std::string aTypes = theData->getProperty("string_list"); @@ -70,7 +76,8 @@ ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent, QHBoxLayout* aLayout = new QHBoxLayout(this); myChoiceCtrl = new ModuleBase_ChoiceCtrl(this, aList, aIconList, - (aWgtType == "radiobuttons")? ModuleBase_ChoiceCtrl::RadioButtons : ModuleBase_ChoiceCtrl::ComboBox, + (aWgtType == "radiobuttons")? ModuleBase_ChoiceCtrl::RadioButtons : + ModuleBase_ChoiceCtrl::ComboBox, (aWgtDir == "horizontal")? Qt::Horizontal : Qt::Vertical); myChoiceCtrl->setLabel(aLabelText); @@ -93,7 +100,16 @@ bool ModuleBase_WidgetChoice::storeValueCustom() DataPtr aData = myFeature->data(); std::shared_ptr aIntAttr = aData->integer(attributeID()); - aIntAttr->setValue(myChoiceCtrl->value()); + int aCase = 0; + if (myIsFirst) + aCase = myHasValue? myDefValue : myChoiceCtrl->value(); + else + aCase = myChoiceCtrl->value(); + + aIntAttr->setValue(aCase); + myDefValue = aCase; + myIsFirst = false; + updateObject(myFeature); return true; } @@ -115,15 +131,24 @@ bool ModuleBase_WidgetChoice::restoreValueCustom() myChoiceCtrl->setChoiceList(aChoiceList); } } - if (aIntAttr->isInitialized()) + if (aIntAttr->isInitialized()) { myChoiceCtrl->setValue(aIntAttr->value()); + + myChoiceCtrl->blockSignals(isBlocked); + emit itemSelected(this, aIntAttr->value()); + myDefValue = aIntAttr->value(); + } else { bool aHasDefaultValue; int aDefaultVal = QString::fromStdString(getDefaultValue()).toInt(&aHasDefaultValue); - myChoiceCtrl->setValue(aHasDefaultValue ? aDefaultVal : 0); + int aVal = aHasDefaultValue ? aDefaultVal : 0; + myChoiceCtrl->setValue(aVal); + + myChoiceCtrl->blockSignals(isBlocked); + emit itemSelected(this, aVal); + myDefValue = aVal; } - myChoiceCtrl->blockSignals(isBlocked); - emit itemSelected(this, aIntAttr->value()); + myIsFirst = false; } return true; } @@ -154,3 +179,8 @@ void ModuleBase_WidgetChoice::onCurrentIndexChanged(int theIndex) emit itemSelected(this, theIndex); } + +void ModuleBase_WidgetChoice::onFeatureAccepted() +{ + defaultValues[myFeatureId + attributeID()] = myDefValue; +}