Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickeventreplayclient.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 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// Qt-Security score:significant
4
6
7#include <private/qpacket_p.h>
8#include <private/qqmldebugconnection_p.h>
9#include <private/qqmlprofilerdefinitions_p.h>
10
11#include <QtCore/qxmlstream.h>
12
14
15using namespace Qt::StringLiterals;
16
17QQuickEventReplayClient::QQuickEventReplayClient(QQmlDebugConnection *connection)
18 : QQmlDebugClient(QLatin1String("EventReplay"), connection)
19{
20}
21
23 int eventType = -1;
24 int detailType = -1;
25};
26
27bool QQuickEventReplayClient::sendEvents(const QString &fileName)
28{
29 QFile file(fileName);
30 if (!file.open(QIODevice::ReadOnly)) {
31 qWarning() << "Cannot open file" << fileName << "for reading";
32 return false;
33 }
34
35 int currentEventIndex = -1;
36
37 QHash<int, SendEventType> types;
38
39 QXmlStreamReader reader(&file);
40 while (!reader.atEnd()) {
41 if (reader.readNext() != QXmlStreamReader::StartElement)
42 continue;
43
44 const QStringView name = reader.name();
45 if (name == "event"_L1) {
46 currentEventIndex = reader.attributes().value("index"_L1).toInt();
47 } else if (name == "mouseEvent"_L1) {
48 types[currentEventIndex] = SendEventType {
49 QQmlProfilerDefinitions::EventType::Mouse,
50 reader.readElementText().toInt(),
51 };
52 } else if (name == "keyEvent"_L1) {
53 types[currentEventIndex] = SendEventType {
54 QQmlProfilerDefinitions::EventType::Key,
55 reader.readElementText().toInt(),
56 };
57 } else if (name == "range"_L1) {
58 const QXmlStreamAttributes attributes = reader.attributes();
59 const int eventIndex = attributes.value("eventIndex"_L1).toInt();
60 const SendEventType &type = types[eventIndex];
61 if (type.eventType != -1) {
62 const qint64 startTime = attributes.value("startTime"_L1).toLongLong();
63 const int inputType = attributes.value("type"_L1).toInt();
64 const int data1 = attributes.value("data1"_L1).toInt();
65 const int data2 = attributes.value("data2"_L1).toInt();
66
67 QPacket stream(connection()->currentDataStreamVersion());
68 stream << startTime << QQmlProfilerDefinitions::Message::Event
69 << type.detailType << inputType << data1 << data2;
70 sendMessage(stream.data());
71 }
72 }
73 }
74
75 return true;
76}
77
79 const QQmlProfilerEventType &type, const QQmlProfilerEvent &event)
80{
81 QPacket stream(connection()->currentDataStreamVersion());
82 stream << event.timestamp() << QQmlProfilerDefinitions::Message::Event
83 << type.detailType() << event.number<quint32>(0) << event.number<quint32>(1)
84 << event.number<quint32>(2);
85 sendMessage(stream.data());
86}
87
88QT_END_NAMESPACE
QQmlDebugConnection * connection() const
void sendEvent(const QQmlProfilerEventType &type, const QQmlProfilerEvent &event)
bool sendEvents(const QString &fileName)
Combined button and popup list for selecting options.