Core: Add option to ignore transactions in placement dialog

This commit is contained in:
wmayer
2024-09-05 19:18:20 +02:00
parent bf8b4a7583
commit 8925b2ae4d
2 changed files with 57 additions and 7 deletions

View File

@@ -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<Gui::SelectionObject>& 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<App::DocumentObject*> 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<Gui::SelectionObject>& 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) {