From 3ba88c7c2f8aa17f6fb7ebe9a675b81b8fea4bf3 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 4 Feb 2019 17:26:02 +0100 Subject: [PATCH] Ref T529, added order for CStatusMessage --- src/blackmisc/orderable.h | 3 +++ src/blackmisc/statusmessage.cpp | 12 +++++++++--- src/blackmisc/statusmessage.h | 5 ++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/blackmisc/orderable.h b/src/blackmisc/orderable.h index cbf33642b..b6660428b 100644 --- a/src/blackmisc/orderable.h +++ b/src/blackmisc/orderable.h @@ -53,6 +53,9 @@ namespace BlackMisc //! Constructor IOrderable(int order); + //! Constructor + IOrderable(const IOrderable &orderable) : IOrderable(orderable.m_order) {} + //! \copydoc BlackMisc::Mixin::Index::propertyByIndex CVariant propertyByIndex(const CPropertyIndex &index) const; diff --git a/src/blackmisc/statusmessage.cpp b/src/blackmisc/statusmessage.cpp index 6233c18ac..e6c888959 100644 --- a/src/blackmisc/statusmessage.cpp +++ b/src/blackmisc/statusmessage.cpp @@ -89,7 +89,8 @@ namespace BlackMisc CStatusMessage::CStatusMessage(const CStatusMessage &other) : CValueObject(other), CMessageBase(other), - ITimestampBased(other) + ITimestampBased(other), + IOrderable(other) { QReadLocker lock(&other.m_lock); m_handledByObjects = other.m_handledByObjects; @@ -103,13 +104,15 @@ namespace BlackMisc static_cast(*this) = other; QReadLocker readLock(&other.m_lock); - auto handledBy = other.m_handledByObjects; - qint64 ts = other.m_timestampMSecsSinceEpoch; + const auto handledBy = other.m_handledByObjects; + const qint64 ts = other.m_timestampMSecsSinceEpoch; + const int order = other.m_order; readLock.unlock(); // avoid deadlock QWriteLocker writeLock(&m_lock); m_handledByObjects = handledBy; m_timestampMSecsSinceEpoch = ts; + m_order = order; return *this; } @@ -420,6 +423,7 @@ namespace BlackMisc { if (index.isMyself()) { return CVariant::from(*this); } if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); } + if (IOrderable::canHandleIndex(index)) { return IOrderable::propertyByIndex(index); } const ColumnIndex i = index.frontCasted(); switch (i) { @@ -438,6 +442,7 @@ namespace BlackMisc { if (index.isMyself()) { (*this) = variant.to(); return; } if (ITimestampBased::canHandleIndex(index)) { ITimestampBased::setPropertyByIndex(index, variant); return; } + if (IOrderable::canHandleIndex(index)) { IOrderable::setPropertyByIndex(index, variant); return; } const ColumnIndex i = index.frontCasted(); switch (i) { @@ -455,6 +460,7 @@ namespace BlackMisc { if (index.isMyself()) { return Compare::compare(this->getSeverity(), compareValue.getSeverity()); } if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::comparePropertyByIndex(index, compareValue); } + if (IOrderable::canHandleIndex(index)) { return IOrderable::comparePropertyByIndex(index, compareValue); } const ColumnIndex i = index.frontCasted(); switch (i) { diff --git a/src/blackmisc/statusmessage.h b/src/blackmisc/statusmessage.h index 05c1ecd63..3d57f3b9f 100644 --- a/src/blackmisc/statusmessage.h +++ b/src/blackmisc/statusmessage.h @@ -294,7 +294,8 @@ namespace BlackMisc class BLACKMISC_EXPORT CStatusMessage : public CValueObject, public CMessageBase, - public ITimestampBased + public ITimestampBased, + public IOrderable { public: //! \copydoc BlackMisc::StatusSeverity @@ -518,12 +519,14 @@ namespace BlackMisc mutable QVector m_handledByObjects; mutable QReadWriteLock m_lock; //!< lock (because of mutable members) + //! \fixme KB 2019-01 order and timestamp "disabled" for Ref T184 token bucket. Would it be better to enable those and use a special comparison function for that (e.g. "equalMessageAndSeverity")? BLACK_METACLASS( CStatusMessage, BLACK_METAMEMBER(categories), BLACK_METAMEMBER(severity), BLACK_METAMEMBER(message), BLACK_METAMEMBER(args), + BLACK_METAMEMBER(order, 0, DisabledForHashing | DisabledForComparison), BLACK_METAMEMBER(timestampMSecsSinceEpoch, 0, DisabledForHashing | DisabledForComparison) ); };