Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quickwidgets/qquickwidget.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 QtQuick 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 "qquickwidget.h" | - | ||||||||||||||||||
41 | #include "qquickwidget_p.h" | - | ||||||||||||||||||
42 | - | |||||||||||||||||||
43 | #include "private/qquickwindow_p.h" | - | ||||||||||||||||||
44 | #include "private/qquickitem_p.h" | - | ||||||||||||||||||
45 | #include "private/qquickitemchangelistener_p.h" | - | ||||||||||||||||||
46 | #include "private/qquickrendercontrol_p.h" | - | ||||||||||||||||||
47 | - | |||||||||||||||||||
48 | #include "private/qsgsoftwarerenderer_p.h" | - | ||||||||||||||||||
49 | - | |||||||||||||||||||
50 | #include <private/qqmldebugconnector_p.h> | - | ||||||||||||||||||
51 | #include <private/qquickprofiler_p.h> | - | ||||||||||||||||||
52 | #include <private/qqmldebugserviceinterfaces_p.h> | - | ||||||||||||||||||
53 | #include <private/qqmlmemoryprofiler_p.h> | - | ||||||||||||||||||
54 | - | |||||||||||||||||||
55 | #include <QtQml/qqmlengine.h> | - | ||||||||||||||||||
56 | #include <private/qqmlengine_p.h> | - | ||||||||||||||||||
57 | #include <QtCore/qbasictimer.h> | - | ||||||||||||||||||
58 | #include <QtGui/QOffscreenSurface> | - | ||||||||||||||||||
59 | #include <QtGui/private/qguiapplication_p.h> | - | ||||||||||||||||||
60 | #include <QtGui/qpa/qplatformintegration.h> | - | ||||||||||||||||||
61 | - | |||||||||||||||||||
62 | #if QT_CONFIG(opengl) | - | ||||||||||||||||||
63 | #include <QtGui/QOpenGLContext> | - | ||||||||||||||||||
64 | #include <QtGui/QOpenGLFunctions> | - | ||||||||||||||||||
65 | #include <QtGui/private/qopenglextensions_p.h> | - | ||||||||||||||||||
66 | #endif | - | ||||||||||||||||||
67 | #include <QtGui/QPainter> | - | ||||||||||||||||||
68 | - | |||||||||||||||||||
69 | #include <QtQuick/QSGRendererInterface> | - | ||||||||||||||||||
70 | - | |||||||||||||||||||
71 | #ifdef Q_OS_WIN | - | ||||||||||||||||||
72 | # include <QtWidgets/QMessageBox> | - | ||||||||||||||||||
73 | # include <QtCore/QLibraryInfo> | - | ||||||||||||||||||
74 | # include <QtCore/qt_windows.h> | - | ||||||||||||||||||
75 | #endif | - | ||||||||||||||||||
76 | - | |||||||||||||||||||
77 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
78 | - | |||||||||||||||||||
79 | class QQuickWidgetRenderControl : public QQuickRenderControl | - | ||||||||||||||||||
80 | { | - | ||||||||||||||||||
81 | public: | - | ||||||||||||||||||
82 | QQuickWidgetRenderControl(QQuickWidget *quickwidget) : m_quickWidget(quickwidget) {} executed 118 times by 2 tests: end of block Executed by:
| 118 | ||||||||||||||||||
83 | QWindow *renderWindow(QPoint *offset) override { | - | ||||||||||||||||||
84 | if (offset)
| 0-694 | ||||||||||||||||||
85 | *offset = m_quickWidget->mapTo(m_quickWidget->window(), QPoint()); never executed: *offset = m_quickWidget->mapTo(m_quickWidget->window(), QPoint()); | 0 | ||||||||||||||||||
86 | return m_quickWidget->window()->windowHandle(); executed 694 times by 2 tests: return m_quickWidget->window()->windowHandle(); Executed by:
| 694 | ||||||||||||||||||
87 | } | - | ||||||||||||||||||
88 | private: | - | ||||||||||||||||||
89 | QQuickWidget *m_quickWidget; | - | ||||||||||||||||||
90 | }; | - | ||||||||||||||||||
91 | - | |||||||||||||||||||
92 | void QQuickWidgetPrivate::init(QQmlEngine* e) | - | ||||||||||||||||||
93 | { | - | ||||||||||||||||||
94 | Q_Q(QQuickWidget); | - | ||||||||||||||||||
95 | - | |||||||||||||||||||
96 | renderControl = new QQuickWidgetRenderControl(q); | - | ||||||||||||||||||
97 | offscreenWindow = new QQuickWindow(renderControl); | - | ||||||||||||||||||
98 | offscreenWindow->setTitle(QString::fromLatin1("Offscreen")); | - | ||||||||||||||||||
99 | // Do not call create() on offscreenWindow. | - | ||||||||||||||||||
100 | - | |||||||||||||||||||
101 | // Check if the Software Adaptation is being used | - | ||||||||||||||||||
102 | auto sgRendererInterface = offscreenWindow->rendererInterface(); | - | ||||||||||||||||||
103 | if (sgRendererInterface && sgRendererInterface->graphicsApi() == QSGRendererInterface::Software)
| 0-118 | ||||||||||||||||||
104 | useSoftwareRenderer = true; never executed: useSoftwareRenderer = true; | 0 | ||||||||||||||||||
105 | - | |||||||||||||||||||
106 | if (!useSoftwareRenderer) {
| 0-118 | ||||||||||||||||||
107 | #if QT_CONFIG(opengl) | - | ||||||||||||||||||
108 | if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::RasterGLSurface))
| 0-118 | ||||||||||||||||||
109 | setRenderToTexture(); executed 118 times by 2 tests: setRenderToTexture(); Executed by:
| 118 | ||||||||||||||||||
110 | else | - | ||||||||||||||||||
111 | #endif | - | ||||||||||||||||||
112 | qWarning("QQuickWidget is not supported on this platform."); never executed: QMessageLogger(__FILE__, 112, __PRETTY_FUNCTION__).warning("QQuickWidget is not supported on this platform."); | 0 | ||||||||||||||||||
113 | } | - | ||||||||||||||||||
114 | - | |||||||||||||||||||
115 | engine = e; | - | ||||||||||||||||||
116 | - | |||||||||||||||||||
117 | if (!engine.isNull() && !engine.data()->incubationController())
| 0-114 | ||||||||||||||||||
118 | engine.data()->setIncubationController(offscreenWindow->incubationController()); executed 4 times by 1 test: engine.data()->setIncubationController(offscreenWindow->incubationController()); Executed by:
| 4 | ||||||||||||||||||
119 | - | |||||||||||||||||||
120 | #if QT_CONFIG(draganddrop) | - | ||||||||||||||||||
121 | q->setAcceptDrops(true); | - | ||||||||||||||||||
122 | #endif | - | ||||||||||||||||||
123 | - | |||||||||||||||||||
124 | QWidget::connect(offscreenWindow, SIGNAL(sceneGraphInitialized()), q, SLOT(createFramebufferObject())); | - | ||||||||||||||||||
125 | QWidget::connect(offscreenWindow, SIGNAL(sceneGraphInvalidated()), q, SLOT(destroyFramebufferObject())); | - | ||||||||||||||||||
126 | QObject::connect(renderControl, SIGNAL(renderRequested()), q, SLOT(triggerUpdate())); | - | ||||||||||||||||||
127 | QObject::connect(renderControl, SIGNAL(sceneChanged()), q, SLOT(triggerUpdate())); | - | ||||||||||||||||||
128 | } executed 118 times by 2 tests: end of block Executed by:
| 118 | ||||||||||||||||||
129 | - | |||||||||||||||||||
130 | void QQuickWidgetPrivate::ensureEngine() const | - | ||||||||||||||||||
131 | { | - | ||||||||||||||||||
132 | Q_Q(const QQuickWidget); | - | ||||||||||||||||||
133 | if (!engine.isNull())
| 12-104 | ||||||||||||||||||
134 | return; executed 12 times by 1 test: return; Executed by:
| 12 | ||||||||||||||||||
135 | - | |||||||||||||||||||
136 | engine = new QQmlEngine(const_cast<QQuickWidget*>(q)); | - | ||||||||||||||||||
137 | engine.data()->setIncubationController(offscreenWindow->incubationController()); | - | ||||||||||||||||||
138 | } executed 104 times by 2 tests: end of block Executed by:
| 104 | ||||||||||||||||||
139 | - | |||||||||||||||||||
140 | void QQuickWidgetPrivate::invalidateRenderControl() | - | ||||||||||||||||||
141 | { | - | ||||||||||||||||||
142 | #if QT_CONFIG(opengl) | - | ||||||||||||||||||
143 | if (!useSoftwareRenderer) {
| 0-126 | ||||||||||||||||||
144 | if (!context) // this is not an error, could be called before creating the context, or multiple times
| 14-112 | ||||||||||||||||||
145 | return; executed 14 times by 1 test: return; Executed by:
| 14 | ||||||||||||||||||
146 | - | |||||||||||||||||||
147 | bool success = context->makeCurrent(offscreenSurface); | - | ||||||||||||||||||
148 | if (!success) {
| 0-112 | ||||||||||||||||||
149 | qWarning("QQuickWidget::invalidateRenderControl could not make context current"); | - | ||||||||||||||||||
150 | return; never executed: return; | 0 | ||||||||||||||||||
151 | } | - | ||||||||||||||||||
152 | } executed 112 times by 2 tests: end of block Executed by:
| 112 | ||||||||||||||||||
153 | #endif | - | ||||||||||||||||||
154 | - | |||||||||||||||||||
155 | renderControl->invalidate(); | - | ||||||||||||||||||
156 | - | |||||||||||||||||||
157 | // Many things can happen inside the above invalidate() call, including a | - | ||||||||||||||||||
158 | // change of current context. Restore if needed since some code will rely | - | ||||||||||||||||||
159 | // on the fact that this function makes and leaves the context current. | - | ||||||||||||||||||
160 | #if QT_CONFIG(opengl) | - | ||||||||||||||||||
161 | if (!useSoftwareRenderer && context) {
| 0-112 | ||||||||||||||||||
162 | if (QOpenGLContext::currentContext() != context)
| 0-112 | ||||||||||||||||||
163 | context->makeCurrent(offscreenSurface); never executed: context->makeCurrent(offscreenSurface); | 0 | ||||||||||||||||||
164 | } executed 112 times by 2 tests: end of block Executed by:
| 112 | ||||||||||||||||||
165 | #endif | - | ||||||||||||||||||
166 | } executed 112 times by 2 tests: end of block Executed by:
| 112 | ||||||||||||||||||
167 | - | |||||||||||||||||||
168 | void QQuickWidgetPrivate::handleWindowChange() | - | ||||||||||||||||||
169 | { | - | ||||||||||||||||||
170 | if (offscreenWindow->isPersistentSceneGraph() && qGuiApp->testAttribute(Qt::AA_ShareOpenGLContexts))
| 0-8 | ||||||||||||||||||
171 | return; never executed: return; | 0 | ||||||||||||||||||
172 | - | |||||||||||||||||||
173 | // In case of !isPersistentSceneGraph or when we need a new context due to | - | ||||||||||||||||||
174 | // the need to share resources with the new window's context, we must both | - | ||||||||||||||||||
175 | // invalidate the scenegraph and destroy the context. With | - | ||||||||||||||||||
176 | // QQuickRenderControl destroying the context must be preceded by an | - | ||||||||||||||||||
177 | // invalidate to prevent being left with dangling context references in the | - | ||||||||||||||||||
178 | // rendercontrol. | - | ||||||||||||||||||
179 | - | |||||||||||||||||||
180 | invalidateRenderControl(); | - | ||||||||||||||||||
181 | - | |||||||||||||||||||
182 | if (!useSoftwareRenderer)
| 0-8 | ||||||||||||||||||
183 | destroyContext(); executed 8 times by 1 test: destroyContext(); Executed by:
| 8 | ||||||||||||||||||
184 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
185 | - | |||||||||||||||||||
186 | QQuickWidgetPrivate::QQuickWidgetPrivate() | - | ||||||||||||||||||
187 | : root(nullptr) | - | ||||||||||||||||||
188 | , component(nullptr) | - | ||||||||||||||||||
189 | , offscreenWindow(nullptr) | - | ||||||||||||||||||
190 | , offscreenSurface(nullptr) | - | ||||||||||||||||||
191 | , renderControl(nullptr) | - | ||||||||||||||||||
192 | #if QT_CONFIG(opengl) | - | ||||||||||||||||||
193 | , fbo(nullptr) | - | ||||||||||||||||||
194 | , resolvedFbo(nullptr) | - | ||||||||||||||||||
195 | , context(nullptr) | - | ||||||||||||||||||
196 | #endif | - | ||||||||||||||||||
197 | , resizeMode(QQuickWidget::SizeViewToRootObject) | - | ||||||||||||||||||
198 | , initialSize(0,0) | - | ||||||||||||||||||
199 | , eventPending(false) | - | ||||||||||||||||||
200 | , updatePending(false) | - | ||||||||||||||||||
201 | , fakeHidden(false) | - | ||||||||||||||||||
202 | , requestedSamples(0) | - | ||||||||||||||||||
203 | , useSoftwareRenderer(false) | - | ||||||||||||||||||
204 | , forceFullUpdate(false) | - | ||||||||||||||||||
205 | { | - | ||||||||||||||||||
206 | } executed 118 times by 2 tests: end of block Executed by:
| 118 | ||||||||||||||||||
207 | - | |||||||||||||||||||
208 | QQuickWidgetPrivate::~QQuickWidgetPrivate() | - | ||||||||||||||||||
209 | { | - | ||||||||||||||||||
210 | invalidateRenderControl(); | - | ||||||||||||||||||
211 | - | |||||||||||||||||||
212 | if (useSoftwareRenderer) {
| 0-118 | ||||||||||||||||||
213 | delete renderControl; | - | ||||||||||||||||||
214 | delete offscreenWindow; | - | ||||||||||||||||||
215 | } else { never executed: end of block | 0 | ||||||||||||||||||
216 | #if QT_CONFIG(opengl) | - | ||||||||||||||||||
217 | // context and offscreenSurface are current at this stage, if the context was created. | - | ||||||||||||||||||
218 | Q_ASSERT(!context || (QOpenGLContext::currentContext() == context && context->surface() == offscreenSurface)); | - | ||||||||||||||||||
219 | delete renderControl; // always delete the rendercontrol first | - | ||||||||||||||||||
220 | delete offscreenWindow; | - | ||||||||||||||||||
221 | delete resolvedFbo; | - | ||||||||||||||||||
222 | delete fbo; | - | ||||||||||||||||||
223 | - | |||||||||||||||||||
224 | destroyContext(); | - | ||||||||||||||||||
225 | #endif | - | ||||||||||||||||||
226 | } executed 118 times by 2 tests: end of block Executed by:
| 118 | ||||||||||||||||||
227 | } | - | ||||||||||||||||||
228 | - | |||||||||||||||||||
229 | void QQuickWidgetPrivate::execute() | - | ||||||||||||||||||
230 | { | - | ||||||||||||||||||
231 | Q_Q(QQuickWidget); | - | ||||||||||||||||||
232 | ensureEngine(); | - | ||||||||||||||||||
233 | - | |||||||||||||||||||
234 | if (root) {
| 0-102 | ||||||||||||||||||
235 | delete root; | - | ||||||||||||||||||
236 | root = nullptr; | - | ||||||||||||||||||
237 | } never executed: end of block | 0 | ||||||||||||||||||
238 | if (component) {
| 0-102 | ||||||||||||||||||
239 | delete component; | - | ||||||||||||||||||
240 | component = nullptr; | - | ||||||||||||||||||
241 | } never executed: end of block | 0 | ||||||||||||||||||
242 | if (!source.isEmpty()) {
| 0-102 | ||||||||||||||||||
243 | QML_MEMORY_SCOPE_URL(engine.data()->baseUrl().resolved(source)); | - | ||||||||||||||||||
244 | component = new QQmlComponent(engine.data(), source, q); | - | ||||||||||||||||||
245 | if (!component->isLoading()) {
| 0-102 | ||||||||||||||||||
246 | q->continueExecute(); | - | ||||||||||||||||||
247 | } else { executed 102 times by 2 tests: end of block Executed by:
| 102 | ||||||||||||||||||
248 | QObject::connect(component, SIGNAL(statusChanged(QQmlComponent::Status)), | - | ||||||||||||||||||
249 | q, SLOT(continueExecute())); | - | ||||||||||||||||||
250 | } never executed: end of block | 0 | ||||||||||||||||||
251 | } | - | ||||||||||||||||||
252 | } executed 102 times by 2 tests: end of block Executed by:
| 102 | ||||||||||||||||||
253 | - | |||||||||||||||||||
254 | void QQuickWidgetPrivate::itemGeometryChanged(QQuickItem *resizeItem, QQuickGeometryChange change, | - | ||||||||||||||||||
255 | const QRectF &oldGeometry) | - | ||||||||||||||||||
256 | { | - | ||||||||||||||||||
257 | Q_Q(QQuickWidget); | - | ||||||||||||||||||
258 | if (resizeItem == root && resizeMode == QQuickWidget::SizeViewToRootObject) {
| 0-10 | ||||||||||||||||||
259 | // wait for both width and height to be changed | - | ||||||||||||||||||
260 | resizetimer.start(0,q); | - | ||||||||||||||||||
261 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||
262 | QQuickItemChangeListener::itemGeometryChanged(resizeItem, change, oldGeometry); | - | ||||||||||||||||||
263 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||
264 | - | |||||||||||||||||||
265 | void QQuickWidgetPrivate::render(bool needsSync) | - | ||||||||||||||||||
266 | { | - | ||||||||||||||||||
267 | if (!useSoftwareRenderer) {
| 0-332 | ||||||||||||||||||
268 | #if QT_CONFIG(opengl) | - | ||||||||||||||||||
269 | // createFramebufferObject() bails out when the size is empty. In this case | - | ||||||||||||||||||
270 | // we cannot render either. | - | ||||||||||||||||||
271 | if (!fbo)
| 4-328 | ||||||||||||||||||
272 | return; executed 4 times by 1 test: return; Executed by:
| 4 | ||||||||||||||||||
273 | - | |||||||||||||||||||
274 | Q_ASSERT(context); | - | ||||||||||||||||||
275 | - | |||||||||||||||||||
276 | if (!context->makeCurrent(offscreenSurface)) {
| 0-328 | ||||||||||||||||||
277 | qWarning("QQuickWidget: Cannot render due to failing makeCurrent()"); | - | ||||||||||||||||||
278 | return; never executed: return; | 0 | ||||||||||||||||||
279 | } | - | ||||||||||||||||||
280 | - | |||||||||||||||||||
281 | QOpenGLContextPrivate::get(context)->defaultFboRedirect = fbo->handle(); | - | ||||||||||||||||||
282 | - | |||||||||||||||||||
283 | if (needsSync) {
| 4-324 | ||||||||||||||||||
284 | renderControl->polishItems(); | - | ||||||||||||||||||
285 | renderControl->sync(); | - | ||||||||||||||||||
286 | } executed 324 times by 2 tests: end of block Executed by:
| 324 | ||||||||||||||||||
287 | - | |||||||||||||||||||
288 | renderControl->render(); | - | ||||||||||||||||||
289 | - | |||||||||||||||||||
290 | if (resolvedFbo) {
| 0-328 | ||||||||||||||||||
291 | QRect rect(QPoint(0, 0), fbo->size()); | - | ||||||||||||||||||
292 | QOpenGLFramebufferObject::blitFramebuffer(resolvedFbo, rect, fbo, rect); | - | ||||||||||||||||||
293 | } never executed: end of block | 0 | ||||||||||||||||||
294 | - | |||||||||||||||||||
295 | static_cast<QOpenGLExtensions *>(context->functions())->flushShared(); | - | ||||||||||||||||||
296 | - | |||||||||||||||||||
297 | QOpenGLContextPrivate::get(context)->defaultFboRedirect = 0; | - | ||||||||||||||||||
298 | #endif | - | ||||||||||||||||||
299 | } else { executed 328 times by 2 tests: end of block Executed by:
| 328 | ||||||||||||||||||
300 | //Software Renderer | - | ||||||||||||||||||
301 | if (needsSync) {
| 0 | ||||||||||||||||||
302 | renderControl->polishItems(); | - | ||||||||||||||||||
303 | renderControl->sync(); | - | ||||||||||||||||||
304 | } never executed: end of block | 0 | ||||||||||||||||||
305 | - | |||||||||||||||||||
306 | QQuickWindowPrivate *cd = QQuickWindowPrivate::get(offscreenWindow); | - | ||||||||||||||||||
307 | auto softwareRenderer = static_cast<QSGSoftwareRenderer*>(cd->renderer); | - | ||||||||||||||||||
308 | if (softwareRenderer && !softwareImage.isNull()) {
| 0 | ||||||||||||||||||
309 | softwareRenderer->setCurrentPaintDevice(&softwareImage); | - | ||||||||||||||||||
310 | if (forceFullUpdate) {
| 0 | ||||||||||||||||||
311 | softwareRenderer->markDirty(); | - | ||||||||||||||||||
312 | forceFullUpdate = false; | - | ||||||||||||||||||
313 | } never executed: end of block | 0 | ||||||||||||||||||
314 | renderControl->render(); | - | ||||||||||||||||||
315 | - | |||||||||||||||||||
316 | updateRegion += softwareRenderer->flushRegion(); | - | ||||||||||||||||||
317 | } never executed: end of block | 0 | ||||||||||||||||||
318 | } never executed: end of block | 0 | ||||||||||||||||||
319 | } | - | ||||||||||||||||||
320 | - | |||||||||||||||||||
321 | void QQuickWidgetPrivate::renderSceneGraph() | - | ||||||||||||||||||
322 | { | - | ||||||||||||||||||
323 | Q_Q(QQuickWidget); | - | ||||||||||||||||||
324 | updatePending = false; | - | ||||||||||||||||||
325 | - | |||||||||||||||||||
326 | if (!q->isVisible() || fakeHidden)
| 0-102 | ||||||||||||||||||
327 | return; executed 4 times by 1 test: return; Executed by:
| 4 | ||||||||||||||||||
328 | - | |||||||||||||||||||
329 | if (!useSoftwareRenderer) {
| 0-98 | ||||||||||||||||||
330 | QOpenGLContext *context = offscreenWindow->openglContext(); | - | ||||||||||||||||||
331 | if (!context) {
| 0-98 | ||||||||||||||||||
332 | qWarning("QQuickWidget: Attempted to render scene with no context"); | - | ||||||||||||||||||
333 | return; never executed: return; | 0 | ||||||||||||||||||
334 | } | - | ||||||||||||||||||
335 | - | |||||||||||||||||||
336 | Q_ASSERT(offscreenSurface); | - | ||||||||||||||||||
337 | } executed 98 times by 2 tests: end of block Executed by:
| 98 | ||||||||||||||||||
338 | - | |||||||||||||||||||
339 | render(true); | - | ||||||||||||||||||
340 | - | |||||||||||||||||||
341 | #if QT_CONFIG(graphicsview) | - | ||||||||||||||||||
342 | if (q->window()->graphicsProxyWidget())
| 0-98 | ||||||||||||||||||
343 | QWidgetPrivate::nearestGraphicsProxyWidget(q)->update(); never executed: QWidgetPrivate::nearestGraphicsProxyWidget(q)->update(); | 0 | ||||||||||||||||||
344 | else | - | ||||||||||||||||||
345 | #endif | - | ||||||||||||||||||
346 | { | - | ||||||||||||||||||
347 | if (!useSoftwareRenderer)
| 0-98 | ||||||||||||||||||
348 | q->update(); // schedule composition executed 98 times by 2 tests: q->update(); Executed by:
| 98 | ||||||||||||||||||
349 | else if (!updateRegion.isEmpty())
| 0 | ||||||||||||||||||
350 | q->update(updateRegion); never executed: q->update(updateRegion); | 0 | ||||||||||||||||||
351 | } executed 98 times by 2 tests: end of block Executed by:
| 98 | ||||||||||||||||||
352 | } | - | ||||||||||||||||||
353 | - | |||||||||||||||||||
354 | QImage QQuickWidgetPrivate::grabFramebuffer() | - | ||||||||||||||||||
355 | { | - | ||||||||||||||||||
356 | if (!useSoftwareRenderer) {
| 0-8 | ||||||||||||||||||
357 | #if QT_CONFIG(opengl) | - | ||||||||||||||||||
358 | if (!context)
| 0-8 | ||||||||||||||||||
359 | return QImage(); never executed: return QImage(); | 0 | ||||||||||||||||||
360 | - | |||||||||||||||||||
361 | context->makeCurrent(offscreenSurface); | - | ||||||||||||||||||
362 | #endif | - | ||||||||||||||||||
363 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
364 | return renderControl->grab(); executed 8 times by 1 test: return renderControl->grab(); Executed by:
| 8 | ||||||||||||||||||
365 | } | - | ||||||||||||||||||
366 | - | |||||||||||||||||||
367 | // Intentionally not overriding the QQuickWindow's focusObject. | - | ||||||||||||||||||
368 | // Key events should go to our key event handlers, and then to the | - | ||||||||||||||||||
369 | // QQuickWindow, not any in-scene item. | - | ||||||||||||||||||
370 | - | |||||||||||||||||||
371 | /*! | - | ||||||||||||||||||
372 | \module QtQuickWidgets | - | ||||||||||||||||||
373 | \title Qt Quick Widgets C++ Classes | - | ||||||||||||||||||
374 | \ingroup modules | - | ||||||||||||||||||
375 | \brief The C++ API provided by the Qt Quick Widgets module. | - | ||||||||||||||||||
376 | \qtvariable quickwidgets | - | ||||||||||||||||||
377 | - | |||||||||||||||||||
378 | To link against the module, add this line to your \l qmake | - | ||||||||||||||||||
379 | \c .pro file: | - | ||||||||||||||||||
380 | - | |||||||||||||||||||
381 | \code | - | ||||||||||||||||||
382 | QT += quickwidgets | - | ||||||||||||||||||
383 | \endcode | - | ||||||||||||||||||
384 | - | |||||||||||||||||||
385 | For more information, see the QQuickWidget class documentation. | - | ||||||||||||||||||
386 | */ | - | ||||||||||||||||||
387 | - | |||||||||||||||||||
388 | /*! | - | ||||||||||||||||||
389 | \class QQuickWidget | - | ||||||||||||||||||
390 | \since 5.3 | - | ||||||||||||||||||
391 | \brief The QQuickWidget class provides a widget for displaying a Qt Quick user interface. | - | ||||||||||||||||||
392 | - | |||||||||||||||||||
393 | \inmodule QtQuickWidgets | - | ||||||||||||||||||
394 | - | |||||||||||||||||||
395 | This is a convenience wrapper for QQuickWindow which will automatically load and display a QML | - | ||||||||||||||||||
396 | scene when given the URL of the main source file. Alternatively, you can instantiate your own | - | ||||||||||||||||||
397 | objects using QQmlComponent and place them in a manually set up QQuickWidget. | - | ||||||||||||||||||
398 | - | |||||||||||||||||||
399 | Typical usage: | - | ||||||||||||||||||
400 | - | |||||||||||||||||||
401 | \code | - | ||||||||||||||||||
402 | QQuickWidget *view = new QQuickWidget; | - | ||||||||||||||||||
403 | view->setSource(QUrl::fromLocalFile("myqmlfile.qml")); | - | ||||||||||||||||||
404 | view->show(); | - | ||||||||||||||||||
405 | \endcode | - | ||||||||||||||||||
406 | - | |||||||||||||||||||
407 | To receive errors related to loading and executing QML with QQuickWidget, | - | ||||||||||||||||||
408 | you can connect to the statusChanged() signal and monitor for QQuickWidget::Error. | - | ||||||||||||||||||
409 | The errors are available via QQuickWidget::errors(). | - | ||||||||||||||||||
410 | - | |||||||||||||||||||
411 | QQuickWidget also manages sizing of the view and root object. By default, the \l resizeMode | - | ||||||||||||||||||
412 | is SizeViewToRootObject, which will load the component and resize it to the | - | ||||||||||||||||||
413 | size of the view. Alternatively the resizeMode may be set to SizeRootObjectToView which | - | ||||||||||||||||||
414 | will resize the view to the size of the root object. | - | ||||||||||||||||||
415 | - | |||||||||||||||||||
416 | \note QQuickWidget is an alternative to using QQuickView and QWidget::createWindowContainer(). | - | ||||||||||||||||||
417 | The restrictions on stacking order do not apply, making QQuickWidget the more flexible | - | ||||||||||||||||||
418 | alternative, behaving more like an ordinary widget. This comes at the expense of | - | ||||||||||||||||||
419 | performance. Unlike QQuickWindow and QQuickView, QQuickWidget involves rendering into OpenGL | - | ||||||||||||||||||
420 | framebuffer objects. This will naturally carry a minor performance hit. | - | ||||||||||||||||||
421 | - | |||||||||||||||||||
422 | \note Using QQuickWidget disables the threaded render loop on all platforms. This means that | - | ||||||||||||||||||
423 | some of the benefits of threaded rendering, for example \l Animator classes and vsync driven | - | ||||||||||||||||||
424 | animations, will not be available. | - | ||||||||||||||||||
425 | - | |||||||||||||||||||
426 | \note Avoid calling winId() on a QQuickWidget. This function triggers the creation of | - | ||||||||||||||||||
427 | a native window, resulting in reduced performance and possibly rendering glitches. The | - | ||||||||||||||||||
428 | entire purpose of QQuickWidget is to render Quick scenes without a separate native | - | ||||||||||||||||||
429 | window, hence making it a native widget should always be avoided. | - | ||||||||||||||||||
430 | - | |||||||||||||||||||
431 | \section1 Scene Graph and Context Persistency | - | ||||||||||||||||||
432 | - | |||||||||||||||||||
433 | QQuickWidget honors QQuickWindow::isPersistentSceneGraph(), meaning that | - | ||||||||||||||||||
434 | applications can decide - by calling | - | ||||||||||||||||||
435 | QQuickWindow::setPersistentSceneGraph() on the window returned from the | - | ||||||||||||||||||
436 | quickWindow() function - to let scenegraph nodes and other Qt Quick scene | - | ||||||||||||||||||
437 | related resources be released whenever the widget becomes hidden. By default | - | ||||||||||||||||||
438 | persistency is enabled, just like with QQuickWindow. | - | ||||||||||||||||||
439 | - | |||||||||||||||||||
440 | When running with the OpenGL backend of the scene graph, QQuickWindow | - | ||||||||||||||||||
441 | offers the possibility to disable persistent OpenGL contexts as well. This | - | ||||||||||||||||||
442 | setting is currently ignored by QQuickWidget and the context is always | - | ||||||||||||||||||
443 | persistent. The OpenGL context is thus not destroyed when hiding the | - | ||||||||||||||||||
444 | widget. The context is destroyed only when the widget is destroyed or when | - | ||||||||||||||||||
445 | the widget gets reparented into another top-level widget's child hierarchy. | - | ||||||||||||||||||
446 | However, some applications, in particular those that have their own | - | ||||||||||||||||||
447 | graphics resources due to performing custom OpenGL rendering in the Qt | - | ||||||||||||||||||
448 | Quick scene, may wish to disable the latter since they may not be prepared | - | ||||||||||||||||||
449 | to handle the loss of the context when moving a QQuickWidget into another | - | ||||||||||||||||||
450 | window. Such applications can set the | - | ||||||||||||||||||
451 | QCoreApplication::AA_ShareOpenGLContexts attribute. For a discussion on the | - | ||||||||||||||||||
452 | details of resource initialization and cleanup, refer to the QOpenGLWidget | - | ||||||||||||||||||
453 | documentation. | - | ||||||||||||||||||
454 | - | |||||||||||||||||||
455 | \note QQuickWidget offers less fine-grained control over its internal | - | ||||||||||||||||||
456 | OpenGL context than QOpenGLWidget, and there are subtle differences, most | - | ||||||||||||||||||
457 | notably that disabling the persistent scene graph will lead to destroying | - | ||||||||||||||||||
458 | the context on a window change regardless of the presence of | - | ||||||||||||||||||
459 | QCoreApplication::AA_ShareOpenGLContexts. | - | ||||||||||||||||||
460 | - | |||||||||||||||||||
461 | \section1 Limitations | - | ||||||||||||||||||
462 | - | |||||||||||||||||||
463 | Putting other widgets underneath and making the QQuickWidget transparent will not lead | - | ||||||||||||||||||
464 | to the expected results: the widgets underneath will not be visible. This is because | - | ||||||||||||||||||
465 | in practice the QQuickWidget is drawn before all other regular, non-OpenGL widgets, | - | ||||||||||||||||||
466 | and so see-through types of solutions are not feasible. Other type of layouts, like | - | ||||||||||||||||||
467 | having widgets on top of the QQuickWidget, will function as expected. | - | ||||||||||||||||||
468 | - | |||||||||||||||||||
469 | When absolutely necessary, this limitation can be overcome by setting the | - | ||||||||||||||||||
470 | Qt::WA_AlwaysStackOnTop attribute on the QQuickWidget. Be aware, however that this | - | ||||||||||||||||||
471 | breaks stacking order. For example it will not be possible to have other widgets on | - | ||||||||||||||||||
472 | top of the QQuickWidget, so it should only be used in situations where a | - | ||||||||||||||||||
473 | semi-transparent QQuickWidget with other widgets visible underneath is required. | - | ||||||||||||||||||
474 | - | |||||||||||||||||||
475 | This limitation only applies when there are other widgets underneath the QQuickWidget | - | ||||||||||||||||||
476 | inside the same window. Making the window semi-transparent, with other applications | - | ||||||||||||||||||
477 | and the desktop visible in the background, is done in the traditional way: Set | - | ||||||||||||||||||
478 | Qt::WA_TranslucentBackground on the top-level window, request an alpha channel, and | - | ||||||||||||||||||
479 | change the Qt Quick Scenegraph's clear color to Qt::transparent via setClearColor(). | - | ||||||||||||||||||
480 | - | |||||||||||||||||||
481 | \section1 Support when not using OpenGL | - | ||||||||||||||||||
482 | - | |||||||||||||||||||
483 | In addition to OpenGL, the \c software backend of Qt Quick also supports | - | ||||||||||||||||||
484 | QQuickWidget. Other backends, for example the Direct 3D 12 one, are not | - | ||||||||||||||||||
485 | compatible however and attempting to construct a QQuickWidget will lead to | - | ||||||||||||||||||
486 | problems. | - | ||||||||||||||||||
487 | - | |||||||||||||||||||
488 | \section1 Tab Key Handling | - | ||||||||||||||||||
489 | - | |||||||||||||||||||
490 | On press of the \c[TAB] key, the item inside the QQuickWidget gets focus. If | - | ||||||||||||||||||
491 | this item can handle \c[TAB] key press, focus will change accordingly within | - | ||||||||||||||||||
492 | the item, otherwise the next widget in the focus chain gets focus. | - | ||||||||||||||||||
493 | - | |||||||||||||||||||
494 | \sa {Exposing Attributes of C++ Types to QML}, {Qt Quick Widgets Example}, QQuickView | - | ||||||||||||||||||
495 | */ | - | ||||||||||||||||||
496 | - | |||||||||||||||||||
497 | - | |||||||||||||||||||
498 | /*! | - | ||||||||||||||||||
499 | \fn void QQuickWidget::statusChanged(QQuickWidget::Status status) | - | ||||||||||||||||||
500 | This signal is emitted when the component's current \a status changes. | - | ||||||||||||||||||
501 | */ | - | ||||||||||||||||||
502 | - | |||||||||||||||||||
503 | /*! | - | ||||||||||||||||||
504 | Constructs a QQuickWidget with the given \a parent. | - | ||||||||||||||||||
505 | The default value of \a parent is 0. | - | ||||||||||||||||||
506 | - | |||||||||||||||||||
507 | */ | - | ||||||||||||||||||
508 | QQuickWidget::QQuickWidget(QWidget *parent) | - | ||||||||||||||||||
509 | : QWidget(*(new QQuickWidgetPrivate), parent, nullptr) | - | ||||||||||||||||||
510 | { | - | ||||||||||||||||||
511 | setMouseTracking(true); | - | ||||||||||||||||||
512 | setFocusPolicy(Qt::StrongFocus); | - | ||||||||||||||||||
513 | d_func()->init(); | - | ||||||||||||||||||
514 | } executed 114 times by 2 tests: end of block Executed by:
| 114 | ||||||||||||||||||
515 | - | |||||||||||||||||||
516 | /*! | - | ||||||||||||||||||
517 | Constructs a QQuickWidget with the given QML \a source and \a parent. | - | ||||||||||||||||||
518 | The default value of \a parent is 0. | - | ||||||||||||||||||
519 | - | |||||||||||||||||||
520 | */ | - | ||||||||||||||||||
521 | QQuickWidget::QQuickWidget(const QUrl &source, QWidget *parent) | - | ||||||||||||||||||
522 | : QQuickWidget(parent) | - | ||||||||||||||||||
523 | { | - | ||||||||||||||||||
524 | setSource(source); | - | ||||||||||||||||||
525 | } never executed: end of block | 0 | ||||||||||||||||||
526 | - | |||||||||||||||||||
527 | /*! | - | ||||||||||||||||||
528 | Constructs a QQuickWidget with the given QML \a engine and \a parent. | - | ||||||||||||||||||
529 | - | |||||||||||||||||||
530 | Note: In this case, the QQuickWidget does not own the given \a engine object; | - | ||||||||||||||||||
531 | it is the caller's responsibility to destroy the engine. If the \a engine is deleted | - | ||||||||||||||||||
532 | before the view, status() will return QQuickWidget::Error. | - | ||||||||||||||||||
533 | - | |||||||||||||||||||
534 | \sa Status, status(), errors() | - | ||||||||||||||||||
535 | */ | - | ||||||||||||||||||
536 | QQuickWidget::QQuickWidget(QQmlEngine* engine, QWidget *parent) | - | ||||||||||||||||||
537 | : QWidget(*(new QQuickWidgetPrivate), parent, nullptr) | - | ||||||||||||||||||
538 | { | - | ||||||||||||||||||
539 | setMouseTracking(true); | - | ||||||||||||||||||
540 | setFocusPolicy(Qt::StrongFocus); | - | ||||||||||||||||||
541 | d_func()->init(engine); | - | ||||||||||||||||||
542 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
543 | - | |||||||||||||||||||
544 | /*! | - | ||||||||||||||||||
545 | Destroys the QQuickWidget. | - | ||||||||||||||||||
546 | */ | - | ||||||||||||||||||
547 | QQuickWidget::~QQuickWidget() | - | ||||||||||||||||||
548 | { | - | ||||||||||||||||||
549 | // Ensure that the component is destroyed before the engine; the engine may | - | ||||||||||||||||||
550 | // be a child of the QQuickWidgetPrivate, and will be destroyed by its dtor | - | ||||||||||||||||||
551 | Q_D(QQuickWidget); | - | ||||||||||||||||||
552 | delete d->root; | - | ||||||||||||||||||
553 | d->root = nullptr; | - | ||||||||||||||||||
554 | } executed 118 times by 2 tests: end of block Executed by:
| 118 | ||||||||||||||||||
555 | - | |||||||||||||||||||
556 | /*! | - | ||||||||||||||||||
557 | \property QQuickWidget::source | - | ||||||||||||||||||
558 | \brief The URL of the source of the QML component. | - | ||||||||||||||||||
559 | - | |||||||||||||||||||
560 | Ensure that the URL provided is full and correct, in particular, use | - | ||||||||||||||||||
561 | \l QUrl::fromLocalFile() when loading a file from the local filesystem. | - | ||||||||||||||||||
562 | - | |||||||||||||||||||
563 | \note Setting a source URL will result in the QML component being | - | ||||||||||||||||||
564 | instantiated, even if the URL is unchanged from the current value. | - | ||||||||||||||||||
565 | */ | - | ||||||||||||||||||
566 | - | |||||||||||||||||||
567 | /*! | - | ||||||||||||||||||
568 | Sets the source to the \a url, loads the QML component and instantiates it. | - | ||||||||||||||||||
569 | - | |||||||||||||||||||
570 | Ensure that the URL provided is full and correct, in particular, use | - | ||||||||||||||||||
571 | \l QUrl::fromLocalFile() when loading a file from the local filesystem. | - | ||||||||||||||||||
572 | - | |||||||||||||||||||
573 | Calling this method multiple times with the same URL will result | - | ||||||||||||||||||
574 | in the QML component being reinstantiated. | - | ||||||||||||||||||
575 | */ | - | ||||||||||||||||||
576 | void QQuickWidget::setSource(const QUrl& url) | - | ||||||||||||||||||
577 | { | - | ||||||||||||||||||
578 | Q_D(QQuickWidget); | - | ||||||||||||||||||
579 | d->source = url; | - | ||||||||||||||||||
580 | d->execute(); | - | ||||||||||||||||||
581 | } executed 102 times by 2 tests: end of block Executed by:
| 102 | ||||||||||||||||||
582 | - | |||||||||||||||||||
583 | /*! | - | ||||||||||||||||||
584 | \internal | - | ||||||||||||||||||
585 | - | |||||||||||||||||||
586 | Sets the source \a url, \a component and content \a item (root of the QML object hierarchy) directly. | - | ||||||||||||||||||
587 | */ | - | ||||||||||||||||||
588 | void QQuickWidget::setContent(const QUrl& url, QQmlComponent *component, QObject* item) | - | ||||||||||||||||||
589 | { | - | ||||||||||||||||||
590 | Q_D(QQuickWidget); | - | ||||||||||||||||||
591 | d->source = url; | - | ||||||||||||||||||
592 | d->component = component; | - | ||||||||||||||||||
593 | - | |||||||||||||||||||
594 | if (d->component && d->component->isError()) {
| 0-8 | ||||||||||||||||||
595 | const QList<QQmlError> errorList = d->component->errors(); | - | ||||||||||||||||||
596 | for (const QQmlError &error : errorList) { | - | ||||||||||||||||||
597 | QMessageLogger(error.url().toString().toLatin1().constData(), error.line(), nullptr).warning() | - | ||||||||||||||||||
598 | << error; | - | ||||||||||||||||||
599 | } never executed: end of block | 0 | ||||||||||||||||||
600 | emit statusChanged(status()); | - | ||||||||||||||||||
601 | return; never executed: return; | 0 | ||||||||||||||||||
602 | } | - | ||||||||||||||||||
603 | - | |||||||||||||||||||
604 | d->setRootObject(item); | - | ||||||||||||||||||
605 | emit statusChanged(status()); | - | ||||||||||||||||||
606 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
607 | - | |||||||||||||||||||
608 | /*! | - | ||||||||||||||||||
609 | Returns the source URL, if set. | - | ||||||||||||||||||
610 | - | |||||||||||||||||||
611 | \sa setSource() | - | ||||||||||||||||||
612 | */ | - | ||||||||||||||||||
613 | QUrl QQuickWidget::source() const | - | ||||||||||||||||||
614 | { | - | ||||||||||||||||||
615 | Q_D(const QQuickWidget); | - | ||||||||||||||||||
616 | return d->source; never executed: return d->source; | 0 | ||||||||||||||||||
617 | } | - | ||||||||||||||||||
618 | - | |||||||||||||||||||
619 | /*! | - | ||||||||||||||||||
620 | Returns a pointer to the QQmlEngine used for instantiating | - | ||||||||||||||||||
621 | QML Components. | - | ||||||||||||||||||
622 | */ | - | ||||||||||||||||||
623 | QQmlEngine* QQuickWidget::engine() const | - | ||||||||||||||||||
624 | { | - | ||||||||||||||||||
625 | Q_D(const QQuickWidget); | - | ||||||||||||||||||
626 | d->ensureEngine(); | - | ||||||||||||||||||
627 | return const_cast<QQmlEngine *>(d->engine.data()); executed 12 times by 1 test: return const_cast<QQmlEngine *>(d->engine.data()); Executed by:
| 12 | ||||||||||||||||||
628 | } | - | ||||||||||||||||||
629 | - | |||||||||||||||||||
630 | /*! | - | ||||||||||||||||||
631 | This function returns the root of the context hierarchy. Each QML | - | ||||||||||||||||||
632 | component is instantiated in a QQmlContext. QQmlContext's are | - | ||||||||||||||||||
633 | essential for passing data to QML components. In QML, contexts are | - | ||||||||||||||||||
634 | arranged hierarchically and this hierarchy is managed by the | - | ||||||||||||||||||
635 | QQmlEngine. | - | ||||||||||||||||||
636 | */ | - | ||||||||||||||||||
637 | QQmlContext* QQuickWidget::rootContext() const | - | ||||||||||||||||||
638 | { | - | ||||||||||||||||||
639 | Q_D(const QQuickWidget); | - | ||||||||||||||||||
640 | d->ensureEngine(); | - | ||||||||||||||||||
641 | return d->engine.data()->rootContext(); executed 2 times by 1 test: return d->engine.data()->rootContext(); Executed by:
| 2 | ||||||||||||||||||
642 | } | - | ||||||||||||||||||
643 | - | |||||||||||||||||||
644 | /*! | - | ||||||||||||||||||
645 | \enum QQuickWidget::Status | - | ||||||||||||||||||
646 | Specifies the loading status of the QQuickWidget. | - | ||||||||||||||||||
647 | - | |||||||||||||||||||
648 | \value Null This QQuickWidget has no source set. | - | ||||||||||||||||||
649 | \value Ready This QQuickWidget has loaded and created the QML component. | - | ||||||||||||||||||
650 | \value Loading This QQuickWidget is loading network data. | - | ||||||||||||||||||
651 | \value Error One or more errors occurred. Call errors() to retrieve a list | - | ||||||||||||||||||
652 | of errors. | - | ||||||||||||||||||
653 | */ | - | ||||||||||||||||||
654 | - | |||||||||||||||||||
655 | /*! \enum QQuickWidget::ResizeMode | - | ||||||||||||||||||
656 | - | |||||||||||||||||||
657 | This enum specifies how to resize the view. | - | ||||||||||||||||||
658 | - | |||||||||||||||||||
659 | \value SizeViewToRootObject The view resizes with the root item in the QML. | - | ||||||||||||||||||
660 | \value SizeRootObjectToView The view will automatically resize the root item to the size of the view. | - | ||||||||||||||||||
661 | */ | - | ||||||||||||||||||
662 | - | |||||||||||||||||||
663 | /*! | - | ||||||||||||||||||
664 | \fn void QQuickWidget::sceneGraphError(QQuickWindow::SceneGraphError error, const QString &message) | - | ||||||||||||||||||
665 | - | |||||||||||||||||||
666 | This signal is emitted when an \a error occurred during scene graph initialization. | - | ||||||||||||||||||
667 | - | |||||||||||||||||||
668 | Applications should connect to this signal if they wish to handle errors, | - | ||||||||||||||||||
669 | like OpenGL context creation failures, in a custom way. When no slot is | - | ||||||||||||||||||
670 | connected to the signal, the behavior will be different: Quick will print | - | ||||||||||||||||||
671 | the \a message, or show a message box, and terminate the application. | - | ||||||||||||||||||
672 | - | |||||||||||||||||||
673 | This signal will be emitted from the gui thread. | - | ||||||||||||||||||
674 | - | |||||||||||||||||||
675 | \sa QQuickWindow::sceneGraphError() | - | ||||||||||||||||||
676 | */ | - | ||||||||||||||||||
677 | - | |||||||||||||||||||
678 | /*! | - | ||||||||||||||||||
679 | \property QQuickWidget::status | - | ||||||||||||||||||
680 | The component's current \l{QQuickWidget::Status} {status}. | - | ||||||||||||||||||
681 | */ | - | ||||||||||||||||||
682 | - | |||||||||||||||||||
683 | QQuickWidget::Status QQuickWidget::status() const | - | ||||||||||||||||||
684 | { | - | ||||||||||||||||||
685 | Q_D(const QQuickWidget); | - | ||||||||||||||||||
686 | if (!d->engine && !d->source.isEmpty())
| 0-104 | ||||||||||||||||||
687 | return QQuickWidget::Error; never executed: return QQuickWidget::Error; | 0 | ||||||||||||||||||
688 | - | |||||||||||||||||||
689 | if (!d->component)
| 10-104 | ||||||||||||||||||
690 | return QQuickWidget::Null; executed 10 times by 1 test: return QQuickWidget::Null; Executed by:
| 10 | ||||||||||||||||||
691 | - | |||||||||||||||||||
692 | if (d->component->status() == QQmlComponent::Ready && !d->root)
| 0-100 | ||||||||||||||||||
693 | return QQuickWidget::Error; never executed: return QQuickWidget::Error; | 0 | ||||||||||||||||||
694 | - | |||||||||||||||||||
695 | return QQuickWidget::Status(d->component->status()); executed 104 times by 2 tests: return QQuickWidget::Status(d->component->status()); Executed by:
| 104 | ||||||||||||||||||
696 | } | - | ||||||||||||||||||
697 | - | |||||||||||||||||||
698 | /*! | - | ||||||||||||||||||
699 | Return the list of errors that occurred during the last compile or create | - | ||||||||||||||||||
700 | operation. When the status is not \l Error, an empty list is returned. | - | ||||||||||||||||||
701 | - | |||||||||||||||||||
702 | \sa status | - | ||||||||||||||||||
703 | */ | - | ||||||||||||||||||
704 | QList<QQmlError> QQuickWidget::errors() const | - | ||||||||||||||||||
705 | { | - | ||||||||||||||||||
706 | Q_D(const QQuickWidget); | - | ||||||||||||||||||
707 | QList<QQmlError> errs; | - | ||||||||||||||||||
708 | - | |||||||||||||||||||
709 | if (d->component)
| 2-4 | ||||||||||||||||||
710 | errs = d->component->errors(); executed 2 times by 1 test: errs = d->component->errors(); Executed by:
| 2 | ||||||||||||||||||
711 | - | |||||||||||||||||||
712 | if (!d->engine && !d->source.isEmpty()) {
| 0-4 | ||||||||||||||||||
713 | QQmlError error; | - | ||||||||||||||||||
714 | error.setDescription(QLatin1String("QQuickWidget: invalid qml engine.")); | - | ||||||||||||||||||
715 | errs << error; | - | ||||||||||||||||||
716 | } never executed: end of block | 0 | ||||||||||||||||||
717 | if (d->component && d->component->status() == QQmlComponent::Ready && !d->root) {
| 0-4 | ||||||||||||||||||
718 | QQmlError error; | - | ||||||||||||||||||
719 | error.setDescription(QLatin1String("QQuickWidget: invalid root object.")); | - | ||||||||||||||||||
720 | errs << error; | - | ||||||||||||||||||
721 | } never executed: end of block | 0 | ||||||||||||||||||
722 | - | |||||||||||||||||||
723 | return errs; executed 6 times by 1 test: return errs; Executed by:
| 6 | ||||||||||||||||||
724 | } | - | ||||||||||||||||||
725 | - | |||||||||||||||||||
726 | /*! | - | ||||||||||||||||||
727 | \property QQuickWidget::resizeMode | - | ||||||||||||||||||
728 | \brief Determines whether the view should resize the window contents. | - | ||||||||||||||||||
729 | - | |||||||||||||||||||
730 | If this property is set to SizeViewToRootObject (the default), the view | - | ||||||||||||||||||
731 | resizes to the size of the root item in the QML. | - | ||||||||||||||||||
732 | - | |||||||||||||||||||
733 | If this property is set to SizeRootObjectToView, the view will | - | ||||||||||||||||||
734 | automatically resize the root item to the size of the view. | - | ||||||||||||||||||
735 | - | |||||||||||||||||||
736 | Regardless of this property, the sizeHint of the view | - | ||||||||||||||||||
737 | is the initial size of the root item. Note though that | - | ||||||||||||||||||
738 | since QML may load dynamically, that size may change. | - | ||||||||||||||||||
739 | - | |||||||||||||||||||
740 | \sa initialSize() | - | ||||||||||||||||||
741 | */ | - | ||||||||||||||||||
742 | - | |||||||||||||||||||
743 | void QQuickWidget::setResizeMode(ResizeMode mode) | - | ||||||||||||||||||
744 | { | - | ||||||||||||||||||
745 | Q_D(QQuickWidget); | - | ||||||||||||||||||
746 | if (d->resizeMode == mode)
| 4-8 | ||||||||||||||||||
747 | return; executed 4 times by 1 test: return; Executed by:
| 4 | ||||||||||||||||||
748 | - | |||||||||||||||||||
749 | if (d->root) {
| 4 | ||||||||||||||||||
750 | if (d->resizeMode == SizeViewToRootObject) {
| 2 | ||||||||||||||||||
751 | QQuickItemPrivate *p = QQuickItemPrivate::get(d->root); | - | ||||||||||||||||||
752 | p->removeItemChangeListener(d, QQuickItemPrivate::Geometry); | - | ||||||||||||||||||
753 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
754 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
755 | - | |||||||||||||||||||
756 | d->resizeMode = mode; | - | ||||||||||||||||||
757 | if (d->root) {
| 4 | ||||||||||||||||||
758 | d->initResize(); | - | ||||||||||||||||||
759 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
760 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
761 | - | |||||||||||||||||||
762 | void QQuickWidgetPrivate::initResize() | - | ||||||||||||||||||
763 | { | - | ||||||||||||||||||
764 | if (root) {
| 0-112 | ||||||||||||||||||
765 | if (resizeMode == QQuickWidget::SizeViewToRootObject) {
| 6-106 | ||||||||||||||||||
766 | QQuickItemPrivate *p = QQuickItemPrivate::get(root); | - | ||||||||||||||||||
767 | p->addItemChangeListener(this, QQuickItemPrivate::Geometry); | - | ||||||||||||||||||
768 | } executed 106 times by 2 tests: end of block Executed by:
| 106 | ||||||||||||||||||
769 | } executed 112 times by 2 tests: end of block Executed by:
| 112 | ||||||||||||||||||
770 | updateSize(); | - | ||||||||||||||||||
771 | } executed 112 times by 2 tests: end of block Executed by:
| 112 | ||||||||||||||||||
772 | - | |||||||||||||||||||
773 | void QQuickWidgetPrivate::updateSize() | - | ||||||||||||||||||
774 | { | - | ||||||||||||||||||
775 | Q_Q(QQuickWidget); | - | ||||||||||||||||||
776 | if (!root)
| 0-126 | ||||||||||||||||||
777 | return; never executed: return; | 0 | ||||||||||||||||||
778 | - | |||||||||||||||||||
779 | if (resizeMode == QQuickWidget::SizeViewToRootObject) {
| 14-112 | ||||||||||||||||||
780 | QSize newSize = QSize(root->width(), root->height()); | - | ||||||||||||||||||
781 | if (newSize.isValid() && newSize != q->size()) {
| 0-112 | ||||||||||||||||||
782 | q->resize(newSize); | - | ||||||||||||||||||
783 | q->updateGeometry(); | - | ||||||||||||||||||
784 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||
785 | } else if (resizeMode == QQuickWidget::SizeRootObjectToView) { executed 112 times by 2 tests: end of block Executed by:
| 0-112 | ||||||||||||||||||
786 | bool needToUpdateWidth = !qFuzzyCompare(q->width(), root->width()); | - | ||||||||||||||||||
787 | bool needToUpdateHeight = !qFuzzyCompare(q->height(), root->height()); | - | ||||||||||||||||||
788 | - | |||||||||||||||||||
789 | if (needToUpdateWidth && needToUpdateHeight)
| 0-8 | ||||||||||||||||||
790 | root->setSize(QSizeF(q->width(), q->height())); executed 6 times by 1 test: root->setSize(QSizeF(q->width(), q->height())); Executed by:
| 6 | ||||||||||||||||||
791 | else if (needToUpdateWidth)
| 0-8 | ||||||||||||||||||
792 | root->setWidth(q->width()); never executed: root->setWidth(q->width()); | 0 | ||||||||||||||||||
793 | else if (needToUpdateHeight)
| 0-8 | ||||||||||||||||||
794 | root->setHeight(q->height()); never executed: root->setHeight(q->height()); | 0 | ||||||||||||||||||
795 | } executed 14 times by 1 test: end of block Executed by:
| 14 | ||||||||||||||||||
796 | } executed 126 times by 2 tests: end of block Executed by:
| 126 | ||||||||||||||||||
797 | - | |||||||||||||||||||
798 | /*! | - | ||||||||||||||||||
799 | \internal | - | ||||||||||||||||||
800 | - | |||||||||||||||||||
801 | Update the position of the offscreen window, so it matches the position of the QQuickWidget. | - | ||||||||||||||||||
802 | */ | - | ||||||||||||||||||
803 | void QQuickWidgetPrivate::updatePosition() | - | ||||||||||||||||||
804 | { | - | ||||||||||||||||||
805 | Q_Q(QQuickWidget); | - | ||||||||||||||||||
806 | if (offscreenWindow == nullptr)
| 0-222 | ||||||||||||||||||
807 | return; never executed: return; | 0 | ||||||||||||||||||
808 | - | |||||||||||||||||||
809 | const QPoint &pos = q->mapToGlobal(QPoint(0, 0)); | - | ||||||||||||||||||
810 | if (offscreenWindow->position() != pos)
| 8-214 | ||||||||||||||||||
811 | offscreenWindow->setPosition(pos); executed 8 times by 1 test: offscreenWindow->setPosition(pos); Executed by:
| 8 | ||||||||||||||||||
812 | } executed 222 times by 2 tests: end of block Executed by:
| 222 | ||||||||||||||||||
813 | - | |||||||||||||||||||
814 | QSize QQuickWidgetPrivate::rootObjectSize() const | - | ||||||||||||||||||
815 | { | - | ||||||||||||||||||
816 | QSize rootObjectSize(0,0); | - | ||||||||||||||||||
817 | int widthCandidate = -1; | - | ||||||||||||||||||
818 | int heightCandidate = -1; | - | ||||||||||||||||||
819 | if (root) {
| 2-128 | ||||||||||||||||||
820 | widthCandidate = root->width(); | - | ||||||||||||||||||
821 | heightCandidate = root->height(); | - | ||||||||||||||||||
822 | } executed 128 times by 2 tests: end of block Executed by:
| 128 | ||||||||||||||||||
823 | if (widthCandidate > 0) {
| 6-124 | ||||||||||||||||||
824 | rootObjectSize.setWidth(widthCandidate); | - | ||||||||||||||||||
825 | } executed 124 times by 2 tests: end of block Executed by:
| 124 | ||||||||||||||||||
826 | if (heightCandidate > 0) {
| 6-124 | ||||||||||||||||||
827 | rootObjectSize.setHeight(heightCandidate); | - | ||||||||||||||||||
828 | } executed 124 times by 2 tests: end of block Executed by:
| 124 | ||||||||||||||||||
829 | return rootObjectSize; executed 130 times by 2 tests: return rootObjectSize; Executed by:
| 130 | ||||||||||||||||||
830 | } | - | ||||||||||||||||||
831 | - | |||||||||||||||||||
832 | void QQuickWidgetPrivate::handleContextCreationFailure(const QSurfaceFormat &format, bool isEs) | - | ||||||||||||||||||
833 | { | - | ||||||||||||||||||
834 | Q_Q(QQuickWidget); | - | ||||||||||||||||||
835 | - | |||||||||||||||||||
836 | QString translatedMessage; | - | ||||||||||||||||||
837 | QString untranslatedMessage; | - | ||||||||||||||||||
838 | QQuickWindowPrivate::contextCreationFailureMessage(format, &translatedMessage, &untranslatedMessage, isEs); | - | ||||||||||||||||||
839 | - | |||||||||||||||||||
840 | static const QMetaMethod errorSignal = QMetaMethod::fromSignal(&QQuickWidget::sceneGraphError); | - | ||||||||||||||||||
841 | const bool signalConnected = q->isSignalConnected(errorSignal); | - | ||||||||||||||||||
842 | if (signalConnected)
| 0 | ||||||||||||||||||
843 | emit q->sceneGraphError(QQuickWindow::ContextNotAvailable, translatedMessage); never executed: q->sceneGraphError(QQuickWindow::ContextNotAvailable, translatedMessage); | 0 | ||||||||||||||||||
844 | - | |||||||||||||||||||
845 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) | - | ||||||||||||||||||
846 | if (!signalConnected && !QLibraryInfo::isDebugBuild() && !GetConsoleWindow()) | - | ||||||||||||||||||
847 | QMessageBox::critical(q, QCoreApplication::applicationName(), translatedMessage); | - | ||||||||||||||||||
848 | #endif // Q_OS_WIN && !Q_OS_WINRT | - | ||||||||||||||||||
849 | if (!signalConnected)
| 0 | ||||||||||||||||||
850 | qFatal("%s", qPrintable(untranslatedMessage)); never executed: QMessageLogger(__FILE__, 850, __PRETTY_FUNCTION__).fatal("%s", QtPrivate::asString(untranslatedMessage).toLocal8Bit().constData()); | 0 | ||||||||||||||||||
851 | } never executed: end of block | 0 | ||||||||||||||||||
852 | - | |||||||||||||||||||
853 | // Never called by Software Rendering backend | - | ||||||||||||||||||
854 | void QQuickWidgetPrivate::createContext() | - | ||||||||||||||||||
855 | { | - | ||||||||||||||||||
856 | #if QT_CONFIG(opengl) | - | ||||||||||||||||||
857 | Q_Q(QQuickWidget); | - | ||||||||||||||||||
858 | - | |||||||||||||||||||
859 | // On hide-show we may invalidate() (when !isPersistentSceneGraph) but our | - | ||||||||||||||||||
860 | // context is kept. We may need to initialize() again, though. | - | ||||||||||||||||||
861 | const bool reinit = context && !offscreenWindow->openglContext();
| 0-112 | ||||||||||||||||||
862 | - | |||||||||||||||||||
863 | if (!reinit) {
| 0-214 | ||||||||||||||||||
864 | if (context)
| 102-112 | ||||||||||||||||||
865 | return; executed 102 times by 2 tests: return; Executed by:
| 102 | ||||||||||||||||||
866 | - | |||||||||||||||||||
867 | context = new QOpenGLContext; | - | ||||||||||||||||||
868 | context->setFormat(offscreenWindow->requestedFormat()); | - | ||||||||||||||||||
869 | - | |||||||||||||||||||
870 | QOpenGLContext *shareContext = qt_gl_global_share_context(); | - | ||||||||||||||||||
871 | if (!shareContext)
| 0-112 | ||||||||||||||||||
872 | shareContext = QWidgetPrivate::get(q->window())->shareContext(); executed 112 times by 2 tests: shareContext = QWidgetPrivate::get(q->window())->shareContext(); Executed by:
| 112 | ||||||||||||||||||
873 | if (shareContext) {
| 4-108 | ||||||||||||||||||
874 | context->setShareContext(shareContext); | - | ||||||||||||||||||
875 | context->setScreen(shareContext->screen()); | - | ||||||||||||||||||
876 | } executed 108 times by 2 tests: end of block Executed by:
| 108 | ||||||||||||||||||
877 | if (!context->create()) {
| 0-112 | ||||||||||||||||||
878 | const bool isEs = context->isOpenGLES(); | - | ||||||||||||||||||
879 | delete context; | - | ||||||||||||||||||
880 | context = nullptr; | - | ||||||||||||||||||
881 | handleContextCreationFailure(offscreenWindow->requestedFormat(), isEs); | - | ||||||||||||||||||
882 | return; never executed: return; | 0 | ||||||||||||||||||
883 | } | - | ||||||||||||||||||
884 | - | |||||||||||||||||||
885 | offscreenSurface = new QOffscreenSurface; | - | ||||||||||||||||||
886 | // Pass the context's format(), which, now that the underlying platform context is created, | - | ||||||||||||||||||
887 | // contains a QSurfaceFormat representing the _actual_ format of the underlying | - | ||||||||||||||||||
888 | // configuration. This is essential to get a surface that is compatible with the context. | - | ||||||||||||||||||
889 | offscreenSurface->setFormat(context->format()); | - | ||||||||||||||||||
890 | offscreenSurface->setScreen(context->screen()); | - | ||||||||||||||||||
891 | offscreenSurface->create(); | - | ||||||||||||||||||
892 | } executed 112 times by 2 tests: end of block Executed by:
| 112 | ||||||||||||||||||
893 | - | |||||||||||||||||||
894 | if (context->makeCurrent(offscreenSurface)) {
| 0-112 | ||||||||||||||||||
895 | if (!offscreenWindow->openglContext())
| 0-112 | ||||||||||||||||||
896 | renderControl->initialize(context); executed 112 times by 2 tests: renderControl->initialize(context); Executed by:
| 112 | ||||||||||||||||||
897 | } else executed 112 times by 2 tests: end of block Executed by:
| 112 | ||||||||||||||||||
898 | #endif | - | ||||||||||||||||||
899 | qWarning("QQuickWidget: Failed to make context current"); never executed: QMessageLogger(__FILE__, 899, __PRETTY_FUNCTION__).warning("QQuickWidget: Failed to make context current"); | 0 | ||||||||||||||||||
900 | } | - | ||||||||||||||||||
901 | - | |||||||||||||||||||
902 | // Never called by Software Rendering backend | - | ||||||||||||||||||
903 | void QQuickWidgetPrivate::destroyContext() | - | ||||||||||||||||||
904 | { | - | ||||||||||||||||||
905 | delete offscreenSurface; | - | ||||||||||||||||||
906 | offscreenSurface = nullptr; | - | ||||||||||||||||||
907 | #if QT_CONFIG(opengl) | - | ||||||||||||||||||
908 | delete context; | - | ||||||||||||||||||
909 | context = nullptr; | - | ||||||||||||||||||
910 | #endif | - | ||||||||||||||||||
911 | } executed 126 times by 2 tests: end of block Executed by:
| 126 | ||||||||||||||||||
912 | - | |||||||||||||||||||
913 | void QQuickWidget::createFramebufferObject() | - | ||||||||||||||||||
914 | { | - | ||||||||||||||||||
915 | Q_D(QQuickWidget); | - | ||||||||||||||||||
916 | - | |||||||||||||||||||
917 | // Could come from Show -> createContext -> sceneGraphInitialized in which case the size may | - | ||||||||||||||||||
918 | // still be invalid on some platforms. Bail out. A resize will come later on. | - | ||||||||||||||||||
919 | if (size().isEmpty())
| 4-124 | ||||||||||||||||||
920 | return; executed 4 times by 1 test: return; Executed by:
| 4 | ||||||||||||||||||
921 | - | |||||||||||||||||||
922 | // Even though this is just an offscreen window we should set the position on it, as it might be | - | ||||||||||||||||||
923 | // useful for an item to know the actual position of the scene. | - | ||||||||||||||||||
924 | // Note: The position will be update when we get a move event (see: updatePosition()). | - | ||||||||||||||||||
925 | const QPoint &globalPos = mapToGlobal(QPoint(0, 0)); | - | ||||||||||||||||||
926 | d->offscreenWindow->setGeometry(globalPos.x(), globalPos.y(), width(), height()); | - | ||||||||||||||||||
927 | - | |||||||||||||||||||
928 | if (d->useSoftwareRenderer) {
| 0-124 | ||||||||||||||||||
929 | const QSize imageSize = size() * devicePixelRatioF(); | - | ||||||||||||||||||
930 | d->softwareImage = QImage(imageSize, QImage::Format_ARGB32_Premultiplied); | - | ||||||||||||||||||
931 | d->softwareImage.setDevicePixelRatio(devicePixelRatioF()); | - | ||||||||||||||||||
932 | d->forceFullUpdate = true; | - | ||||||||||||||||||
933 | return; never executed: return; | 0 | ||||||||||||||||||
934 | } | - | ||||||||||||||||||
935 | - | |||||||||||||||||||
936 | #if QT_CONFIG(opengl) | - | ||||||||||||||||||
937 | QOpenGLContext *context = d->offscreenWindow->openglContext(); | - | ||||||||||||||||||
938 | - | |||||||||||||||||||
939 | if (!context) {
| 0-124 | ||||||||||||||||||
940 | qWarning("QQuickWidget: Attempted to create FBO with no context"); | - | ||||||||||||||||||
941 | return; never executed: return; | 0 | ||||||||||||||||||
942 | } | - | ||||||||||||||||||
943 | - | |||||||||||||||||||
944 | QOpenGLContext *shareWindowContext = QWidgetPrivate::get(window())->shareContext(); | - | ||||||||||||||||||
945 | if (shareWindowContext && context->shareContext() != shareWindowContext && !qGuiApp->testAttribute(Qt::AA_ShareOpenGLContexts)) {
| 0-120 | ||||||||||||||||||
946 | context->setShareContext(shareWindowContext); | - | ||||||||||||||||||
947 | context->setScreen(shareWindowContext->screen()); | - | ||||||||||||||||||
948 | if (!context->create())
| 0 | ||||||||||||||||||
949 | qWarning("QQuickWidget: Failed to recreate context"); never executed: QMessageLogger(__FILE__, 949, __PRETTY_FUNCTION__).warning("QQuickWidget: Failed to recreate context"); | 0 | ||||||||||||||||||
950 | // The screen may be different so we must recreate the offscreen surface too. | - | ||||||||||||||||||
951 | // Unlike QOpenGLContext, QOffscreenSurface's create() does not recreate so have to destroy() first. | - | ||||||||||||||||||
952 | d->offscreenSurface->destroy(); | - | ||||||||||||||||||
953 | d->offscreenSurface->setScreen(context->screen()); | - | ||||||||||||||||||
954 | d->offscreenSurface->create(); | - | ||||||||||||||||||
955 | } never executed: end of block | 0 | ||||||||||||||||||
956 | - | |||||||||||||||||||
957 | context->makeCurrent(d->offscreenSurface); | - | ||||||||||||||||||
958 | - | |||||||||||||||||||
959 | int samples = d->requestedSamples; | - | ||||||||||||||||||
960 | if (!QOpenGLExtensions(context).hasOpenGLExtension(QOpenGLExtensions::FramebufferMultisample))
| 0-124 | ||||||||||||||||||
961 | samples = 0; never executed: samples = 0; | 0 | ||||||||||||||||||
962 | - | |||||||||||||||||||
963 | QOpenGLFramebufferObjectFormat format; | - | ||||||||||||||||||
964 | format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); | - | ||||||||||||||||||
965 | format.setSamples(samples); | - | ||||||||||||||||||
966 | - | |||||||||||||||||||
967 | // The default framebuffer for normal windows have sRGB support on OS X which leads to the Qt Quick text item | - | ||||||||||||||||||
968 | // utilizing sRGB blending. To get identical results with QQuickWidget we have to have our framebuffer backed | - | ||||||||||||||||||
969 | // by an sRGB texture. | - | ||||||||||||||||||
970 | #ifdef Q_OS_OSX | - | ||||||||||||||||||
971 | if (context->hasExtension("GL_ARB_framebuffer_sRGB") | - | ||||||||||||||||||
972 | && context->hasExtension("GL_EXT_texture_sRGB") | - | ||||||||||||||||||
973 | && context->hasExtension("GL_EXT_texture_sRGB_decode")) | - | ||||||||||||||||||
974 | format.setInternalTextureFormat(GL_SRGB8_ALPHA8_EXT); | - | ||||||||||||||||||
975 | #endif | - | ||||||||||||||||||
976 | - | |||||||||||||||||||
977 | const QSize fboSize = size() * devicePixelRatioF(); | - | ||||||||||||||||||
978 | - | |||||||||||||||||||
979 | // Could be a simple hide - show, in which case the previous fbo is just fine. | - | ||||||||||||||||||
980 | if (!d->fbo || d->fbo->size() != fboSize) {
| 0-108 | ||||||||||||||||||
981 | delete d->fbo; | - | ||||||||||||||||||
982 | d->fbo = new QOpenGLFramebufferObject(fboSize, format); | - | ||||||||||||||||||
983 | } executed 124 times by 2 tests: end of block Executed by:
| 124 | ||||||||||||||||||
984 | - | |||||||||||||||||||
985 | // When compositing in the backingstore, sampling the sRGB texture would perform an | - | ||||||||||||||||||
986 | // sRGB-linear conversion which is not what we want when the final framebuffer (the window's) | - | ||||||||||||||||||
987 | // is sRGB too. Disable the conversion. | - | ||||||||||||||||||
988 | #ifdef Q_OS_OSX | - | ||||||||||||||||||
989 | if (format.internalTextureFormat() == GL_SRGB8_ALPHA8_EXT) { | - | ||||||||||||||||||
990 | QOpenGLFunctions *funcs = context->functions(); | - | ||||||||||||||||||
991 | funcs->glBindTexture(GL_TEXTURE_2D, d->fbo->texture()); | - | ||||||||||||||||||
992 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT); | - | ||||||||||||||||||
993 | } | - | ||||||||||||||||||
994 | #endif | - | ||||||||||||||||||
995 | - | |||||||||||||||||||
996 | d->offscreenWindow->setRenderTarget(d->fbo); | - | ||||||||||||||||||
997 | - | |||||||||||||||||||
998 | if (samples > 0)
| 0-124 | ||||||||||||||||||
999 | d->resolvedFbo = new QOpenGLFramebufferObject(fboSize); never executed: d->resolvedFbo = new QOpenGLFramebufferObject(fboSize); | 0 | ||||||||||||||||||
1000 | - | |||||||||||||||||||
1001 | // Sanity check: The window must not have an underlying platform window. | - | ||||||||||||||||||
1002 | // Having one would mean create() was called and platforms that only support | - | ||||||||||||||||||
1003 | // a single native window were in trouble. | - | ||||||||||||||||||
1004 | Q_ASSERT(!d->offscreenWindow->handle()); | - | ||||||||||||||||||
1005 | #endif | - | ||||||||||||||||||
1006 | } executed 124 times by 2 tests: end of block Executed by:
| 124 | ||||||||||||||||||
1007 | - | |||||||||||||||||||
1008 | void QQuickWidget::destroyFramebufferObject() | - | ||||||||||||||||||
1009 | { | - | ||||||||||||||||||
1010 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1011 | - | |||||||||||||||||||
1012 | if (d->useSoftwareRenderer) {
| 0-2 | ||||||||||||||||||
1013 | d->softwareImage = QImage(); | - | ||||||||||||||||||
1014 | return; never executed: return; | 0 | ||||||||||||||||||
1015 | } | - | ||||||||||||||||||
1016 | - | |||||||||||||||||||
1017 | #if QT_CONFIG(opengl) | - | ||||||||||||||||||
1018 | delete d->fbo; | - | ||||||||||||||||||
1019 | d->fbo = nullptr; | - | ||||||||||||||||||
1020 | delete d->resolvedFbo; | - | ||||||||||||||||||
1021 | d->resolvedFbo = nullptr; | - | ||||||||||||||||||
1022 | #endif | - | ||||||||||||||||||
1023 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
1024 | - | |||||||||||||||||||
1025 | QQuickWidget::ResizeMode QQuickWidget::resizeMode() const | - | ||||||||||||||||||
1026 | { | - | ||||||||||||||||||
1027 | Q_D(const QQuickWidget); | - | ||||||||||||||||||
1028 | return d->resizeMode; never executed: return d->resizeMode; | 0 | ||||||||||||||||||
1029 | } | - | ||||||||||||||||||
1030 | - | |||||||||||||||||||
1031 | /*! | - | ||||||||||||||||||
1032 | \internal | - | ||||||||||||||||||
1033 | */ | - | ||||||||||||||||||
1034 | void QQuickWidget::continueExecute() | - | ||||||||||||||||||
1035 | { | - | ||||||||||||||||||
1036 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1037 | disconnect(d->component, SIGNAL(statusChanged(QQmlComponent::Status)), this, SLOT(continueExecute())); | - | ||||||||||||||||||
1038 | - | |||||||||||||||||||
1039 | if (d->component->isError()) {
| 2-100 | ||||||||||||||||||
1040 | const QList<QQmlError> errorList = d->component->errors(); | - | ||||||||||||||||||
1041 | for (const QQmlError &error : errorList) { | - | ||||||||||||||||||
1042 | QMessageLogger(error.url().toString().toLatin1().constData(), error.line(), nullptr).warning() | - | ||||||||||||||||||
1043 | << error; | - | ||||||||||||||||||
1044 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
1045 | emit statusChanged(status()); | - | ||||||||||||||||||
1046 | return; executed 2 times by 1 test: return; Executed by:
| 2 | ||||||||||||||||||
1047 | } | - | ||||||||||||||||||
1048 | - | |||||||||||||||||||
1049 | QObject *obj = d->component->create(); | - | ||||||||||||||||||
1050 | - | |||||||||||||||||||
1051 | if (d->component->isError()) {
| 0-100 | ||||||||||||||||||
1052 | const QList<QQmlError> errorList = d->component->errors(); | - | ||||||||||||||||||
1053 | for (const QQmlError &error : errorList) { | - | ||||||||||||||||||
1054 | QMessageLogger(error.url().toString().toLatin1().constData(), error.line(), nullptr).warning() | - | ||||||||||||||||||
1055 | << error; | - | ||||||||||||||||||
1056 | } never executed: end of block | 0 | ||||||||||||||||||
1057 | emit statusChanged(status()); | - | ||||||||||||||||||
1058 | return; never executed: return; | 0 | ||||||||||||||||||
1059 | } | - | ||||||||||||||||||
1060 | - | |||||||||||||||||||
1061 | d->setRootObject(obj); | - | ||||||||||||||||||
1062 | emit statusChanged(status()); | - | ||||||||||||||||||
1063 | } executed 100 times by 2 tests: end of block Executed by:
| 100 | ||||||||||||||||||
1064 | - | |||||||||||||||||||
1065 | - | |||||||||||||||||||
1066 | /*! | - | ||||||||||||||||||
1067 | \internal | - | ||||||||||||||||||
1068 | */ | - | ||||||||||||||||||
1069 | void QQuickWidgetPrivate::setRootObject(QObject *obj) | - | ||||||||||||||||||
1070 | { | - | ||||||||||||||||||
1071 | Q_Q(QQuickWidget); | - | ||||||||||||||||||
1072 | if (root == obj)
| 0-108 | ||||||||||||||||||
1073 | return; never executed: return; | 0 | ||||||||||||||||||
1074 | if (QQuickItem *sgItem = qobject_cast<QQuickItem *>(obj)) {
| 0-108 | ||||||||||||||||||
1075 | root = sgItem; | - | ||||||||||||||||||
1076 | sgItem->setParentItem(offscreenWindow->contentItem()); | - | ||||||||||||||||||
1077 | } else if (qobject_cast<QWindow *>(obj)) { executed 108 times by 2 tests: end of block Executed by:
| 0-108 | ||||||||||||||||||
1078 | qWarning() << "QQuickWidget does not support using windows as a root item." << endl | - | ||||||||||||||||||
1079 | << endl | - | ||||||||||||||||||
1080 | << "If you wish to create your root window from QML, consider using QQmlApplicationEngine instead." << endl; | - | ||||||||||||||||||
1081 | } else { never executed: end of block | 0 | ||||||||||||||||||
1082 | qWarning() << "QQuickWidget only supports loading of root objects that derive from QQuickItem." << endl | - | ||||||||||||||||||
1083 | << endl | - | ||||||||||||||||||
1084 | << "Ensure your QML code is written for QtQuick 2, and uses a root that is or" << endl | - | ||||||||||||||||||
1085 | << "inherits from QtQuick's Item (not a Timer, QtObject, etc)." << endl; | - | ||||||||||||||||||
1086 | delete obj; | - | ||||||||||||||||||
1087 | root = nullptr; | - | ||||||||||||||||||
1088 | } never executed: end of block | 0 | ||||||||||||||||||
1089 | if (root) {
| 0-108 | ||||||||||||||||||
1090 | initialSize = rootObjectSize(); | - | ||||||||||||||||||
1091 | bool resized = q->testAttribute(Qt::WA_Resized); | - | ||||||||||||||||||
1092 | if ((resizeMode == QQuickWidget::SizeViewToRootObject || !resized) &&
| 2-104 | ||||||||||||||||||
1093 | initialSize != q->size()) {
| 42-64 | ||||||||||||||||||
1094 | q->resize(initialSize); | - | ||||||||||||||||||
1095 | } executed 42 times by 1 test: end of block Executed by:
| 42 | ||||||||||||||||||
1096 | initResize(); | - | ||||||||||||||||||
1097 | } executed 108 times by 2 tests: end of block Executed by:
| 108 | ||||||||||||||||||
1098 | } executed 108 times by 2 tests: end of block Executed by:
| 108 | ||||||||||||||||||
1099 | - | |||||||||||||||||||
1100 | #if QT_CONFIG(opengl) | - | ||||||||||||||||||
1101 | GLuint QQuickWidgetPrivate::textureId() const | - | ||||||||||||||||||
1102 | { | - | ||||||||||||||||||
1103 | Q_Q(const QQuickWidget); | - | ||||||||||||||||||
1104 | if (!q->isWindow() && q->internalWinId()) {
| 0-148 | ||||||||||||||||||
1105 | qWarning() << "QQuickWidget cannot be used as a native child widget." | - | ||||||||||||||||||
1106 | << "Consider setting Qt::AA_DontCreateNativeWidgetSiblings"; | - | ||||||||||||||||||
1107 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
1108 | } | - | ||||||||||||||||||
1109 | return resolvedFbo ? resolvedFbo->texture() executed 198 times by 2 tests: return resolvedFbo ? resolvedFbo->texture() : (fbo ? fbo->texture() : 0); Executed by:
| 198 | ||||||||||||||||||
1110 | : (fbo ? fbo->texture() : 0); executed 198 times by 2 tests: return resolvedFbo ? resolvedFbo->texture() : (fbo ? fbo->texture() : 0); Executed by:
| 198 | ||||||||||||||||||
1111 | } | - | ||||||||||||||||||
1112 | #endif | - | ||||||||||||||||||
1113 | - | |||||||||||||||||||
1114 | /*! | - | ||||||||||||||||||
1115 | \internal | - | ||||||||||||||||||
1116 | Handle item resize and scene updates. | - | ||||||||||||||||||
1117 | */ | - | ||||||||||||||||||
1118 | void QQuickWidget::timerEvent(QTimerEvent* e) | - | ||||||||||||||||||
1119 | { | - | ||||||||||||||||||
1120 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1121 | if (!e || e->timerId() == d->resizetimer.timerId()) {
| 0-108 | ||||||||||||||||||
1122 | d->updateSize(); | - | ||||||||||||||||||
1123 | d->resizetimer.stop(); | - | ||||||||||||||||||
1124 | } else if (e->timerId() == d->updateTimer.timerId()) { executed 6 times by 1 test: end of block Executed by:
| 0-102 | ||||||||||||||||||
1125 | d->eventPending = false; | - | ||||||||||||||||||
1126 | d->updateTimer.stop(); | - | ||||||||||||||||||
1127 | if (d->updatePending)
| 0-102 | ||||||||||||||||||
1128 | d->renderSceneGraph(); executed 102 times by 2 tests: d->renderSceneGraph(); Executed by:
| 102 | ||||||||||||||||||
1129 | } executed 102 times by 2 tests: end of block Executed by:
| 102 | ||||||||||||||||||
1130 | } executed 108 times by 2 tests: end of block Executed by:
| 108 | ||||||||||||||||||
1131 | - | |||||||||||||||||||
1132 | /*! | - | ||||||||||||||||||
1133 | \internal | - | ||||||||||||||||||
1134 | Preferred size follows the root object geometry. | - | ||||||||||||||||||
1135 | */ | - | ||||||||||||||||||
1136 | QSize QQuickWidget::sizeHint() const | - | ||||||||||||||||||
1137 | { | - | ||||||||||||||||||
1138 | Q_D(const QQuickWidget); | - | ||||||||||||||||||
1139 | QSize rootObjectSize = d->rootObjectSize(); | - | ||||||||||||||||||
1140 | if (rootObjectSize.isEmpty()) {
| 2-20 | ||||||||||||||||||
1141 | return size(); executed 2 times by 1 test: return size(); Executed by:
| 2 | ||||||||||||||||||
1142 | } else { | - | ||||||||||||||||||
1143 | return rootObjectSize; executed 20 times by 1 test: return rootObjectSize; Executed by:
| 20 | ||||||||||||||||||
1144 | } | - | ||||||||||||||||||
1145 | } | - | ||||||||||||||||||
1146 | - | |||||||||||||||||||
1147 | /*! | - | ||||||||||||||||||
1148 | Returns the initial size of the root object. | - | ||||||||||||||||||
1149 | - | |||||||||||||||||||
1150 | If \l resizeMode is SizeRootObjectToView, the root object will be | - | ||||||||||||||||||
1151 | resized to the size of the view. This function returns the size of the | - | ||||||||||||||||||
1152 | root object before it was resized. | - | ||||||||||||||||||
1153 | */ | - | ||||||||||||||||||
1154 | QSize QQuickWidget::initialSize() const | - | ||||||||||||||||||
1155 | { | - | ||||||||||||||||||
1156 | Q_D(const QQuickWidget); | - | ||||||||||||||||||
1157 | return d->initialSize; executed 12 times by 1 test: return d->initialSize; Executed by:
| 12 | ||||||||||||||||||
1158 | } | - | ||||||||||||||||||
1159 | - | |||||||||||||||||||
1160 | /*! | - | ||||||||||||||||||
1161 | Returns the view's root \l {QQuickItem} {item}. Can be null | - | ||||||||||||||||||
1162 | when setSource() has not been called, if it was called with | - | ||||||||||||||||||
1163 | broken QtQuick code or while the QtQuick contents are being created. | - | ||||||||||||||||||
1164 | */ | - | ||||||||||||||||||
1165 | QQuickItem *QQuickWidget::rootObject() const | - | ||||||||||||||||||
1166 | { | - | ||||||||||||||||||
1167 | Q_D(const QQuickWidget); | - | ||||||||||||||||||
1168 | return d->root; executed 12 times by 1 test: return d->root; Executed by:
| 12 | ||||||||||||||||||
1169 | } | - | ||||||||||||||||||
1170 | - | |||||||||||||||||||
1171 | /*! | - | ||||||||||||||||||
1172 | \internal | - | ||||||||||||||||||
1173 | This function handles the \l {QResizeEvent} {resize event} | - | ||||||||||||||||||
1174 | \a e. | - | ||||||||||||||||||
1175 | */ | - | ||||||||||||||||||
1176 | void QQuickWidget::resizeEvent(QResizeEvent *e) | - | ||||||||||||||||||
1177 | { | - | ||||||||||||||||||
1178 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1179 | if (d->resizeMode == SizeRootObjectToView)
| 8-122 | ||||||||||||||||||
1180 | d->updateSize(); executed 8 times by 1 test: d->updateSize(); Executed by:
| 8 | ||||||||||||||||||
1181 | - | |||||||||||||||||||
1182 | if (e->size().isEmpty()) {
| 4-126 | ||||||||||||||||||
1183 | //stop rendering | - | ||||||||||||||||||
1184 | d->fakeHidden = true; | - | ||||||||||||||||||
1185 | return; executed 4 times by 1 test: return; Executed by:
| 4 | ||||||||||||||||||
1186 | } | - | ||||||||||||||||||
1187 | - | |||||||||||||||||||
1188 | bool needsSync = false; | - | ||||||||||||||||||
1189 | if (d->fakeHidden) {
| 0-126 | ||||||||||||||||||
1190 | //restart rendering | - | ||||||||||||||||||
1191 | d->fakeHidden = false; | - | ||||||||||||||||||
1192 | needsSync = true; | - | ||||||||||||||||||
1193 | } never executed: end of block | 0 | ||||||||||||||||||
1194 | - | |||||||||||||||||||
1195 | // Software Renderer | - | ||||||||||||||||||
1196 | if (d->useSoftwareRenderer) {
| 0-126 | ||||||||||||||||||
1197 | needsSync = true; | - | ||||||||||||||||||
1198 | if (d->softwareImage.size() != size() * devicePixelRatioF()) {
| 0 | ||||||||||||||||||
1199 | createFramebufferObject(); | - | ||||||||||||||||||
1200 | } never executed: end of block | 0 | ||||||||||||||||||
1201 | } else { never executed: end of block | 0 | ||||||||||||||||||
1202 | #if QT_CONFIG(opengl) | - | ||||||||||||||||||
1203 | if (d->context) {
| 20-106 | ||||||||||||||||||
1204 | // Bail out when receiving a resize after scenegraph invalidation. This can happen | - | ||||||||||||||||||
1205 | // during hide - resize - show sequences and also during application exit. | - | ||||||||||||||||||
1206 | if (!d->fbo && !d->offscreenWindow->openglContext())
| 0-20 | ||||||||||||||||||
1207 | return; never executed: return; | 0 | ||||||||||||||||||
1208 | if (!d->fbo || d->fbo->size() != size() * devicePixelRatioF()) {
| 0-20 | ||||||||||||||||||
1209 | needsSync = true; | - | ||||||||||||||||||
1210 | createFramebufferObject(); | - | ||||||||||||||||||
1211 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||||||||
1212 | } else { executed 20 times by 1 test: end of block Executed by:
| 20 | ||||||||||||||||||
1213 | // This will result in a scenegraphInitialized() signal which | - | ||||||||||||||||||
1214 | // is connected to createFramebufferObject(). | - | ||||||||||||||||||
1215 | needsSync = true; | - | ||||||||||||||||||
1216 | d->createContext(); | - | ||||||||||||||||||
1217 | } executed 106 times by 2 tests: end of block Executed by:
| 106 | ||||||||||||||||||
1218 | - | |||||||||||||||||||
1219 | QOpenGLContext *context = d->offscreenWindow->openglContext(); | - | ||||||||||||||||||
1220 | if (!context) {
| 0-126 | ||||||||||||||||||
1221 | qWarning("QQuickWidget::resizeEvent() no OpenGL context"); | - | ||||||||||||||||||
1222 | return; never executed: return; | 0 | ||||||||||||||||||
1223 | } | - | ||||||||||||||||||
1224 | #endif | - | ||||||||||||||||||
1225 | } executed 126 times by 2 tests: end of block Executed by:
| 126 | ||||||||||||||||||
1226 | - | |||||||||||||||||||
1227 | d->render(needsSync); | - | ||||||||||||||||||
1228 | } executed 126 times by 2 tests: end of block Executed by:
| 126 | ||||||||||||||||||
1229 | - | |||||||||||||||||||
1230 | /*! \reimp */ | - | ||||||||||||||||||
1231 | bool QQuickWidget::focusNextPrevChild(bool next) | - | ||||||||||||||||||
1232 | { | - | ||||||||||||||||||
1233 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1234 | QKeyEvent event(QEvent::KeyPress, next ? Qt::Key_Tab : Qt::Key_Backtab, Qt::NoModifier); | - | ||||||||||||||||||
1235 | Q_QUICK_INPUT_PROFILE(QQuickProfiler::Key, QQuickProfiler::InputKeyPress, event.key(), never executed: end of block never executed: (void)0 ;
| 0 | ||||||||||||||||||
1236 | Qt::NoModifier); never executed: (void)0 ; | 0 | ||||||||||||||||||
1237 | QCoreApplication::sendEvent(d->offscreenWindow, &event); | - | ||||||||||||||||||
1238 | - | |||||||||||||||||||
1239 | QKeyEvent releaseEvent(QEvent::KeyRelease, next ? Qt::Key_Tab : Qt::Key_Backtab, Qt::NoModifier); | - | ||||||||||||||||||
1240 | Q_QUICK_INPUT_PROFILE(QQuickProfiler::Key, QQuickProfiler::InputKeyRelease, releaseEvent.key(), never executed: end of block never executed: (void)0 ;
| 0 | ||||||||||||||||||
1241 | Qt::NoModifier); never executed: (void)0 ; | 0 | ||||||||||||||||||
1242 | QCoreApplication::sendEvent(d->offscreenWindow, &releaseEvent); | - | ||||||||||||||||||
1243 | return event.isAccepted(); never executed: return event.isAccepted(); | 0 | ||||||||||||||||||
1244 | } | - | ||||||||||||||||||
1245 | - | |||||||||||||||||||
1246 | /*! \reimp */ | - | ||||||||||||||||||
1247 | void QQuickWidget::keyPressEvent(QKeyEvent *e) | - | ||||||||||||||||||
1248 | { | - | ||||||||||||||||||
1249 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1250 | Q_QUICK_INPUT_PROFILE(QQuickProfiler::Key, QQuickProfiler::InputKeyPress, e->key(), never executed: end of block never executed: (void)0 ;
| 0 | ||||||||||||||||||
1251 | e->modifiers()); never executed: (void)0 ; | 0 | ||||||||||||||||||
1252 | - | |||||||||||||||||||
1253 | QCoreApplication::sendEvent(d->offscreenWindow, e); | - | ||||||||||||||||||
1254 | } never executed: end of block | 0 | ||||||||||||||||||
1255 | - | |||||||||||||||||||
1256 | /*! \reimp */ | - | ||||||||||||||||||
1257 | void QQuickWidget::keyReleaseEvent(QKeyEvent *e) | - | ||||||||||||||||||
1258 | { | - | ||||||||||||||||||
1259 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1260 | Q_QUICK_INPUT_PROFILE(QQuickProfiler::Key, QQuickProfiler::InputKeyRelease, e->key(), never executed: end of block executed 2 times by 1 test: (void)0 ; Executed by:
| 0-2 | ||||||||||||||||||
1261 | e->modifiers()); executed 2 times by 1 test: (void)0 ; Executed by:
| 2 | ||||||||||||||||||
1262 | - | |||||||||||||||||||
1263 | QCoreApplication::sendEvent(d->offscreenWindow, e); | - | ||||||||||||||||||
1264 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
1265 | - | |||||||||||||||||||
1266 | /*! \reimp */ | - | ||||||||||||||||||
1267 | void QQuickWidget::mouseMoveEvent(QMouseEvent *e) | - | ||||||||||||||||||
1268 | { | - | ||||||||||||||||||
1269 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1270 | Q_QUICK_INPUT_PROFILE(QQuickProfiler::Mouse, QQuickProfiler::InputMouseMove, e->localPos().x(), never executed: end of block executed 2 times by 1 test: (void)0 ; Executed by:
| 0-2 | ||||||||||||||||||
1271 | e->localPos().y()); executed 2 times by 1 test: (void)0 ; Executed by:
| 2 | ||||||||||||||||||
1272 | - | |||||||||||||||||||
1273 | // Put localPos into the event's localPos and windowPos, and screenPos into the | - | ||||||||||||||||||
1274 | // event's screenPos. This way the windowPos in e is ignored and is replaced by | - | ||||||||||||||||||
1275 | // localPos. This is necessary because QQuickWindow thinks of itself as a | - | ||||||||||||||||||
1276 | // top-level window always. | - | ||||||||||||||||||
1277 | QMouseEvent mappedEvent(e->type(), e->localPos(), e->localPos(), e->screenPos(), | - | ||||||||||||||||||
1278 | e->button(), e->buttons(), e->modifiers(), e->source()); | - | ||||||||||||||||||
1279 | QCoreApplication::sendEvent(d->offscreenWindow, &mappedEvent); | - | ||||||||||||||||||
1280 | e->setAccepted(mappedEvent.isAccepted()); | - | ||||||||||||||||||
1281 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
1282 | - | |||||||||||||||||||
1283 | /*! \reimp */ | - | ||||||||||||||||||
1284 | void QQuickWidget::mouseDoubleClickEvent(QMouseEvent *e) | - | ||||||||||||||||||
1285 | { | - | ||||||||||||||||||
1286 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1287 | Q_QUICK_INPUT_PROFILE(QQuickProfiler::Mouse, QQuickProfiler::InputMouseDoubleClick, never executed: end of block never executed: (void)0 ;
| 0 | ||||||||||||||||||
1288 | e->button(), e->buttons()); never executed: (void)0 ; | 0 | ||||||||||||||||||
1289 | - | |||||||||||||||||||
1290 | // As the second mouse press is suppressed in widget windows we emulate it here for QML. | - | ||||||||||||||||||
1291 | // See QTBUG-25831 | - | ||||||||||||||||||
1292 | QMouseEvent pressEvent(QEvent::MouseButtonPress, e->localPos(), e->localPos(), e->screenPos(), | - | ||||||||||||||||||
1293 | e->button(), e->buttons(), e->modifiers(), e->source()); | - | ||||||||||||||||||
1294 | QCoreApplication::sendEvent(d->offscreenWindow, &pressEvent); | - | ||||||||||||||||||
1295 | e->setAccepted(pressEvent.isAccepted()); | - | ||||||||||||||||||
1296 | QMouseEvent mappedEvent(e->type(), e->localPos(), e->localPos(), e->screenPos(), | - | ||||||||||||||||||
1297 | e->button(), e->buttons(), e->modifiers(), e->source()); | - | ||||||||||||||||||
1298 | QCoreApplication::sendEvent(d->offscreenWindow, &mappedEvent); | - | ||||||||||||||||||
1299 | } never executed: end of block | 0 | ||||||||||||||||||
1300 | - | |||||||||||||||||||
1301 | /*! \reimp */ | - | ||||||||||||||||||
1302 | void QQuickWidget::showEvent(QShowEvent *) | - | ||||||||||||||||||
1303 | { | - | ||||||||||||||||||
1304 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1305 | if (!d->useSoftwareRenderer) {
| 0-108 | ||||||||||||||||||
1306 | d->createContext(); | - | ||||||||||||||||||
1307 | if (d->offscreenWindow->openglContext()) {
| 0-108 | ||||||||||||||||||
1308 | d->render(true); | - | ||||||||||||||||||
1309 | // render() may have led to a QQuickWindow::update() call (for | - | ||||||||||||||||||
1310 | // example, having a scene with a QQuickFramebufferObject::Renderer | - | ||||||||||||||||||
1311 | // calling update() in its render()) which in turn results in | - | ||||||||||||||||||
1312 | // renderRequested in the rendercontrol, ending up in | - | ||||||||||||||||||
1313 | // triggerUpdate. In this case just calling update() is not | - | ||||||||||||||||||
1314 | // acceptable, we need the full renderSceneGraph issued from | - | ||||||||||||||||||
1315 | // timerEvent(). | - | ||||||||||||||||||
1316 | if (!d->eventPending && d->updatePending) {
| 0-108 | ||||||||||||||||||
1317 | d->updatePending = false; | - | ||||||||||||||||||
1318 | update(); | - | ||||||||||||||||||
1319 | } never executed: end of block | 0 | ||||||||||||||||||
1320 | } else { executed 108 times by 2 tests: end of block Executed by:
| 108 | ||||||||||||||||||
1321 | triggerUpdate(); | - | ||||||||||||||||||
1322 | } never executed: end of block | 0 | ||||||||||||||||||
1323 | } | - | ||||||||||||||||||
1324 | QWindowPrivate *offscreenPrivate = QWindowPrivate::get(d->offscreenWindow); | - | ||||||||||||||||||
1325 | if (!offscreenPrivate->visible) {
| 0-108 | ||||||||||||||||||
1326 | offscreenPrivate->visible = true; | - | ||||||||||||||||||
1327 | emit d->offscreenWindow->visibleChanged(true); | - | ||||||||||||||||||
1328 | offscreenPrivate->updateVisibility(); | - | ||||||||||||||||||
1329 | } executed 108 times by 2 tests: end of block Executed by:
| 108 | ||||||||||||||||||
1330 | if (QQmlInspectorService *service = QQmlDebugConnector::service<QQmlInspectorService>())
| 0-108 | ||||||||||||||||||
1331 | service->setParentWindow(d->offscreenWindow, window()->windowHandle()); never executed: service->setParentWindow(d->offscreenWindow, window()->windowHandle()); | 0 | ||||||||||||||||||
1332 | } executed 108 times by 2 tests: end of block Executed by:
| 108 | ||||||||||||||||||
1333 | - | |||||||||||||||||||
1334 | /*! \reimp */ | - | ||||||||||||||||||
1335 | void QQuickWidget::hideEvent(QHideEvent *) | - | ||||||||||||||||||
1336 | { | - | ||||||||||||||||||
1337 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1338 | if (!d->offscreenWindow->isPersistentSceneGraph())
| 0-20 | ||||||||||||||||||
1339 | d->invalidateRenderControl(); never executed: d->invalidateRenderControl(); | 0 | ||||||||||||||||||
1340 | QWindowPrivate *offscreenPrivate = QWindowPrivate::get(d->offscreenWindow); | - | ||||||||||||||||||
1341 | if (offscreenPrivate->visible) {
| 0-20 | ||||||||||||||||||
1342 | offscreenPrivate->visible = false; | - | ||||||||||||||||||
1343 | emit d->offscreenWindow->visibleChanged(false); | - | ||||||||||||||||||
1344 | offscreenPrivate->updateVisibility(); | - | ||||||||||||||||||
1345 | } executed 20 times by 1 test: end of block Executed by:
| 20 | ||||||||||||||||||
1346 | if (QQmlInspectorService *service = QQmlDebugConnector::service<QQmlInspectorService>())
| 0-20 | ||||||||||||||||||
1347 | service->setParentWindow(d->offscreenWindow, d->offscreenWindow); never executed: service->setParentWindow(d->offscreenWindow, d->offscreenWindow); | 0 | ||||||||||||||||||
1348 | } executed 20 times by 1 test: end of block Executed by:
| 20 | ||||||||||||||||||
1349 | - | |||||||||||||||||||
1350 | /*! \reimp */ | - | ||||||||||||||||||
1351 | void QQuickWidget::mousePressEvent(QMouseEvent *e) | - | ||||||||||||||||||
1352 | { | - | ||||||||||||||||||
1353 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1354 | Q_QUICK_INPUT_PROFILE(QQuickProfiler::Mouse, QQuickProfiler::InputMousePress, e->button(), never executed: end of block never executed: (void)0 ;
| 0 | ||||||||||||||||||
1355 | e->buttons()); never executed: (void)0 ; | 0 | ||||||||||||||||||
1356 | - | |||||||||||||||||||
1357 | QMouseEvent mappedEvent(e->type(), e->localPos(), e->localPos(), e->screenPos(), | - | ||||||||||||||||||
1358 | e->button(), e->buttons(), e->modifiers(), e->source()); | - | ||||||||||||||||||
1359 | QCoreApplication::sendEvent(d->offscreenWindow, &mappedEvent); | - | ||||||||||||||||||
1360 | e->setAccepted(mappedEvent.isAccepted()); | - | ||||||||||||||||||
1361 | } never executed: end of block | 0 | ||||||||||||||||||
1362 | - | |||||||||||||||||||
1363 | /*! \reimp */ | - | ||||||||||||||||||
1364 | void QQuickWidget::mouseReleaseEvent(QMouseEvent *e) | - | ||||||||||||||||||
1365 | { | - | ||||||||||||||||||
1366 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1367 | Q_QUICK_INPUT_PROFILE(QQuickProfiler::Mouse, QQuickProfiler::InputMouseRelease, e->button(), never executed: end of block never executed: (void)0 ;
| 0 | ||||||||||||||||||
1368 | e->buttons()); never executed: (void)0 ; | 0 | ||||||||||||||||||
1369 | - | |||||||||||||||||||
1370 | QMouseEvent mappedEvent(e->type(), e->localPos(), e->localPos(), e->screenPos(), | - | ||||||||||||||||||
1371 | e->button(), e->buttons(), e->modifiers(), e->source()); | - | ||||||||||||||||||
1372 | QCoreApplication::sendEvent(d->offscreenWindow, &mappedEvent); | - | ||||||||||||||||||
1373 | e->setAccepted(mappedEvent.isAccepted()); | - | ||||||||||||||||||
1374 | } never executed: end of block | 0 | ||||||||||||||||||
1375 | - | |||||||||||||||||||
1376 | #if QT_CONFIG(wheelevent) | - | ||||||||||||||||||
1377 | /*! \reimp */ | - | ||||||||||||||||||
1378 | void QQuickWidget::wheelEvent(QWheelEvent *e) | - | ||||||||||||||||||
1379 | { | - | ||||||||||||||||||
1380 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1381 | Q_QUICK_INPUT_PROFILE(QQuickProfiler::Mouse, QQuickProfiler::InputMouseWheel, never executed: end of block never executed: (void)0 ;
| 0 | ||||||||||||||||||
1382 | e->angleDelta().x(), e->angleDelta().y()); never executed: (void)0 ; | 0 | ||||||||||||||||||
1383 | - | |||||||||||||||||||
1384 | // Wheel events only have local and global positions, no need to map. | - | ||||||||||||||||||
1385 | QCoreApplication::sendEvent(d->offscreenWindow, e); | - | ||||||||||||||||||
1386 | } never executed: end of block | 0 | ||||||||||||||||||
1387 | #endif | - | ||||||||||||||||||
1388 | - | |||||||||||||||||||
1389 | /*! | - | ||||||||||||||||||
1390 | \reimp | - | ||||||||||||||||||
1391 | */ | - | ||||||||||||||||||
1392 | void QQuickWidget::focusInEvent(QFocusEvent * event) | - | ||||||||||||||||||
1393 | { | - | ||||||||||||||||||
1394 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1395 | d->offscreenWindow->focusInEvent(event); | - | ||||||||||||||||||
1396 | } never executed: end of block | 0 | ||||||||||||||||||
1397 | - | |||||||||||||||||||
1398 | /*! | - | ||||||||||||||||||
1399 | \reimp | - | ||||||||||||||||||
1400 | */ | - | ||||||||||||||||||
1401 | void QQuickWidget::focusOutEvent(QFocusEvent * event) | - | ||||||||||||||||||
1402 | { | - | ||||||||||||||||||
1403 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1404 | d->offscreenWindow->focusOutEvent(event); | - | ||||||||||||||||||
1405 | } never executed: end of block | 0 | ||||||||||||||||||
1406 | - | |||||||||||||||||||
1407 | static Qt::WindowState resolveWindowState(Qt::WindowStates states) | - | ||||||||||||||||||
1408 | { | - | ||||||||||||||||||
1409 | // No more than one of these 3 can be set | - | ||||||||||||||||||
1410 | if (states & Qt::WindowMinimized)
| 0 | ||||||||||||||||||
1411 | return Qt::WindowMinimized; never executed: return Qt::WindowMinimized; | 0 | ||||||||||||||||||
1412 | if (states & Qt::WindowMaximized)
| 0 | ||||||||||||||||||
1413 | return Qt::WindowMaximized; never executed: return Qt::WindowMaximized; | 0 | ||||||||||||||||||
1414 | if (states & Qt::WindowFullScreen)
| 0 | ||||||||||||||||||
1415 | return Qt::WindowFullScreen; never executed: return Qt::WindowFullScreen; | 0 | ||||||||||||||||||
1416 | - | |||||||||||||||||||
1417 | // No state means "windowed" - we ignore Qt::WindowActive | - | ||||||||||||||||||
1418 | return Qt::WindowNoState; never executed: return Qt::WindowNoState; | 0 | ||||||||||||||||||
1419 | } | - | ||||||||||||||||||
1420 | - | |||||||||||||||||||
1421 | static void remapInputMethodQueryEvent(QObject *object, QInputMethodQueryEvent *e) | - | ||||||||||||||||||
1422 | { | - | ||||||||||||||||||
1423 | auto item = qobject_cast<QQuickItem *>(object); | - | ||||||||||||||||||
1424 | if (!item)
| 0 | ||||||||||||||||||
1425 | return; never executed: return; | 0 | ||||||||||||||||||
1426 | - | |||||||||||||||||||
1427 | // Remap all QRectF values. | - | ||||||||||||||||||
1428 | for (auto query : {Qt::ImCursorRectangle, Qt::ImAnchorRectangle, Qt::ImInputItemClipRectangle}) { | - | ||||||||||||||||||
1429 | if (e->queries() & query) {
| 0 | ||||||||||||||||||
1430 | auto value = e->value(query); | - | ||||||||||||||||||
1431 | if (value.canConvert<QRectF>())
| 0 | ||||||||||||||||||
1432 | e->setValue(query, item->mapRectToScene(value.toRectF())); never executed: e->setValue(query, item->mapRectToScene(value.toRectF())); | 0 | ||||||||||||||||||
1433 | } never executed: end of block | 0 | ||||||||||||||||||
1434 | } never executed: end of block | 0 | ||||||||||||||||||
1435 | // Remap all QPointF values. | - | ||||||||||||||||||
1436 | if (e->queries() & Qt::ImCursorPosition) {
| 0 | ||||||||||||||||||
1437 | auto value = e->value(Qt::ImCursorPosition); | - | ||||||||||||||||||
1438 | if (value.canConvert<QPointF>())
| 0 | ||||||||||||||||||
1439 | e->setValue(Qt::ImCursorPosition, item->mapToScene(value.toPointF())); never executed: e->setValue(Qt::ImCursorPosition, item->mapToScene(value.toPointF())); | 0 | ||||||||||||||||||
1440 | } never executed: end of block | 0 | ||||||||||||||||||
1441 | } never executed: end of block | 0 | ||||||||||||||||||
1442 | - | |||||||||||||||||||
1443 | /*! \reimp */ | - | ||||||||||||||||||
1444 | bool QQuickWidget::event(QEvent *e) | - | ||||||||||||||||||
1445 | { | - | ||||||||||||||||||
1446 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1447 | - | |||||||||||||||||||
1448 | switch (e->type()) { | - | ||||||||||||||||||
1449 | - | |||||||||||||||||||
1450 | case QEvent::Leave: executed 2 times by 1 test: case QEvent::Leave: Executed by:
| 2 | ||||||||||||||||||
1451 | case QEvent::TouchBegin: never executed: case QEvent::TouchBegin: | 0 | ||||||||||||||||||
1452 | case QEvent::TouchEnd: never executed: case QEvent::TouchEnd: | 0 | ||||||||||||||||||
1453 | case QEvent::TouchUpdate: never executed: case QEvent::TouchUpdate: | 0 | ||||||||||||||||||
1454 | case QEvent::TouchCancel: never executed: case QEvent::TouchCancel: | 0 | ||||||||||||||||||
1455 | // Touch events only have local and global positions, no need to map. | - | ||||||||||||||||||
1456 | return QCoreApplication::sendEvent(d->offscreenWindow, e); executed 2 times by 1 test: return QCoreApplication::sendEvent(d->offscreenWindow, e); Executed by:
| 2 | ||||||||||||||||||
1457 | - | |||||||||||||||||||
1458 | case QEvent::InputMethod: never executed: case QEvent::InputMethod: | 0 | ||||||||||||||||||
1459 | return QCoreApplication::sendEvent(d->offscreenWindow->focusObject(), e); never executed: return QCoreApplication::sendEvent(d->offscreenWindow->focusObject(), e); | 0 | ||||||||||||||||||
1460 | case QEvent::InputMethodQuery: never executed: case QEvent::InputMethodQuery: | 0 | ||||||||||||||||||
1461 | { | - | ||||||||||||||||||
1462 | bool eventResult = QCoreApplication::sendEvent(d->offscreenWindow->focusObject(), e); | - | ||||||||||||||||||
1463 | // The result in focusObject are based on offscreenWindow. But | - | ||||||||||||||||||
1464 | // the inputMethodTransform won't get updated because the focus | - | ||||||||||||||||||
1465 | // is on QQuickWidget. We need to remap the value based on the | - | ||||||||||||||||||
1466 | // widget. | - | ||||||||||||||||||
1467 | remapInputMethodQueryEvent(d->offscreenWindow->focusObject(), static_cast<QInputMethodQueryEvent *>(e)); | - | ||||||||||||||||||
1468 | return eventResult; never executed: return eventResult; | 0 | ||||||||||||||||||
1469 | } | - | ||||||||||||||||||
1470 | - | |||||||||||||||||||
1471 | case QEvent::WindowChangeInternal: executed 8 times by 1 test: case QEvent::WindowChangeInternal: Executed by:
| 8 | ||||||||||||||||||
1472 | d->handleWindowChange(); | - | ||||||||||||||||||
1473 | break; executed 8 times by 1 test: break; Executed by:
| 8 | ||||||||||||||||||
1474 | - | |||||||||||||||||||
1475 | case QEvent::ScreenChangeInternal: never executed: case QEvent::ScreenChangeInternal: | 0 | ||||||||||||||||||
1476 | if (QWindow *window = this->window()->windowHandle()) {
| 0 | ||||||||||||||||||
1477 | QScreen *newScreen = window->screen(); | - | ||||||||||||||||||
1478 | - | |||||||||||||||||||
1479 | if (d->offscreenWindow)
| 0 | ||||||||||||||||||
1480 | d->offscreenWindow->setScreen(newScreen); never executed: d->offscreenWindow->setScreen(newScreen); | 0 | ||||||||||||||||||
1481 | if (d->offscreenSurface)
| 0 | ||||||||||||||||||
1482 | d->offscreenSurface->setScreen(newScreen); never executed: d->offscreenSurface->setScreen(newScreen); | 0 | ||||||||||||||||||
1483 | #if QT_CONFIG(opengl) | - | ||||||||||||||||||
1484 | if (d->context)
| 0 | ||||||||||||||||||
1485 | d->context->setScreen(newScreen); never executed: d->context->setScreen(newScreen); | 0 | ||||||||||||||||||
1486 | #endif | - | ||||||||||||||||||
1487 | } never executed: end of block | 0 | ||||||||||||||||||
1488 | - | |||||||||||||||||||
1489 | if (d->useSoftwareRenderer
| 0 | ||||||||||||||||||
1490 | #if QT_CONFIG(opengl) | - | ||||||||||||||||||
1491 | || d->fbo
| 0 | ||||||||||||||||||
1492 | #endif | - | ||||||||||||||||||
1493 | ) { | - | ||||||||||||||||||
1494 | // This will check the size taking the devicePixelRatio into account | - | ||||||||||||||||||
1495 | // and recreate if needed. | - | ||||||||||||||||||
1496 | createFramebufferObject(); | - | ||||||||||||||||||
1497 | d->render(true); | - | ||||||||||||||||||
1498 | } never executed: end of block | 0 | ||||||||||||||||||
1499 | break; never executed: break; | 0 | ||||||||||||||||||
1500 | - | |||||||||||||||||||
1501 | case QEvent::Show: executed 108 times by 2 tests: case QEvent::Show: Executed by:
| 108 | ||||||||||||||||||
1502 | case QEvent::Move: executed 114 times by 2 tests: case QEvent::Move: Executed by:
| 114 | ||||||||||||||||||
1503 | d->updatePosition(); | - | ||||||||||||||||||
1504 | break; executed 222 times by 2 tests: break; Executed by:
| 222 | ||||||||||||||||||
1505 | - | |||||||||||||||||||
1506 | case QEvent::WindowStateChange: never executed: case QEvent::WindowStateChange: | 0 | ||||||||||||||||||
1507 | d->offscreenWindow->setWindowState(resolveWindowState(windowState())); | - | ||||||||||||||||||
1508 | break; never executed: break; | 0 | ||||||||||||||||||
1509 | - | |||||||||||||||||||
1510 | case QEvent::ShortcutOverride: executed 4 times by 1 test: case QEvent::ShortcutOverride: Executed by:
| 4 | ||||||||||||||||||
1511 | return QCoreApplication::sendEvent(d->offscreenWindow, e); executed 4 times by 1 test: return QCoreApplication::sendEvent(d->offscreenWindow, e); Executed by:
| 4 | ||||||||||||||||||
1512 | - | |||||||||||||||||||
1513 | case QEvent::Enter: { executed 12 times by 1 test: case QEvent::Enter: Executed by:
| 12 | ||||||||||||||||||
1514 | QEnterEvent *enterEvent = static_cast<QEnterEvent *>(e); | - | ||||||||||||||||||
1515 | QEnterEvent mappedEvent(enterEvent->localPos(), enterEvent->windowPos(), | - | ||||||||||||||||||
1516 | enterEvent->screenPos()); | - | ||||||||||||||||||
1517 | const bool ret = QCoreApplication::sendEvent(d->offscreenWindow, &mappedEvent); | - | ||||||||||||||||||
1518 | e->setAccepted(mappedEvent.isAccepted()); | - | ||||||||||||||||||
1519 | return ret; executed 12 times by 1 test: return ret; Executed by:
| 12 | ||||||||||||||||||
1520 | } | - | ||||||||||||||||||
1521 | default: executed 1716 times by 2 tests: default: Executed by:
| 1716 | ||||||||||||||||||
1522 | break; executed 1716 times by 2 tests: break; Executed by:
| 1716 | ||||||||||||||||||
1523 | } | - | ||||||||||||||||||
1524 | - | |||||||||||||||||||
1525 | return QWidget::event(e); executed 1946 times by 2 tests: return QWidget::event(e); Executed by:
| 1946 | ||||||||||||||||||
1526 | } | - | ||||||||||||||||||
1527 | - | |||||||||||||||||||
1528 | #if QT_CONFIG(draganddrop) | - | ||||||||||||||||||
1529 | - | |||||||||||||||||||
1530 | /*! \reimp */ | - | ||||||||||||||||||
1531 | void QQuickWidget::dragEnterEvent(QDragEnterEvent *e) | - | ||||||||||||||||||
1532 | { | - | ||||||||||||||||||
1533 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1534 | // Don't reject drag events for the entire widget when one | - | ||||||||||||||||||
1535 | // item rejects the drag enter | - | ||||||||||||||||||
1536 | d->offscreenWindow->event(e); | - | ||||||||||||||||||
1537 | e->accept(); | - | ||||||||||||||||||
1538 | } never executed: end of block | 0 | ||||||||||||||||||
1539 | - | |||||||||||||||||||
1540 | /*! \reimp */ | - | ||||||||||||||||||
1541 | void QQuickWidget::dragMoveEvent(QDragMoveEvent *e) | - | ||||||||||||||||||
1542 | { | - | ||||||||||||||||||
1543 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1544 | // Drag/drop events only have local pos, so no need to map, | - | ||||||||||||||||||
1545 | // but QQuickWindow::event() does not return true | - | ||||||||||||||||||
1546 | d->offscreenWindow->event(e); | - | ||||||||||||||||||
1547 | } never executed: end of block | 0 | ||||||||||||||||||
1548 | - | |||||||||||||||||||
1549 | /*! \reimp */ | - | ||||||||||||||||||
1550 | void QQuickWidget::dragLeaveEvent(QDragLeaveEvent *e) | - | ||||||||||||||||||
1551 | { | - | ||||||||||||||||||
1552 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1553 | d->offscreenWindow->event(e); | - | ||||||||||||||||||
1554 | } never executed: end of block | 0 | ||||||||||||||||||
1555 | - | |||||||||||||||||||
1556 | /*! \reimp */ | - | ||||||||||||||||||
1557 | void QQuickWidget::dropEvent(QDropEvent *e) | - | ||||||||||||||||||
1558 | { | - | ||||||||||||||||||
1559 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1560 | d->offscreenWindow->event(e); | - | ||||||||||||||||||
1561 | } never executed: end of block | 0 | ||||||||||||||||||
1562 | - | |||||||||||||||||||
1563 | #endif // draganddrop | - | ||||||||||||||||||
1564 | - | |||||||||||||||||||
1565 | // TODO: try to separate the two cases of | - | ||||||||||||||||||
1566 | // 1. render() unconditionally without sync | - | ||||||||||||||||||
1567 | // 2. sync() and then render if necessary | - | ||||||||||||||||||
1568 | void QQuickWidget::triggerUpdate() | - | ||||||||||||||||||
1569 | { | - | ||||||||||||||||||
1570 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1571 | d->updatePending = true; | - | ||||||||||||||||||
1572 | if (!d->eventPending) {
| 208-974 | ||||||||||||||||||
1573 | // There's no sense in immediately kicking a render off now, as | - | ||||||||||||||||||
1574 | // there may be a number of triggerUpdate calls to come from a multitude | - | ||||||||||||||||||
1575 | // of different sources (network, touch/mouse/keyboard, timers, | - | ||||||||||||||||||
1576 | // animations, ...), and we want to batch them all into single frames as | - | ||||||||||||||||||
1577 | // much as possible for the sake of interactivity and responsiveness. | - | ||||||||||||||||||
1578 | // | - | ||||||||||||||||||
1579 | // To achieve this, we set a timer and only perform the rendering when | - | ||||||||||||||||||
1580 | // this is complete. | - | ||||||||||||||||||
1581 | const int exhaustDelay = 5; | - | ||||||||||||||||||
1582 | d->updateTimer.start(exhaustDelay, Qt::PreciseTimer, this); | - | ||||||||||||||||||
1583 | d->eventPending = true; | - | ||||||||||||||||||
1584 | } executed 208 times by 2 tests: end of block Executed by:
| 208 | ||||||||||||||||||
1585 | } executed 1182 times by 2 tests: end of block Executed by:
| 1182 | ||||||||||||||||||
1586 | - | |||||||||||||||||||
1587 | /*! | - | ||||||||||||||||||
1588 | Sets the surface \a format for the context and offscreen surface used | - | ||||||||||||||||||
1589 | by this widget. | - | ||||||||||||||||||
1590 | - | |||||||||||||||||||
1591 | Call this function when there is a need to request a context for a | - | ||||||||||||||||||
1592 | given OpenGL version or profile. The sizes for depth, stencil and | - | ||||||||||||||||||
1593 | alpha buffers are taken care of automatically and there is no need | - | ||||||||||||||||||
1594 | to request those explicitly. | - | ||||||||||||||||||
1595 | - | |||||||||||||||||||
1596 | \sa QWindow::setFormat(), QWindow::format(), format() | - | ||||||||||||||||||
1597 | */ | - | ||||||||||||||||||
1598 | void QQuickWidget::setFormat(const QSurfaceFormat &format) | - | ||||||||||||||||||
1599 | { | - | ||||||||||||||||||
1600 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1601 | QSurfaceFormat currentFormat = d->offscreenWindow->format(); | - | ||||||||||||||||||
1602 | QSurfaceFormat newFormat = format; | - | ||||||||||||||||||
1603 | newFormat.setDepthBufferSize(qMax(newFormat.depthBufferSize(), currentFormat.depthBufferSize())); | - | ||||||||||||||||||
1604 | newFormat.setStencilBufferSize(qMax(newFormat.stencilBufferSize(), currentFormat.stencilBufferSize())); | - | ||||||||||||||||||
1605 | newFormat.setAlphaBufferSize(qMax(newFormat.alphaBufferSize(), currentFormat.alphaBufferSize())); | - | ||||||||||||||||||
1606 | - | |||||||||||||||||||
1607 | // Do not include the sample count. Requesting a multisampled context is not necessary | - | ||||||||||||||||||
1608 | // since we render into an FBO, never to an actual surface. What's more, attempting to | - | ||||||||||||||||||
1609 | // create a pbuffer with a multisampled config crashes certain implementations. Just | - | ||||||||||||||||||
1610 | // avoid the entire hassle, the result is the same. | - | ||||||||||||||||||
1611 | d->requestedSamples = newFormat.samples(); | - | ||||||||||||||||||
1612 | newFormat.setSamples(0); | - | ||||||||||||||||||
1613 | - | |||||||||||||||||||
1614 | d->offscreenWindow->setFormat(newFormat); | - | ||||||||||||||||||
1615 | } never executed: end of block | 0 | ||||||||||||||||||
1616 | - | |||||||||||||||||||
1617 | /*! | - | ||||||||||||||||||
1618 | Returns the actual surface format. | - | ||||||||||||||||||
1619 | - | |||||||||||||||||||
1620 | If the widget has not yet been shown, the requested format is returned. | - | ||||||||||||||||||
1621 | - | |||||||||||||||||||
1622 | \sa setFormat() | - | ||||||||||||||||||
1623 | */ | - | ||||||||||||||||||
1624 | QSurfaceFormat QQuickWidget::format() const | - | ||||||||||||||||||
1625 | { | - | ||||||||||||||||||
1626 | Q_D(const QQuickWidget); | - | ||||||||||||||||||
1627 | return d->offscreenWindow->format(); never executed: return d->offscreenWindow->format(); | 0 | ||||||||||||||||||
1628 | } | - | ||||||||||||||||||
1629 | - | |||||||||||||||||||
1630 | /*! | - | ||||||||||||||||||
1631 | Renders a frame and reads it back into an image. | - | ||||||||||||||||||
1632 | - | |||||||||||||||||||
1633 | \note This is a potentially expensive operation. | - | ||||||||||||||||||
1634 | */ | - | ||||||||||||||||||
1635 | QImage QQuickWidget::grabFramebuffer() const | - | ||||||||||||||||||
1636 | { | - | ||||||||||||||||||
1637 | return const_cast<QQuickWidgetPrivate *>(d_func())->grabFramebuffer(); executed 4 times by 1 test: return const_cast<QQuickWidgetPrivate *>(d_func())->grabFramebuffer(); Executed by:
| 4 | ||||||||||||||||||
1638 | } | - | ||||||||||||||||||
1639 | - | |||||||||||||||||||
1640 | /*! | - | ||||||||||||||||||
1641 | Sets the clear \a color. By default this is an opaque color. | - | ||||||||||||||||||
1642 | - | |||||||||||||||||||
1643 | To get a semi-transparent QQuickWidget, call this function with | - | ||||||||||||||||||
1644 | \a color set to Qt::transparent, set the Qt::WA_TranslucentBackground | - | ||||||||||||||||||
1645 | widget attribute on the top-level window, and request an alpha | - | ||||||||||||||||||
1646 | channel via setFormat(). | - | ||||||||||||||||||
1647 | - | |||||||||||||||||||
1648 | \sa QQuickWindow::setColor() | - | ||||||||||||||||||
1649 | */ | - | ||||||||||||||||||
1650 | void QQuickWidget::setClearColor(const QColor &color) | - | ||||||||||||||||||
1651 | { | - | ||||||||||||||||||
1652 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1653 | d->offscreenWindow->setColor(color); | - | ||||||||||||||||||
1654 | } never executed: end of block | 0 | ||||||||||||||||||
1655 | - | |||||||||||||||||||
1656 | /*! | - | ||||||||||||||||||
1657 | \since 5.5 | - | ||||||||||||||||||
1658 | - | |||||||||||||||||||
1659 | Returns the offscreen QQuickWindow which is used by this widget to drive | - | ||||||||||||||||||
1660 | the Qt Quick rendering. This is useful if you want to use QQuickWindow | - | ||||||||||||||||||
1661 | APIs that are not currently exposed by QQuickWidget, for instance | - | ||||||||||||||||||
1662 | connecting to the QQuickWindow::beforeRendering() signal in order | - | ||||||||||||||||||
1663 | to draw native OpenGL content below Qt Quick's own rendering. | - | ||||||||||||||||||
1664 | - | |||||||||||||||||||
1665 | \warning Use the return value of this function with caution. In | - | ||||||||||||||||||
1666 | particular, do not ever attempt to show the QQuickWindow, and be | - | ||||||||||||||||||
1667 | very careful when using other QWindow-only APIs. | - | ||||||||||||||||||
1668 | */ | - | ||||||||||||||||||
1669 | QQuickWindow *QQuickWidget::quickWindow() const | - | ||||||||||||||||||
1670 | { | - | ||||||||||||||||||
1671 | Q_D(const QQuickWidget); | - | ||||||||||||||||||
1672 | return d->offscreenWindow; executed 14 times by 1 test: return d->offscreenWindow; Executed by:
| 14 | ||||||||||||||||||
1673 | } | - | ||||||||||||||||||
1674 | - | |||||||||||||||||||
1675 | /*! | - | ||||||||||||||||||
1676 | \reimp | - | ||||||||||||||||||
1677 | */ | - | ||||||||||||||||||
1678 | void QQuickWidget::paintEvent(QPaintEvent *event) | - | ||||||||||||||||||
1679 | { | - | ||||||||||||||||||
1680 | Q_D(QQuickWidget); | - | ||||||||||||||||||
1681 | if (d->useSoftwareRenderer) {
| 0-160 | ||||||||||||||||||
1682 | QPainter painter(this); | - | ||||||||||||||||||
1683 | d->updateRegion = d->updateRegion.united(event->region()); | - | ||||||||||||||||||
1684 | if (d->updateRegion.isNull()) {
| 0 | ||||||||||||||||||
1685 | //Paint everything | - | ||||||||||||||||||
1686 | painter.drawImage(rect(), d->softwareImage); | - | ||||||||||||||||||
1687 | } else { never executed: end of block | 0 | ||||||||||||||||||
1688 | QTransform transform; | - | ||||||||||||||||||
1689 | transform.scale(devicePixelRatioF(), devicePixelRatioF()); | - | ||||||||||||||||||
1690 | //Paint only the updated areas | - | ||||||||||||||||||
1691 | QRegion targetRegion; | - | ||||||||||||||||||
1692 | d->updateRegion.swap(targetRegion); | - | ||||||||||||||||||
1693 | for (auto targetRect : targetRegion) { | - | ||||||||||||||||||
1694 | auto sourceRect = transform.mapRect(QRectF(targetRect)); | - | ||||||||||||||||||
1695 | painter.drawImage(targetRect, d->softwareImage, sourceRect); | - | ||||||||||||||||||
1696 | } never executed: end of block | 0 | ||||||||||||||||||
1697 | } never executed: end of block | 0 | ||||||||||||||||||
1698 | } | - | ||||||||||||||||||
1699 | } executed 160 times by 2 tests: end of block Executed by:
| 160 | ||||||||||||||||||
1700 | - | |||||||||||||||||||
1701 | QT_END_NAMESPACE | - | ||||||||||||||||||
1702 | - | |||||||||||||||||||
1703 | #include "moc_qquickwidget.cpp" | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |