mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 06:35:52 +08:00
refs #568, improved display / sorting for status message categories
* display technical categories when no hr categories are available * compare function for status message
This commit is contained in:
@@ -623,7 +623,7 @@ namespace BlackGui
|
||||
// http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html
|
||||
template class CListModelBase<BlackMisc::Aviation::CLivery, BlackMisc::Aviation::CLiveryList, true>;
|
||||
template class CListModelBase<BlackMisc::CIdentifier, BlackMisc::CIdentifierList, false>;
|
||||
template class CListModelBase<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList, false>;
|
||||
template class CListModelBase<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList, true>;
|
||||
template class CListModelBase<BlackMisc::CNameVariantPair, BlackMisc::CNameVariantPairList, false>;
|
||||
template class CListModelBase<BlackMisc::CCountry, BlackMisc::CCountryList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAtcStation, BlackMisc::Aviation::CAtcStationList, false>;
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
CStatusMessageListModel::CStatusMessageListModel(QObject *parent) :
|
||||
CListModelBase<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList>("ViewStatusMessageList", parent)
|
||||
CListModelBase<CStatusMessage, CStatusMessageList, true>("ViewStatusMessageList", parent)
|
||||
{
|
||||
setMode(Detailed);
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace BlackGui
|
||||
case Detailed:
|
||||
{
|
||||
this->m_columns.addColumn(CColumn("time", CStatusMessage::IndexUtcTimestamp, new CDateTimeFormatter(CDateTimeFormatter::formatHms())));
|
||||
this->m_columns.addColumn(CColumn::standardString("category", CStatusMessage::IndexCategoryHumanReadable));
|
||||
this->m_columns.addColumn(CColumn::standardString("category", CStatusMessage::IndexCategoryHumanReadableOrTechnicalAsString));
|
||||
CColumn col = CColumn("severity", CStatusMessage::IndexIcon);
|
||||
col.setSortPropertyIndex(CStatusMessage::IndexSeverityAsString);
|
||||
this->m_columns.addColumn(col);
|
||||
|
||||
@@ -25,9 +25,8 @@ namespace BlackGui
|
||||
/*!
|
||||
* Server list model
|
||||
*/
|
||||
class BLACKGUI_EXPORT CStatusMessageListModel : public CListModelBase<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList>
|
||||
class BLACKGUI_EXPORT CStatusMessageListModel : public CListModelBase<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList, true>
|
||||
{
|
||||
|
||||
public:
|
||||
//! Mode
|
||||
enum Mode
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "iconlist.h"
|
||||
#include "loghandler.h"
|
||||
#include "logmessage.h"
|
||||
#include "comparefunctions.h"
|
||||
#include <QMetaEnum>
|
||||
|
||||
namespace BlackMisc
|
||||
@@ -39,19 +40,19 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
CStatusMessage::CStatusMessage(const QString &message)
|
||||
: m_message(message)
|
||||
: m_message(message.trimmed())
|
||||
{}
|
||||
|
||||
CStatusMessage::CStatusMessage(StatusSeverity severity, const QString &message)
|
||||
: m_severity(severity), m_message(message)
|
||||
: m_severity(severity), m_message(message.trimmed())
|
||||
{}
|
||||
|
||||
CStatusMessage::CStatusMessage(const CLogCategoryList &categories, StatusSeverity severity, const QString &message)
|
||||
: m_categories(categories), m_severity(severity), m_message(message)
|
||||
: m_categories(categories), m_severity(severity), m_message(message.trimmed())
|
||||
{}
|
||||
|
||||
CStatusMessage::CStatusMessage(QtMsgType type, const QMessageLogContext &context, const QString &message)
|
||||
: CStatusMessage(message)
|
||||
: CStatusMessage(message.trimmed())
|
||||
{
|
||||
bool debug = CLogMessageHelper::hasDebugFlag(context.category);
|
||||
auto categories = CLogMessageHelper::stripFlags(context.category);
|
||||
@@ -113,6 +114,11 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
QString CStatusMessage::getCategoriesAsString() const
|
||||
{
|
||||
return this->m_categories.toQString();
|
||||
}
|
||||
|
||||
QString CStatusMessage::getHumanReadablePattern() const
|
||||
{
|
||||
QStringList patternNames(getHumanReadablePatterns());
|
||||
@@ -129,6 +135,13 @@ namespace BlackMisc
|
||||
return patternNames;
|
||||
}
|
||||
|
||||
QString CStatusMessage::getHumanOrTechnicalCategoriesAsString() const
|
||||
{
|
||||
if (this->m_categories.isEmpty()) { return ""; }
|
||||
QString c(getHumanReadablePattern());
|
||||
return c.isEmpty() ? this->getCategoriesAsString() : c;
|
||||
}
|
||||
|
||||
void CStatusMessage::prependMessage(const QString &msg)
|
||||
{
|
||||
if (msg.isEmpty()) { return; }
|
||||
@@ -303,10 +316,12 @@ namespace BlackMisc
|
||||
return CVariant::from(this->m_severity);
|
||||
case IndexSeverityAsString:
|
||||
return CVariant::from(this->getSeverityAsString());
|
||||
case IndexCategories:
|
||||
case IndexCategoriesAsString:
|
||||
return CVariant::from(this->m_categories.toQString());
|
||||
case IndexCategoryHumanReadable:
|
||||
case IndexCategoriesHumanReadableAsString:
|
||||
return CVariant::from(this->getHumanReadablePattern());
|
||||
case IndexCategoryHumanReadableOrTechnicalAsString:
|
||||
return CVariant::from(this->getHumanOrTechnicalCategoriesAsString());
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
@@ -325,7 +340,7 @@ namespace BlackMisc
|
||||
case IndexSeverity:
|
||||
this->m_severity = variant.value<StatusSeverity>();
|
||||
break;
|
||||
case IndexCategories:
|
||||
case IndexCategoriesAsString:
|
||||
this->m_categories = variant.value<CLogCategoryList>();
|
||||
break;
|
||||
default:
|
||||
@@ -334,6 +349,32 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
int CStatusMessage::comparePropertyByIndex(const CStatusMessage &compareValue, const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return Compare::compare(this->getSeverity(), compareValue.getSeverity()); }
|
||||
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::comparePropertyByIndex(compareValue, index); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexMessage:
|
||||
return this->getMessage().compare(compareValue.getMessage());
|
||||
case IndexSeverity:
|
||||
return Compare::compare(this->getSeverity(), compareValue.getSeverity());
|
||||
case IndexSeverityAsString:
|
||||
return this->getSeverityAsString().compare(compareValue.getSeverityAsString());
|
||||
case IndexCategoriesAsString:
|
||||
return this->getCategoriesAsString().compare(compareValue.getCategoriesAsString());
|
||||
case IndexCategoriesHumanReadableAsString:
|
||||
return this->getHumanReadablePattern().compare(compareValue.getHumanReadablePattern());
|
||||
case IndexCategoryHumanReadableOrTechnicalAsString:
|
||||
return this->getHumanOrTechnicalCategoriesAsString().compare(compareValue.getHumanOrTechnicalCategoriesAsString());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "Comapre failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
QString CStatusMessage::toHtml() const
|
||||
{
|
||||
QString html;
|
||||
|
||||
@@ -43,8 +43,9 @@ namespace BlackMisc
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexCategories = BlackMisc::CPropertyIndex::GlobalIndexCStatusMessage,
|
||||
IndexCategoryHumanReadable,
|
||||
IndexCategoriesAsString = BlackMisc::CPropertyIndex::GlobalIndexCStatusMessage,
|
||||
IndexCategoriesHumanReadableAsString,
|
||||
IndexCategoryHumanReadableOrTechnicalAsString,
|
||||
IndexSeverity,
|
||||
IndexSeverityAsString,
|
||||
IndexMessage
|
||||
@@ -82,15 +83,21 @@ namespace BlackMisc
|
||||
//! If message is empty then do nothing, otherwise throw a CStatusException.
|
||||
void maybeThrow() const;
|
||||
|
||||
//! Message category
|
||||
//! Message categories
|
||||
const CLogCategoryList &getCategories() const { return this->m_categories; }
|
||||
|
||||
//! Message categories as string
|
||||
QString getCategoriesAsString() const;
|
||||
|
||||
//! Human readable category
|
||||
QString getHumanReadablePattern() const;
|
||||
|
||||
//! All human readable categories
|
||||
QStringList getHumanReadablePatterns() const;
|
||||
|
||||
//! The human or technical categories
|
||||
QString getHumanOrTechnicalCategoriesAsString() const;
|
||||
|
||||
//! Message severity
|
||||
StatusSeverity getSeverity() const { return this->m_severity; }
|
||||
|
||||
@@ -165,6 +172,9 @@ namespace BlackMisc
|
||||
//! \copydoc CValueObject::setPropertyByIndex
|
||||
void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index);
|
||||
|
||||
//! Compare for index
|
||||
int comparePropertyByIndex(const CStatusMessage &compareValue, const CPropertyIndex &index) const;
|
||||
|
||||
//! To HTML
|
||||
QString toHtml() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user