onAppendText() only appends text.
onReplaceLast() replaces the last line in the text edit window.
This commit is contained in:
@@ -12,10 +12,10 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
, m_worker(worker)
|
||||
, m_width(52) {
|
||||
, m_width(70) {
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->updateProgress->setRange(1, 100);
|
||||
ui->updateProgress->setRange(0, 100);
|
||||
ui->updateProgress->reset();
|
||||
|
||||
QStringList lst;
|
||||
@@ -57,6 +57,7 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
|
||||
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)));
|
||||
connect(m_worker, SIGNAL(replaceLast(QString, QString)), this, SLOT(onReplaceLast(QString,QString)));
|
||||
|
||||
ui->updateStatus->setText(lst.join('\n'));
|
||||
ui->updateStatus->setEnabled(true);
|
||||
@@ -71,7 +72,11 @@ MainWindow::~MainWindow() {
|
||||
void MainWindow::customEvent(QEvent *event) {
|
||||
if (event->type() == ProgressEvent::type()) {
|
||||
int progress = ((ProgressEvent *)(event))->progressPercent();
|
||||
ui->updateProgress->setValue(progress);
|
||||
if (progress > 0) {
|
||||
ui->updateProgress->setValue(progress);
|
||||
} else {
|
||||
ui->updateProgress->reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,22 +105,36 @@ void MainWindow::onQuit() {
|
||||
|
||||
void MainWindow::onAppendText(QString text, QString suffix) {
|
||||
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');
|
||||
for (int i=0; i<lines.size(); ++i) {
|
||||
qCritical() << lines.at(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;
|
||||
}
|
||||
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->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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user