1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQMLPREVIEWHANDLER_H
5#define QQMLPREVIEWHANDLER_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qqmlpreviewposition.h"
19
20#include <QtCore/qobject.h>
21#include <QtCore/qvector.h>
22#include <QtCore/qrect.h>
23#include <QtCore/qpointer.h>
24#include <QtCore/qelapsedtimer.h>
25#include <QtQml/qqmlengine.h>
26
27QT_BEGIN_NAMESPACE
28
29class QQmlEngine;
30class QQuickItem;
31class QQmlPreviewUrlInterceptor;
32class QQuickWindow;
33
34class QQmlPreviewHandler : public QObject
35{
36 Q_OBJECT
37public:
38 explicit QQmlPreviewHandler(QObject *parent = nullptr);
39 ~QQmlPreviewHandler();
40
41 QQuickItem *currentRootItem();
42
43 void addEngine(QQmlEngine *engine);
44 void removeEngine(QQmlEngine *engine);
45
46 void loadUrl(const QUrl &url);
47 void dropCU(const QUrl &url);
48 void rerun();
49 void zoom(qreal newFactor);
50
51 void clear();
52
53 struct FpsInfo {
54 quint16 numSyncs;
55 quint16 minSync;
56 quint16 maxSync;
57 quint16 totalSync;
58
59 quint16 numRenders;
60 quint16 minRender;
61 quint16 maxRender;
62 quint16 totalRender;
63 };
64
65Q_SIGNALS:
66 void error(const QString &message);
67 void fps(const FpsInfo &info);
68
69protected:
70 bool eventFilter(QObject *obj, QEvent *event) override;
71private:
72 void doZoom();
73 void tryCreateObject();
74 void showObject(QObject *object);
75 void setCurrentWindow(QQuickWindow *window);
76
77 void beforeSynchronizing();
78 void afterSynchronizing();
79 void beforeRendering();
80 void frameSwapped();
81
82 void fpsTimerHit();
83
84 QScopedPointer<QQuickItem> m_dummyItem;
85 QList<QQmlEngine *> m_engines;
86 QPointer<QQuickItem> m_currentRootItem;
87 QVector<QPointer<QObject>> m_createdObjects;
88 QScopedPointer<QQmlComponent> m_component;
89 QPointer<QQuickWindow> m_currentWindow;
90 qreal m_zoomFactor = 1.0;
91 bool m_supportsMultipleWindows;
92 QQmlPreviewPosition m_lastPosition;
93
94 QTimer m_fpsTimer;
95
96 struct FrameTime {
97 void beginFrame();
98 void recordFrame();
99 void endFrame();
100 void reset();
101
102 QElapsedTimer timer;
103 qint64 elapsed = -1;
104 quint16 min = std::numeric_limits<quint16>::max();
105 quint16 max = 0;
106 quint16 total = 0;
107 quint16 number = 0;
108 };
109
110 FrameTime m_rendering;
111 FrameTime m_synchronizing;
112};
113
114QT_END_NAMESPACE
115
116Q_DECLARE_METATYPE(QQmlPreviewHandler::FpsInfo)
117
118#endif // QQMLPREVIEWHANDLER_H
119

source code of qtdeclarative/src/plugins/qmltooling/qmldbg_preview/qqmlpreviewhandler.h