Gui: [skip ci] avoid to write several time stamps to a single line

This commit is contained in:
wmayer
2020-07-15 12:49:20 +02:00
parent 03fa5cf92b
commit 79e8562f9b
2 changed files with 19 additions and 13 deletions

View File

@@ -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);
}

View File

@@ -186,6 +186,7 @@ private:
class Data;
Data* d;
bool gotoEnd;
bool blockStart;
ReportHighlighter* reportHl; /**< Syntax highlighter */
int messageSize;
ParameterGrp::handle _prefs;