Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qqmlpreviewservice.cpp
Go to the documentation of this file.
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
5
6#include <QtCore/qpointer.h>
7#include <QtQml/qqmlengine.h>
8#include <QtQml/qqmlcomponent.h>
9#include <QtQuick/qquickwindow.h>
10#include <QtQuick/qquickitem.h>
11#include <QtGui/qguiapplication.h>
12
13#include <private/qquickpixmap_p.h>
14#include <private/qqmldebugconnector_p.h>
15#include <private/qversionedpacket_p.h>
16
18
20using QQmlDebugPacket = QVersionedPacket<QQmlDebugConnector>;
21
36
40
42{
43 QQmlDebugPacket packet(data);
44 qint8 command;
45
46 packet >> command;
47 switch (command) {
48 case File: {
51 packet >> path >> contents;
53
54 // Replace the whole scene with the first file successfully loaded over the debug
55 // connection. This is an OK approximation of the root component, and if the client wants
56 // something specific, it will send an explicit Load anyway.
57 if (m_currentUrl.isEmpty() && path.endsWith(".qml")) {
58 if (path.startsWith(':'))
59 m_currentUrl = QUrl("qrc" + path);
60 else
61 m_currentUrl = QUrl::fromLocalFile(path);
62 emit load(m_currentUrl);
63 }
64 break;
65 }
66 case Directory: {
68 QStringList entries;
69 packet >> path >> entries;
70 emit directory(path, entries);
71 break;
72 }
73 case Load: {
74 QUrl url;
75 packet >> url;
76 if (url.isEmpty())
77 url = m_currentUrl;
78 else
79 m_currentUrl = url;
80 emit load(url);
81 break;
82 }
83 case Error: {
85 packet >> file;
87 break;
88 }
89 case Rerun:
90 emit rerun();
91 break;
92 case ClearCache:
94 break;
95 case Zoom: {
96 float factor;
97 packet >> factor;
98 emit zoom(static_cast<qreal>(factor));
99 break;
100 }
101 default:
102 forwardError(QString::fromLatin1("Invalid command: %1").arg(command));
103 break;
104 }
105}
106
108{
109 if (QQmlEngine *qmlEngine = qobject_cast<QQmlEngine *>(engine))
110 m_handler.addEngine(qmlEngine);
112}
113
120
122{
123 m_fileEngine.reset(state == Enabled ? new QQmlPreviewFileEngineHandler(m_loader.data())
124 : nullptr);
125}
126
128{
129 QQmlDebugPacket packet;
130 packet << static_cast<qint8>(Request) << file;
131 emit messageToClient(name(), packet.data());
132}
133
135{
136 QQmlDebugPacket packet;
137 packet << static_cast<qint8>(Error) << error;
138 emit messageToClient(name(), packet.data());
139}
140
142{
143 QQmlDebugPacket packet;
144 packet << static_cast<qint8>(Fps)
145 << frames.numSyncs << frames.minSync << frames.maxSync << frames.totalSync
146 << frames.numRenders << frames.minRender << frames.maxRender << frames.totalRender;
147 emit messageToClient(name(), packet.data());
148}
149
154
156
157#include "moc_qqmlpreviewservice.cpp"
\inmodule QtCore
Definition qbytearray.h:57
The QJSEngine class provides an environment for evaluating JavaScript code.
Definition qjsengine.h:26
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
const QByteArray & data() const
Returns a reference to the raw packet data.
Definition qpacket.cpp:77
void messageToClient(const QString &name, const QByteArray &message)
void detachedFromEngine(QJSEngine *)
const QString & name() const
void attachedToEngine(QJSEngine *)
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
void whitelist(const QUrl &url)
void zoom(qreal newFactor)
QQuickItem * currentRootItem()
void fps(const FpsInfo &info)
void removeEngine(QQmlEngine *engine)
void error(const QString &message)
void addEngine(QQmlEngine *engine)
void loadUrl(const QUrl &url)
void forwardRequest(const QString &file)
void engineAboutToBeRemoved(QJSEngine *engine) override
QQmlPreviewServiceImpl(QObject *parent=nullptr)
void engineAboutToBeAdded(QJSEngine *engine) override
void forwardFps(const QQmlPreviewHandler::FpsInfo &frames)
void zoom(qreal factor)
static const QString s_key
void load(const QUrl &url)
void stateChanged(State state) override
void forwardError(const QString &error)
void messageReceived(const QByteArray &message) override
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
T * data() const noexcept
Returns the value of the pointer referenced by this object.
void reset(T *other=nullptr) noexcept(noexcept(Cleanup::cleanup(std::declval< T * >())))
Deletes the existing object it is pointing to (if any), and sets its pointer to other.
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5871
\inmodule QtCore
Definition qurl.h:94
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition qurl.cpp:3368
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
Definition qurl.cpp:1896
else opt state
[0]
Combined button and popup list for selecting options.
@ DirectConnection
DBusConnection const char DBusError * error
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLsizei const GLchar *const * path
QQmlEngine * qmlEngine(const QObject *obj)
Definition qqml.cpp:80
SSL_CTX int void * arg
#define QStringLiteral(str)
#define emit
QT_BEGIN_NAMESPACE typedef signed char qint8
Definition qtypes.h:45
double qreal
Definition qtypes.h:187
QFile file
[0]
QUrl url("example.com")
[constructor-url-reference]
QJSEngine engine
[0]