From 1f9f14851959a2e3d1fc97974b8eb4a690963f93 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 11 May 2018 03:00:30 +0200 Subject: [PATCH] Status message fix, copy timestamp in assigmnet operator * the timestamp of status message was not copied, so every time a status message was sorted or otherwise assigned the ts got lost or wrongly assigned. * this meant the log messages were in wrong order, leading to very confusing results in the log screen or file. * also added new timestamp formatter * new function "BlackMisc::CVariant displayRole(const PQ &pq) const" which can be used if the PQ is already available --- src/blackgui/models/columnformatters.h | 18 ++++++++++++------ src/blackgui/models/statusmessagelistmodel.cpp | 2 +- src/blackmisc/registermetadata.cpp | 1 + src/blackmisc/statusmessage.cpp | 4 +++- src/blackmisc/statusmessage.h | 2 +- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/blackgui/models/columnformatters.h b/src/blackgui/models/columnformatters.h index afd577c9a..27d236296 100644 --- a/src/blackgui/models/columnformatters.h +++ b/src/blackgui/models/columnformatters.h @@ -275,6 +275,9 @@ namespace BlackGui //! Hour minute second static const QString &formatHms() { static const QString f = "HH:mm:ss"; return f; } + //! Hour minute second and milliseconds + static const QString &formatHmsz() { static const QString f = "HH:mm:ss.zzz"; return f; } + private: QString m_formatString = "yyyy-MM-dd HH:mm"; //!< how the value is displayed }; @@ -333,12 +336,8 @@ namespace BlackGui { if (physicalQuantity.canConvert()) { - PQ pq = physicalQuantity.value(); - if (!m_unit.isNull()) - { - pq.switchUnit(m_unit); - } - return pq.valueRoundedWithUnit(m_digits, m_useI18n); + const PQ pq = physicalQuantity.value(); + return this->displayRole(pq); } else { @@ -347,6 +346,13 @@ namespace BlackGui } } + //! Version if value is already available as PQ + BlackMisc::CVariant displayRole(const PQ &pq) const + { + if (m_unit.isNull()) { return pq.valueRoundedWithUnit(m_digits, m_useI18n); } + return pq.valueRoundedWithUnit(m_unit, m_digits, m_useI18n); + } + //! Set unit virtual void setUnit(const MU &unit) { m_unit = unit; } diff --git a/src/blackgui/models/statusmessagelistmodel.cpp b/src/blackgui/models/statusmessagelistmodel.cpp index 3a1068fe0..69f7e89e1 100644 --- a/src/blackgui/models/statusmessagelistmodel.cpp +++ b/src/blackgui/models/statusmessagelistmodel.cpp @@ -55,7 +55,7 @@ namespace BlackGui break; case Simplified: { - this->m_columns.addColumn(CColumn("time", CStatusMessage::IndexUtcTimestamp, new CDateTimeFormatter(CDateTimeFormatter::formatHms()))); + m_columns.addColumn(CColumn("time", CStatusMessage::IndexUtcTimestamp, new CDateTimeFormatter(CDateTimeFormatter::formatHmsz()))); CColumn col = CColumn("severity", CStatusMessage::IndexIcon); col.setSortPropertyIndex(CStatusMessage::IndexSeverityAsString); m_columns.addColumn(col); diff --git a/src/blackmisc/registermetadata.cpp b/src/blackmisc/registermetadata.cpp index 674c99c64..4ba9cc64e 100644 --- a/src/blackmisc/registermetadata.cpp +++ b/src/blackmisc/registermetadata.cpp @@ -80,6 +80,7 @@ namespace BlackMisc CPropertyIndexVariantMap::registerMetadata(); CRgbColor::registerMetadata(); CStatusMessage::registerMetadata(); + qDBusRegisterMetaType(); CStatusMessageList::registerMetadata(); CValueCachePacket::registerMetadata(); CVariant::registerMetadata(); diff --git a/src/blackmisc/statusmessage.cpp b/src/blackmisc/statusmessage.cpp index 642847791..aa3885137 100644 --- a/src/blackmisc/statusmessage.cpp +++ b/src/blackmisc/statusmessage.cpp @@ -97,10 +97,12 @@ namespace BlackMisc QReadLocker readLock(&other.m_lock); auto handledBy = other.m_handledByObjects; + qint64 ts = other.m_timestampMSecsSinceEpoch; readLock.unlock(); // avoid deadlock - QWriteLocker writeLock(&this->m_lock); + QWriteLocker writeLock(&m_lock); m_handledByObjects = handledBy; + m_timestampMSecsSinceEpoch = ts; return *this; } diff --git a/src/blackmisc/statusmessage.h b/src/blackmisc/statusmessage.h index ac570c5e0..c85c82545 100644 --- a/src/blackmisc/statusmessage.h +++ b/src/blackmisc/statusmessage.h @@ -53,7 +53,7 @@ namespace BlackMisc CMessageBase() {} //! Construct a message with some specific category. - explicit CMessageBase(const CLogCategory &category) : m_categories( { category }) {} + explicit CMessageBase(const CLogCategory &category) : m_categories({ category }) {} //! Construct a message with some specific categories. explicit CMessageBase(const CLogCategoryList &categories) : m_categories(categories) {}