onAppendText() only appends text.
onReplaceLast() replaces the last line in the text edit window.
This commit is contained in:
parent
a8994423f4
commit
1fd2269753
@ -12,10 +12,10 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
|
|||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
, m_worker(worker)
|
, m_worker(worker)
|
||||||
, m_width(52) {
|
, m_width(70) {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
ui->updateProgress->setRange(1, 100);
|
ui->updateProgress->setRange(0, 100);
|
||||||
ui->updateProgress->reset();
|
ui->updateProgress->reset();
|
||||||
|
|
||||||
QStringList lst;
|
QStringList lst;
|
||||||
@ -57,6 +57,7 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
|
|||||||
connect(m_worker, SIGNAL(restartExitTimer()), this, SLOT(onRestartExitTimer()));
|
connect(m_worker, SIGNAL(restartExitTimer()), this, SLOT(onRestartExitTimer()));
|
||||||
connect(m_worker, SIGNAL(appendText(QString, QString)), this, SLOT(onAppendText(QString, QString)));
|
connect(m_worker, SIGNAL(appendText(QString, QString)), this, SLOT(onAppendText(QString, QString)));
|
||||||
connect(m_worker, SIGNAL(showErrorMessage(QString,QString)), this, SLOT(onShowErrorMessage(QString,QString)));
|
connect(m_worker, SIGNAL(showErrorMessage(QString,QString)), this, SLOT(onShowErrorMessage(QString,QString)));
|
||||||
|
connect(m_worker, SIGNAL(replaceLast(QString, QString)), this, SLOT(onReplaceLast(QString,QString)));
|
||||||
|
|
||||||
ui->updateStatus->setText(lst.join('\n'));
|
ui->updateStatus->setText(lst.join('\n'));
|
||||||
ui->updateStatus->setEnabled(true);
|
ui->updateStatus->setEnabled(true);
|
||||||
@ -71,7 +72,11 @@ MainWindow::~MainWindow() {
|
|||||||
void MainWindow::customEvent(QEvent *event) {
|
void MainWindow::customEvent(QEvent *event) {
|
||||||
if (event->type() == ProgressEvent::type()) {
|
if (event->type() == ProgressEvent::type()) {
|
||||||
int progress = ((ProgressEvent *)(event))->progressPercent();
|
int progress = ((ProgressEvent *)(event))->progressPercent();
|
||||||
|
if (progress > 0) {
|
||||||
ui->updateProgress->setValue(progress);
|
ui->updateProgress->setValue(progress);
|
||||||
|
} else {
|
||||||
|
ui->updateProgress->reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,22 +105,36 @@ void MainWindow::onQuit() {
|
|||||||
|
|
||||||
void MainWindow::onAppendText(QString text, QString suffix) {
|
void MainWindow::onAppendText(QString text, QString suffix) {
|
||||||
QString editText = ui->updateStatus->toPlainText();
|
QString editText = ui->updateStatus->toPlainText();
|
||||||
|
if (suffix.size() > 0) {
|
||||||
|
editText += QString("\n").leftJustified(m_width-3, '=');
|
||||||
|
editText += " ";
|
||||||
|
editText += (QString("\n") + text).leftJustified(m_width - (2 + suffix.size()) ) + suffix;
|
||||||
|
} else {
|
||||||
|
editText += text.leftJustified(m_width-9);
|
||||||
|
}
|
||||||
|
|
||||||
QStringList lines = editText.split('\n');
|
QStringList lines = editText.split('\n');
|
||||||
for (int i=0; i<lines.size(); ++i) {
|
for (int i=0; i<lines.size(); ++i) {
|
||||||
qCritical() << lines.at(i);
|
qDebug() << lines.at(i);
|
||||||
}
|
} qDebug() << ""; qDebug() << "";
|
||||||
if (suffix.contains("[SUCCESS]")) {
|
|
||||||
editText += QString("\n").leftJustified(m_width-3, '=');
|
|
||||||
editText += QString("\n").leftJustified(m_width-12) + " [SUCCESS]";
|
|
||||||
} else
|
|
||||||
if (suffix.contains(" [fail]")) {
|
|
||||||
editText += QString("\n").leftJustified(m_width-3, '=');
|
|
||||||
editText += QString("\n").leftJustified(m_width-9) + " [fail]";
|
|
||||||
} else {
|
|
||||||
editText += text.leftJustified(m_width-9) + suffix;
|
|
||||||
ui->updateStatus->setPlainText(editText);
|
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;
|
||||||
}
|
}
|
||||||
ui->updateStatus->setText(editText);
|
|
||||||
|
for (int i=0; i<lines.size(); ++i) {
|
||||||
|
qDebug() << lines.at(i);
|
||||||
|
} qDebug() << ""; qDebug() << "";
|
||||||
|
|
||||||
|
ui->updateStatus->setText(lines.join('\n'));
|
||||||
ui->updateStatus->setEnabled(true);
|
ui->updateStatus->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,8 @@ public:
|
|||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onAppendText(QString, QString);
|
void onAppendText(QString, QString suffix = "");
|
||||||
|
void onReplaceLast(QString, QString);
|
||||||
void onShowErrorMessage(QString, QString);
|
void onShowErrorMessage(QString, QString);
|
||||||
void onStopStartTimer();
|
void onStopStartTimer();
|
||||||
void onRestartExitTimer();
|
void onRestartExitTimer();
|
||||||
|
16
worker.cpp
16
worker.cpp
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
QString const Worker::UPDATE_STEP_OK(" [ ok]");
|
QString const Worker::UPDATE_STEP_OK(" [ ok]");
|
||||||
QString const Worker::UPDATE_STEP_DONE(" [done]");
|
QString const Worker::UPDATE_STEP_DONE(" [done]");
|
||||||
QString const Worker::UPDATE_STEP_FAIL(" [fail]");
|
QString const Worker::UPDATE_STEP_FAIL(" [FAIL]");
|
||||||
QString const Worker::UPDATE_STEP_SUCCESS(" [SUCCESS]");
|
QString const Worker::UPDATE_STEP_SUCCESS(" [SUCCESS]");
|
||||||
|
|
||||||
Worker::Worker(hwinf *hw,
|
Worker::Worker(hwinf *hw,
|
||||||
@ -130,6 +130,18 @@ void Worker::privateUpdate() {
|
|||||||
QPushButton *start = qobject_cast<QPushButton *>(QObject::sender());
|
QPushButton *start = qobject_cast<QPushButton *>(QObject::sender());
|
||||||
start->setEnabled(false);
|
start->setEnabled(false);
|
||||||
|
|
||||||
|
//emit appendText("\nConnecting backend ...");
|
||||||
|
//
|
||||||
|
//for (int i=0;i <= 100; ++i) {
|
||||||
|
// setProgress(i);
|
||||||
|
// QThread::msleep(100);
|
||||||
|
//}
|
||||||
|
//emit replaceLast("Connecting backend ...", UPDATE_STEP_OK);
|
||||||
|
//emit appendText(QString("UPDATE "), UPDATE_STEP_SUCCESS);
|
||||||
|
//emit appendText(QString("UPDATE "), UPDATE_STEP_FAIL);
|
||||||
|
// setProgress(0);
|
||||||
|
// return;
|
||||||
|
|
||||||
emit stopStartTimer();
|
emit stopStartTimer();
|
||||||
emit disableExit();
|
emit disableExit();
|
||||||
m_updateProcessRunning = true;
|
m_updateProcessRunning = true;
|
||||||
@ -211,7 +223,7 @@ void Worker::privateUpdate() {
|
|||||||
progress = 90;
|
progress = 90;
|
||||||
setProgress(progress);
|
setProgress(progress);
|
||||||
m_ismasClient.setProgressInPercent(progress);
|
m_ismasClient.setProgressInPercent(progress);
|
||||||
emit appendText(QString(""), UPDATE_STEP_SUCCESS);
|
emit appendText(QString("Update process "), UPDATE_STEP_SUCCESS);
|
||||||
|
|
||||||
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
|
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
|
||||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||||
|
3
worker.h
3
worker.h
@ -180,7 +180,8 @@ public:
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void appendText(QString, QString);
|
void appendText(QString, QString suffix = "");
|
||||||
|
void replaceLast(QString, QString);
|
||||||
void showErrorMessage(QString title, QString description);
|
void showErrorMessage(QString title, QString description);
|
||||||
void stopStartTimer();
|
void stopStartTimer();
|
||||||
void restartExitTimer();
|
void restartExitTimer();
|
||||||
|
Loading…
Reference in New Issue
Block a user