Use a pimpl in QLoggingCategory
With the usual pros/cons. Cleans up the publicly visible interface and gives some headroom for further extensions. Change-Id: I7237b1fd2a22c66574d1b7e532d99137bb56ce1d Reviewed-by: Kai Koehne <kai.koehne@digia.com>
This commit is contained in:
parent
29585ec3d3
commit
9ff81bdc1a
@ -97,6 +97,20 @@ Q_GLOBAL_STATIC_WITH_ARGS(QLoggingCategory, qtDefaultCategory,
|
||||
configure categories globally.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
typedef QVector<QTracer *> Tracers;
|
||||
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
class QLoggingCategoryPrivate
|
||||
{
|
||||
public:
|
||||
Tracers tracers;
|
||||
};
|
||||
|
||||
/*!
|
||||
Constructs a QLoggingCategory object with the provided \a category name.
|
||||
The object becomes the local identifier for the category.
|
||||
@ -104,7 +118,8 @@ Q_GLOBAL_STATIC_WITH_ARGS(QLoggingCategory, qtDefaultCategory,
|
||||
If \a category is \c{0}, the category name is changed to \c{"default"}.
|
||||
*/
|
||||
QLoggingCategory::QLoggingCategory(const char *category)
|
||||
: name(0),
|
||||
: d(new QLoggingCategoryPrivate),
|
||||
name(0),
|
||||
enabledDebug(false),
|
||||
enabledWarning(true),
|
||||
enabledCritical(true),
|
||||
@ -133,6 +148,7 @@ QLoggingCategory::~QLoggingCategory()
|
||||
{
|
||||
if (QLoggingRegistry *reg = QLoggingRegistry::instance())
|
||||
reg->unregisterCategory(this);
|
||||
delete d;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -459,7 +475,7 @@ void QLoggingCategory::setFilterRules(const QString &rules)
|
||||
|
||||
void QTracer::addToCategory(QLoggingCategory &category)
|
||||
{
|
||||
category.tracers.append(this);
|
||||
category.d->tracers.append(this);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -571,7 +587,7 @@ void QTracer::addToCategory(QLoggingCategory &category)
|
||||
|
||||
void QTraceGuard::start()
|
||||
{
|
||||
QLoggingCategory::Tracers &tracers = target->tracers;
|
||||
const Tracers &tracers = target->d->tracers;
|
||||
for (int i = tracers.size(); --i >= 0; )
|
||||
tracers.at(i)->start();
|
||||
}
|
||||
@ -584,7 +600,7 @@ void QTraceGuard::start()
|
||||
|
||||
void QTraceGuard::end()
|
||||
{
|
||||
QLoggingCategory::Tracers &tracers = target->tracers;
|
||||
const Tracers &tracers = target->d->tracers;
|
||||
for (int i = tracers.size(); --i >= 0; )
|
||||
tracers.at(i)->end();
|
||||
}
|
||||
@ -599,7 +615,7 @@ void QTraceGuard::end()
|
||||
|
||||
QTraceGuard &QTraceGuard::operator<<(int msg)
|
||||
{
|
||||
QLoggingCategory::Tracers &tracers = target->tracers;
|
||||
const Tracers &tracers = target->d->tracers;
|
||||
for (int i = tracers.size(); --i >= 0; )
|
||||
tracers.at(i)->record(msg);
|
||||
return *this;
|
||||
@ -614,7 +630,7 @@ QTraceGuard &QTraceGuard::operator<<(int msg)
|
||||
|
||||
QTraceGuard &QTraceGuard::operator<<(const char *msg)
|
||||
{
|
||||
QLoggingCategory::Tracers &tracers = target->tracers;
|
||||
const Tracers &tracers = target->d->tracers;
|
||||
for (int i = tracers.size(); --i >= 0; )
|
||||
tracers.at(i)->record(msg);
|
||||
return *this;
|
||||
@ -630,7 +646,7 @@ QTraceGuard &QTraceGuard::operator<<(const char *msg)
|
||||
|
||||
QTraceGuard &QTraceGuard::operator<<(const QVariant &msg)
|
||||
{
|
||||
QLoggingCategory::Tracers &tracers = target->tracers;
|
||||
const Tracers &tracers = target->d->tracers;
|
||||
for (int i = tracers.size(); --i >= 0; )
|
||||
tracers.at(i)->record(msg);
|
||||
return *this;
|
||||
|
@ -50,6 +50,7 @@ QT_BEGIN_NAMESPACE
|
||||
|
||||
class QTracer;
|
||||
class QTraceGuard;
|
||||
class QLoggingCategoryPrivate;
|
||||
|
||||
class Q_CORE_EXPORT QLoggingCategory
|
||||
{
|
||||
@ -80,18 +81,18 @@ public:
|
||||
static void setFilterRules(const QString &rules);
|
||||
|
||||
private:
|
||||
friend class QLoggingCategoryPrivate;
|
||||
friend class QLoggingRegistry;
|
||||
friend class QTraceGuard;
|
||||
friend class QTracer;
|
||||
|
||||
QLoggingCategoryPrivate *d;
|
||||
const char *name;
|
||||
|
||||
bool enabledDebug;
|
||||
bool enabledWarning;
|
||||
bool enabledCritical;
|
||||
bool enabledTrace;
|
||||
typedef QVector<QTracer *> Tracers;
|
||||
Tracers tracers;
|
||||
};
|
||||
|
||||
template <>
|
||||
|
Loading…
Reference in New Issue
Block a user