Fix calling GUI methods from script thread

This commit is contained in:
2024-06-08 20:11:25 +02:00
parent 461ffea874
commit 66f0c05a48
5 changed files with 60 additions and 21 deletions
+29
View File
@@ -14,6 +14,7 @@
#include <QCloseEvent>
#include <QDBusConnection>
#include <QDBusMessage>
#include <QInputDialog>
#include <QMessageBox>
#endif
@@ -235,3 +236,31 @@ void BatchProcessing::newMessage(const QString &message, bool error)
else _ui->log->setTextColor(_textColor);
_ui->log->append(message);
}
QJSValue BatchProcessing::getString(const QString &label, const QString &text)
{
bool ok = false;
QString ret = QInputDialog::getText(this, tr("Enter text"), label, QLineEdit::Normal, text, &ok);
return ok ? ret : QJSValue();
}
QJSValue BatchProcessing::getInt(const QString &label, int value)
{
bool ok = false;
int ret = QInputDialog::getInt(this, tr("Enter integer number"), label, value, INT_MIN, INT_MAX, 1, &ok);
return ok ? ret : QJSValue();
}
QJSValue BatchProcessing::getFloat(const QString &label, double value, int decimals)
{
bool ok = false;
double ret = QInputDialog::getDouble(this, tr("Enter float number"), label, value, -INFINITY, INFINITY, decimals, &ok);
return ok ? ret : QJSValue();
}
QJSValue BatchProcessing::getItem(const QStringList &items, const QString &label, int current)
{
bool ok = false;
QString ret = QInputDialog::getItem(this, tr("Select item"), label, items, current, false, &ok);
return ok ? ret : QJSValue();
}