aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlloggingcategory.cpp
diff options
context:
space:
mode:
authorTomasz Olszak <olszak.tomasz@gmail.com>2018-03-22 11:25:59 +0100
committerTomasz Olszak <olszak.tomasz@gmail.com>2018-06-25 10:25:40 +0000
commitf319fcf70917c392913cf6db6115d18623dd4fd5 (patch)
tree22ebe95ccd8076b1f7b17ba12e3c86b4347da128 /src/qml/qml/qqmlloggingcategory.cpp
parent8597f74e520c18e0ac1c7a90e02a3b5ba33d4753 (diff)
Add defaultLogLevel to LoggingCategory
Add possibility to define default logging category log level. Just like in QLoggingCategory constructor. [ChangeLog][QML Elements][LoggingCategory] Added defaultLogLevel property. It is possible to define default log level that LoggingCategory is enabled for. Task-number: QTBUG-67094 Change-Id: I12557dfb7c228c40b325d0dccde4c525acae0300 Reviewed-by: Michael Brasser <michael.brasser@live.com>
Diffstat (limited to 'src/qml/qml/qqmlloggingcategory.cpp')
-rw-r--r--src/qml/qml/qqmlloggingcategory.cpp36
1 files changed, 33 insertions, 3 deletions
diff --git a/src/qml/qml/qqmlloggingcategory.cpp b/src/qml/qml/qqmlloggingcategory.cpp
index 597fe458fa..b59a26e17e 100644
--- a/src/qml/qml/qqmlloggingcategory.cpp
+++ b/src/qml/qml/qqmlloggingcategory.cpp
@@ -59,6 +59,7 @@
LoggingCategory {
id: category
name: "com.qt.category"
+ defaultLogLevel: LoggingCategory.Warning
}
Component.onCompleted: {
@@ -84,6 +85,17 @@
\sa QLoggingCategory::categoryName()
*/
+/*!
+ \qmlproperty enumeration QtQml::LoggingCategory::defaultLogLevel
+ \since 5.12
+
+ Holds the default log level of the logging category. By default it is
+ created with the LoggingCategory.Debug log level.
+
+ \note This property needs to be set when declaring the LoggingCategory
+ and cannot be changed later.
+*/
+
QQmlLoggingCategory::QQmlLoggingCategory(QObject *parent)
: QObject(parent)
, m_initialized(false)
@@ -99,6 +111,11 @@ QString QQmlLoggingCategory::name() const
return QString::fromUtf8(m_name);
}
+QQmlLoggingCategory::DefaultLogLevel QQmlLoggingCategory::defaultLogLevel() const
+{
+ return m_defaultLogLevel;
+}
+
QLoggingCategory *QQmlLoggingCategory::category() const
{
return m_category.data();
@@ -111,10 +128,25 @@ void QQmlLoggingCategory::classBegin()
void QQmlLoggingCategory::componentComplete()
{
m_initialized = true;
- if (m_name.isNull())
+ if (m_name.isNull()) {
qmlWarning(this) << QLatin1String("Declaring the name of the LoggingCategory is mandatory and cannot be changed later !");
+ } else {
+ QScopedPointer<QLoggingCategory> category(new QLoggingCategory(m_name.constData(), QtMsgType(m_defaultLogLevel)));
+ m_category.swap(category);
+ }
}
+void QQmlLoggingCategory::setDefaultLogLevel(DefaultLogLevel defaultLogLevel)
+{
+ if (m_initialized) {
+ qmlWarning(this) << QLatin1String("The defaultLogLevel of a LoggingCategory cannot be changed after the Item is created");
+ return;
+ }
+
+ m_defaultLogLevel = defaultLogLevel;
+}
+
+
void QQmlLoggingCategory::setName(const QString &name)
{
if (m_initialized) {
@@ -123,8 +155,6 @@ void QQmlLoggingCategory::setName(const QString &name)
}
m_name = name.toUtf8();
- QScopedPointer<QLoggingCategory> category(new QLoggingCategory(m_name.constData()));
- m_category.swap(category);
}
#include "moc_qqmlloggingcategory_p.cpp"