From 06fa64a00d72f8a930a23dd08a997f555cc17e91 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 10 Nov 2018 14:50:58 +0100 Subject: [PATCH] add method to check if an open transaction is empty This is needed to avoid to incorrectly abort a transaction if a recompute was done between opening and closing an editor in the property view --- src/App/Document.cpp | 9 +++++++++ src/App/Document.h | 3 +++ src/App/Transactions.cpp | 5 +++++ src/App/Transactions.h | 2 ++ src/Gui/propertyeditor/PropertyEditor.cpp | 7 +++++-- 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 9278e0e077..51269d7d5c 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -1029,6 +1029,15 @@ bool Document::hasPendingTransaction() const return false; } +bool Document::isTransactionEmpty() const +{ + if (d->activeUndoTransaction) { + return d->activeUndoTransaction->isEmpty(); + } + + return true; +} + void Document::clearUndos() { if (d->activeUndoTransaction) diff --git a/src/App/Document.h b/src/App/Document.h index e570cc5c85..6c046bb119 100644 --- a/src/App/Document.h +++ b/src/App/Document.h @@ -303,6 +303,9 @@ public: void abortTransaction(); /// Check if a transaction is open bool hasPendingTransaction() const; + /// Check if a transaction is open and its list is empty. + /// If no transaction is open true is returned. + bool isTransactionEmpty() const; /// Set the Undo limit in Byte! void setUndoLimit(unsigned int UndoMemSize=0); /// Returns the actual memory consumption of the Undo redo stuff. diff --git a/src/App/Transactions.cpp b/src/App/Transactions.cpp index 232189d734..d147a8fcff 100644 --- a/src/App/Transactions.cpp +++ b/src/App/Transactions.cpp @@ -110,6 +110,11 @@ void Transaction::Restore(Base::XMLReader &/*reader*/) assert(0); } +bool Transaction::isEmpty() const +{ + return _Objects.empty(); +} + int Transaction::getPos(void) const { return iPos; diff --git a/src/App/Transactions.h b/src/App/Transactions.h index 71165e8457..e8b9ef97ce 100644 --- a/src/App/Transactions.h +++ b/src/App/Transactions.h @@ -62,6 +62,8 @@ public: /// This method is used to restore properties from an XML document. virtual void Restore(Base::XMLReader &reader); + /// Returns true if the transaction list is empty; otherwise returns false. + bool isEmpty() const; /// get the position in the transaction history int getPos(void) const; /// check if this object is used in a transaction diff --git a/src/Gui/propertyeditor/PropertyEditor.cpp b/src/Gui/propertyeditor/PropertyEditor.cpp index 4f029c895a..b0204d0d5a 100644 --- a/src/Gui/propertyeditor/PropertyEditor.cpp +++ b/src/Gui/propertyeditor/PropertyEditor.cpp @@ -104,9 +104,12 @@ void PropertyEditor::closeEditor (QWidget * editor, QAbstractItemDelegate::EndEd if (autoupdate) { App::Document* doc = App::GetApplication().getActiveDocument(); if (doc) { - if (doc->isTouched()) { + if (!doc->isTransactionEmpty()) { doc->commitTransaction(); - doc->recompute(); + // Between opening and committing a transaction a recompute + // could already have been done + if (doc->isTouched()) + doc->recompute(); } else { doc->abortTransaction();