Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qqmldebugservice.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant
4
5
#
include
"qqmldebugservice_p.h"
6
#
include
"qqmldebugconnector_p.h"
7
#
include
<
private
/
qqmldata_p
.
h
>
8
#
include
<
private
/
qqmlcontext_p
.
h
>
9
10
#
include
<
QtCore
/
qdebug
.
h
>
11
#
include
<
QtCore
/
qfileinfo
.
h
>
12
#
include
<
QtCore
/
qstringlist
.
h
>
13
#
include
<
QtCore
/
qthread
.
h
>
14
15
QT_BEGIN_NAMESPACE
16
17
/*!
18
\class QQmlDebugService
19
\inmodule QtQml
20
\internal
21
*/
22
23
class
QQmlDebugServer;
24
25
class
QQmlDebugServicePrivate
:
public
QObjectPrivate
26
{
27
Q_DECLARE_PUBLIC(QQmlDebugService)
28
public
:
29
QQmlDebugServicePrivate
(
const
QString
&
name
,
float
version
);
30
31
const
QString
name
;
32
const
float
version
;
33
QQmlDebugService
::
State
state
;
34
};
35
36
QQmlDebugServicePrivate
::QQmlDebugServicePrivate(
const
QString &name,
float
version) :
37
name(name),
version
(version), state(QQmlDebugService::NotConnected)
38
{
39
}
40
41
QQmlDebugService::QQmlDebugService(
const
QString &name,
float
version, QObject *parent)
42
: QObject(*(
new
QQmlDebugServicePrivate(name, version)), parent)
43
{
44
Q_D(QQmlDebugService);
45
QQmlDebugConnector *server = QQmlDebugConnector::instance();
46
47
if
(!server)
48
return
;
49
50
if
(server->service(d->name)) {
51
qWarning() <<
"QQmlDebugService: Conflicting plugin name"
<< d->name;
52
}
else
{
53
server->addService(d->name,
this
);
54
}
55
}
56
57
QQmlDebugService::~QQmlDebugService()
58
{
59
QThread *currentThread = QThread::currentThread();
60
QThread *mainThread = thread();
61
if
(currentThread != mainThread) {
62
qFatal(
"Qml debugging framework was cleaned up from wrong thread. Did you leak your "
63
"QCoreApplication?"
);
64
}
65
Q_D(QQmlDebugService);
66
QQmlDebugConnector *server = QQmlDebugConnector::instance();
67
68
if
(!server)
69
return
;
70
71
if
(server->service(d->name) !=
this
)
72
qWarning() <<
"QQmlDebugService: Plugin"
<< d->name <<
"is not registered."
;
73
else
74
server->removeService(d->name);
75
}
76
77
const
QString &QQmlDebugService::name()
const
78
{
79
Q_D(
const
QQmlDebugService);
80
return
d->name;
81
}
82
83
float
QQmlDebugService::version()
const
84
{
85
Q_D(
const
QQmlDebugService);
86
return
d->version;
87
}
88
89
QQmlDebugService::State QQmlDebugService::state()
const
90
{
91
Q_D(
const
QQmlDebugService);
92
return
d->state;
93
}
94
95
void
QQmlDebugService::setState(QQmlDebugService::State newState)
96
{
97
Q_D(QQmlDebugService);
98
d->state = newState;
99
}
100
101
namespace
{
102
class
ObjectReferenceHash :
public
QObject
103
{
104
Q_OBJECT
105
public
:
106
ObjectReferenceHash() : nextId(0) {}
107
108
QHash<QObject *,
int
> objects;
109
QHash<
int
, QObject *> ids;
110
111
int
nextId;
112
113
void
remove(QObject *obj);
114
};
115
}
116
Q_GLOBAL_STATIC(ObjectReferenceHash, objectReferenceHash)
117
118
void
ObjectReferenceHash::remove(QObject *obj)
119
{
120
const
auto
iter = objects.constFind(obj);
121
if
(iter != objects.cend()) {
122
ids.remove(iter.value());
123
objects.erase(iter);
124
}
125
}
126
127
/*!
128
\internal
129
Returns a unique id for \a object. Calling this method multiple times
130
for the same object will return the same id.
131
*/
132
int
QQmlDebugService::idForObject(QObject *object)
133
{
134
if
(!object)
135
return
-1;
136
137
ObjectReferenceHash *hash = objectReferenceHash();
138
if
(
auto
iter = hash->objects.constFind(object); iter != hash->objects.cend())
139
return
iter.value();
140
141
connect(object, &QObject::destroyed, hash, &ObjectReferenceHash::remove);
142
const
int
id = hash->nextId++;
143
hash->ids.insert(id, object);
144
hash->objects.insert(object, id);
145
return
id;
146
}
147
148
/*!
149
\internal
150
Returns the mapping of objects to unique \a ids, created through
151
calls to idForObject().
152
*/
153
const
QHash<
int
, QObject *> &QQmlDebugService::objectsForIds()
154
{
155
return
objectReferenceHash()->ids;
156
}
157
158
QT_END_NAMESPACE
159
160
#
include
"qqmldebugservice.moc"
161
#
include
"moc_qqmldebugservice_p.cpp"
QQmlDebugServicePrivate
Definition
qqmldebugservice.cpp:26
QQmlDebugServicePrivate::name
const QString name
Definition
qqmldebugservice.cpp:31
QQmlDebugServicePrivate::state
QQmlDebugService::State state
Definition
qqmldebugservice.cpp:33
QQmlDebugServicePrivate::version
const float version
Definition
qqmldebugservice.cpp:32
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
qml
debugger
qqmldebugservice.cpp
Generated on
for Qt by
1.18.0