File indexing completed on 2024-04-21 03:49:41
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2009 Patrick Spendrin <ps_ml@gmx.de> 0004 // 0005 0006 #ifndef MARBLE_MARBLEDEBUG_H 0007 #define MARBLE_MARBLEDEBUG_H 0008 0009 #include <QDebug> 0010 #include <QLoggingCategory> 0011 0012 #include "marble_export.h" 0013 0014 #ifndef LOGGING_IDENTIFIER 0015 #define LOGGING_IDENTIFIER MARBLE_DEFAULT 0016 #endif 0017 MARBLE_EXPORT Q_DECLARE_LOGGING_CATEGORY(LOGGING_IDENTIFIER) 0018 0019 0020 namespace Marble 0021 { 0022 0023 /** 0024 * A class which handles Marble debugging messages and settings. 0025 * 0026 * Use of this class is deprecated. The preferred way to generate 0027 * debugging output within Marble is to use Qt categorised logging, 0028 * which allows control over the debugging output either via the 0029 * Qt configuration files and environment variables or the Plasma 0030 * @c kdebugsettings utility. 0031 0032 * The @c mDebug() macro below logs debug messages under the category 0033 * named by @c LOGGING_CATEGORY or, if this is not specified, a 0034 * default. In order to use a different logging category for a part 0035 * of the Marble source tree, define the logging category for ECM in 0036 * the @c CMakeLists.txt file for that part of the tree and then specify 0037 * the category to be used by the code, for example: 0038 * 0039 * @code 0040 * ecm_qt_export_logging_category( 0041 * IDENTIFIER "MARBLE_SPECIAL" 0042 * CATEGORY_NAME "marble_special" 0043 * EXPORT marble 0044 * DESCRIPTION "Marble (special category)") 0045 * add_definitions("-DLOGGING_IDENTIFIER=MARBLE_SPECIAL") 0046 * @endcode 0047 * 0048 * and then messages can be output by using @c qCDebug(MARBLE_SPECIAL) 0049 * if @c mDebug() is not being used. 0050 * 0051 * The logging identifier and category name must also be defined in 0052 * the @c MarbleDebug.cpp source file using @c Q_LOGGING_CATEGORY, 0053 * otherwise there will be undefined symbols which may not be resolved 0054 * until run time. 0055 * 0056 * ECM will collect together all of the logging definitions and install 0057 * the categories file to be use by @c kdebugsettings. 0058 * 0059 * @see QLoggingCategory 0060 */ 0061 class MARBLE_EXPORT MarbleDebug 0062 { 0063 public: 0064 /** 0065 * @brief isEnabled returns whether debug information output is generated 0066 */ 0067 static bool isEnabled(); 0068 0069 /** 0070 * @brief setEnabled Toggle debug information output generation 0071 * @param enabled Set to true to enable debug output, false to disable 0072 */ 0073 static void setEnabled(bool enabled); 0074 0075 private: 0076 static bool m_enabled; 0077 }; 0078 0079 /** 0080 * A replacement for qDebug() in Marble library code. 0081 * 0082 * @note This cannot be a function (not even inline), because @c qCDebug() 0083 * is itself defined as a macro which captures the source location where 0084 * it is called. 0085 * @deprecated Use @c qCDebug() with a logging category 0086 */ 0087 #define mDebug() qCDebug(LOGGING_IDENTIFIER) 0088 0089 } // namespace Marble 0090 0091 #endif