Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/qml/qqmlguard_p.h |
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 QtCore 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 | #ifndef QQMLGUARD_P_H | - | ||||||||||||||||||
41 | #define QQMLGUARD_P_H | - | ||||||||||||||||||
42 | - | |||||||||||||||||||
43 | // | - | ||||||||||||||||||
44 | // W A R N I N G | - | ||||||||||||||||||
45 | // ------------- | - | ||||||||||||||||||
46 | // | - | ||||||||||||||||||
47 | // This file is not part of the Qt API. It exists for the convenience | - | ||||||||||||||||||
48 | // of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header | - | ||||||||||||||||||
49 | // file may change from version to version without notice, or even be removed. | - | ||||||||||||||||||
50 | // | - | ||||||||||||||||||
51 | // We mean it. | - | ||||||||||||||||||
52 | // | - | ||||||||||||||||||
53 | - | |||||||||||||||||||
54 | #include <QtCore/qglobal.h> | - | ||||||||||||||||||
55 | #include <QtCore/qvariant.h> | - | ||||||||||||||||||
56 | #include <private/qqmldata_p.h> | - | ||||||||||||||||||
57 | - | |||||||||||||||||||
58 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
59 | - | |||||||||||||||||||
60 | class QQmlGuardImpl | - | ||||||||||||||||||
61 | { | - | ||||||||||||||||||
62 | public: | - | ||||||||||||||||||
63 | inline QQmlGuardImpl(); | - | ||||||||||||||||||
64 | inline QQmlGuardImpl(QObject *); | - | ||||||||||||||||||
65 | inline QQmlGuardImpl(const QQmlGuardImpl &); | - | ||||||||||||||||||
66 | inline ~QQmlGuardImpl(); | - | ||||||||||||||||||
67 | - | |||||||||||||||||||
68 | QObject *o = nullptr; | - | ||||||||||||||||||
69 | QQmlGuardImpl *next = nullptr; | - | ||||||||||||||||||
70 | QQmlGuardImpl **prev = nullptr; | - | ||||||||||||||||||
71 | - | |||||||||||||||||||
72 | inline void addGuard(); | - | ||||||||||||||||||
73 | inline void remGuard(); | - | ||||||||||||||||||
74 | }; | - | ||||||||||||||||||
75 | - | |||||||||||||||||||
76 | class QObject; | - | ||||||||||||||||||
77 | template<class T> | - | ||||||||||||||||||
78 | class QQmlGuard : private QQmlGuardImpl | - | ||||||||||||||||||
79 | { | - | ||||||||||||||||||
80 | friend class QQmlData; | - | ||||||||||||||||||
81 | public: | - | ||||||||||||||||||
82 | inline QQmlGuard(); | - | ||||||||||||||||||
83 | inline QQmlGuard(T *); | - | ||||||||||||||||||
84 | inline QQmlGuard(const QQmlGuard<T> &); | - | ||||||||||||||||||
85 | inline virtual ~QQmlGuard(); | - | ||||||||||||||||||
86 | - | |||||||||||||||||||
87 | inline QQmlGuard<T> &operator=(const QQmlGuard<T> &o); | - | ||||||||||||||||||
88 | inline QQmlGuard<T> &operator=(T *); | - | ||||||||||||||||||
89 | - | |||||||||||||||||||
90 | inline T *object() const; | - | ||||||||||||||||||
91 | inline void setObject(T *g); | - | ||||||||||||||||||
92 | - | |||||||||||||||||||
93 | inline bool isNull() const | - | ||||||||||||||||||
94 | { return !o; } executed 548 times by 2 tests: return !o; Executed by:
| 548 | ||||||||||||||||||
95 | - | |||||||||||||||||||
96 | inline T* operator->() const | - | ||||||||||||||||||
97 | { return static_cast<T*>(const_cast<QObject*>(o)); } executed 104267 times by 32 tests: return static_cast<T*>(const_cast<QObject*>(o)); Executed by:
| 104267 | ||||||||||||||||||
98 | inline T& operator*() const | - | ||||||||||||||||||
99 | { return *static_cast<T*>(const_cast<QObject*>(o)); } never executed: return *static_cast<T*>(const_cast<QObject*>(o)); | 0 | ||||||||||||||||||
100 | inline operator T*() const | - | ||||||||||||||||||
101 | { return static_cast<T*>(const_cast<QObject*>(o)); } executed 1563468 times by 50 tests: return static_cast<T*>(const_cast<QObject*>(o)); Executed by:
| 1563468 | ||||||||||||||||||
102 | inline T* data() const | - | ||||||||||||||||||
103 | { return static_cast<T*>(const_cast<QObject*>(o)); } executed 481965 times by 85 tests: return static_cast<T*>(const_cast<QObject*>(o)); Executed by:
| 481965 | ||||||||||||||||||
104 | - | |||||||||||||||||||
105 | protected: | - | ||||||||||||||||||
106 | virtual void objectDestroyed(T *) {} | - | ||||||||||||||||||
107 | }; | - | ||||||||||||||||||
108 | - | |||||||||||||||||||
109 | template <typename T> | - | ||||||||||||||||||
110 | class QQmlStrongJSQObjectReference : public QQmlGuard<T> | - | ||||||||||||||||||
111 | { | - | ||||||||||||||||||
112 | public: | - | ||||||||||||||||||
113 | void setObject(T *o, QObject *parent) { | - | ||||||||||||||||||
114 | T *old = this->object(); | - | ||||||||||||||||||
115 | if (o == old)
| 3240-13920 | ||||||||||||||||||
116 | return; executed 3240 times by 24 tests: return; Executed by:
| 3240 | ||||||||||||||||||
117 | - | |||||||||||||||||||
118 | if (m_jsOwnership && old && old->parent() == parent)
| 0-13916 | ||||||||||||||||||
119 | QQml_setParent_noEvent(old, nullptr); executed 4 times by 1 test: QQml_setParent_noEvent(old, nullptr); Executed by:
| 4 | ||||||||||||||||||
120 | - | |||||||||||||||||||
121 | this->QQmlGuard<T>::operator=(o); | - | ||||||||||||||||||
122 | - | |||||||||||||||||||
123 | if (o && !o->parent() && !QQmlData::keepAliveDuringGarbageCollection(o)) {
| 6-10120 | ||||||||||||||||||
124 | m_jsOwnership = true; | - | ||||||||||||||||||
125 | QQml_setParent_noEvent(o, parent); | - | ||||||||||||||||||
126 | } else { executed 6 times by 2 tests: end of block Executed by:
| 6 | ||||||||||||||||||
127 | m_jsOwnership = false; | - | ||||||||||||||||||
128 | } executed 13914 times by 31 tests: end of block Executed by:
| 13914 | ||||||||||||||||||
129 | } | - | ||||||||||||||||||
130 | - | |||||||||||||||||||
131 | private: | - | ||||||||||||||||||
132 | using QQmlGuard<T>::setObject; | - | ||||||||||||||||||
133 | using QQmlGuard<T>::operator=; | - | ||||||||||||||||||
134 | bool m_jsOwnership = false; | - | ||||||||||||||||||
135 | }; | - | ||||||||||||||||||
136 | - | |||||||||||||||||||
137 | QT_END_NAMESPACE | - | ||||||||||||||||||
138 | - | |||||||||||||||||||
139 | Q_DECLARE_METATYPE(QQmlGuard<QObject>) never executed: return id; never executed: return newId;
| 0 | ||||||||||||||||||
140 | - | |||||||||||||||||||
141 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
142 | - | |||||||||||||||||||
143 | QQmlGuardImpl::QQmlGuardImpl() | - | ||||||||||||||||||
144 | { | - | ||||||||||||||||||
145 | } | - | ||||||||||||||||||
146 | - | |||||||||||||||||||
147 | QQmlGuardImpl::QQmlGuardImpl(QObject *g) | - | ||||||||||||||||||
148 | : o(g) | - | ||||||||||||||||||
149 | { | - | ||||||||||||||||||
150 | if (o) addGuard(); executed 10948 times by 10 tests: addGuard(); Executed by:
| 10948-13064 | ||||||||||||||||||
151 | } executed 24012 times by 57 tests: end of block Executed by:
| 24012 | ||||||||||||||||||
152 | - | |||||||||||||||||||
153 | QQmlGuardImpl::QQmlGuardImpl(const QQmlGuardImpl &g) | - | ||||||||||||||||||
154 | : o(g.o) | - | ||||||||||||||||||
155 | { | - | ||||||||||||||||||
156 | if (o) addGuard(); executed 7310 times by 23 tests: addGuard(); Executed by:
| 114-7310 | ||||||||||||||||||
157 | } executed 7424 times by 23 tests: end of block Executed by:
| 7424 | ||||||||||||||||||
158 | - | |||||||||||||||||||
159 | QQmlGuardImpl::~QQmlGuardImpl() | - | ||||||||||||||||||
160 | { | - | ||||||||||||||||||
161 | if (prev) remGuard(); executed 23573 times by 55 tests: remGuard(); Executed by:
| 23573-243132 | ||||||||||||||||||
162 | o = nullptr; | - | ||||||||||||||||||
163 | } executed 266705 times by 115 tests: end of block Executed by:
| 266705 | ||||||||||||||||||
164 | - | |||||||||||||||||||
165 | void QQmlGuardImpl::addGuard() | - | ||||||||||||||||||
166 | { | - | ||||||||||||||||||
167 | Q_ASSERT(!prev); | - | ||||||||||||||||||
168 | - | |||||||||||||||||||
169 | if (QObjectPrivate::get(o)->wasDeleted)
| 0-258223 | ||||||||||||||||||
170 | return; never executed: return; | 0 | ||||||||||||||||||
171 | - | |||||||||||||||||||
172 | QQmlData *data = QQmlData::get(o, true); | - | ||||||||||||||||||
173 | next = data->guards; | - | ||||||||||||||||||
174 | if (next) next->prev = &next; executed 31356 times by 54 tests: next->prev = &next; Executed by:
| 31356-226867 | ||||||||||||||||||
175 | data->guards = this; | - | ||||||||||||||||||
176 | prev = &data->guards; | - | ||||||||||||||||||
177 | } executed 258223 times by 121 tests: end of block Executed by:
| 258223 | ||||||||||||||||||
178 | - | |||||||||||||||||||
179 | void QQmlGuardImpl::remGuard() | - | ||||||||||||||||||
180 | { | - | ||||||||||||||||||
181 | Q_ASSERT(prev); | - | ||||||||||||||||||
182 | - | |||||||||||||||||||
183 | if (next) next->prev = prev; executed 13646 times by 22 tests: next->prev = prev; Executed by:
| 13646-13941 | ||||||||||||||||||
184 | *prev = next; | - | ||||||||||||||||||
185 | next = nullptr; | - | ||||||||||||||||||
186 | prev = nullptr; | - | ||||||||||||||||||
187 | } executed 27587 times by 58 tests: end of block Executed by:
| 27587 | ||||||||||||||||||
188 | - | |||||||||||||||||||
189 | template<class T> | - | ||||||||||||||||||
190 | QQmlGuard<T>::QQmlGuard() | - | ||||||||||||||||||
191 | { | - | ||||||||||||||||||
192 | } | - | ||||||||||||||||||
193 | - | |||||||||||||||||||
194 | template<class T> | - | ||||||||||||||||||
195 | QQmlGuard<T>::QQmlGuard(T *g) | - | ||||||||||||||||||
196 | : QQmlGuardImpl(g) | - | ||||||||||||||||||
197 | { | - | ||||||||||||||||||
198 | } executed 24012 times by 57 tests: end of block Executed by:
| 24012 | ||||||||||||||||||
199 | - | |||||||||||||||||||
200 | template<class T> | - | ||||||||||||||||||
201 | QQmlGuard<T>::QQmlGuard(const QQmlGuard<T> &g) | - | ||||||||||||||||||
202 | : QQmlGuardImpl(g) | - | ||||||||||||||||||
203 | { | - | ||||||||||||||||||
204 | } executed 7424 times by 23 tests: end of block Executed by:
| 7424 | ||||||||||||||||||
205 | - | |||||||||||||||||||
206 | template<class T> | - | ||||||||||||||||||
207 | QQmlGuard<T>::~QQmlGuard() | - | ||||||||||||||||||
208 | { | - | ||||||||||||||||||
209 | } | - | ||||||||||||||||||
210 | - | |||||||||||||||||||
211 | template<class T> | - | ||||||||||||||||||
212 | QQmlGuard<T> &QQmlGuard<T>::operator=(const QQmlGuard<T> &g) | - | ||||||||||||||||||
213 | { | - | ||||||||||||||||||
214 | setObject(g.object()); | - | ||||||||||||||||||
215 | return *this; executed 102 times by 2 tests: return *this; Executed by:
| 102 | ||||||||||||||||||
216 | } | - | ||||||||||||||||||
217 | - | |||||||||||||||||||
218 | template<class T> | - | ||||||||||||||||||
219 | QQmlGuard<T> &QQmlGuard<T>::operator=(T *g) | - | ||||||||||||||||||
220 | { | - | ||||||||||||||||||
221 | setObject(g); | - | ||||||||||||||||||
222 | return *this; executed 241661 times by 116 tests: return *this; Executed by:
| 241661 | ||||||||||||||||||
223 | } | - | ||||||||||||||||||
224 | - | |||||||||||||||||||
225 | template<class T> | - | ||||||||||||||||||
226 | T *QQmlGuard<T>::object() const | - | ||||||||||||||||||
227 | { | - | ||||||||||||||||||
228 | return static_cast<T *>(o); executed 539182 times by 32 tests: return static_cast<T *>(o); Executed by:
| 539182 | ||||||||||||||||||
229 | } | - | ||||||||||||||||||
230 | - | |||||||||||||||||||
231 | template<class T> | - | ||||||||||||||||||
232 | void QQmlGuard<T>::setObject(T *g) | - | ||||||||||||||||||
233 | { | - | ||||||||||||||||||
234 | if (g != o) {
| 313-243827 | ||||||||||||||||||
235 | if (prev) remGuard(); executed 4014 times by 23 tests: remGuard(); Executed by:
| 4014-239813 | ||||||||||||||||||
236 | o = g; | - | ||||||||||||||||||
237 | if (o) addGuard(); executed 239965 times by 121 tests: addGuard(); Executed by:
| 3862-239965 | ||||||||||||||||||
238 | } executed 243827 times by 121 tests: end of block Executed by:
| 243827 | ||||||||||||||||||
239 | } executed 244140 times by 121 tests: end of block Executed by:
| 244140 | ||||||||||||||||||
240 | - | |||||||||||||||||||
241 | QT_END_NAMESPACE | - | ||||||||||||||||||
242 | - | |||||||||||||||||||
243 | #endif // QQMLGUARD_P_H | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |