From 97e04f8360bc0bcf90d6101db0e9d89bfd420dbe Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 20 Nov 2014 17:53:02 +0100 Subject: [PATCH] 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 --- src/blackgui/models/columns.cpp | 4 +- src/blackgui/models/columns.h | 2 +- .../models/statusmessagelistmodel.cpp | 37 +++------------- src/blackgui/models/statusmessagelistmodel.h | 3 -- src/blackmisc/logcategory.h | 6 +-- src/blackmisc/logcategorylist.h | 3 +- src/blackmisc/statusmessage.cpp | 42 ++++++++++++++----- src/blackmisc/statusmessage.h | 16 ++++--- 8 files changed, 56 insertions(+), 57 deletions(-) diff --git a/src/blackgui/models/columns.cpp b/src/blackgui/models/columns.cpp index cfa34ee06..985f84e82 100644 --- a/src/blackgui/models/columns.cpp +++ b/src/blackgui/models/columns.cpp @@ -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 diff --git a/src/blackgui/models/columns.h b/src/blackgui/models/columns.h index 8bb938ab3..433678866 100644 --- a/src/blackgui/models/columns.h +++ b/src/blackgui/models/columns.h @@ -88,7 +88,7 @@ namespace BlackGui QString m_columnToolTip; QSharedPointer 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; diff --git a/src/blackgui/models/statusmessagelistmodel.cpp b/src/blackgui/models/statusmessagelistmodel.cpp index a7b489c5d..5a99d24de 100644 --- a/src/blackgui/models/statusmessagelistmodel.cpp +++ b/src/blackgui/models/statusmessagelistmodel.cpp @@ -27,9 +27,10 @@ namespace BlackGui CListModelBase("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 diff --git a/src/blackgui/models/statusmessagelistmodel.h b/src/blackgui/models/statusmessagelistmodel.h index db060a8ef..3cbe5eabc 100644 --- a/src/blackgui/models/statusmessagelistmodel.h +++ b/src/blackgui/models/statusmessagelistmodel.h @@ -34,9 +34,6 @@ namespace BlackGui //! Destructor virtual ~CStatusMessageListModel() {} - - //! \copydoc CListModelBase::data - QVariant data(const QModelIndex &modelIndex, int role = Qt::DisplayRole) const override; }; } } diff --git a/src/blackmisc/logcategory.h b/src/blackmisc/logcategory.h index 386367a27..2365c441c 100644 --- a/src/blackmisc/logcategory.h +++ b/src/blackmisc/logcategory.h @@ -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 \ No newline at end of file +#endif diff --git a/src/blackmisc/logcategorylist.h b/src/blackmisc/logcategorylist.h index be438d6c5..4fdc8cbed 100644 --- a/src/blackmisc/logcategorylist.h +++ b/src/blackmisc/logcategorylist.h @@ -18,6 +18,7 @@ #include #include #include +#include namespace BlackMisc { @@ -141,4 +142,4 @@ Q_DECLARE_METATYPE(BlackMisc::CLogCategoryList) Q_DECLARE_METATYPE(BlackMisc::CCollection) Q_DECLARE_METATYPE(BlackMisc::CSequence) -#endif \ No newline at end of file +#endif diff --git a/src/blackmisc/statusmessage.cpp b/src/blackmisc/statusmessage.cpp index dc3f69042..73b100ce5 100644 --- a/src/blackmisc/statusmessage.cpp +++ b/src/blackmisc/statusmessage.cpp @@ -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(variant.value()); break; - case IndexCategory: + case IndexCategories: this->m_categories = variant.value(); break; default: diff --git a/src/blackmisc/statusmessage.h b/src/blackmisc/statusmessage.h index 3d7a84774..6d203cefb 100644 --- a/src/blackmisc/statusmessage.h +++ b/src/blackmisc/statusmessage.h @@ -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 m_handledByObjects; + mutable QString m_humanReadableCategory; //!< human readable category cache + }; } // namespace