From 8925b2ae4d6200ab3483c70f5f73e558f91324fd Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 5 Sep 2024 19:18:20 +0200 Subject: [PATCH] Core: Add option to ignore transactions in placement dialog --- src/Gui/Placement.cpp | 54 +++++++++++++++++++++++++++++++++++++------ src/Gui/Placement.h | 10 ++++++++ 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/src/Gui/Placement.cpp b/src/Gui/Placement.cpp index 72f1b1064e..896b0ff410 100644 --- a/src/Gui/Placement.cpp +++ b/src/Gui/Placement.cpp @@ -104,6 +104,7 @@ public: PlacementHandler::PlacementHandler() : propertyName{"Placement"} , changeProperty{false} + , ignoreTransaction{false} { setupDocument(); } @@ -123,6 +124,11 @@ void PlacementHandler::setPropertyName(const std::string& name) changeProperty = (propertyName != "Placement"); } +void PlacementHandler::setIgnoreTransactions(bool value) +{ + ignoreTransaction = value; +} + void PlacementHandler::setSelection(const std::vector& selection) { selectionObjects = selection; @@ -185,7 +191,7 @@ void PlacementHandler::revertTransformation() revertTransformationOfViewProviders(document); } else { - document->abortCommand(); + abortCommandIfActive(document); } } } @@ -288,19 +294,18 @@ void PlacementHandler::applyPlacement(const QString& data, bool incremental) // When directly changing the property we now only have to commit the transaction, // do a recompute and open a new transaction if (changeProperty) { - document->commitCommand(); + commitCommandIfActive(document); tryRecompute(document); - document->openCommand(QT_TRANSLATE_NOOP("Command", "Placement")); + openCommandIfActive(document); } else { std::vector sel = getSelectedObjects(document); if (!sel.empty()) { - document->openCommand(QT_TRANSLATE_NOOP("Command", "Placement")); + openCommandIfActive(document); for (const auto & it : sel) { applyPlacement(it, data, incremental); } - - document->commitCommand(); + commitCommandIfActive(document); tryRecompute(document); } else { @@ -417,6 +422,27 @@ void PlacementHandler::slotActiveDocument(const Gui::Document& doc) activatedDocument(doc.getDocument()->getName()); } +void PlacementHandler::openCommandIfActive(Gui::Document* doc) +{ + if (!ignoreTransaction) { + doc->openCommand(QT_TRANSLATE_NOOP("Command", "Placement")); + } +} + +void PlacementHandler::commitCommandIfActive(Gui::Document* doc) +{ + if (!ignoreTransaction) { + doc->commitCommand(); + } +} + +void PlacementHandler::abortCommandIfActive(Gui::Document* doc) +{ + if (!ignoreTransaction) { + doc->abortCommand(); + } +} + // ---------------------------------------------------------------------------- /* TRANSLATOR Gui::Dialog::Placement */ @@ -839,11 +865,16 @@ void Placement::setSelection(const std::vector& selection) handler.setSelection(selection); } -void Placement::setPropertyName(const std::string& name) +void Placement::setPropertyName(const std::string& name) { handler.setPropertyName(name); } +void Placement::setIgnoreTransactions(bool value) +{ + handler.setIgnoreTransactions(value); +} + /*! * \brief Placement::bindObject * Binds the spin boxes to the placement components of the first object of the selection. @@ -1172,6 +1203,7 @@ void TaskPlacementPy::init_type() add_varargs_method("setSelection",&TaskPlacementPy::setSelection,"setSelection(list)"); add_varargs_method("bindObject",&TaskPlacementPy::bindObject,"bindObject()"); + add_varargs_method("setIgnoreTransactions",&TaskPlacementPy::setIgnoreTransactions, "setIgnoreTransactions(bool)"); add_varargs_method("showDefaultButtons",&TaskPlacementPy::showDefaultButtons, "showDefaultButtons(bool)"); add_varargs_method("accept",&TaskPlacementPy::accept,"accept()"); add_varargs_method("reject",&TaskPlacementPy::reject,"reject()"); @@ -1282,6 +1314,14 @@ Py::Object TaskPlacementPy::bindObject(const Py::Tuple& args) return Py::None(); } +Py::Object TaskPlacementPy::setIgnoreTransactions(const Py::Tuple& args) +{ + if (widget) { + widget->setIgnoreTransactions(Py::Boolean(args[0])); + } + return Py::None(); +} + Py::Object TaskPlacementPy::showDefaultButtons(const Py::Tuple& args) { if (widget) { diff --git a/src/Gui/Placement.h b/src/Gui/Placement.h index 66fcf7ac3b..0d99302b6e 100644 --- a/src/Gui/Placement.h +++ b/src/Gui/Placement.h @@ -51,6 +51,7 @@ public: PlacementHandler(); void openTransactionIfNeeded(); void setPropertyName(const std::string&); + void setIgnoreTransactions(bool value); void setSelection(const std::vector&); void reselectObjects(); const App::DocumentObject* getFirstOfSelection() const; @@ -78,6 +79,9 @@ private: QString getSimplePlacement(App::DocumentObject*, const QString&) const; void setupDocument(); void slotActiveDocument(const Gui::Document&); + void openCommandIfActive(Gui::Document*); + void commitCommandIfActive(Gui::Document*); + void abortCommandIfActive(Gui::Document*); private Q_SLOTS: void openTransaction(); @@ -90,6 +94,10 @@ private: * otherwise change the placement property. */ bool changeProperty; + /** If true do not open or commit transactions. In this case it's expected + * that it's done by the calling instance. + */ + bool ignoreTransaction; Connection connectAct; /** * store these so we can reselect original object @@ -114,6 +122,7 @@ public: void setPropertyName(const std::string&); void setSelection(const std::vector&); void bindObject(); + void setIgnoreTransactions(bool value); Base::Vector3d getDirection() const; void setPlacement(const Base::Placement&); Base::Placement getPlacement() const; @@ -229,6 +238,7 @@ public: Py::Object setPlacement(const Py::Tuple&); Py::Object setSelection(const Py::Tuple&); Py::Object bindObject(const Py::Tuple&); + Py::Object setIgnoreTransactions(const Py::Tuple&); Py::Object showDefaultButtons(const Py::Tuple&); Py::Object accept(const Py::Tuple&);