From: vsv Date: Thu, 28 Apr 2016 16:03:41 +0000 (+0300) Subject: Issue #1424: Make impossible to create non-valid parameters more the a one X-Git-Tag: V_2.3.0~71 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=561ec84c4405975d78d8cd7d50c5bfa6dba8d738;p=modules%2Fshaper.git Issue #1424: Make impossible to create non-valid parameters more the a one --- diff --git a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp index d511c6636..524e92710 100644 --- a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp +++ b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp @@ -282,6 +282,8 @@ void ParametersPlugin_WidgetParamsMgr::updateFeaturesPart() void ParametersPlugin_WidgetParamsMgr::updateParametersPart() { updateItem(myParameters, parametersItems(myParametersList)); + bool aIsValid = checkIsValid(); + enableButtons(aIsValid); } @@ -339,15 +341,15 @@ QList ParametersPlugin_WidgetParamsMgr:: QStringList aValues; std::string aName = aParameter->string(ParametersPlugin_Parameter::VARIABLE_ID())->value(); - if (aName.empty()) + if (aName.empty()) { aValues << NoName; - else + } else aValues << aName.c_str(); std::string aExpr = aParameter->string(ParametersPlugin_Parameter::EXPRESSION_ID())->value(); - if (aName.empty()) + if (aName.empty()) { aValues << NoValue; - else + } else aValues << aExpr.c_str(); std::string aErr = aParameter->data()->string(ParametersPlugin_Parameter::EXPRESSION_ERROR_ID())->value(); @@ -495,6 +497,8 @@ void ParametersPlugin_WidgetParamsMgr::onAdd() myTable->scrollToItem(aItem); myTable->setCurrentItem(aItem); myTable->editItem(aItem); + + enableButtons(false); } QTreeWidgetItem* ParametersPlugin_WidgetParamsMgr::selectedItem() const @@ -666,17 +670,52 @@ void ParametersPlugin_WidgetParamsMgr::sendWarning() void ParametersPlugin_WidgetParamsMgr::onSelectionChanged() { - QList aItemsList = myTable->selectedItems(); - bool isParameter = false; - foreach(QTreeWidgetItem* aItem, aItemsList) { - if (aItem->parent() == myParameters) { - isParameter = true; + bool isValid = checkIsValid(); + if (isValid) { + QList aItemsList = myTable->selectedItems(); + bool isParameter = false; + foreach(QTreeWidgetItem* aItem, aItemsList) { + if (aItem->parent() == myParameters) { + isParameter = true; + break; + } + } + myInsertBtn->setEnabled(isParameter); + myRemoveBtn->setEnabled(isParameter); + myUpBtn->setEnabled(isParameter); + myDownBtn->setEnabled(isParameter); + } else { + myInsertBtn->setEnabled(false); + myRemoveBtn->setEnabled(false); + myUpBtn->setEnabled(false); + myDownBtn->setEnabled(false); + } +} + +void ParametersPlugin_WidgetParamsMgr::enableButtons(bool theEnable) +{ + myAddBtn->setEnabled(theEnable); + if (theEnable) + onSelectionChanged(); + else { + myInsertBtn->setEnabled(theEnable); + myRemoveBtn->setEnabled(theEnable); + myUpBtn->setEnabled(theEnable); + myDownBtn->setEnabled(theEnable); + } +} + +bool ParametersPlugin_WidgetParamsMgr::checkIsValid() +{ + QTreeWidgetItem* aItem; + bool aIsValid = true; + for(int i = 0; i < myParameters->childCount(); i++) { + aItem = myParameters->child(i); + if ((aItem->text(Col_Name) == NoName) || (aItem->text(Col_Equation) == NoValue)) { + aIsValid = false; break; } } - myInsertBtn->setEnabled(isParameter); - myRemoveBtn->setEnabled(isParameter); - myUpBtn->setEnabled(isParameter); - myDownBtn->setEnabled(isParameter); + return aIsValid; } diff --git a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h index 5780c4b55..7f2b493eb 100644 --- a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h +++ b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h @@ -113,6 +113,11 @@ private: /// Returns true if parameter with the given name already exists bool hasName(const QString& theName) const; + /// Enable or disable buttons for parameters managemnt + void enableButtons(bool theEnable); + + bool checkIsValid(); + QList featuresItems(const QList& theFeatures) const; QList parametersItems(const QList& theFeatures) const;