Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/qml/qqmlinfo.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
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 "qqmlinfo.h" | - | ||||||||||||
41 | - | |||||||||||||
42 | #include "qqmldata_p.h" | - | ||||||||||||
43 | #include "qqmlcontext.h" | - | ||||||||||||
44 | #include "qqmlcontext_p.h" | - | ||||||||||||
45 | #include "qqmlmetatype_p.h" | - | ||||||||||||
46 | #include "qqmlengine_p.h" | - | ||||||||||||
47 | - | |||||||||||||
48 | #include <QCoreApplication> | - | ||||||||||||
49 | - | |||||||||||||
50 | QT_BEGIN_NAMESPACE | - | ||||||||||||
51 | - | |||||||||||||
52 | /*! | - | ||||||||||||
53 | \fn QQmlInfo QtQml::qmlDebug(const QObject *object) | - | ||||||||||||
54 | \relates QQmlEngine | - | ||||||||||||
55 | \since 5.9 | - | ||||||||||||
56 | - | |||||||||||||
57 | Prints debug messages that include the file and line number for the | - | ||||||||||||
58 | specified QML \a object. | - | ||||||||||||
59 | - | |||||||||||||
60 | When QML types produce logging messages, it improves traceability | - | ||||||||||||
61 | if they include the QML file and line number on which the | - | ||||||||||||
62 | particular instance was instantiated. | - | ||||||||||||
63 | - | |||||||||||||
64 | To include the file and line number, an object must be passed. If | - | ||||||||||||
65 | the file and line number is not available for that instance | - | ||||||||||||
66 | (either it was not instantiated by the QML engine or location | - | ||||||||||||
67 | information is disabled), "unknown location" will be used instead. | - | ||||||||||||
68 | - | |||||||||||||
69 | For example, | - | ||||||||||||
70 | - | |||||||||||||
71 | \code | - | ||||||||||||
72 | qmlDebug(object) << "Internal state: 42"; | - | ||||||||||||
73 | \endcode | - | ||||||||||||
74 | - | |||||||||||||
75 | prints | - | ||||||||||||
76 | - | |||||||||||||
77 | \code | - | ||||||||||||
78 | QML MyCustomType (unknown location): Internal state: 42 | - | ||||||||||||
79 | \endcode | - | ||||||||||||
80 | - | |||||||||||||
81 | \sa QtQml::qmlInfo, QtQml::qmlWarning | - | ||||||||||||
82 | */ | - | ||||||||||||
83 | - | |||||||||||||
84 | /*! | - | ||||||||||||
85 | \fn QQmlInfo QtQml::qmlInfo(const QObject *object) | - | ||||||||||||
86 | \relates QQmlEngine | - | ||||||||||||
87 | - | |||||||||||||
88 | Prints informational messages that include the file and line number for the | - | ||||||||||||
89 | specified QML \a object. | - | ||||||||||||
90 | - | |||||||||||||
91 | When QML types produce logging messages, it improves traceability | - | ||||||||||||
92 | if they include the QML file and line number on which the | - | ||||||||||||
93 | particular instance was instantiated. | - | ||||||||||||
94 | - | |||||||||||||
95 | To include the file and line number, an object must be passed. If | - | ||||||||||||
96 | the file and line number is not available for that instance | - | ||||||||||||
97 | (either it was not instantiated by the QML engine or location | - | ||||||||||||
98 | information is disabled), "unknown location" will be used instead. | - | ||||||||||||
99 | - | |||||||||||||
100 | For example, | - | ||||||||||||
101 | - | |||||||||||||
102 | \code | - | ||||||||||||
103 | qmlInfo(object) << tr("component property is a write-once property"); | - | ||||||||||||
104 | \endcode | - | ||||||||||||
105 | - | |||||||||||||
106 | prints | - | ||||||||||||
107 | - | |||||||||||||
108 | \code | - | ||||||||||||
109 | QML MyCustomType (unknown location): component property is a write-once property | - | ||||||||||||
110 | \endcode | - | ||||||||||||
111 | - | |||||||||||||
112 | \note In versions prior to Qt 5.9, qmlInfo reported messages using a warning | - | ||||||||||||
113 | QtMsgType. For Qt 5.9 and above, qmlInfo uses an info QtMsgType. To send | - | ||||||||||||
114 | warnings, use qmlWarning. | - | ||||||||||||
115 | - | |||||||||||||
116 | \sa QtQml::qmlDebug, QtQml::qmlWarning | - | ||||||||||||
117 | */ | - | ||||||||||||
118 | - | |||||||||||||
119 | - | |||||||||||||
120 | /*! | - | ||||||||||||
121 | \fn QQmlInfo QtQml::qmlWarning(const QObject *object) | - | ||||||||||||
122 | \relates QQmlEngine | - | ||||||||||||
123 | \since 5.9 | - | ||||||||||||
124 | - | |||||||||||||
125 | Prints warning messages that include the file and line number for the | - | ||||||||||||
126 | specified QML \a object. | - | ||||||||||||
127 | - | |||||||||||||
128 | When QML types produce logging messages, it improves traceability | - | ||||||||||||
129 | if they include the QML file and line number on which the | - | ||||||||||||
130 | particular instance was instantiated. | - | ||||||||||||
131 | - | |||||||||||||
132 | To include the file and line number, an object must be passed. If | - | ||||||||||||
133 | the file and line number is not available for that instance | - | ||||||||||||
134 | (either it was not instantiated by the QML engine or location | - | ||||||||||||
135 | information is disabled), "unknown location" will be used instead. | - | ||||||||||||
136 | - | |||||||||||||
137 | For example, | - | ||||||||||||
138 | - | |||||||||||||
139 | \code | - | ||||||||||||
140 | qmlInfo(object) << tr("property cannot be set to 0"); | - | ||||||||||||
141 | \endcode | - | ||||||||||||
142 | - | |||||||||||||
143 | prints | - | ||||||||||||
144 | - | |||||||||||||
145 | \code | - | ||||||||||||
146 | QML MyCustomType (unknown location): property cannot be set to 0 | - | ||||||||||||
147 | \endcode | - | ||||||||||||
148 | - | |||||||||||||
149 | \sa QtQml::qmlDebug, QtQml::qmlInfo | - | ||||||||||||
150 | */ | - | ||||||||||||
151 | - | |||||||||||||
152 | class QQmlInfoPrivate | - | ||||||||||||
153 | { | - | ||||||||||||
154 | public: | - | ||||||||||||
155 | QQmlInfoPrivate(QtMsgType type) | - | ||||||||||||
156 | : ref (1) | - | ||||||||||||
157 | , msgType(type) | - | ||||||||||||
158 | , object(nullptr) | - | ||||||||||||
159 | {} executed 976 times by 30 tests: end of block Executed by:
| 976 | ||||||||||||
160 | - | |||||||||||||
161 | int ref; | - | ||||||||||||
162 | QtMsgType msgType; | - | ||||||||||||
163 | const QObject *object; | - | ||||||||||||
164 | QString buffer; | - | ||||||||||||
165 | QList<QQmlError> errors; | - | ||||||||||||
166 | }; | - | ||||||||||||
167 | - | |||||||||||||
168 | QQmlInfo::QQmlInfo(QQmlInfoPrivate *p) | - | ||||||||||||
169 | : QDebug(&p->buffer), d(p) | - | ||||||||||||
170 | { | - | ||||||||||||
171 | nospace(); | - | ||||||||||||
172 | } executed 976 times by 30 tests: end of block Executed by:
| 976 | ||||||||||||
173 | - | |||||||||||||
174 | QQmlInfo::QQmlInfo(const QQmlInfo &other) | - | ||||||||||||
175 | : QDebug(other), d(other.d) | - | ||||||||||||
176 | { | - | ||||||||||||
177 | d->ref++; | - | ||||||||||||
178 | } never executed: end of block | 0 | ||||||||||||
179 | - | |||||||||||||
180 | QQmlInfo::~QQmlInfo() | - | ||||||||||||
181 | { | - | ||||||||||||
182 | if (0 == --d->ref) {
| 0-976 | ||||||||||||
183 | QList<QQmlError> errors = d->errors; | - | ||||||||||||
184 | - | |||||||||||||
185 | QQmlEngine *engine = nullptr; | - | ||||||||||||
186 | - | |||||||||||||
187 | if (!d->buffer.isEmpty()) {
| 0-976 | ||||||||||||
188 | QQmlError error; | - | ||||||||||||
189 | error.setMessageType(d->msgType); | - | ||||||||||||
190 | - | |||||||||||||
191 | QObject *object = const_cast<QObject *>(d->object); | - | ||||||||||||
192 | - | |||||||||||||
193 | if (object) {
| 52-924 | ||||||||||||
194 | engine = qmlEngine(d->object); | - | ||||||||||||
195 | - | |||||||||||||
196 | d->buffer.prepend(QLatin1String("QML ") + QQmlMetaType::prettyTypeName(object) + QLatin1String(": ")); | - | ||||||||||||
197 | - | |||||||||||||
198 | QQmlData *ddata = QQmlData::get(object, false); | - | ||||||||||||
199 | if (ddata && ddata->outerContext) {
| 204-720 | ||||||||||||
200 | error.setUrl(ddata->outerContext->url()); | - | ||||||||||||
201 | error.setLine(ddata->lineNumber); | - | ||||||||||||
202 | error.setColumn(ddata->columnNumber); | - | ||||||||||||
203 | } executed 506 times by 27 tests: end of block Executed by:
| 506 | ||||||||||||
204 | } executed 924 times by 30 tests: end of block Executed by:
| 924 | ||||||||||||
205 | - | |||||||||||||
206 | error.setDescription(d->buffer); | - | ||||||||||||
207 | - | |||||||||||||
208 | errors.prepend(error); | - | ||||||||||||
209 | } executed 976 times by 30 tests: end of block Executed by:
| 976 | ||||||||||||
210 | - | |||||||||||||
211 | QQmlEnginePrivate::warning(engine, errors); | - | ||||||||||||
212 | - | |||||||||||||
213 | delete d; | - | ||||||||||||
214 | } executed 976 times by 30 tests: end of block Executed by:
| 976 | ||||||||||||
215 | } executed 976 times by 30 tests: end of block Executed by:
| 976 | ||||||||||||
216 | - | |||||||||||||
217 | namespace QtQml { | - | ||||||||||||
218 | - | |||||||||||||
219 | #define MESSAGE_FUNCS(FuncName, MessageLevel) \ | - | ||||||||||||
220 | QQmlInfo FuncName(const QObject *me) \ | - | ||||||||||||
221 | { \ | - | ||||||||||||
222 | QQmlInfoPrivate *d = new QQmlInfoPrivate(MessageLevel); \ | - | ||||||||||||
223 | d->object = me; \ | - | ||||||||||||
224 | return QQmlInfo(d); \ | - | ||||||||||||
225 | } \ | - | ||||||||||||
226 | QQmlInfo FuncName(const QObject *me, const QQmlError &error) \ | - | ||||||||||||
227 | { \ | - | ||||||||||||
228 | QQmlInfoPrivate *d = new QQmlInfoPrivate(MessageLevel); \ | - | ||||||||||||
229 | d->object = me; \ | - | ||||||||||||
230 | d->errors << error; \ | - | ||||||||||||
231 | return QQmlInfo(d); \ | - | ||||||||||||
232 | } \ | - | ||||||||||||
233 | QQmlInfo FuncName(const QObject *me, const QList<QQmlError> &errors) \ | - | ||||||||||||
234 | { \ | - | ||||||||||||
235 | QQmlInfoPrivate *d = new QQmlInfoPrivate(MessageLevel); \ | - | ||||||||||||
236 | d->object = me; \ | - | ||||||||||||
237 | d->errors = errors; \ | - | ||||||||||||
238 | return QQmlInfo(d); \ | - | ||||||||||||
239 | } | - | ||||||||||||
240 | - | |||||||||||||
241 | MESSAGE_FUNCS(qmlDebug, QtMsgType::QtDebugMsg) executed 2 times by 1 test: return QQmlInfo(d); Executed by:
never executed: return QQmlInfo(d); never executed: return QQmlInfo(d); | 0-2 | ||||||||||||
242 | MESSAGE_FUNCS(qmlInfo, QtMsgType::QtInfoMsg) executed 48 times by 1 test: return QQmlInfo(d); Executed by:
never executed: return QQmlInfo(d); never executed: return QQmlInfo(d); | 0-48 | ||||||||||||
243 | MESSAGE_FUNCS(qmlWarning, QtMsgType::QtWarningMsg) executed 926 times by 30 tests: return QQmlInfo(d); Executed by:
never executed: return QQmlInfo(d); never executed: return QQmlInfo(d); | 0-926 | ||||||||||||
244 | - | |||||||||||||
245 | - | |||||||||||||
246 | } // namespace QtQml | - | ||||||||||||
247 | - | |||||||||||||
248 | #if QT_DEPRECATED_SINCE(5, 1) | - | ||||||||||||
249 | - | |||||||||||||
250 | // Also define symbols outside namespace to keep binary compatibility with Qt 5.0 | - | ||||||||||||
251 | - | |||||||||||||
252 | QQmlInfo qmlInfo(const QObject *me) | - | ||||||||||||
253 | { | - | ||||||||||||
254 | return QtQml::qmlInfo(me); never executed: return QtQml::qmlInfo(me); | 0 | ||||||||||||
255 | } | - | ||||||||||||
256 | - | |||||||||||||
257 | QQmlInfo qmlInfo(const QObject *me, const QQmlError &error) | - | ||||||||||||
258 | { | - | ||||||||||||
259 | return QtQml::qmlInfo(me, error); never executed: return QtQml::qmlInfo(me, error); | 0 | ||||||||||||
260 | } | - | ||||||||||||
261 | - | |||||||||||||
262 | QQmlInfo qmlInfo(const QObject *me, const QList<QQmlError> &errors) | - | ||||||||||||
263 | { | - | ||||||||||||
264 | return QtQml::qmlInfo(me, errors); never executed: return QtQml::qmlInfo(me, errors); | 0 | ||||||||||||
265 | } | - | ||||||||||||
266 | - | |||||||||||||
267 | #endif // QT_DEPRECATED_SINCE(5, 1) | - | ||||||||||||
268 | - | |||||||||||||
269 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |