From 28fdceaccd9babd972972e0926d1009b89f3d52d Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Thu, 8 Feb 2024 18:18:40 +0100 Subject: [PATCH] Preserve object order when moving them Remove and re-insert the selected objects at the specified point in the tree while preserving their relative order. The code used to insert them in reverse order. Closes #12287 --- src/Mod/PartDesign/Gui/CommandBody.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Mod/PartDesign/Gui/CommandBody.cpp b/src/Mod/PartDesign/Gui/CommandBody.cpp index 412a905bca..a8c032837e 100644 --- a/src/Mod/PartDesign/Gui/CommandBody.cpp +++ b/src/Mod/PartDesign/Gui/CommandBody.cpp @@ -897,18 +897,17 @@ void CmdPartDesignMoveFeatureInTree::activated(int iMsg) openCommand(QT_TRANSLATE_NOOP("Command", "Move an object inside tree")); - App::DocumentObject* lastObject = nullptr; + App::DocumentObject* lastObject = target; for ( auto feat: features ) { if ( feat == target ) continue; - // Remove and re-insert the feature to/from the Body + // Remove and re-insert the feature to/from the Body, preserving their order. // TODO: if tip was moved the new position of tip is quite undetermined (2015-08-07, Fat-Zer) // TODO: warn the user if we are moving an object to some place before the object's link (2015-08-07, Fat-Zer) FCMD_OBJ_CMD(body,"removeObject(" << getObjectCmd(feat) << ")"); - FCMD_OBJ_CMD(body,"insertObject(" << getObjectCmd(feat) << ","<< getObjectCmd(target) << ", True)"); + FCMD_OBJ_CMD(body,"insertObject(" << getObjectCmd(feat) << ","<< getObjectCmd(lastObject) << ", True)"); - if (!lastObject) - lastObject = feat; + lastObject = feat; } // Dependency order check. @@ -954,7 +953,7 @@ void CmdPartDesignMoveFeatureInTree::activated(int iMsg) // If the selected objects have been moved after the current tip then ask the // user if they want the last object to be the new tip. // Only do this for features that can hold a tip (not for e.g. datums) - if ( lastObject && body->Tip.getValue() == target + if ( lastObject != target && body->Tip.getValue() == target && lastObject->isDerivedFrom(PartDesign::Feature::getClassTypeId()) ) { QMessageBox msgBox(Gui::getMainWindow()); msgBox.setIcon(QMessageBox::Question);