Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/debugger/qqmldebugservice.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 "qqmldebugservice_p.h" | - | ||||||
41 | #include "qqmldebugconnector_p.h" | - | ||||||
42 | #include <private/qqmldata_p.h> | - | ||||||
43 | #include <private/qqmlcontext_p.h> | - | ||||||
44 | - | |||||||
45 | #include <QtCore/QDebug> | - | ||||||
46 | #include <QtCore/QStringList> | - | ||||||
47 | #include <QtCore/QFileInfo> | - | ||||||
48 | - | |||||||
49 | QT_BEGIN_NAMESPACE | - | ||||||
50 | - | |||||||
51 | class QQmlDebugServer; | - | ||||||
52 | - | |||||||
53 | class QQmlDebugServicePrivate : public QObjectPrivate | - | ||||||
54 | { | - | ||||||
55 | Q_DECLARE_PUBLIC(QQmlDebugService) | - | ||||||
56 | public: | - | ||||||
57 | QQmlDebugServicePrivate(const QString &name, float version); | - | ||||||
58 | - | |||||||
59 | const QString name; | - | ||||||
60 | const float version; | - | ||||||
61 | QQmlDebugService::State state; | - | ||||||
62 | }; | - | ||||||
63 | - | |||||||
64 | QQmlDebugServicePrivate::QQmlDebugServicePrivate(const QString &name, float version) : | - | ||||||
65 | name(name), version(version), state(QQmlDebugService::NotConnected) | - | ||||||
66 | { | - | ||||||
67 | } executed 158 times by 7 tests: end of block Executed by:
| 158 | ||||||
68 | - | |||||||
69 | QQmlDebugService::QQmlDebugService(const QString &name, float version, QObject *parent) | - | ||||||
70 | : QObject(*(new QQmlDebugServicePrivate(name, version)), parent) | - | ||||||
71 | { | - | ||||||
72 | Q_D(QQmlDebugService); | - | ||||||
73 | QQmlDebugConnector *server = QQmlDebugConnector::instance(); | - | ||||||
74 | - | |||||||
75 | if (!server)
| 0-158 | ||||||
76 | return; never executed: return; | 0 | ||||||
77 | - | |||||||
78 | if (server->service(d->name)) {
| 4-154 | ||||||
79 | qWarning() << "QQmlDebugService: Conflicting plugin name" << d->name; | - | ||||||
80 | } else { executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||
81 | server->addService(d->name, this); | - | ||||||
82 | } executed 154 times by 7 tests: end of block Executed by:
| 154 | ||||||
83 | } | - | ||||||
84 | - | |||||||
85 | QQmlDebugService::~QQmlDebugService() | - | ||||||
86 | { | - | ||||||
87 | Q_D(QQmlDebugService); | - | ||||||
88 | QQmlDebugConnector *server = QQmlDebugConnector::instance(); | - | ||||||
89 | - | |||||||
90 | if (!server)
| 0-152 | ||||||
91 | return; never executed: return; | 0 | ||||||
92 | - | |||||||
93 | if (server->service(d->name) != this)
| 4-148 | ||||||
94 | qWarning() << "QQmlDebugService: Plugin" << d->name << "is not registered."; executed 4 times by 1 test: QMessageLogger(__FILE__, 94, __PRETTY_FUNCTION__).warning() << "QQmlDebugService: Plugin" << d->name << "is not registered."; Executed by:
| 4 | ||||||
95 | else | - | ||||||
96 | server->removeService(d->name); executed 148 times by 5 tests: server->removeService(d->name); Executed by:
| 148 | ||||||
97 | } | - | ||||||
98 | - | |||||||
99 | const QString &QQmlDebugService::name() const | - | ||||||
100 | { | - | ||||||
101 | Q_D(const QQmlDebugService); | - | ||||||
102 | return d->name; executed 732 times by 7 tests: return d->name; Executed by:
| 732 | ||||||
103 | } | - | ||||||
104 | - | |||||||
105 | float QQmlDebugService::version() const | - | ||||||
106 | { | - | ||||||
107 | Q_D(const QQmlDebugService); | - | ||||||
108 | return d->version; executed 158 times by 6 tests: return d->version; Executed by:
| 158 | ||||||
109 | } | - | ||||||
110 | - | |||||||
111 | QQmlDebugService::State QQmlDebugService::state() const | - | ||||||
112 | { | - | ||||||
113 | Q_D(const QQmlDebugService); | - | ||||||
114 | return d->state; executed 836 times by 7 tests: return d->state; Executed by:
| 836 | ||||||
115 | } | - | ||||||
116 | - | |||||||
117 | void QQmlDebugService::setState(QQmlDebugService::State newState) | - | ||||||
118 | { | - | ||||||
119 | Q_D(QQmlDebugService); | - | ||||||
120 | d->state = newState; | - | ||||||
121 | } executed 688 times by 7 tests: end of block Executed by:
| 688 | ||||||
122 | - | |||||||
123 | namespace { | - | ||||||
124 | class ObjectReferenceHash : public QObject | - | ||||||
125 | { | - | ||||||
126 | Q_OBJECT | - | ||||||
127 | public: | - | ||||||
128 | ObjectReferenceHash() : nextId(0) {} executed 28 times by 5 tests: end of block Executed by:
| 28 | ||||||
129 | - | |||||||
130 | QHash<QObject *, int> objects; | - | ||||||
131 | QHash<int, QObject *> ids; | - | ||||||
132 | - | |||||||
133 | int nextId; | - | ||||||
134 | - | |||||||
135 | void remove(QObject *obj); | - | ||||||
136 | }; | - | ||||||
137 | } | - | ||||||
138 | Q_GLOBAL_STATIC(ObjectReferenceHash, objectReferenceHash) executed 28 times by 5 tests: end of block Executed by:
executed 28 times by 5 tests: guard.store(QtGlobalStatic::Destroyed); Executed by:
executed 6804 times by 5 tests: return &holder.value; Executed by:
| 0-6804 | ||||||
139 | - | |||||||
140 | void ObjectReferenceHash::remove(QObject *obj) | - | ||||||
141 | { | - | ||||||
142 | QHash<QObject *, int>::Iterator iter = objects.find(obj); | - | ||||||
143 | if (iter != objects.end()) {
| 0-106 | ||||||
144 | ids.remove(iter.value()); | - | ||||||
145 | objects.erase(iter); | - | ||||||
146 | } executed 106 times by 5 tests: end of block Executed by:
| 106 | ||||||
147 | } executed 106 times by 5 tests: end of block Executed by:
| 106 | ||||||
148 | - | |||||||
149 | /*! | - | ||||||
150 | Returns a unique id for \a object. Calling this method multiple times | - | ||||||
151 | for the same object will return the same id. | - | ||||||
152 | */ | - | ||||||
153 | int QQmlDebugService::idForObject(QObject *object) | - | ||||||
154 | { | - | ||||||
155 | if (!object)
| 840-6436 | ||||||
156 | return -1; executed 840 times by 3 tests: return -1; Executed by:
| 840 | ||||||
157 | - | |||||||
158 | ObjectReferenceHash *hash = objectReferenceHash(); | - | ||||||
159 | QHash<QObject *, int>::Iterator iter = hash->objects.find(object); | - | ||||||
160 | - | |||||||
161 | if (iter == hash->objects.end()) {
| 124-6312 | ||||||
162 | int id = hash->nextId++; | - | ||||||
163 | hash->ids.insert(id, object); | - | ||||||
164 | iter = hash->objects.insert(object, id); | - | ||||||
165 | connect(object, &QObject::destroyed, hash, &ObjectReferenceHash::remove); | - | ||||||
166 | } executed 124 times by 5 tests: end of block Executed by:
| 124 | ||||||
167 | return iter.value(); executed 6436 times by 5 tests: return iter.value(); Executed by:
| 6436 | ||||||
168 | } | - | ||||||
169 | - | |||||||
170 | /*! | - | ||||||
171 | Returns the mapping of objects to unique \a ids, created through calls to idForObject(). | - | ||||||
172 | */ | - | ||||||
173 | const QHash<int, QObject *> &QQmlDebugService::objectsForIds() | - | ||||||
174 | { | - | ||||||
175 | return objectReferenceHash()->ids; executed 368 times by 4 tests: return objectReferenceHash()->ids; Executed by:
| 368 | ||||||
176 | } | - | ||||||
177 | - | |||||||
178 | QT_END_NAMESPACE | - | ||||||
179 | - | |||||||
180 | #include "qqmldebugservice.moc" | - | ||||||
181 | #include "moc_qqmldebugservice_p.cpp" | - | ||||||
Source code | Switch to Preprocessed file |