From 17ddfd0ddd94da9ad4c8004809412a32295f6294 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Fri, 18 Aug 2023 11:48:29 +0200 Subject: [PATCH] Added slot onReplaceLast() to handle adding a QStringList to the text edit. --- mainwindow.cpp | 35 +++++++++++++++++++++++++++++++++-- mainwindow.h | 1 + 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 02fd3c9..02918c7 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -161,9 +161,40 @@ void MainWindow::onAppendText(QString text, QString suffix) { } Utils::printLineEditInfo(editText.split('\n')); - ui->updateStatus->setPlainText(editText.trimmed()); - ui->updateStatus->setEnabled(true); + scrollDownTextEdit(); +} + +void MainWindow::onReplaceLast(QStringList newTextLines, QString suffix) { + int const s = newTextLines.size(); + if (s > 0) { + QString editText = ui->updateStatus->toPlainText(); + QStringList lines = editText.split('\n'); + QString newText; + if (lines.size() >= s) { + for (int i = 0; i < s; ++i) { + lines.removeLast(); + } + if (lines.size() > 0) { + newText = lines.join('\n'); + newText += '\n'; + } + QStringList newLines; + for (int i = 0; i < s; ++i) { + if (i == 0 && !suffix.isNull() && suffix.size() > 0 && suffix != "\n") { + newLines += Utils::rstrip(newTextLines.at(i).leftJustified(m_width-10) + suffix); + } else { + newLines += Utils::rstrip(newTextLines.at(i).leftJustified(m_width-10)); + } + } + lines += newLines; + newText += newLines.join(' '); + } + + ui->updateStatus->setText(newText); + Utils::printLineEditInfo(lines); + scrollDownTextEdit(); + } } void MainWindow::onReplaceLast(QString text, QString suffix) { diff --git a/mainwindow.h b/mainwindow.h index c217a3a..5dcef5b 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -27,6 +27,7 @@ public: public slots: void onAppendText(QString, QString suffix = ""); + void onReplaceLast(QStringList, QString suffix = ""); void onReplaceLast(QString, QString suffix = ""); void onShowErrorMessage(QString, QString); void onStopStartTimer();