OpenCoverage

qqmlloggingcategory.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/qml/qqmlloggingcategory.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 Pelagicore AG-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtQml module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qqmlloggingcategory_p.h"-
41-
42#include <QtQml/qqmlinfo.h>-
43-
44/*!-
45 \qmltype LoggingCategory-
46 \ingroup qml-utility-elements-
47 \inqmlmodule QtQml-
48 \brief Defines a logging category in QML.-
49 \since 5.8-
50-
51 A logging category can be passed to console.log() and friends as the first argument.-
52 If supplied to to the logger the LoggingCategory's name will be used as Logging Category-
53 otherwise the default logging category will be used.-
54-
55 \qml-
56 import QtQuick 2.8-
57-
58 Item {-
59 LoggingCategory {-
60 id: category-
61 name: "com.qt.category"-
62 defaultLogLevel: LoggingCategory.Warning-
63 }-
64-
65 Component.onCompleted: {-
66 console.log(category, "message");-
67 }-
68 }-
69 \endqml-
70-
71 \note As the creation of objects is expensive, it is encouraged to put the needed-
72 LoggingCategory definitions into a singleton and import this where needed.-
73-
74 \sa QLoggingCategory-
75*/-
76-
77/*!-
78 \qmlproperty string QtQml::LoggingCategory::name-
79-
80 Holds the name of the logging category.-
81-
82 \note This property needs to be set when declaring the LoggingCategory-
83 and cannot be changed later.-
84-
85 \sa QLoggingCategory::categoryName()-
86*/-
87-
88/*!-
89 \qmlproperty enumeration QtQml::LoggingCategory::defaultLogLevel-
90 \since 5.12-
91-
92 Holds the default log level of the logging category. By default it is-
93 created with the LoggingCategory.Debug log level.-
94-
95 \note This property needs to be set when declaring the LoggingCategory-
96 and cannot be changed later.-
97*/-
98-
99QQmlLoggingCategory::QQmlLoggingCategory(QObject *parent)-
100 : QObject(parent)-
101 , m_initialized(false)-
102{-
103}
executed 6 times by 1 test: end of block
Executed by:
  • tst_qqmlconsole
6
104-
105QQmlLoggingCategory::~QQmlLoggingCategory()-
106{-
107}-
108-
109QString QQmlLoggingCategory::name() const-
110{-
111 return QString::fromUtf8(m_name);
never executed: return QString::fromUtf8(m_name);
0
112}-
113-
114QQmlLoggingCategory::DefaultLogLevel QQmlLoggingCategory::defaultLogLevel() const-
115{-
116 return m_defaultLogLevel;
never executed: return m_defaultLogLevel;
0
117}-
118-
119QLoggingCategory *QQmlLoggingCategory::category() const-
120{-
121 return m_category.data();
executed 42 times by 1 test: return m_category.data();
Executed by:
  • tst_qqmlconsole
42
122}-
123-
124void QQmlLoggingCategory::classBegin()-
125{-
126}-
127-
128void QQmlLoggingCategory::componentComplete()-
129{-
130 m_initialized = true;-
131 if (m_name.isNull()) {
m_name.isNull()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qqmlconsole
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qqmlconsole
2-4
132 qmlWarning(this) << QLatin1String("Declaring the name of the LoggingCategory is mandatory and cannot be changed later !");-
133 } else {
executed 2 times by 1 test: end of block
Executed by:
  • tst_qqmlconsole
2
134 QScopedPointer<QLoggingCategory> category(new QLoggingCategory(m_name.constData(), QtMsgType(m_defaultLogLevel)));-
135 m_category.swap(category);-
136 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_qqmlconsole
4
137}-
138-
139void QQmlLoggingCategory::setDefaultLogLevel(DefaultLogLevel defaultLogLevel)-
140{-
141 if (m_initialized) {
m_initializedDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qqmlconsole
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qqmlconsole
2
142 qmlWarning(this) << QLatin1String("The defaultLogLevel of a LoggingCategory cannot be changed after the Item is created");-
143 return;
executed 2 times by 1 test: return;
Executed by:
  • tst_qqmlconsole
2
144 }-
145-
146 m_defaultLogLevel = defaultLogLevel;-
147}
executed 2 times by 1 test: end of block
Executed by:
  • tst_qqmlconsole
2
148-
149-
150void QQmlLoggingCategory::setName(const QString &name)-
151{-
152 if (m_initialized) {
m_initializedDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qqmlconsole
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qqmlconsole
2-4
153 qmlWarning(this) << QLatin1String("The name of a LoggingCategory cannot be changed after the Item is created");-
154 return;
executed 2 times by 1 test: return;
Executed by:
  • tst_qqmlconsole
2
155 }-
156-
157 m_name = name.toUtf8();-
158}
executed 4 times by 1 test: end of block
Executed by:
  • tst_qqmlconsole
4
159-
160#include "moc_qqmlloggingcategory_p.cpp"-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0