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 | |
27 | QT_BEGIN_NAMESPACE |
28 | |
29 | class QQmlEngine; |
30 | class QQuickItem; |
31 | class QQmlPreviewUrlInterceptor; |
32 | class QQuickWindow; |
33 | |
34 | class QQmlPreviewHandler : public QObject |
35 | { |
36 | Q_OBJECT |
37 | public: |
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 rerun(); |
48 | void zoom(qreal newFactor); |
49 | |
50 | void clear(); |
51 | |
52 | struct FpsInfo { |
53 | quint16 numSyncs; |
54 | quint16 minSync; |
55 | quint16 maxSync; |
56 | quint16 totalSync; |
57 | |
58 | quint16 numRenders; |
59 | quint16 minRender; |
60 | quint16 maxRender; |
61 | quint16 totalRender; |
62 | }; |
63 | |
64 | Q_SIGNALS: |
65 | void error(const QString &message); |
66 | void fps(const FpsInfo &info); |
67 | |
68 | protected: |
69 | bool eventFilter(QObject *obj, QEvent *event) override; |
70 | private: |
71 | void doZoom(); |
72 | void tryCreateObject(); |
73 | void showObject(QObject *object); |
74 | void setCurrentWindow(QQuickWindow *window); |
75 | |
76 | void beforeSynchronizing(); |
77 | void afterSynchronizing(); |
78 | void beforeRendering(); |
79 | void frameSwapped(); |
80 | |
81 | void fpsTimerHit(); |
82 | |
83 | QScopedPointer<QQuickItem> m_dummyItem; |
84 | QList<QQmlEngine *> m_engines; |
85 | QPointer<QQuickItem> m_currentRootItem; |
86 | QVector<QPointer<QObject>> m_createdObjects; |
87 | QScopedPointer<QQmlComponent> m_component; |
88 | QPointer<QQuickWindow> m_currentWindow; |
89 | qreal m_zoomFactor = 1.0; |
90 | bool m_supportsMultipleWindows; |
91 | QQmlPreviewPosition m_lastPosition; |
92 | |
93 | QTimer m_fpsTimer; |
94 | |
95 | struct FrameTime { |
96 | void beginFrame(); |
97 | void recordFrame(); |
98 | void endFrame(); |
99 | void reset(); |
100 | |
101 | QElapsedTimer timer; |
102 | qint64 elapsed = -1; |
103 | quint16 min = std::numeric_limits<quint16>::max(); |
104 | quint16 max = 0; |
105 | quint16 total = 0; |
106 | quint16 number = 0; |
107 | }; |
108 | |
109 | FrameTime m_rendering; |
110 | FrameTime m_synchronizing; |
111 | }; |
112 | |
113 | QT_END_NAMESPACE |
114 | |
115 | Q_DECLARE_METATYPE(QQmlPreviewHandler::FpsInfo) |
116 | |
117 | #endif // QQMLPREVIEWHANDLER_H |
118 |