Skip to content

Commit b478174

Browse files
committed
Add LongJobHelper to the Addons::SwapAxes
1 parent f23b6a5 commit b478174

6 files changed

Lines changed: 130 additions & 229 deletions

File tree

addons/src/addons-actions.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,11 +464,13 @@ void Addons::Actions::doSwapAxes()
464464
{
465465
Addons::Context ctx;
466466

467-
if (!ctx.pull(Addons::Context::ALL)) {
467+
if (!ctx.pull(Addons::Context::SELECTED_OR_ALL)) {
468468
return;
469469
}
470470

471-
Addons::doSwapAxes(GCodeWorkShop::instance(), Medium::instance().settings(), ctx.textEdit());
471+
if (Addons::doSwapAxes(GCodeWorkShop::instance(), Medium::instance().settings(), ctx.text())) {
472+
ctx.push();
473+
}
472474
}
473475

474476
void Addons::Actions::doTriangle()

addons/src/swapaxes/addons-swapaxes.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (C) 2006-2018 by Artur Kozioł, artkoz78@gmail.com
3-
* Copyright (C) 2023 Nick Egorrov, nicegorov@yandex.ru
3+
* Copyright (C) 2023-2025 Nick Egorrov, nicegorov@yandex.ru
44
*
55
* This file is part of GCodeWorkShop.
66
*
@@ -18,19 +18,22 @@
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
2020

21+
#include <functional> // for function
22+
2123
#include <QDialog> // for QDialog, QDialog::Accepted
2224
#include <QString> // for QString
2325
#include <QWidget> // for QWidget
2426

27+
#include <ui/longjobhelper.h> // for LongJobHelper, LongJobHelper::CANCEL
28+
2529
#include "addons-swapaxes.h"
2630
#include "swapaxesdialog.h" // for SwapAxesDialog
2731
#include "swapaxesoptions.h" // for SwapAxesOptions
2832
#include "utils-swapaxes.h" // for swapAxes, COMMENT_ID_UNKNOWN
2933

3034

31-
int Addons::doSwapAxes(QWidget* parent, QSettings* settings, QPlainTextEdit* textEdit)
35+
bool Addons::doSwapAxes(QWidget* parent, QSettings* settings, QString& text)
3236
{
33-
int result = 0;
3437
QString key = "SwapAxesDialog";
3538
SwapAxesDialog* dlg;
3639
dlg = parent->findChild<SwapAxesDialog*>(key);
@@ -41,10 +44,19 @@ int Addons::doSwapAxes(QWidget* parent, QSettings* settings, QPlainTextEdit* tex
4144
dlg->loadSettings(SwapAxesOptions());
4245
}
4346

44-
if (dlg->exec() == QDialog::Accepted) {
45-
Utils::swapAxes(textEdit, false, 40000, COMMENT_ID_UNKNOWN, dlg->options());
47+
if (dlg->exec() != QDialog::Accepted) {
48+
return false;
4649
}
4750

51+
52+
LongJobHelper helper{parent};
53+
helper.begin(text.length(), QCoreApplication::translate("Addons::Actions", "Axis exchange"), 20);
54+
55+
bool changed = Utils::swapAxes(text, dlg->options(), [&helper](int pos) -> bool{
56+
return helper.check(pos) == LongJobHelper::CANCEL;
57+
});
58+
59+
helper.end();
4860
dlg->deleteLater();
49-
return result;
61+
return changed;
5062
}

addons/src/swapaxes/addons-swapaxes.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2023 Nick Egorrov, nicegorov@yandex.ru
2+
* Copyright (C) 2023-2025 Nick Egorrov, nicegorov@yandex.ru
33
*
44
* This file is part of GCodeWorkShop.
55
*
@@ -20,13 +20,13 @@
2020
#ifndef ADDONS_SWAPAXES_H
2121
#define ADDONS_SWAPAXES_H
2222

23-
class QPlainTextEdit;
2423
class QSettings;
24+
class QString;
2525
class QWidget;
2626

2727

2828
namespace Addons {
29-
int doSwapAxes(QWidget* parent, QSettings* settings, QPlainTextEdit* textEdit);
29+
bool doSwapAxes(QWidget* parent, QSettings* settings, QString& text);
3030
}
3131

3232
#endif // ADDONS_SWAPAXES_H

addons/src/swapaxes/swapaxesoptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct SwapAxesOptions {
4141
} limit;
4242

4343
enum Operation {
44+
Nop = -1,
4445
Add,
4546
Subtract,
4647
Multiply,

0 commit comments

Comments
 (0)