diff --git a/src/Base/Parameter.cpp b/src/Base/Parameter.cpp index 93344260a5..f81f45f95b 100644 --- a/src/Base/Parameter.cpp +++ b/src/Base/Parameter.cpp @@ -882,7 +882,7 @@ void ParameterGrp::RemoveGrp(const char* Name) // if this or any of its children is referenced by an observer // it cannot be deleted -#if 0 +#if 1 if (!it->second->ShouldRemove()) { it->second->Clear(); } @@ -899,7 +899,7 @@ void ParameterGrp::RemoveGrp(const char* Name) DOMNode* node = _pGroupNode->removeChild(pcElem); node->release(); -#if 0 +#if 1 } #endif @@ -907,6 +907,28 @@ void ParameterGrp::RemoveGrp(const char* Name) Notify(Name); } +bool ParameterGrp::RenameGrp(const char* OldName, const char* NewName) +{ + auto it = _GroupMap.find(OldName); + if (it == _GroupMap.end()) + return false; + auto jt = _GroupMap.find(NewName); + if (jt != _GroupMap.end()) + return false; + + // rename group handle + _GroupMap[NewName] = _GroupMap[OldName]; + _GroupMap.erase(OldName); + _GroupMap[NewName]->_cName = NewName; + + // check if Element in group + DOMElement *pcElem = FindElement(_pGroupNode, "FCParamGroup", OldName); + if (pcElem) + pcElem-> setAttribute(XStr("Name").unicodeForm(), XStr(NewName).unicodeForm()); + + return true; +} + void ParameterGrp::Clear(void) { std::vector vecNodes; diff --git a/src/Base/Parameter.h b/src/Base/Parameter.h index b4e7e61afc..0929be5b63 100644 --- a/src/Base/Parameter.h +++ b/src/Base/Parameter.h @@ -132,6 +132,8 @@ public: typedef Base::Reference handle; /// remove a sub group from this group void RemoveGrp(const char* Name); + /// rename a sub group from this group + bool RenameGrp(const char* OldName, const char* NewName); /// clears everything in this group (all types) void Clear(void); //@} diff --git a/src/Gui/DlgParameterImp.cpp b/src/Gui/DlgParameterImp.cpp index 51fb0438c2..63b5df542f 100644 --- a/src/Gui/DlgParameterImp.cpp +++ b/src/Gui/DlgParameterImp.cpp @@ -984,10 +984,8 @@ void ParameterGroupItem::setData ( int column, int role, const QVariant & value else { // rename the group by adding a new group, copy the content and remove the old group - Base::Reference hOldGrp = item->_hcGrp->GetGroup( oldName.toLatin1() ); - Base::Reference hNewGrp = item->_hcGrp->GetGroup( newName.toLatin1() ); - hOldGrp->copyTo( hNewGrp ); - item->_hcGrp->RemoveGrp( oldName.toLatin1() ); + if (!item->_hcGrp->RenameGrp(oldName.toLatin1(), newName.toLatin1())) + return; } }