mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Issue #77 Break cyclic dependency between CStatusMessage and CLogPattern by moving methods from one to the other
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
#include "blackgui/components/statusmessageform.h"
|
||||
#include "blackmisc/logcategories.h"
|
||||
#include "blackmisc/logpattern.h"
|
||||
#include "ui_statusmessageform.h"
|
||||
|
||||
#include <QLabel>
|
||||
@@ -41,7 +41,7 @@ namespace BlackGui
|
||||
{
|
||||
ui->te_Message->setPlainText(message.getMessage());
|
||||
ui->lbl_SeverityIcon->setPixmap(CIcon(message.toIcon()));
|
||||
const QString hrc(message.getHumanReadablePattern());
|
||||
const QString hrc(CLogPattern::humanReadableNamesFrom(message).join(", "));
|
||||
if (hrc.isEmpty())
|
||||
{
|
||||
ui->le_Categories->setText(message.getCategories().toQString());
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
#include "blackgui/components/statusmessageformsmall.h"
|
||||
#include "blackmisc/logpattern.h"
|
||||
#include "ui_statusmessageformsmall.h"
|
||||
|
||||
#include <QLabel>
|
||||
@@ -39,7 +40,7 @@ namespace BlackGui
|
||||
{
|
||||
ui->te_Message->setPlainText(message.getMessage());
|
||||
ui->lbl_SeverityIcon->setPixmap(CIcon(message.toIcon()));
|
||||
ui->le_Categories->setText(message.getHumanOrTechnicalCategoriesAsString());
|
||||
ui->le_Categories->setText(CLogPattern::humanOrTechnicalCategoriesFrom(message).join(", "));
|
||||
ui->le_Severity->setText(message.getSeverityAsString());
|
||||
ui->le_Timestamp->setText(message.getFormattedUtcTimestampYmdhms());
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace BlackGui
|
||||
|
||||
if (!this->m_category.isEmpty())
|
||||
{
|
||||
if (!this->stringMatchesFilterExpression(msg.getHumanOrTechnicalCategoriesAsString(), this->m_category)) { continue; }
|
||||
if (!this->stringMatchesFilterExpression(CLogPattern::humanOrTechnicalCategoriesFrom(msg).join(", "), this->m_category)) { continue; }
|
||||
}
|
||||
|
||||
outContainer.push_back(msg);
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace BlackGui
|
||||
col.setSortPropertyIndex(CStatusMessage::IndexSeverityAsString);
|
||||
m_columns.addColumn(col);
|
||||
m_columns.addColumn(CColumn::standardString("message", CStatusMessage::IndexMessage));
|
||||
m_columns.addColumn(CColumn::standardString("category", CStatusMessage::IndexCategoryHumanReadableOrTechnicalAsString));
|
||||
m_columns.addColumn(CColumn::standardString("category", CStatusMessage::IndexCategoriesAsString));
|
||||
}
|
||||
break;
|
||||
case SimplifiedWithOrder:
|
||||
|
||||
@@ -71,6 +71,23 @@ namespace BlackMisc
|
||||
return names;
|
||||
}
|
||||
|
||||
QStringList CLogPattern::humanReadableNamesFrom(const CStatusMessage &message)
|
||||
{
|
||||
QStringList patternNames;
|
||||
for (const QString &name : CLogPattern::allHumanReadableNames())
|
||||
{
|
||||
if (CLogPattern::fromHumanReadableName(name).match(message)) { patternNames.push_back(name); }
|
||||
}
|
||||
return patternNames;
|
||||
}
|
||||
|
||||
QStringList CLogPattern::humanOrTechnicalCategoriesFrom(const CStatusMessage &message)
|
||||
{
|
||||
if (message.getCategories().isEmpty()) { return {}; }
|
||||
QStringList c(humanReadableNamesFrom(message).join(", "));
|
||||
return c.isEmpty() ? message.getCategories().toQStringList() : c;
|
||||
}
|
||||
|
||||
const CLogPattern &CLogPattern::fromHumanReadableName(const QString &name)
|
||||
{
|
||||
static const CLogPattern empty {};
|
||||
|
||||
@@ -58,6 +58,12 @@ namespace BlackMisc
|
||||
//! Return a predefined CLogPattern corresponding to the given human-readable name.
|
||||
static const CLogPattern &fromHumanReadableName(const QString &name);
|
||||
|
||||
//! Human readable categories of message.
|
||||
static QStringList humanReadableNamesFrom(const CStatusMessage &message);
|
||||
|
||||
//! Human or machine readable categories of message.
|
||||
static QStringList humanOrTechnicalCategoriesFrom(const CStatusMessage &message);
|
||||
|
||||
//! Default constructed CLogPattern will match any message.
|
||||
CLogPattern();
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "blackmisc/statusmessage.h"
|
||||
#include "blackmisc/propertyindexref.h"
|
||||
#include "blackmisc/iconlist.h"
|
||||
#include "blackmisc/logpattern.h"
|
||||
#include "blackmisc/comparefunctions.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
#include "blackmisc/verify.h"
|
||||
@@ -196,29 +195,6 @@ namespace BlackMisc
|
||||
return m_categories.toQString();
|
||||
}
|
||||
|
||||
QString CStatusMessage::getHumanReadablePattern() const
|
||||
{
|
||||
const QStringList patternNames(getHumanReadablePatterns());
|
||||
return patternNames.isEmpty() ? QString() : patternNames.join(", ");
|
||||
}
|
||||
|
||||
QStringList CStatusMessage::getHumanReadablePatterns() const
|
||||
{
|
||||
QStringList patternNames;
|
||||
for (const QString &name : CLogPattern::allHumanReadableNames())
|
||||
{
|
||||
if (CLogPattern::fromHumanReadableName(name).match(*this)) { patternNames.push_back(name); }
|
||||
}
|
||||
return patternNames;
|
||||
}
|
||||
|
||||
QString CStatusMessage::getHumanOrTechnicalCategoriesAsString() const
|
||||
{
|
||||
if (m_categories.isEmpty()) { return {}; }
|
||||
const QString c(getHumanReadablePattern());
|
||||
return c.isEmpty() ? this->getCategoriesAsString() : c;
|
||||
}
|
||||
|
||||
bool CStatusMessage::clampSeverity(CStatusMessage::StatusSeverity severity)
|
||||
{
|
||||
if (this->getSeverity() <= severity) { return false; }
|
||||
@@ -430,8 +406,6 @@ namespace BlackMisc
|
||||
case IndexSeverityAsString: return QVariant::fromValue(this->getSeverityAsString());
|
||||
case IndexSeverityAsIcon: return QVariant::fromValue(this->getSeverityAsIcon());
|
||||
case IndexCategoriesAsString: return QVariant::fromValue(m_categories.toQString());
|
||||
case IndexCategoriesHumanReadableAsString: return QVariant::fromValue(this->getHumanReadablePattern());
|
||||
case IndexCategoryHumanReadableOrTechnicalAsString: return QVariant::fromValue(this->getHumanOrTechnicalCategoriesAsString());
|
||||
case IndexMessageAsHtml: return QVariant::fromValue(this->toHtml(false, true));
|
||||
default: return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
@@ -469,8 +443,6 @@ namespace BlackMisc
|
||||
case IndexSeverityAsIcon:
|
||||
case IndexSeverity: return Compare::compare(this->getSeverity(), compareValue.getSeverity());
|
||||
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;
|
||||
}
|
||||
return CValueObject::comparePropertyByIndex(index, compareValue);
|
||||
|
||||
@@ -307,8 +307,6 @@ namespace BlackMisc
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexCategoriesAsString = CPropertyIndexRef::GlobalIndexCStatusMessage,
|
||||
IndexCategoriesHumanReadableAsString,
|
||||
IndexCategoryHumanReadableOrTechnicalAsString,
|
||||
IndexSeverity,
|
||||
IndexSeverityAsString,
|
||||
IndexSeverityAsIcon,
|
||||
@@ -380,12 +378,6 @@ namespace BlackMisc
|
||||
//! 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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user