From 3433520a7475b0270f7428d0265aa77c2416af6c Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 5 Oct 2022 11:45:18 +0200 Subject: [PATCH] Gui: open and commit a transaction after renaming an object in the tree view For more details see: https://forum.freecadweb.org/viewtopic.php?f=3&t=72351 --- src/Gui/Tree.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index d53735e35474..98ab70a754bc 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -4884,10 +4884,17 @@ void DocumentObjectItem::setData(int column, int role, const QVariant& value) if (role == Qt::EditRole && column <= 1) { auto obj = object()->getObject(); auto& label = column ? obj->Label2 : obj->Label; - std::ostringstream ss; - ss << "Change " << getName() << '.' << label.getName(); - App::AutoTransaction committer(ss.str().c_str()); - label.setValue((const char*)value.toString().toUtf8()); + + std::ostringstream str; + str << TreeWidget::tr("Rename").toStdString() << ' ' << getName() << '.' << label.getName(); + + // Explicitly open and commit a transaction since this is a single change here + // For more details: https://forum.freecadweb.org/viewtopic.php?f=3&t=72351 + App::Document* doc = obj->getDocument(); + doc->openTransaction(str.str().c_str()); + label.setValue(value.toString().toUtf8().constData()); + doc->commitTransaction(); + myValue = QString::fromUtf8(label.getValue()); } QTreeWidgetItem::setData(column, role, myValue);