On 18 April 2017 at 00:47, Thiago Macieira <[email protected]> wrote: > On segunda-feira, 17 de abril de 2017 14:41:13 PDT Lubomir I. Ivanov wrote: >> On 18 April 2017 at 00:18, Thiago Macieira <[email protected]> wrote: >> > On segunda-feira, 17 de abril de 2017 14:10:28 PDT Lubomir I. Ivanov > wrote: >> >> i guess we could just do a: >> >> void MarbleDebug::setEnabled(bool enabled) >> >> { >> >> >> >> Marble::loggingCategory.setEnabled(enabled); >> >> MarbleDebug::m_enabled = enabled; >> >> >> >> } >> > >> > I'd go a little further and drop the m_enabled variable completely. You >> > don't need it, let the bit in the QLoggingCategory variable keep the >> > state. >> > >> > You'd have: >> > >> > namespace MarbleDebug { >> > Q_LOGGING_CATEGORY(category, "marble", QtWarningMsg) >> > >> > void setEnabled(bool enabled) >> > { >> > >> > category.setEnabled(QtDebugMsg, enabled); >> > >> > } >> > >> > bool isEnabled() // do you even need this function? >> > { >> > >> > return category.isDebugEnabled(); >> > >> > } >> > } //namespace MarbleDebug >> > >> > This changes to the MarbleDebug namespace too. >> >> thanks, i think i understand. >> >> here are the updated Marble files and a patch diff for review. >> i can't build Marble to test these changes ATM though. > > Looks good, so long as "Marble::category" isn't too generic a name. >
ok, i've renamed it to Marable::loggingCategory. Stefan, could you please try building and running the attached patch? you can toggle the debugging with MarbleDebug::setEnabled(true/false) e.g. from the Subsurface source code. lubomir --
// // This file is part of the Marble Virtual Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2009 Patrick Spendrin <[email protected]> // #ifndef MARBLE_MARBLEDEBUG_H #define MARBLE_MARBLEDEBUG_H #include <QDebug> #include <QLoggingCategory> #include "marble_export.h" namespace Marble { Q_DECLARE_LOGGING_CATEGORY(loggingCategory) /** * a class which takes all the settings and exposes them */ class MARBLE_EXPORT MarbleDebug { public: /** * @brief isEnabled returns whether debug information output is generated */ static bool isEnabled(); /** * @brief setEnabled Toggle debug information output generation * @param enabled Set to true to enable debug output, false to disable */ static void setEnabled(bool enabled); }; // logging category #define mDebug qCDebug(Marble::loggingCategory) } // namespace Marble #endif
// // This file is part of the Marble Virtual Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2009 Patrick Spendrin <[email protected]> // #include "MarbleDebug.h" #include <QLoggingCategory> namespace Marble { Q_LOGGING_CATEGORY(loggingCategory, "marble", QtDebugMsg) bool MarbleDebug::isEnabled() { return loggingCategory.isDebugEnabled(); } void MarbleDebug::setEnabled(bool enabled) { loggingCategory.setEnabled(QtDebugMsg, enabled); } } // namespace Marble
From 4548472e15b3424c68d9099d67b2a97b36ebb643 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" <[email protected]> Date: Tue, 18 Apr 2017 00:36:17 +0300 Subject: [PATCH] MarbleDebug: use a custom QLoggingCategory --- src/lib/marble/MarbleDebug.cpp | 22 ++++------------------ src/lib/marble/MarbleDebug.h | 12 +++++------- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/src/lib/marble/MarbleDebug.cpp b/src/lib/marble/MarbleDebug.cpp index 5f53f6f..57bc1c9 100644 --- a/src/lib/marble/MarbleDebug.cpp +++ b/src/lib/marble/MarbleDebug.cpp @@ -10,35 +10,21 @@ #include "MarbleDebug.h" -#include <QFile> -#include <QProcess> +#include <QLoggingCategory> namespace Marble { -// bool MarbleDebug::m_enabled = true; -bool MarbleDebug::m_enabled = false; -QDebug mDebug() -{ - if ( MarbleDebug::isEnabled() ) { - return QDebug( QtDebugMsg ); - } - else { - static QFile *nullDevice = new QFile(QProcess::nullDevice()); - if ( !nullDevice->isOpen() ) - nullDevice->open(QIODevice::WriteOnly); - return QDebug( nullDevice ); - } -} +Q_LOGGING_CATEGORY(loggingCategory, "marble", QtDebugMsg) bool MarbleDebug::isEnabled() { - return MarbleDebug::m_enabled; + return loggingCategory.isDebugEnabled(); } void MarbleDebug::setEnabled(bool enabled) { - MarbleDebug::m_enabled = enabled; + loggingCategory.setEnabled(QtDebugMsg, enabled); } } // namespace Marble diff --git a/src/lib/marble/MarbleDebug.h b/src/lib/marble/MarbleDebug.h index 74b71ae..46bed7e 100644 --- a/src/lib/marble/MarbleDebug.h +++ b/src/lib/marble/MarbleDebug.h @@ -12,12 +12,15 @@ #define MARBLE_MARBLEDEBUG_H #include <QDebug> +#include <QLoggingCategory> #include "marble_export.h" namespace Marble { +Q_DECLARE_LOGGING_CATEGORY(loggingCategory) + /** * a class which takes all the settings and exposes them */ @@ -35,15 +38,10 @@ public: */ static void setEnabled(bool enabled); -private: - static bool m_enabled; - }; -/** - * a function to replace qDebug() in Marble library code - */ -MARBLE_EXPORT QDebug mDebug(); +// logging category +#define mDebug qCDebug(Marble::loggingCategory) } // namespace Marble -- 1.7.11.msysgit.0
_______________________________________________ subsurface mailing list [email protected] http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
