mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35:34 +08:00
refs #336 Added class CLogCategory to represent a log category. The category logic of CLogMessage is moved into this new class.
This commit is contained in:
153
src/blackmisc/logcategory.h
Normal file
153
src/blackmisc/logcategory.h
Normal file
@@ -0,0 +1,153 @@
|
||||
/* Copyright (C) 2014
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef BLACKMISC_LOGCATEGORY_H
|
||||
#define BLACKMISC_LOGCATEGORY_H
|
||||
|
||||
//! \file
|
||||
|
||||
#include "sequence.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
/*!
|
||||
* A log category is an arbitrary string tag which can be attached to log messages.
|
||||
*
|
||||
* A log handler can filter messages based on their categories.
|
||||
*/
|
||||
class CLogCategory : public CValueObject
|
||||
{
|
||||
public:
|
||||
//! \name Predefined special categories (public static methods)
|
||||
//! @{
|
||||
|
||||
//! Uncategorized
|
||||
static const CLogCategory &uncategorized()
|
||||
{
|
||||
static const CLogCategory cat { "swift.uncategorized" };
|
||||
return cat;
|
||||
}
|
||||
|
||||
//! Validation
|
||||
static const CLogCategory &validation()
|
||||
{
|
||||
static const CLogCategory cat { "swift.validation" };
|
||||
return cat;
|
||||
}
|
||||
|
||||
//! Settings updates
|
||||
static const CLogCategory &settingsUpdate()
|
||||
{
|
||||
static const CLogCategory cat { "swift.settings.update" };
|
||||
return cat;
|
||||
}
|
||||
|
||||
//! Contexts
|
||||
static const CLogCategory &context()
|
||||
{
|
||||
static const CLogCategory cat { "swift.context" };
|
||||
return cat;
|
||||
}
|
||||
|
||||
//! Context slots
|
||||
static const CLogCategory &contextSlot()
|
||||
{
|
||||
static const CLogCategory cat { "swift.context.slot" };
|
||||
return cat;
|
||||
}
|
||||
|
||||
//! GUI components
|
||||
static const CLogCategory &guiComponent()
|
||||
{
|
||||
static const CLogCategory cat { "swift.gui.component" };
|
||||
return cat;
|
||||
}
|
||||
|
||||
//! All predefined special categories
|
||||
static const QList<CLogCategory> &allSpecialCategories()
|
||||
{
|
||||
static const QList<CLogCategory> cats
|
||||
{
|
||||
uncategorized(),
|
||||
validation(),
|
||||
settingsUpdate(),
|
||||
context(),
|
||||
contextSlot(),
|
||||
guiComponent()
|
||||
};
|
||||
return cats;
|
||||
}
|
||||
|
||||
//! @}
|
||||
|
||||
//! Constructor.
|
||||
CLogCategory() = default;
|
||||
|
||||
//! Constructor.
|
||||
CLogCategory(const QString &categoryString) : m_string(categoryString) {}
|
||||
|
||||
//! Constructor.
|
||||
CLogCategory(const char *categoryString) : m_string(categoryString) {}
|
||||
|
||||
//! Returns true if the category string starts with the given prefix.
|
||||
bool startsWith(const QString &prefix) const { return m_string.startsWith(prefix); }
|
||||
|
||||
//! Returns true if the category string ends with the given suffix.
|
||||
bool endsWith(const QString &suffix) const { return m_string.endsWith(suffix); }
|
||||
|
||||
//! Returns true if the category string contains the given substring.
|
||||
bool contains(const QString &substring) const { return m_string.contains(substring); }
|
||||
|
||||
//! Register metadata
|
||||
static void registerMetadata();
|
||||
|
||||
//! \copydoc CValueObject::toQVariant
|
||||
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
|
||||
|
||||
//! \copydoc CValueObject::convertFromQVariant
|
||||
virtual void convertFromQVariant(const QVariant &variant) override { BlackMisc::setFromQVariant(this, variant); }
|
||||
|
||||
//! \copydoc CValueObject::getValueHash
|
||||
virtual uint getValueHash() const override;
|
||||
|
||||
//! Equal operator
|
||||
bool operator ==(const CLogCategory &other) const;
|
||||
|
||||
//! Not equal operator
|
||||
bool operator !=(const CLogCategory &other) const;
|
||||
|
||||
protected:
|
||||
//! \copydoc CValueObject::convertToQString()
|
||||
virtual QString convertToQString(bool i18n = false) const override;
|
||||
|
||||
//! \copydoc CValueObject::getMetaTypeId
|
||||
virtual int getMetaTypeId() const override;
|
||||
|
||||
//! \copydoc CValueObject::isA
|
||||
virtual bool isA(int metaTypeId) const override;
|
||||
|
||||
//! \copydoc CValueObject::compareImpl
|
||||
virtual int compareImpl(const CValueObject &other) const override;
|
||||
|
||||
//! \copydoc CValueObject::marshallToDbus()
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const override;
|
||||
|
||||
//! \copydoc CValueObject::marshallFromDbus()
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
||||
|
||||
private:
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CLogCategory)
|
||||
QString m_string;
|
||||
};
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::CLogCategory)
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::CLogCategory, (o.m_string))
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user