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 QQMLPREVIEWSERVICE_H
5#define QQMLPREVIEWSERVICE_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 "qqmlpreviewhandler.h"
19#include "qqmlpreviewfileengine.h"
20#include <private/qqmldebugserviceinterfaces_p.h>
21
22QT_BEGIN_NAMESPACE
23
24class QQmlPreviewFileEngineHandler;
25class QQmlPreviewHandler;
26class QQmlPreviewServiceImpl : public QQmlDebugService
27{
28 Q_OBJECT
29
30public:
31 enum Command {
32 File,
33 Load,
34 Request,
35 Error,
36 Rerun,
37 Directory,
38 ClearCache,
39 Zoom,
40 Fps
41 };
42
43 static const QString s_key;
44
45 QQmlPreviewServiceImpl(QObject *parent = nullptr);
46 virtual ~QQmlPreviewServiceImpl();
47
48 void messageReceived(const QByteArray &message) override;
49 void engineAboutToBeAdded(QJSEngine *engine) override;
50 void engineAboutToBeRemoved(QJSEngine *engine) override;
51 void stateChanged(State state) override;
52
53 void forwardRequest(const QString &file);
54 void forwardError(const QString &error);
55 void forwardFps(const QQmlPreviewHandler::FpsInfo &frames);
56
57 QQuickItem *currentRootItem();
58
59Q_SIGNALS:
60 void error(const QString &file);
61 void file(const QString &file, const QByteArray &contents);
62 void directory(const QString &file, const QStringList &entries);
63 void load(const QUrl &url);
64 void rerun();
65 void clearCache();
66 void zoom(qreal factor);
67
68private:
69 QScopedPointer<QQmlPreviewFileEngineHandler> m_fileEngine;
70 QScopedPointer<QQmlPreviewFileLoader> m_loader;
71 QQmlPreviewHandler m_handler;
72 QUrl m_currentUrl;
73};
74
75QT_END_NAMESPACE
76
77#endif // QQMLPREVIEWSERVICE_H
78

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