From bcc630bf2fafca72ff0e41ab9e6d6f6b9da30467 Mon Sep 17 00:00:00 2001 From: vsv Date: Fri, 22 Apr 2016 15:33:16 +0300 Subject: [PATCH] Issue #1437: provide update of parameters table part on editing of any parameter --- .../ParametersPlugin_WidgetParamsMgr.cpp | 76 +++++++++++-------- .../ParametersPlugin_WidgetParamsMgr.h | 7 +- 2 files changed, 52 insertions(+), 31 deletions(-) diff --git a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp index 81a06e84f..45c10175d 100644 --- a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp +++ b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp @@ -223,38 +223,31 @@ void ParametersPlugin_WidgetParamsMgr::activateCustom() DocumentPtr aDoc = aFeature->document(); int aNbParam = aDoc->size(ModelAPI_ResultParameter::group()); ObjectPtr aObj; - QTreeWidgetItem* aItem; - ResultParameterPtr aParam; FeaturePtr aParamFeature; for (int i = 0; i < aNbParam; i++) { aObj = aDoc->object(ModelAPI_ResultParameter::group(), i); - aParam = std::dynamic_pointer_cast(aObj); - if (aParam.get()) { - // Set parameter feature - aParamFeature = ModelAPI_Feature::feature(aParam); - - QStringList aValues; - aValues << aParamFeature->string(ParametersPlugin_Parameter::VARIABLE_ID())->value().c_str(); - aValues << aParamFeature->string(ParametersPlugin_Parameter::EXPRESSION_ID())->value().c_str(); - - AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE()); - aValues << QString::number(aValueAttribute->value()); - - aValues << aParamFeature->string(ParametersPlugin_Parameter::COMMENT_ID())->value().c_str(); - - aItem = new QTreeWidgetItem(aValues); - aItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled); - myParameters->addChild(aItem); - + aParamFeature = ModelAPI_Feature::feature(aObj); + if (aParamFeature.get() && (aParamFeature->getKind() == ParametersPlugin_Parameter::ID())) { myParametersList.append(aParamFeature); } } + updateParametersPart(); updateFeaturesPart(); myFeatures->setExpanded(true); myParameters->setExpanded(true); } +void ParametersPlugin_WidgetParamsMgr::updateFeaturesPart() +{ + updateItem(myFeatures, featuresItems(myParametersList)); +} + +void ParametersPlugin_WidgetParamsMgr::updateParametersPart() +{ + updateItem(myParameters, parametersItems(myParametersList)); +} + QList ParametersPlugin_WidgetParamsMgr:: featuresItems(const QList& theFeatures) const @@ -299,6 +292,26 @@ QList ParametersPlugin_WidgetParamsMgr:: } +QList ParametersPlugin_WidgetParamsMgr:: + parametersItems(const QList& theFeatures) const +{ + QList aItemsList; + foreach(FeaturePtr aParameter, theFeatures) { + ResultPtr aParam = aParameter->firstResult(); + QStringList aValues; + aValues << aParameter->string(ParametersPlugin_Parameter::VARIABLE_ID())->value().c_str(); + aValues << aParameter->string(ParametersPlugin_Parameter::EXPRESSION_ID())->value().c_str(); + + AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE()); + aValues << QString::number(aValueAttribute->value()); + + aValues << aParameter->string(ParametersPlugin_Parameter::COMMENT_ID())->value().c_str(); + aItemsList.append(aValues); + } + return aItemsList; +} + + void ParametersPlugin_WidgetParamsMgr::onDoubleClick(const QModelIndex& theIndex) { if (myDelegate->isEditable(theIndex)) { @@ -369,26 +382,29 @@ void ParametersPlugin_WidgetParamsMgr::onCloseEditor(QWidget* theEditor, aItem->setText(Col_Result, QString::number(aValueAttribute->value())); } myEditingIndex = QModelIndex(); + + if (aColumn == Col_Equation) + updateParametersPart(); updateFeaturesPart(); } -void ParametersPlugin_WidgetParamsMgr::updateFeaturesPart() +void ParametersPlugin_WidgetParamsMgr::updateItem(QTreeWidgetItem* theItem, + const QList& theFeaturesList) { - QList aFeaturesList = featuresItems(myParametersList); - if (aFeaturesList.count() != myFeatures->childCount()) { - if (myFeatures->childCount() < aFeaturesList.count()) { - while (myFeatures->childCount() != aFeaturesList.count()) - myFeatures->addChild(new QTreeWidgetItem()); + if (theFeaturesList.count() != theItem->childCount()) { + if (theItem->childCount() < theFeaturesList.count()) { + while (theItem->childCount() != theFeaturesList.count()) + theItem->addChild(createNewItem()); } else { - while (myFeatures->childCount() != aFeaturesList.count()) - myFeatures->removeChild(myFeatures->child(myFeatures->childCount() - 1)); + while (theItem->childCount() != theFeaturesList.count()) + theItem->removeChild(theItem->child(theItem->childCount() - 1)); } } int i = 0; - foreach(QStringList aFeature, aFeaturesList) { + foreach(QStringList aFeature, theFeaturesList) { int aCol = 0; foreach(QString aText, aFeature) { - myFeatures->child(i)->setText(aCol, aText); + theItem->child(i)->setText(aCol, aText); aCol++; } i++; diff --git a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h index 9f9fda3b0..f722402af 100644 --- a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h +++ b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h @@ -88,15 +88,20 @@ private: QTreeWidgetItem* selectedItem() const; /// Select the given Item and scroll the table to make it visible - void selectItemScroll(QTreeWidgetItem* aItem); + void selectItemScroll(QTreeWidgetItem* theItem); /// Update values in features part + void updateItem(QTreeWidgetItem* theItem, const QList& theFeaturesList); + void updateFeaturesPart(); + void updateParametersPart(); + /// Returns true if parameter with the given name already exists bool hasName(const QString& theName) const; QList featuresItems(const QList& theFeatures) const; + QList parametersItems(const QList& theFeatures) const; QTreeWidget* myTable; QTreeWidgetItem* myFeatures; -- 2.39.2