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 | |
5 | #include "qqmlpreviewclient_p_p.h" |
6 | #include <private/qpacket_p.h> |
7 | |
8 | #include <QtCore/qurl.h> |
9 | #include <QtCore/qfile.h> |
10 | #include <QtCore/qfileinfo.h> |
11 | #include <QtCore/qdir.h> |
12 | #include <QtQml/qqmlfile.h> |
13 | |
14 | QT_BEGIN_NAMESPACE |
15 | |
16 | QQmlPreviewClient::QQmlPreviewClient(QQmlDebugConnection *connection) |
17 | : QQmlDebugClient(*(new QQmlPreviewClientPrivate(connection))) |
18 | { |
19 | } |
20 | |
21 | void QQmlPreviewClient::messageReceived(const QByteArray &message) |
22 | { |
23 | QPacket packet(connection()->currentDataStreamVersion(), message); |
24 | |
25 | qint8 command; |
26 | packet >> command; |
27 | |
28 | switch (command) { |
29 | case Error: { |
30 | QString seviceError; |
31 | packet >> seviceError; |
32 | emit error(message: seviceError); |
33 | break; |
34 | } |
35 | case Request: { |
36 | QString fileName; |
37 | packet >> fileName; |
38 | emit request(path: fileName); |
39 | break; |
40 | } |
41 | case Fps: { |
42 | FpsInfo info; |
43 | packet >> info.numSyncs >> info.minSync >> info.maxSync >> info.totalSync |
44 | >> info.numRenders >> info.minRender >> info.maxRender >> info.totalRender; |
45 | emit fps(info); |
46 | break; |
47 | } |
48 | default: |
49 | emit error(message: QString::fromLatin1(ba: "Unknown command received: %1").arg(a: command)); |
50 | break; |
51 | } |
52 | } |
53 | |
54 | void QQmlPreviewClient::sendDirectory(const QString &path, const QStringList &entries) |
55 | { |
56 | QPacket packet(connection()->currentDataStreamVersion()); |
57 | packet << static_cast<qint8>(Directory) << path << entries; |
58 | sendMessage(message: packet.data()); |
59 | } |
60 | |
61 | void QQmlPreviewClient::sendFile(const QString &path, const QByteArray &contents) |
62 | { |
63 | QPacket packet(connection()->currentDataStreamVersion()); |
64 | packet << static_cast<qint8>(File) << path << contents; |
65 | sendMessage(message: packet.data()); |
66 | } |
67 | |
68 | void QQmlPreviewClient::sendError(const QString &path) |
69 | { |
70 | QPacket packet(connection()->currentDataStreamVersion()); |
71 | packet << static_cast<qint8>(Error) << path; |
72 | sendMessage(message: packet.data()); |
73 | } |
74 | |
75 | void QQmlPreviewClient::triggerLoad(const QUrl &url) |
76 | { |
77 | QPacket packet(connection()->currentDataStreamVersion()); |
78 | packet << static_cast<qint8>(Load) << url; |
79 | sendMessage(message: packet.data()); |
80 | } |
81 | |
82 | void QQmlPreviewClient::triggerRerun() |
83 | { |
84 | QPacket packet(connection()->currentDataStreamVersion()); |
85 | packet << static_cast<qint8>(Rerun); |
86 | sendMessage(message: packet.data()); |
87 | } |
88 | |
89 | void QQmlPreviewClient::triggerZoom(float factor) |
90 | { |
91 | QPacket packet(connection()->currentDataStreamVersion()); |
92 | packet << static_cast<qint8>(Zoom) << factor; |
93 | sendMessage(message: packet.data()); |
94 | } |
95 | |
96 | QT_END_NAMESPACE |
97 | |
98 | #include "moc_qqmlpreviewclient_p.cpp" |
99 |