Skip to content

Commit 88742b8

Browse files
committed
Add LongJobHelper to the Addons::InsertDot
1 parent 2be40a5 commit 88742b8

3 files changed

Lines changed: 34 additions & 11 deletions

File tree

addons/src/dot/addons-dot.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 translate
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-dot.h"
2631
#include "dotdialog.h" // for DotDialog
@@ -41,11 +46,19 @@ int Addons::doDot(QWidget* parent, QSettings* settings, QString& tx)
4146
dlg->loadSettings(DotOptions());
4247
}
4348

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

53+
LongJobHelper helper{parent};
54+
helper.begin(tx.length(), QCoreApplication::translate("Addons::Actions", "Inserting dots"), 20);
55+
56+
DotOptions opt = dlg->options();
57+
result = Utils::insertDot(tx, opt.axes, opt.convert, opt.divider, [&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/dot/utils-insertdot.cpp

Lines changed: 10 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
*
@@ -26,7 +26,11 @@
2626
#include "utils-insertdot.h"
2727

2828

29-
int Utils::insertDot(QString& tx, const QString& addr, bool convert, int divider)
29+
int Utils::insertDot(QString& tx,
30+
const QString& addr,
31+
bool convert,
32+
int divider,
33+
const std::function<bool (int)>& interrupt)
3034
{
3135
int count = 0;
3236
int pos = 0;
@@ -41,6 +45,10 @@ int Utils::insertDot(QString& tx, const QString& addr, bool convert, int divider
4145
f_tx = match.captured();
4246
pos = match.capturedEnd();
4347

48+
if (interrupt(pos)) {
49+
return count;
50+
}
51+
4452
if (!f_tx.contains(QLatin1Char('(')) && !f_tx.contains(QLatin1Char('\''))
4553
&& !f_tx.contains(QLatin1Char(';'))) {
4654
if (convert && !f_tx.contains(QLatin1Char('.'))) {

addons/src/dot/utils-insertdot.h

Lines changed: 4 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,13 @@
2121
#ifndef UTILS_INSERTDOT_H
2222
#define UTILS_INSERTDOT_H
2323

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

2628

2729
namespace Utils {
28-
int insertDot(QString& tx, const QString& addr, bool convert, int divider);
30+
int insertDot(QString& tx, const QString& addr, bool convert, int divider, const std::function<bool(int)>& interrupt);
2931
}
3032

3133
#endif // UTILS_INSERTDOT_H

0 commit comments

Comments
 (0)