From 4788c25ecb57b42a4194396879c75a911c0a9de0 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 28 May 2018 21:33:08 +0200 Subject: [PATCH] Some fixes of status message view * push_front as default (in most cases we have "latest first" * as follow up of t270 use CListModelTimestampObjects --- .../components/statusmessagesdetail.cpp | 9 +++--- .../components/statusmessagesdetail.h | 2 +- .../models/listmodeltimestampobjects.cpp | 30 +++++++++++++------ .../models/listmodeltimestampobjects.h | 18 +++++++++-- .../models/statusmessagelistmodel.cpp | 2 +- src/blackgui/models/statusmessagelistmodel.h | 8 ++--- 6 files changed, 47 insertions(+), 22 deletions(-) diff --git a/src/blackgui/components/statusmessagesdetail.cpp b/src/blackgui/components/statusmessagesdetail.cpp index d33134743..cc7057529 100644 --- a/src/blackgui/components/statusmessagesdetail.cpp +++ b/src/blackgui/components/statusmessagesdetail.cpp @@ -26,6 +26,7 @@ namespace BlackGui connect(ui->tvp_StatusMessages, &CStatusMessageView::objectSelected, ui->form_StatusMessage, &CStatusMessageForm::setVariant); connect(ui->tvp_StatusMessages, &CStatusMessageView::modelDataChangedDigest, this, &CStatusMessagesDetail::modelDataChangedDigest); ui->tvp_StatusMessages->setAutoResizeFrequency(3); + ui->tvp_StatusMessages->setSorting(CStatusMessage::IndexUtcTimestamp, Qt::DescendingOrder); ui->tvp_StatusMessages->setCustomMenu(new CMessageMenu(this)); ui->tvp_StatusMessages->menuAddItems(CStatusMessageView::MenuSave); this->showFilterBar(); // default @@ -37,14 +38,14 @@ namespace BlackGui void CStatusMessagesDetail::appendStatusMessageToList(const CStatusMessage &message) { if (message.isEmpty()) { return; } - m_pending.push_back(message); + m_pending.push_front(message); // in many cases we want to havethe latest "on top" m_dsDeferredUpdate.inputSignal(); } void CStatusMessagesDetail::appendStatusMessagesToList(const CStatusMessageList &messages) { if (messages.isEmpty()) { return; } - m_pending.push_back(messages); + m_pending.push_front(messages); m_dsDeferredUpdate.inputSignal(); } @@ -93,9 +94,9 @@ namespace BlackGui m_pending.clear(); CStatusMessageList newMsgs(ui->tvp_StatusMessages->container()); - newMsgs.push_back(add); + newMsgs.push_front(add); // default in many cases, latest first - // do not remove every time, but when a threshold is reached + // cleanup outdated: do not remove every time, but when a threshold is reached if (m_maxLogMessages < 0) { // do not restrict diff --git a/src/blackgui/components/statusmessagesdetail.h b/src/blackgui/components/statusmessagesdetail.h index e70b868b6..eaf55d639 100644 --- a/src/blackgui/components/statusmessagesdetail.h +++ b/src/blackgui/components/statusmessagesdetail.h @@ -76,7 +76,7 @@ namespace BlackGui private: QScopedPointer ui; int m_maxLogMessages = -1; - BlackMisc::CStatusMessageList m_pending; + BlackMisc::CStatusMessageList m_pending; //!< pending messages which will be added with next CStatusMessagesDetail::deferredUpdate BlackMisc::CDigestSignal m_dsDeferredUpdate { this, &CStatusMessagesDetail::deferredUpdate, 2000, 10 }; //! Do not update each message, but deferred diff --git a/src/blackgui/models/listmodeltimestampobjects.cpp b/src/blackgui/models/listmodeltimestampobjects.cpp index 9c88fbe71..6cf138e00 100644 --- a/src/blackgui/models/listmodeltimestampobjects.cpp +++ b/src/blackgui/models/listmodeltimestampobjects.cpp @@ -26,7 +26,23 @@ namespace BlackGui { } template - void CListModelTimestampObjects::push_frontKeepLatestAdjustedFirst(const ObjectType &object, int max) + void CListModelTimestampObjects::addTimestampColumns() + { + CListModelBaseNonTemplate::m_columns.addColumn(CColumn::standardString("timestamp", ObjectType::IndexUtcTimestampFormattedMdhmsz)); + CListModelBaseNonTemplate::m_columns.addColumn(CColumn("ms", ObjectType::IndexMSecsSinceEpoch, new CIntegerFormatter())); + } + + template class CListModelTimestampObjects; + template class CListModelTimestampObjects; + template class CListModelTimestampObjects; + + template + CListModelTimestampWithOffsetObjects::CListModelTimestampWithOffsetObjects(const QString &translationContext, QObject *parent) : + CListModelTimestampObjects(translationContext, parent) + { } + + template + void CListModelTimestampWithOffsetObjects::push_frontKeepLatestAdjustedFirst(const ObjectType &object, int max) { this->beginInsertRows(QModelIndex(), 0, 0); CListModelBase::m_container.push_frontKeepLatestAdjustedFirst(object, max); @@ -34,18 +50,14 @@ namespace BlackGui } template - void CListModelTimestampObjects::addTimestampOffsetColumns() + void CListModelTimestampWithOffsetObjects::addTimestampOffsetColumns() { - CListModelBaseNonTemplate::m_columns.addColumn(CColumn::standardString("timestamp", ObjectType::IndexUtcTimestampFormattedMdhmsz)); - CListModelBaseNonTemplate::m_columns.addColumn(CColumn("ms", ObjectType::IndexMSecsSinceEpoch, new CIntegerFormatter())); + CListModelTimestampObjects::addTimestampColumns(); CListModelBaseNonTemplate::m_columns.addColumn(CColumn("ms adj.", ObjectType::IndexAdjustedMsWithOffset, new CIntegerFormatter())); CListModelBaseNonTemplate::m_columns.addColumn(CColumn("offset", ObjectType::IndexOffsetMs, new CIntegerFormatter())); } - // see here for the reason of thess forward instantiations - // https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl - template class CListModelTimestampObjects; - template class CListModelTimestampObjects; - + template class CListModelTimestampWithOffsetObjects; + template class CListModelTimestampWithOffsetObjects; } // namespace } // namespace diff --git a/src/blackgui/models/listmodeltimestampobjects.h b/src/blackgui/models/listmodeltimestampobjects.h index 486b4acb5..bfa5a5eb3 100644 --- a/src/blackgui/models/listmodeltimestampobjects.h +++ b/src/blackgui/models/listmodeltimestampobjects.h @@ -25,20 +25,32 @@ namespace BlackGui { namespace Models { - //! List model for timestamp based objects + //! List model for timestamp based objects with offset template class CListModelTimestampObjects : public CListModelBase { + protected: + //! Constructor + CListModelTimestampObjects(const QString &translationContext, QObject *parent = nullptr); + + //! Standard timestamp columns + void addTimestampColumns(); + }; + + //! List model for timestamp based objects with offset + template class CListModelTimestampWithOffsetObjects : + public CListModelTimestampObjects + { public: //! Destructor - virtual ~CListModelTimestampObjects() {} + virtual ~CListModelTimestampWithOffsetObjects() {} //! Insert as first element by keeping maxElements and the latest first void push_frontKeepLatestAdjustedFirst(const ObjectType &object, int max); protected: //! Constructor - CListModelTimestampObjects(const QString &translationContext, QObject *parent = nullptr); + CListModelTimestampWithOffsetObjects(const QString &translationContext, QObject *parent = nullptr); //! Standard timestamp offset columns void addTimestampOffsetColumns(); diff --git a/src/blackgui/models/statusmessagelistmodel.cpp b/src/blackgui/models/statusmessagelistmodel.cpp index deb2d101e..04d58f876 100644 --- a/src/blackgui/models/statusmessagelistmodel.cpp +++ b/src/blackgui/models/statusmessagelistmodel.cpp @@ -23,7 +23,7 @@ namespace BlackGui namespace Models { CStatusMessageListModel::CStatusMessageListModel(QObject *parent) : - CListModelBase("ViewStatusMessageList", parent) + CListModelTimestampObjects("ViewStatusMessageList", parent) { this->setMode(Detailed); diff --git a/src/blackgui/models/statusmessagelistmodel.h b/src/blackgui/models/statusmessagelistmodel.h index da36bbe12..2952b56fd 100644 --- a/src/blackgui/models/statusmessagelistmodel.h +++ b/src/blackgui/models/statusmessagelistmodel.h @@ -13,8 +13,7 @@ #define BLACKGUI_STATUSMESSAGELISTMODEL_H #include "blackgui/blackguiexport.h" -#include "blackgui/models/listmodelbase.h" -#include "blackmisc/statusmessage.h" +#include "blackgui/models/listmodeltimestampobjects.h" #include "blackmisc/statusmessagelist.h" class QObject; @@ -24,9 +23,10 @@ namespace BlackGui namespace Models { /*! - * Server list model + * Status message list model */ - class BLACKGUI_EXPORT CStatusMessageListModel : public CListModelBase + class BLACKGUI_EXPORT CStatusMessageListModel : + public CListModelTimestampObjects { public: //! Mode