Human readable log category:

* fixed propertyIndex in CStatusMessage
* added method for human readable messages in CStatusMessage
* added typeid based category for classes
* listmodel for staus messages, added column and removed outdated data method
* columns, in class init
This commit is contained in:
Klaus Basan
2014-11-20 17:53:02 +01:00
committed by Roland Winklmeier
parent 6e5e28584f
commit 97e04f8360
8 changed files with 56 additions and 57 deletions

View File

@@ -21,11 +21,11 @@ namespace BlackGui
{}
CColumn::CColumn(const BlackMisc::CPropertyIndex &propertyIndex) :
m_formatter(new CPixmapFormatter()), m_propertyIndex(propertyIndex), m_editable(false)
m_formatter(new CPixmapFormatter()), m_propertyIndex(propertyIndex)
{}
CColumn::CColumn(const QString &toolTip, const BlackMisc::CPropertyIndex &propertyIndex) :
m_columnToolTip(toolTip), m_formatter(new CPixmapFormatter()), m_propertyIndex(propertyIndex), m_editable(false)
m_columnToolTip(toolTip), m_formatter(new CPixmapFormatter()), m_propertyIndex(propertyIndex)
{}
const char *CColumn::getTranslationContextChar() const

View File

@@ -88,7 +88,7 @@ namespace BlackGui
QString m_columnToolTip;
QSharedPointer<CDefaultFormatter> m_formatter;
BlackMisc::CPropertyIndex m_propertyIndex;
bool m_editable;
bool m_editable = false;
const char *getTranslationContextChar() const;
const char *getColumnNameChar() const;
const char *getColumnToolTipChar() const;

View File

@@ -27,9 +27,10 @@ namespace BlackGui
CListModelBase<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList>("ViewStatusMessageList", parent)
{
this->m_columns.addColumn(CColumn("time", CStatusMessage::IndexTimestamp, new CDateTimeFormatter(CDateTimeFormatter::formatHms())));
this->m_columns.addColumn(CColumn("severity", CStatusMessage::IndexSeverity));
this->m_columns.addColumn(CColumn::standardString("category", CStatusMessage::IndexCategoryHumanReadable));
this->m_columns.addColumn(CColumn("severity", CStatusMessage::IndexIcon));
this->m_columns.addColumn(CColumn::standardString("message", CStatusMessage::IndexMessage));
this->m_columns.addColumn(CColumn::standardString("category", CStatusMessage::IndexCategory));
this->m_columns.addColumn(CColumn::standardString("all categories", CStatusMessage::IndexCategories));
this->m_sortedColumn = CStatusMessage::IndexTimestamp;
this->m_sortOrder = Qt::DescendingOrder;
@@ -39,34 +40,8 @@ namespace BlackGui
(void)QT_TRANSLATE_NOOP("ViewStatusMessageList", "severity");
(void)QT_TRANSLATE_NOOP("ViewStatusMessageList", "type");
(void)QT_TRANSLATE_NOOP("ViewStatusMessageList", "message");
(void)QT_TRANSLATE_NOOP("ViewStatusMessageList", "all categories");
}
/*
* Display icons
*/
QVariant CStatusMessageListModel::data(const QModelIndex &modelIndex, int role) const
{
// shortcut, fast check
if (role != Qt::DisplayRole && role != Qt::DecorationRole) return CListModelBase::data(modelIndex, role);
if (this->columnToPropertyIndex(modelIndex.column()) == CStatusMessage::IndexSeverity)
{
if (role == Qt::DecorationRole)
{
CStatusMessage msg = this->at(modelIndex);
return QVariant(msg.toPixmap());
}
else if (role == Qt::DisplayRole)
{
// the text itself should be empty
return QVariant("");
}
else if (role == Qt::ToolTipRole)
{
CStatusMessage msg = this->at(modelIndex);
return QVariant(msg.getSeverityAsString());
}
}
return CListModelBase::data(modelIndex, role);
}
}
}
} // namespace
} // namespace

View File

@@ -34,9 +34,6 @@ namespace BlackGui
//! Destructor
virtual ~CStatusMessageListModel() {}
//! \copydoc CListModelBase::data
QVariant data(const QModelIndex &modelIndex, int role = Qt::DisplayRole) const override;
};
}
}

View File

