2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2014-09-08 18:33:02 +02:00
|
|
|
|
|
|
|
|
#include "inputeventsmodel.h"
|
2016-04-26 10:21:00 +02:00
|
|
|
#include "qmlprofilermodelmanager.h"
|
2016-05-02 12:18:57 +02:00
|
|
|
#include "qmlprofilereventtypes.h"
|
2014-09-08 18:33:02 +02:00
|
|
|
|
2018-05-03 09:50:11 +02:00
|
|
|
#include <tracing/timelineformattime.h>
|
2016-09-16 16:10:19 +02:00
|
|
|
|
2015-10-23 17:49:11 +02:00
|
|
|
#include <QKeyEvent>
|
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
#include <QMetaEnum>
|
|
|
|
|
|
2016-04-26 10:21:00 +02:00
|
|
|
namespace QmlProfiler {
|
2014-09-08 18:33:02 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2018-03-28 15:40:13 +02:00
|
|
|
InputEventsModel::InputEventsModel(QmlProfilerModelManager *manager,
|
|
|
|
|
Timeline::TimelineModelAggregator *parent) :
|
2016-05-02 12:18:57 +02:00
|
|
|
QmlProfilerTimelineModel(manager, Event, MaximumRangeType, ProfileInputEvents, parent),
|
2015-06-30 16:39:58 +02:00
|
|
|
m_keyTypeId(-1), m_mouseTypeId(-1)
|
2014-09-08 18:33:02 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-28 14:30:04 +01:00
|
|
|
int InputEventsModel::typeId(int index) const
|
2014-10-10 18:10:15 +02:00
|
|
|
{
|
2016-05-02 12:18:57 +02:00
|
|
|
return selectionId(index) == Mouse ? m_mouseTypeId : m_keyTypeId;
|
2014-10-10 18:10:15 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-08 18:11:36 +01:00
|
|
|
QRgb InputEventsModel::color(int index) const
|
2014-10-10 18:10:15 +02:00
|
|
|
{
|
|
|
|
|
return colorBySelectionId(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantList InputEventsModel::labels() const
|
|
|
|
|
{
|
|
|
|
|
QVariantList result;
|
|
|
|
|
|
2014-10-29 10:42:22 +01:00
|
|
|
QVariantMap element;
|
|
|
|
|
element.insert(QLatin1String("description"), QVariant(tr("Mouse Events")));
|
2016-05-02 12:18:57 +02:00
|
|
|
element.insert(QLatin1String("id"), QVariant(Mouse));
|
2014-10-29 10:42:22 +01:00
|
|
|
result << element;
|
2014-10-10 18:10:15 +02:00
|
|
|
|
2014-10-29 10:42:22 +01:00
|
|
|
element.clear();
|
|
|
|
|
element.insert(QLatin1String("description"), QVariant(tr("Keyboard Events")));
|
2016-05-02 12:18:57 +02:00
|
|
|
element.insert(QLatin1String("id"), QVariant(Key));
|
2014-10-29 10:42:22 +01:00
|
|
|
result << element;
|
2014-10-10 18:10:15 +02:00
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-23 15:46:41 +01:00
|
|
|
QMetaEnum InputEventsModel::metaEnum(const char *name)
|
|
|
|
|
{
|
2022-07-17 13:43:49 +02:00
|
|
|
return Qt::staticMetaObject.enumerator(Qt::staticMetaObject.indexOfEnumerator(name));
|
2015-11-23 15:46:41 +01:00
|
|
|
}
|
|
|
|
|
|
2014-10-10 18:10:15 +02:00
|
|
|
QVariantMap InputEventsModel::details(int index) const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap result;
|
2017-01-02 19:15:17 +01:00
|
|
|
result.insert(tr("Timestamp"), Timeline::formatTime(startTime(index),
|
2018-03-28 08:57:46 +02:00
|
|
|
modelManager()->traceDuration()));
|
2015-10-23 17:49:11 +02:00
|
|
|
QString type;
|
2018-05-09 09:27:07 +02:00
|
|
|
const Item &event = m_data[index];
|
2015-10-23 17:49:11 +02:00
|
|
|
switch (event.type) {
|
2016-05-02 12:18:57 +02:00
|
|
|
case InputKeyPress:
|
2015-11-13 15:34:57 +01:00
|
|
|
type = tr("Key Press");
|
2018-01-10 16:51:58 +01:00
|
|
|
Q_FALLTHROUGH();
|
2016-05-02 12:18:57 +02:00
|
|
|
case InputKeyRelease:
|
2015-10-23 17:49:11 +02:00
|
|
|
if (type.isEmpty())
|
2015-11-13 15:34:57 +01:00
|
|
|
type = tr("Key Release");
|
2015-10-23 17:49:11 +02:00
|
|
|
if (event.a != 0) {
|
2015-11-23 15:46:41 +01:00
|
|
|
result.insert(tr("Key"), QLatin1String(metaEnum("Key").valueToKey(event.a)));
|
2015-10-23 17:49:11 +02:00
|
|
|
}
|
|
|
|
|
if (event.b != 0) {
|
2015-11-23 15:46:41 +01:00
|
|
|
result.insert(tr("Modifiers"),
|
|
|
|
|
QLatin1String(metaEnum("KeyboardModifiers").valueToKeys(event.b)));
|
2015-10-23 17:49:11 +02:00
|
|
|
}
|
|
|
|
|
break;
|
2016-05-02 12:18:57 +02:00
|
|
|
case InputMouseDoubleClick:
|
2015-11-13 15:34:57 +01:00
|
|
|
type = tr("Double Click");
|
2018-01-10 16:51:58 +01:00
|
|
|
Q_FALLTHROUGH();
|
2016-05-02 12:18:57 +02:00
|
|
|
case InputMousePress:
|
2015-10-23 17:49:11 +02:00
|
|
|
if (type.isEmpty())
|
2015-11-13 15:34:57 +01:00
|
|
|
type = tr("Mouse Press");
|
2018-01-10 16:51:58 +01:00
|
|
|
Q_FALLTHROUGH();
|
2016-05-02 12:18:57 +02:00
|
|
|
case InputMouseRelease:
|
2015-10-23 17:49:11 +02:00
|
|
|
if (type.isEmpty())
|
2015-11-13 15:34:57 +01:00
|
|
|
type = tr("Mouse Release");
|
2015-11-23 15:46:41 +01:00
|
|
|
result.insert(tr("Button"), QLatin1String(metaEnum("MouseButtons").valueToKey(event.a)));
|
|
|
|
|
result.insert(tr("Result"), QLatin1String(metaEnum("MouseButtons").valueToKeys(event.b)));
|
2015-10-23 17:49:11 +02:00
|
|
|
break;
|
2016-05-02 12:18:57 +02:00
|
|
|
case InputMouseMove:
|
2015-11-13 15:34:57 +01:00
|
|
|
type = tr("Mouse Move");
|
|
|
|
|
result.insert(tr("X"), QString::number(event.a));
|
|
|
|
|
result.insert(tr("Y"), QString::number(event.b));
|
2015-10-23 17:49:11 +02:00
|
|
|
break;
|
2016-05-02 12:18:57 +02:00
|
|
|
case InputMouseWheel:
|
2015-11-13 15:34:57 +01:00
|
|
|
type = tr("Mouse Wheel");
|
|
|
|
|
result.insert(tr("Angle X"), QString::number(event.a));
|
|
|
|
|
result.insert(tr("Angle Y"), QString::number(event.b));
|
2015-10-23 17:49:11 +02:00
|
|
|
break;
|
2016-05-02 12:18:57 +02:00
|
|
|
case InputKeyUnknown:
|
2015-11-13 15:34:57 +01:00
|
|
|
type = tr("Keyboard Event");
|
2015-10-23 17:49:11 +02:00
|
|
|
break;
|
2016-05-02 12:18:57 +02:00
|
|
|
case InputMouseUnknown:
|
2015-11-13 15:34:57 +01:00
|
|
|
type = tr("Mouse Event");
|
2015-10-23 17:49:11 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
2017-09-08 17:18:39 +02:00
|
|
|
type = tr("Unknown");
|
2015-10-23 17:49:11 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.insert(QLatin1String("displayName"), type);
|
|
|
|
|
|
2014-10-10 18:10:15 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-17 13:30:53 +01:00
|
|
|
int InputEventsModel::expandedRow(int index) const
|
2014-10-10 18:10:15 +02:00
|
|
|
{
|
2016-05-02 12:18:57 +02:00
|
|
|
return selectionId(index) == Mouse ? 1 : 2;
|
2014-10-10 18:10:15 +02:00
|
|
|
}
|
|
|
|
|
|
2014-11-17 13:30:53 +01:00
|
|
|
int InputEventsModel::collapsedRow(int index) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(index)
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-26 13:23:35 +02:00
|
|
|
void InputEventsModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
|
2014-10-10 18:10:15 +02:00
|
|
|
{
|
2016-06-06 19:51:55 +02:00
|
|
|
m_data.insert(insert(event.timestamp(), 0, type.detailType()),
|
2018-05-09 09:27:07 +02:00
|
|
|
Item(static_cast<InputEventType>(event.number<qint32>(0)),
|
2016-04-26 13:23:35 +02:00
|
|
|
event.number<qint32>(1), event.number<qint32>(2)));
|
|
|
|
|
|
2016-06-06 19:51:55 +02:00
|
|
|
if (type.detailType() == Mouse) {
|
2016-04-26 13:23:35 +02:00
|
|
|
if (m_mouseTypeId == -1)
|
|
|
|
|
m_mouseTypeId = event.typeIndex();
|
|
|
|
|
} else if (m_keyTypeId == -1) {
|
|
|
|
|
m_keyTypeId = event.typeIndex();
|
2014-10-10 18:10:15 +02:00
|
|
|
}
|
2016-04-26 13:23:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InputEventsModel::finalize()
|
|
|
|
|
{
|
2014-10-27 19:54:23 +01:00
|
|
|
setCollapsedRowCount(2);
|
|
|
|
|
setExpandedRowCount(3);
|
2018-04-05 09:47:33 +02:00
|
|
|
QmlProfilerTimelineModel::finalize();
|
2014-10-10 18:10:15 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-28 14:30:04 +01:00
|
|
|
void InputEventsModel::clear()
|
|
|
|
|
{
|
|
|
|
|
m_keyTypeId = m_mouseTypeId = -1;
|
2015-11-17 09:32:38 +01:00
|
|
|
m_data.clear();
|
2014-10-29 10:31:28 +01:00
|
|
|
QmlProfilerTimelineModel::clear();
|
2014-10-28 14:30:04 +01:00
|
|
|
}
|
|
|
|
|
|
2018-05-09 09:27:07 +02:00
|
|
|
InputEventsModel::Item::Item(InputEventType type, int a, int b) :
|
2015-10-23 17:49:11 +02:00
|
|
|
type(type), a(a), b(b)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-26 10:21:00 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlProfiler
|