From: vsv Date: Thu, 21 Apr 2016 14:54:35 +0000 (+0300) Subject: Issue #1425: Delete referenced features on deletion of parameter X-Git-Tag: V_2.3.0~148 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b011e1a7a2904d435f243b90b8f7fbaf9ae693ab;p=modules%2Fshaper.git Issue #1425: Delete referenced features on deletion of parameter --- diff --git a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp index c360eddee..183708fdb 100644 --- a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp +++ b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp @@ -281,6 +281,43 @@ void ParametersPlugin_WidgetParamsMgr::activateCustom() } +void ParametersPlugin_WidgetParamsMgr::rebuildFeatures() +{ + myFeatures->takeChildren(); // Clear list + + ResultParameterPtr aParam; + QTreeWidgetItem* aItem; + foreach(FeaturePtr aParameter, myParametersList) { + aParam = std::dynamic_pointer_cast(aParameter->firstResult()); + const std::set>& aRefs = aParam->data()->refsToMe(); + std::set >::const_iterator aIt; + for(aIt = aRefs.cbegin(); aIt != aRefs.cend(); aIt++) { + std::shared_ptr aAttr = (*aIt); + FeaturePtr aReferenced = std::dynamic_pointer_cast(aAttr->owner()); + if (aReferenced.get()) { + QStringList aValNames; + aValNames << aReferenced->data()->name().c_str(); + + AttributeDoublePtr aDouble = std::dynamic_pointer_cast(aAttr); + if (aDouble.get()) { + aValNames << aDouble->text().c_str(); + aValNames << QString::number(aDouble->value()); + } else { + AttributeIntegerPtr aInt = std::dynamic_pointer_cast(aAttr); + if (aInt.get()) { + aValNames << aInt->text().c_str(); + aValNames << QString::number(aInt->value()); + } + } + + aItem = new QTreeWidgetItem(aValNames); + myFeatures->addChild(aItem); + } + } + } +} + + void ParametersPlugin_WidgetParamsMgr::onDoubleClick(const QModelIndex& theIndex) { if (myDelegate->isEditable(theIndex)) { @@ -490,7 +527,23 @@ void ParametersPlugin_WidgetParamsMgr::onRemove() aIndirectRefFeatures, this, doDeleteReferences)) { myParametersList.removeOne(aCurFeature); myParameters->removeChild(aCurrentItem); + + std::set aFeaturesToDelete; + if (doDeleteReferences) { + aFeaturesToDelete = aDirectRefFeatures; + aFeaturesToDelete.insert(aIndirectRefFeatures.begin(), aIndirectRefFeatures.end()); + } aDoc->removeFeature(aCurFeature); + std::set::const_iterator anIt = aFeaturesToDelete.begin(), + aLast = aFeaturesToDelete.end(); + for (; anIt != aLast; anIt++) { + FeaturePtr aFeature = (*anIt); + DocumentPtr aDoc = aFeature->document(); + aDoc->removeFeature(aFeature); + } + + Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)); + rebuildFeatures(); } } diff --git a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h index 1ddd00d48..ff4d5abb0 100644 --- a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h +++ b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h @@ -71,20 +71,34 @@ private slots: /// Slot for reaction on shift down void onDown(); + /// Slot to show message on closing of editor void sendWarning(); + /// Slot for reaction on selection in the table void onSelectionChanged(); private: + /// Creates a new parameter feature FeaturePtr createParameter() const; + + /// Creates a new item QTreeWidgetItem* createNewItem() const; + + /// Returns currently selected item QTreeWidgetItem* selectedItem() const; + + /// Select the given Item and scroll the table to make it visible void selectItemScroll(QTreeWidgetItem* aItem); + /// Update values in features part void updateFeaturesPart(); + /// Returns true if parameter with the given name already exists bool hasName(const QString& theName) const; + /// Clear and rebuild children of Features item + void rebuildFeatures(); + QTreeWidget* myTable; QTreeWidgetItem* myFeatures; QTreeWidgetItem* myParameters;