Skip to content

Commit 238d6b8

Browse files
committed
Add LongJobHelper to the Addons::I2MProg
1 parent 2e8e640 commit 238d6b8

3 files changed

Lines changed: 36 additions & 11 deletions

File tree

addons/src/i2mprog/addons-i2mprog.cpp

Lines changed: 20 additions & 7 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,9 +18,14 @@
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
2020

21-
#include <QDialog> // for QDialog
22-
#include <QString> // for QString
23-
#include <QWidget> // for QWidget
21+
#include <functional> // for function
22+
23+
#include <QCoreApplication> // for QCoreApplication
24+
#include <QDialog> // for QDialog
25+
#include <QString> // for QString
26+
#include <QWidget> // for QWidget
27+
28+
#include <ui/longjobhelper.h> // for LongJobHelper, LongJobHelper::CANCEL
2429

2530
#include "addons-i2mprog.h"
2631
#include "i2mprogdialog.h" // for I2MProgDialog
@@ -41,11 +46,19 @@ int Addons::doI2MProg(QWidget* parent, QSettings* settings, QString& tx)
4146
dlg->loadSettings(I2MProgOptions());
4247
}
4348

44-
if (dlg->exec() == QDialog::Accepted) {
45-
I2MProgOptions opt = dlg->options();
46-
result = Utils::i2mprog(tx, opt.axes, opt.toInch, opt.prec);
49+
if (dlg->exec() != QDialog::Accepted) {
50+
return 0;
4751
}
4852

53+
LongJobHelper helper{parent};
54+
helper.begin(tx.length(), QCoreApplication::translate("Addons::Actions", "Converting inch to metric"), 20);
55+
56+
I2MProgOptions opt = dlg->options();
57+
result = Utils::i2mprog(tx, opt.axes, opt.toInch, opt.prec, [&helper](int pos) -> bool{
58+
return helper.check(pos) == LongJobHelper::CANCEL;
59+
});
60+
61+
helper.end();
4962
dlg->deleteLater();
5063
return result;
5164
}

addons/src/i2mprog/utils-i2mprog.cpp

Lines changed: 9 additions & 2 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
*
@@ -25,7 +25,10 @@
2525
#include "utils-i2mprog.h"
2626

2727

28-
int Utils::i2mprog(QString tx, const QString& addr, bool toInch, int prec)
28+
int Utils::i2mprog(QString tx,
29+
const QString& addr,
30+
bool toInch, int prec,
31+
const std::function<bool (int)>& interrupt)
2932
{
3033
int count = 0;
3134
QRegularExpression regex;
@@ -38,6 +41,10 @@ int Utils::i2mprog(QString tx, const QString& addr, bool toInch, int prec)
3841
while (match.hasMatch()) {
3942
int pos = match.capturedEnd();
4043

44+
if (interrupt(pos)) {
45+
return count;
46+
}
47+
4148
if (match.capturedLength(1) > 0) {
4249
QString f_tx = match.captured(1);
4350
bool ok;

addons/src/i2mprog/utils-i2mprog.h

Lines changed: 7 additions & 2 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
*
@@ -21,11 +21,16 @@
2121
#ifndef UTILS_I2M_H
2222
#define UTILS_I2M_H
2323

24+
#include <functional> // for function
25+
2426
class QString;
2527

2628

2729
namespace Utils {
28-
int i2mprog(QString tx, const QString& addr, bool toInch, int prec);
30+
int i2mprog(QString tx,
31+
const QString& addr,
32+
bool toInch, int prec,
33+
const std::function<bool(int)>& interrupt);
2934
}
3035

3136
#endif // UTILS_I2M_H

0 commit comments

Comments
 (0)