From 79e8562f9b1de46ef7ab4a156c3934b6f24b2784 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 15 Jul 2020 12:49:20 +0200 Subject: [PATCH] Gui: [skip ci] avoid to write several time stamps to a single line --- src/Gui/ReportView.cpp | 31 ++++++++++++++++++------------- src/Gui/ReportView.h | 1 + 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Gui/ReportView.cpp b/src/Gui/ReportView.cpp index 0c35e0c426..690dbe1015 100644 --- a/src/Gui/ReportView.cpp +++ b/src/Gui/ReportView.cpp @@ -352,7 +352,11 @@ PyObject* ReportOutput::Data::replace_stderr = 0; * name 'name' and widget flags set to 'f' */ ReportOutput::ReportOutput(QWidget* parent) - : QTextEdit(parent), WindowParameter("OutputWindow"), d(new Data), gotoEnd(false) + : QTextEdit(parent) + , WindowParameter("OutputWindow") + , d(new Data) + , gotoEnd(false) + , blockStart(true) { bLog = false; reportHl = new ReportHighlighter(this); @@ -416,17 +420,7 @@ void ReportOutput::SendLog(const std::string& msg, Base::LogStyle level) break; } - QString qMsg; - - bool showTimecode = getWindowParameter()->GetBool("checkShowReportTimecode", true); - if (showTimecode) { - QTime time = QTime::currentTime(); - qMsg = time.toString(QLatin1String("hh:mm:ss ")); - qMsg += QString::fromUtf8(msg.c_str()); - } - else { - qMsg = QString::fromUtf8(msg.c_str()); - } + QString qMsg = QString::fromUtf8(msg.c_str()); // This truncates log messages that are too long if (style == ReportHighlighter::LogText) { @@ -448,11 +442,22 @@ void ReportOutput::customEvent ( QEvent* ev ) CustomReportEvent* ce = (CustomReportEvent*)ev; reportHl->setParagraphType(ce->messageType()); + bool showTimecode = getWindowParameter()->GetBool("checkShowReportTimecode", true); + QString text = ce->message(); + + // The time code can only be set when the cursor is at the block start + if (showTimecode && blockStart) { + QTime time = QTime::currentTime(); + text.prepend(time.toString(QLatin1String("hh:mm:ss "))); + } + QTextCursor cursor(this->document()); cursor.beginEditBlock(); cursor.movePosition(QTextCursor::End); - cursor.insertText(ce->message()); + cursor.insertText(text); cursor.endEditBlock(); + + blockStart = cursor.atBlockStart(); if (gotoEnd) { setTextCursor(cursor); } diff --git a/src/Gui/ReportView.h b/src/Gui/ReportView.h index c0d228027f..ee64ccd971 100644 --- a/src/Gui/ReportView.h +++ b/src/Gui/ReportView.h @@ -186,6 +186,7 @@ private: class Data; Data* d; bool gotoEnd; + bool blockStart; ReportHighlighter* reportHl; /**< Syntax highlighter */ int messageSize; ParameterGrp::handle _prefs;