Some fixes of status message view

* push_front as default (in most cases we have "latest first"
* as follow up of t270 use CListModelTimestampObjects
This commit is contained in:
Klaus Basan
2018-05-28 21:33:08 +02:00
parent 6deb9042c3
commit 4788c25ecb
6 changed files with 47 additions and 22 deletions

View File

@@ -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

View File

@@ -76,7 +76,7 @@ namespace BlackGui
private:
QScopedPointer<Ui::CStatusMessagesDetail> 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

View File

@@ -26,7 +26,23 @@ namespace BlackGui
{ }
template<typename ObjectType, typename ContainerType, bool UseCompare>
void CListModelTimestampObjects<ObjectType, ContainerType, UseCompare>::push_frontKeepLatestAdjustedFirst(const ObjectType &object, int max)
void CListModelTimestampObjects<ObjectType, ContainerType, UseCompare>::addTimestampColumns()
{
CListModelBaseNonTemplate::m_columns.addColumn(CColumn::standardString("timestamp", ObjectType::IndexUtcTimestampFormattedMdhmsz));
CListModelBaseNonTemplate::m_columns.addColumn(CColumn("ms", ObjectType::IndexMSecsSinceEpoch, new CIntegerFormatter()));
}
template class CListModelTimestampObjects<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList, true>;
template class CListModelTimestampObjects<BlackMisc::Aviation::CAircraftParts, BlackMisc::Aviation::CAircraftPartsList, true>;
template class CListModelTimestampObjects<BlackMisc::Aviation::CAircraftSituation, BlackMisc::Aviation::CAircraftSituationList, true>;
template <typename ObjectType, typename ContainerType, bool UseCompare>
CListModelTimestampWithOffsetObjects<ObjectType, ContainerType, UseCompare>::CListModelTimestampWithOffsetObjects(const QString &translationContext, QObject *parent) :
CListModelTimestampObjects<ObjectType, ContainerType, UseCompare>(translationContext, parent)
{ }
template<typename ObjectType, typename ContainerType, bool UseCompare>
void CListModelTimestampWithOffsetObjects<ObjectType, ContainerType, UseCompare>::push_frontKeepLatestAdjustedFirst(const ObjectType &object, int max)
{
this->beginInsertRows(QModelIndex(), 0, 0);
CListModelBase<ObjectType, ContainerType, UseCompare>::m_container.push_frontKeepLatestAdjustedFirst(object, max);
@@ -34,18 +50,14 @@ namespace BlackGui
}
template<typename ObjectType, typename ContainerType, bool UseCompare>
void CListModelTimestampObjects<ObjectType, ContainerType, UseCompare>::addTimestampOffsetColumns()
void CListModelTimestampWithOffsetObjects<ObjectType, ContainerType, UseCompare>::addTimestampOffsetColumns()
{
CListModelBaseNonTemplate::m_columns.addColumn(CColumn::standardString("timestamp", ObjectType::IndexUtcTimestampFormattedMdhmsz));
CListModelBaseNonTemplate::m_columns.addColumn(CColumn("ms", ObjectType::IndexMSecsSinceEpoch, new CIntegerFormatter()));
CListModelTimestampObjects<ObjectType, ContainerType, UseCompare>::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<BlackMisc::Aviation::CAircraftParts, BlackMisc::Aviation::CAircraftPartsList, true>;
template class CListModelTimestampObjects<BlackMisc::Aviation::CAircraftSituation, BlackMisc::Aviation::CAircraftSituationList, true>;
template class CListModelTimestampWithOffsetObjects<BlackMisc::Aviation::CAircraftParts, BlackMisc::Aviation::CAircraftPartsList, true>;
template class CListModelTimestampWithOffsetObjects<BlackMisc::Aviation::CAircraftSituation, BlackMisc::Aviation::CAircraftSituationList, true>;
} // namespace
} // namespace

View File

@@ -25,20 +25,32 @@ namespace BlackGui
{
namespace Models
{
//! List model for timestamp based objects
//! List model for timestamp based objects with offset
template <typename ObjectType, typename ContainerType, bool UseCompare = false> class CListModelTimestampObjects :
public CListModelBase<ObjectType, ContainerType, UseCompare>
{
protected:
//! Constructor
CListModelTimestampObjects(const QString &translationContext, QObject *parent = nullptr);
//! Standard timestamp columns
void addTimestampColumns();
};
//! List model for timestamp based objects with offset
template <typename ObjectType, typename ContainerType, bool UseCompare = false> class CListModelTimestampWithOffsetObjects :
public CListModelTimestampObjects<ObjectType, ContainerType, UseCompare>
{
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();

View File

@@ -23,7 +23,7 @@ namespace BlackGui
namespace Models
{
CStatusMessageListModel::CStatusMessageListModel(QObject *parent) :
CListModelBase<CStatusMessage, CStatusMessageList, true>("ViewStatusMessageList", parent)
CListModelTimestampObjects<CStatusMessage, CStatusMessageList, true>("ViewStatusMessageList", parent)
{
this->setMode(Detailed);

View File

@@ -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<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList, true>
class BLACKGUI_EXPORT CStatusMessageListModel :
public CListModelTimestampObjects<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList, true>
{
public:
//! Mode