mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-09 13:35:34 +08:00
Utility functions to sort text messages by timestamp (ascending/descending)
* compare function for text message * resort function * text message edit can display HTML text messages with ascending/descending timestamp * made CTextMessageListModel -> CListModelTimestampObject
This commit is contained in:
committed by
Mat Sutcliffe
parent
25eb13a83f
commit
e12dc3a73a
@@ -502,6 +502,13 @@ namespace BlackGui
|
||||
this->sort(this->getSortColumn(), this->getSortOrder());
|
||||
}
|
||||
|
||||
template<typename T, bool UseCompare>
|
||||
void CListModelBase<T, UseCompare>::resort()
|
||||
{
|
||||
// sort the values
|
||||
this->updateContainerMaybeAsync(m_container, true);
|
||||
}
|
||||
|
||||
template <typename T, bool UseCompare>
|
||||
void CListModelBase<T, UseCompare>::sort(int column, Qt::SortOrder order)
|
||||
{
|
||||
|
||||
@@ -107,6 +107,10 @@ namespace BlackGui
|
||||
//! Sort by given sort order \sa getSortColumn() \sa getSortOrder()
|
||||
void sort();
|
||||
|
||||
//! Sort by given sort order \sa getSortColumn() \sa getSortOrder()
|
||||
//! \remark always sorts, even if columns did no change
|
||||
void resort();
|
||||
|
||||
//! Truncate to given number
|
||||
void truncate(int maxNumber, bool forceSort = false);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace BlackGui
|
||||
// https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl
|
||||
template class CListModelBase<BlackMisc::Network::CServerList, true>;
|
||||
template class CListModelBase<BlackMisc::Network::CUserList, true>;
|
||||
template class CListModelBase<BlackMisc::Network::CTextMessageList, false>;
|
||||
template class CListModelBase<BlackMisc::Network::CTextMessageList, true>;
|
||||
template class CListModelBase<BlackMisc::Network::CClientList, false>;
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -19,11 +19,18 @@ namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
template <typename T, bool UseCompare>
|
||||
template<typename T, bool UseCompare>
|
||||
CListModelTimestampObjects<T, UseCompare>::CListModelTimestampObjects(const QString &translationContext, QObject *parent) :
|
||||
CListModelBase<ContainerType, UseCompare>(translationContext, parent)
|
||||
{ }
|
||||
|
||||
template<typename T, bool UseCompare>
|
||||
bool CListModelTimestampObjects<T, UseCompare>::isSortedByTimestampProperty() const
|
||||
{
|
||||
const CPropertyIndex pi = this->getSortProperty();
|
||||
return ITimestampBased::canHandleIndex(pi);
|
||||
}
|
||||
|
||||
template<typename T, bool UseCompare>
|
||||
void CListModelTimestampObjects<T, UseCompare>::addTimestampColumns()
|
||||
{
|
||||
@@ -32,6 +39,7 @@ namespace BlackGui
|
||||
}
|
||||
|
||||
template class CListModelTimestampObjects<BlackMisc::CStatusMessageList, true>;
|
||||
template class CListModelTimestampObjects<BlackMisc::Network::CTextMessageList, true>;
|
||||
template class CListModelTimestampObjects<BlackMisc::Aviation::CAircraftPartsList, true>;
|
||||
template class CListModelTimestampObjects<BlackMisc::Aviation::CAircraftSituationList, true>;
|
||||
template class CListModelTimestampObjects<BlackMisc::Aviation::CAircraftSituationChangeList, true>;
|
||||
|
||||
@@ -35,6 +35,9 @@ namespace BlackGui
|
||||
//! Container element type
|
||||
using ObjectType = typename T::value_type;
|
||||
|
||||
//! Sorted by one of the timestamp columns?
|
||||
bool isSortedByTimestampProperty() const;
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
CListModelTimestampObjects(const QString &translationContext, QObject *parent = nullptr);
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
CTextMessageListModel::CTextMessageListModel(TextMessageMode mode, QObject *parent) :
|
||||
CListModelBase("ModelTextMessageList", parent), m_textMessageMode(NotSet)
|
||||
CListModelTimestampObjects("ModelTextMessageList", parent), m_textMessageMode(NotSet)
|
||||
{
|
||||
this->setTextMessageMode(mode);
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
#ifndef BLACKGUI_MODELS_TEXTMESSAGELISTMODEL_H
|
||||
#define BLACKGUI_MODELS_TEXTMESSAGELISTMODEL_H
|
||||
|
||||
#include "blackgui/models/listmodeltimestampobjects.h"
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackgui/models/listmodelbase.h"
|
||||
#include "blackmisc/network/textmessagelist.h"
|
||||
|
||||
class QObject;
|
||||
@@ -23,7 +23,8 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
//! Text message list model
|
||||
class BLACKGUI_EXPORT CTextMessageListModel : public CListModelBase<BlackMisc::Network::CTextMessageList>
|
||||
class BLACKGUI_EXPORT CTextMessageListModel :
|
||||
public CListModelTimestampObjects<BlackMisc::Network::CTextMessageList, true>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -40,7 +41,7 @@ namespace BlackGui
|
||||
explicit CTextMessageListModel(TextMessageMode stationMode, QObject *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CTextMessageListModel() {}
|
||||
virtual ~CTextMessageListModel() override {}
|
||||
|
||||
//! Set mode
|
||||
void setTextMessageMode(TextMessageMode mode);
|
||||
@@ -56,4 +57,5 @@ namespace BlackGui
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user