Skip to content

Commit

Permalink
Gui: open and commit a transaction after renaming an object in the tr…
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Oct 5, 2022
1 parent 7bc3699 commit 3433520
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Gui/Tree.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit 3433520

Please sign in to comment.