1// Copyright (C) 2016 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 QQMLDEBUGSERVICE_H
5#define QQMLDEBUGSERVICE_H
6
7#include <QtCore/qobject.h>
8#include <QtCore/qhash.h>
9
10#include <private/qtqmlglobal_p.h>
11
12//
13// W A R N I N G
14// -------------
15//
16// This file is not part of the Qt API. It exists purely as an
17// implementation detail. This header file may change from version to
18// version without notice, or even be removed.
19//
20// We mean it.
21//
22
23QT_REQUIRE_CONFIG(qml_debug);
24
25QT_BEGIN_NAMESPACE
26
27class QJSEngine;
28
29class QQmlDebugServicePrivate;
30class Q_QML_PRIVATE_EXPORT QQmlDebugService : public QObject
31{
32 Q_OBJECT
33 Q_DECLARE_PRIVATE(QQmlDebugService)
34
35public:
36 ~QQmlDebugService() override;
37
38 const QString &name() const;
39 float version() const;
40
41 enum State { NotConnected, Unavailable, Enabled };
42 State state() const;
43 void setState(State newState);
44
45 virtual void stateAboutToBeChanged(State) {}
46 virtual void stateChanged(State) {}
47 virtual void messageReceived(const QByteArray &) {}
48
49 virtual void engineAboutToBeAdded(QJSEngine *engine) { Q_EMIT attachedToEngine(engine); }
50 virtual void engineAboutToBeRemoved(QJSEngine *engine) { Q_EMIT detachedFromEngine(engine); }
51
52 virtual void engineAdded(QJSEngine *) {}
53 virtual void engineRemoved(QJSEngine *) {}
54
55 static const QHash<int, QObject *> &objectsForIds();
56 static int idForObject(QObject *);
57 static QObject *objectForId(int id) { return objectsForIds().value(key: id); }
58
59protected:
60 explicit QQmlDebugService(const QString &, float version, QObject *parent = nullptr);
61
62Q_SIGNALS:
63 void attachedToEngine(QJSEngine *);
64 void detachedFromEngine(QJSEngine *);
65
66 void messageToClient(const QString &name, const QByteArray &message);
67 void messagesToClient(const QString &name, const QList<QByteArray> &messages);
68};
69
70QT_END_NAMESPACE
71
72#endif // QQMLDEBUGSERVICE_H
73
74

source code of qtdeclarative/src/qml/debugger/qqmldebugservice_p.h