2023-07-31 16:55:36 +02:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "ui_mainwindow.h"
|
|
|
|
#include "worker.h"
|
2023-08-02 15:29:10 +02:00
|
|
|
#include "utils.h"
|
2023-08-05 18:50:50 +02:00
|
|
|
#include "progress_event.h"
|
2023-07-31 16:55:36 +02:00
|
|
|
|
|
|
|
#include <QDateTime>
|
2023-08-02 15:29:10 +02:00
|
|
|
#include <QMessageBox>
|
2023-08-02 15:44:16 +02:00
|
|
|
#include <QDebug>
|
2023-07-31 16:55:36 +02:00
|
|
|
|
|
|
|
MainWindow::MainWindow(Worker *worker, QWidget *parent)
|
|
|
|
: QMainWindow(parent)
|
|
|
|
, ui(new Ui::MainWindow)
|
2023-08-02 15:29:10 +02:00
|
|
|
, m_worker(worker)
|
2023-08-06 14:14:47 +02:00
|
|
|
, m_width(70) {
|
2023-07-31 16:55:36 +02:00
|
|
|
ui->setupUi(this);
|
|
|
|
|
2023-08-06 14:14:47 +02:00
|
|
|
ui->updateProgress->setRange(0, 100);
|
2023-08-02 15:29:10 +02:00
|
|
|
ui->updateProgress->reset();
|
|
|
|
|
2023-08-04 13:44:16 +02:00
|
|
|
QStringList lst;
|
|
|
|
QString start = QDateTime::currentDateTime().toString(Qt::ISODate);
|
|
|
|
lst << QString("Start: ") + start.leftJustified(m_width-10);
|
|
|
|
lst << QString("").leftJustified(m_width-3, '=');
|
|
|
|
lst << QString("Machine number : %1 ").arg(m_worker->machineNr()).leftJustified(m_width-3);
|
|
|
|
lst << QString("Customer number : %1 ").arg(m_worker->customerNr()).leftJustified(m_width-3);
|
|
|
|
lst << QString("Zone number : %1 (%2)").arg(m_worker->zoneNr()).arg(Utils::zoneName(m_worker->zoneNr())).leftJustified(m_width-3);
|
|
|
|
lst << QString("").leftJustified(m_width-3, '=');
|
|
|
|
|
|
|
|
ui->updateStatus->setText(lst.join('\n'));
|
|
|
|
ui->updateStatus->setEnabled(true);
|
|
|
|
|
|
|
|
ui->reserved_1->setVisible(false);
|
|
|
|
ui->reserved_2->setVisible(false);
|
|
|
|
ui->reserved_3->setVisible(false);
|
|
|
|
ui->reserved_4->setVisible(false);
|
|
|
|
ui->reserved_5->setVisible(false);
|
|
|
|
ui->reserved_6->setVisible(false);
|
|
|
|
|
2023-08-02 15:29:10 +02:00
|
|
|
m_startTimer = new QTimer(this);
|
|
|
|
connect(m_startTimer, SIGNAL(timeout()), ui->start, SLOT(click()));
|
|
|
|
m_startTimer->setSingleShot(true);
|
|
|
|
m_startTimer->start(5 * 1000);
|
2023-07-31 16:55:36 +02:00
|
|
|
|
2023-08-02 15:29:10 +02:00
|
|
|
m_exitTimer = new QTimer(this);
|
|
|
|
connect(m_exitTimer, SIGNAL(timeout()), ui->exit, SLOT(click()));
|
|
|
|
m_exitTimer->setSingleShot(true);
|
|
|
|
m_exitTimer->start(1800 * 1000);
|
|
|
|
|
|
|
|
connect(m_startTimer, SIGNAL(timeout()), ui->start, SLOT(click()));
|
2023-08-04 13:45:19 +02:00
|
|
|
connect(m_exitTimer, SIGNAL(timeout()), ui->exit, SLOT(click()));
|
2023-08-02 15:29:10 +02:00
|
|
|
connect(ui->start, SIGNAL(clicked()), m_worker, SLOT(update()));
|
|
|
|
connect(ui->exit, SIGNAL(clicked()), this, SLOT(onQuit()));
|
2023-08-02 17:51:35 +02:00
|
|
|
connect(m_worker, SIGNAL(disableExit()), this, SLOT(onDisableExit()));
|
|
|
|
connect(m_worker, SIGNAL(enableExit()), this, SLOT(onEnableExit()));
|
2023-08-02 15:29:10 +02:00
|
|
|
connect(m_worker, SIGNAL(stopStartTimer()), this, SLOT(onStopStartTimer()));
|
|
|
|
connect(m_worker, SIGNAL(restartExitTimer()), this, SLOT(onRestartExitTimer()));
|
|
|
|
connect(m_worker, SIGNAL(appendText(QString, QString)), this, SLOT(onAppendText(QString, QString)));
|
|
|
|
connect(m_worker, SIGNAL(showErrorMessage(QString,QString)), this, SLOT(onShowErrorMessage(QString,QString)));
|
2023-08-06 14:14:47 +02:00
|
|
|
connect(m_worker, SIGNAL(replaceLast(QString, QString)), this, SLOT(onReplaceLast(QString,QString)));
|
2023-07-31 16:55:36 +02:00
|
|
|
|
|
|
|
ui->updateStatus->setText(lst.join('\n'));
|
|
|
|
ui->updateStatus->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow() {
|
2023-08-02 15:29:10 +02:00
|
|
|
delete m_startTimer;
|
|
|
|
delete m_exitTimer;
|
2023-07-31 16:55:36 +02:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2023-08-05 18:50:50 +02:00
|
|
|
void MainWindow::customEvent(QEvent *event) {
|
|
|
|
if (event->type() == ProgressEvent::type()) {
|
|
|
|
int progress = ((ProgressEvent *)(event))->progressPercent();
|
2023-08-06 14:14:47 +02:00
|
|
|
if (progress > 0) {
|
|
|
|
ui->updateProgress->setValue(progress);
|
|
|
|
} else {
|
|
|
|
ui->updateProgress->reset();
|
|
|
|
}
|
2023-08-05 18:50:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-02 15:29:10 +02:00
|
|
|
void MainWindow::onStopStartTimer() {
|
|
|
|
m_startTimer->stop();
|
|
|
|
}
|
|
|
|
|
2023-08-02 17:51:35 +02:00
|
|
|
void MainWindow::onDisableExit() {
|
|
|
|
ui->exit->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onEnableExit() {
|
|
|
|
ui->exit->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
2023-08-02 15:29:10 +02:00
|
|
|
void MainWindow::onRestartExitTimer() {
|
|
|
|
m_exitTimer->stop();
|
2023-08-02 16:54:47 +02:00
|
|
|
m_exitTimer->start(10 * 1000);
|
2023-08-02 15:29:10 +02:00
|
|
|
}
|
2023-07-31 16:55:36 +02:00
|
|
|
|
2023-08-02 15:29:10 +02:00
|
|
|
void MainWindow::onQuit() {
|
2023-08-04 13:45:56 +02:00
|
|
|
m_exitTimer->stop();
|
|
|
|
qCritical() << QString("ON QUIT: EXIT CODE %1").arg(m_worker->returnCode());
|
2023-08-03 10:14:09 +02:00
|
|
|
qApp->exit(m_worker->returnCode());
|
2023-08-02 15:29:10 +02:00
|
|
|
}
|
2023-07-31 16:55:36 +02:00
|
|
|
|
2023-08-02 15:29:10 +02:00
|
|
|
void MainWindow::onAppendText(QString text, QString suffix) {
|
|
|
|
QString editText = ui->updateStatus->toPlainText();
|
2023-08-06 14:14:47 +02:00
|
|
|
if (suffix.size() > 0) {
|
2023-08-02 15:29:10 +02:00
|
|
|
editText += QString("\n").leftJustified(m_width-3, '=');
|
2023-08-06 14:14:47 +02:00
|
|
|
editText += " ";
|
|
|
|
editText += (QString("\n") + text).leftJustified(m_width - (2 + suffix.size()) ) + suffix;
|
2023-08-03 09:06:50 +02:00
|
|
|
} else {
|
2023-08-06 14:14:47 +02:00
|
|
|
editText += text.leftJustified(m_width-9);
|
2023-08-02 15:29:10 +02:00
|
|
|
}
|
2023-08-06 14:14:47 +02:00
|
|
|
|
|
|
|
QStringList lines = editText.split('\n');
|
|
|
|
for (int i=0; i<lines.size(); ++i) {
|
|
|
|
qDebug() << lines.at(i);
|
|
|
|
} qDebug() << ""; qDebug() << "";
|
|
|
|
|
|
|
|
ui->updateStatus->setPlainText(editText);
|
|
|
|
ui->updateStatus->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onReplaceLast(QString text, QString suffix) {
|
|
|
|
QString editText = ui->updateStatus->toPlainText();
|
|
|
|
QStringList lines = editText.split('\n');
|
|
|
|
if (lines.size() > 0) {
|
|
|
|
lines.removeLast();
|
|
|
|
lines += text.leftJustified(m_width-10) + suffix;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i=0; i<lines.size(); ++i) {
|
|
|
|
qDebug() << lines.at(i);
|
|
|
|
} qDebug() << ""; qDebug() << "";
|
|
|
|
|
|
|
|
ui->updateStatus->setText(lines.join('\n'));
|
2023-08-02 15:29:10 +02:00
|
|
|
ui->updateStatus->setEnabled(true);
|
|
|
|
}
|
2023-07-31 16:55:36 +02:00
|
|
|
|
2023-08-02 15:29:10 +02:00
|
|
|
void MainWindow::onShowErrorMessage(QString title, QString text) {
|
2023-08-04 13:45:56 +02:00
|
|
|
QMessageBox::critical(this, title, text, QMessageBox::Ok);
|
2023-07-31 16:55:36 +02:00
|
|
|
}
|