@@ -1,7 +1,7 @@
/* Copyright (C) 2014
* Swift Project Community / Contributors
* swift Project Community / Contributors
*
* This file is part of Swift Project. It is subject to the license terms in the LICENSE file found in the top-level
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
@@ -117,4 +117,4 @@ namespace BlackMisc
Q_DECLARE_METATYPE(BlackMisc::CLogCategory)
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::CLogCategory, (o.m_string))
#endif
#endif

View File

@@ -18,6 +18,7 @@
#include <QObject>
#include <QThreadStorage>
#include <type_traits>
#include <typeinfo>
namespace BlackMisc
{
@@ -141,4 +142,4 @@ Q_DECLARE_METATYPE(BlackMisc::CLogCategoryList)
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::CLogCategory>)
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::CLogCategory>)
#endif
#endif

View File

@@ -45,10 +45,7 @@ namespace BlackMisc
{
default:
case QtDebugMsg:
if (debug)
this->m_severity = SeverityDebug;
else
this->m_severity = SeverityInfo;
this->m_severity = debug ? SeverityDebug : SeverityInfo;
break;
case QtWarningMsg:
this->m_severity = SeverityWarning;
@@ -94,6 +91,31 @@ namespace BlackMisc
}
}
QString CStatusMessage::getHumanReadableCategory() const
{
if (this->m_humanReadableCategory.isEmpty())
{
const QString cat(this->m_categories.toQString());
// could als be subject of i18n
// from sepcific to unspecific
if (cat.isEmpty()) { this->m_humanReadableCategory = "None"; }
else if (cat.contains(CLogCategory::validation().toQString())) { this->m_humanReadableCategory = "Validation"; }
else if (cat.contains("ContextAudio")) { this->m_humanReadableCategory = "Audio"; }
else if (cat.contains("ContextSimulator")) { this->m_humanReadableCategory = "Simulator"; }
else if (cat.contains("ContextNetwork")) { this->m_humanReadableCategory = "Network"; }
else if (cat.contains("Vatlib")) { this->m_humanReadableCategory = "VATSIM library"; }
else if (cat.contains("BlackMisc")) { this->m_humanReadableCategory = "Library"; }
else if (cat.contains("BlackCore")) { this->m_humanReadableCategory = "Core"; }
else if (cat.contains("BlackGui")) { this->m_humanReadableCategory = "GUI"; }
else if (cat.contains("BlackSound")) { this->m_humanReadableCategory = "GUI"; }
else if (cat.contains("XPlane")) { this->m_humanReadableCategory = "XPlane"; }
else if (cat.contains("FSX")) { this->m_humanReadableCategory = "FSX"; }
else if (cat.contains("FS9")) { this->m_humanReadableCategory = "FS9"; }
else this->m_humanReadableCategory = "Misc.";
}
return this->m_humanReadableCategory;
}
/*
* Handled by
*/
@@ -238,15 +260,13 @@ namespace BlackMisc
if (this->m_timestamp.isNull() || !this->m_timestamp.isValid()) return "";
return this->m_timestamp.toString("HH:mm::ss.zzz");
}
case IndexCategory:
case IndexCategories:
return QVariant(this->m_categories.toQString());
case IndexCategoryHumanReadable:
return QVariant(this->getHumanReadableCategory());
default:
break;
return CValueObject::propertyByIndex(index);
}
Q_ASSERT_X(false, "CStatusMessage", "index unknown");
QString m = QString("no property, index ").append(index.toQString());
return QVariant::fromValue(m);
}
/*
@@ -271,7 +291,7 @@ namespace BlackMisc
case IndexSeverity:
this->m_severity = static_cast<StatusSeverity>(variant.value<uint>());
break;
case IndexCategory:
case IndexCategories:
this->m_categories = variant.value<CLogCategoryList>();
break;
default:

View File

@@ -38,7 +38,8 @@ namespace BlackMisc
//! Properties by index
enum ColumnIndex
{
IndexCategory = BlackMisc::CPropertyIndex::GlobalIndexCStatusMessage,
IndexCategories = BlackMisc::CPropertyIndex::GlobalIndexCStatusMessage,
IndexCategoryHumanReadable,
IndexSeverity,
IndexSeverityAsString,
IndexMessage,
@@ -69,6 +70,9 @@ namespace BlackMisc
//! Message category
const CLogCategoryList &getCategories() const { return this->m_categories; }
//! Human readable category
QString getHumanReadableCategory() const;
//! Message severity
StatusSeverity getSeverity() const { return this->m_severity; }
@@ -127,11 +131,13 @@ namespace BlackMisc
private:
BLACK_ENABLE_TUPLE_CONVERSION(CStatusMessage)
CLogCategoryList m_categories;
StatusSeverity m_severity = SeverityDebug;
QString m_message;
QDateTime m_timestamp = QDateTime::currentDateTimeUtc();
bool m_redundant = false;
StatusSeverity m_severity = SeverityDebug;
QString m_message;
QDateTime m_timestamp = QDateTime::currentDateTimeUtc();
bool m_redundant = false;
mutable QVector<quintptr> m_handledByObjects;
mutable QString m_humanReadableCategory; //!< human readable category cache
};
} // namespace