2014-09-08 18:33:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2015-01-15 10:33:32 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd
|
2014-09-08 18:33:02 +02:00
|
|
|
** All rights reserved.
|
2015-01-15 10:33:32 +01:00
|
|
|
** For any questions to The Qt Company, please use contact form at http://www.qt.io/contact-us
|
2014-09-08 18:33:02 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of the Qt Enterprise Qt Quick Profiler Add-on.
|
|
|
|
|
**
|
|
|
|
|
** Licensees holding valid Qt Enterprise licenses may use this file in
|
|
|
|
|
** accordance with the Qt Enterprise License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-15 10:33:32 +01:00
|
|
|
** a written agreement between you and The Qt Company.
|
2014-09-08 18:33:02 +02:00
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please use
|
2015-01-15 10:33:32 +01:00
|
|
|
** contact form at http://www.qt.io/contact-us
|
2014-09-08 18:33:02 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "inputeventsmodel.h"
|
|
|
|
|
#include "qmldebug/qmlprofilereventtypes.h"
|
|
|
|
|
#include "qmlprofiler/qmlprofilermodelmanager.h"
|
|
|
|
|
|
2015-10-23 17:49:11 +02:00
|
|
|
#include <QKeyEvent>
|
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
#include <QMetaEnum>
|
|
|
|
|
|
2014-09-08 18:33:02 +02:00
|
|
|
namespace QmlProfilerExtension {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
using namespace QmlProfiler;
|
|
|
|
|
|
2014-10-29 10:31:28 +01:00
|
|
|
InputEventsModel::InputEventsModel(QmlProfilerModelManager *manager, QObject *parent) :
|
2015-06-30 16:39:58 +02:00
|
|
|
QmlProfilerTimelineModel(manager, QmlDebug::Event, QmlDebug::MaximumRangeType,
|
|
|
|
|
QmlDebug::ProfileInputEvents, parent),
|
|
|
|
|
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
|
|
|
{
|
2014-10-28 14:30:04 +01:00
|
|
|
return selectionId(index) == QmlDebug::Mouse ? m_mouseTypeId : m_keyTypeId;
|
2014-10-10 18:10:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QColor InputEventsModel::color(int index) const
|
|
|
|
|
{
|
|
|
|
|
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")));
|
|
|
|
|
element.insert(QLatin1String("id"), QVariant(QmlDebug::Mouse));
|
|
|
|
|
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")));
|
|
|
|
|
element.insert(QLatin1String("id"), QVariant(QmlDebug::Key));
|
|
|
|
|
result << element;
|
2014-10-10 18:10:15 +02:00
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap InputEventsModel::details(int index) const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap result;
|
2015-11-13 15:34:57 +01:00
|
|
|
result.insert(tr("Timestamp"), QmlProfilerDataModel::formatTime(startTime(index)));
|
2015-10-23 17:49:11 +02:00
|
|
|
QString type;
|
|
|
|
|
const InputEvent &event = m_data[index];
|
|
|
|
|
switch (event.type) {
|
|
|
|
|
case QmlDebug::InputKeyPress:
|
2015-11-13 15:34:57 +01:00
|
|
|
type = tr("Key Press");
|
2015-10-23 17:49:11 +02:00
|
|
|
case QmlDebug::InputKeyRelease:
|
|
|
|
|
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-13 15:34:57 +01:00
|
|
|
result.insert(tr("Key"), QLatin1String(
|
2015-10-23 17:49:11 +02:00
|
|
|
QMetaEnum::fromType<Qt::Key>().valueToKey(event.a)));
|
|
|
|
|
}
|
|
|
|
|
if (event.b != 0) {
|
2015-11-13 15:34:57 +01:00
|
|
|
result.insert(tr("Modifiers"), QLatin1String(
|
2015-10-23 17:49:11 +02:00
|
|
|
QMetaEnum::fromType<Qt::KeyboardModifiers>().valueToKeys(event.b)));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case QmlDebug::InputMouseDoubleClick:
|
2015-11-13 15:34:57 +01:00
|
|
|
type = tr("Double Click");
|
2015-10-23 17:49:11 +02:00
|
|
|
case QmlDebug::InputMousePress:
|
|
|
|
|
if (type.isEmpty())
|
2015-11-13 15:34:57 +01:00
|
|
|
type = tr("Mouse Press");
|
2015-10-23 17:49:11 +02:00
|
|
|
case QmlDebug::InputMouseRelease:
|
|
|
|
|
if (type.isEmpty())
|
2015-11-13 15:34:57 +01:00
|
|
|
type = tr("Mouse Release");
|
|
|
|
|
result.insert(tr("Button"), QLatin1String(
|
2015-10-23 17:49:11 +02:00
|
|
|
QMetaEnum::fromType<Qt::MouseButtons>().valueToKey(event.a)));
|
2015-11-13 15:34:57 +01:00
|
|
|
result.insert(tr("Result"), QLatin1String(
|
2015-10-23 17:49:11 +02:00
|
|
|
QMetaEnum::fromType<Qt::MouseButtons>().valueToKeys(event.b)));
|
|
|
|
|
break;
|
|
|
|
|
case QmlDebug::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;
|
|
|
|
|
case QmlDebug::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;
|
|
|
|
|
case QmlDebug::InputKeyUnknown:
|
2015-11-13 15:34:57 +01:00
|
|
|
type = tr("Keyboard Event");
|
2015-10-23 17:49:11 +02:00
|
|
|
break;
|
|
|
|
|
case QmlDebug::InputMouseUnknown:
|
2015-11-13 15:34:57 +01:00
|
|
|
type = tr("Mouse Event");
|
2015-10-23 17:49:11 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
return selectionId(index) == QmlDebug::Mouse ? 1 : 2;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-17 13:30:53 +01:00
|
|
|
int InputEventsModel::collapsedRow(int index) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(index)
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-10 18:10:15 +02:00
|
|
|
void InputEventsModel::loadData()
|
|
|
|
|
{
|
2014-10-27 19:54:23 +01:00
|
|
|
QmlProfilerDataModel *simpleModel = modelManager()->qmlModel();
|
2014-10-10 18:10:15 +02:00
|
|
|
if (simpleModel->isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const QVector<QmlProfilerDataModel::QmlEventTypeData> &types = simpleModel->getEventTypes();
|
|
|
|
|
foreach (const QmlProfilerDataModel::QmlEventData &event, simpleModel->getEvents()) {
|
|
|
|
|
const QmlProfilerDataModel::QmlEventTypeData &type = types[event.typeIndex];
|
|
|
|
|
if (!accepted(type))
|
|
|
|
|
continue;
|
2015-10-23 17:49:11 +02:00
|
|
|
|
|
|
|
|
m_data.insert(insert(event.startTime, 0, type.detailType),
|
|
|
|
|
InputEvent(static_cast<QmlDebug::InputEventType>(event.numericData1),
|
|
|
|
|
event.numericData2, event.numericData3));
|
|
|
|
|
|
2014-10-28 14:30:04 +01:00
|
|
|
if (type.detailType == QmlDebug::Mouse) {
|
|
|
|
|
if (m_mouseTypeId == -1)
|
|
|
|
|
m_mouseTypeId = event.typeIndex;
|
|
|
|
|
} else if (m_keyTypeId == -1) {
|
|
|
|
|
m_keyTypeId = event.typeIndex;
|
|
|
|
|
}
|
2014-10-27 19:54:23 +01:00
|
|
|
updateProgress(count(), simpleModel->getEvents().count());
|
2014-10-10 18:10:15 +02:00
|
|
|
}
|
2014-10-27 19:54:23 +01:00
|
|
|
setCollapsedRowCount(2);
|
|
|
|
|
setExpandedRowCount(3);
|
|
|
|
|
updateProgress(1, 1);
|
2014-10-10 18:10:15 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-28 14:30:04 +01:00
|
|
|
void InputEventsModel::clear()
|
|
|
|
|
{
|
|
|
|
|
m_keyTypeId = m_mouseTypeId = -1;
|
2014-10-29 10:31:28 +01:00
|
|
|
QmlProfilerTimelineModel::clear();
|
2014-10-28 14:30:04 +01:00
|
|
|
}
|
|
|
|
|
|
2014-10-10 18:10:15 +02:00
|
|
|
bool InputEventsModel::accepted(const QmlProfilerDataModel::QmlEventTypeData &event) const
|
|
|
|
|
{
|
2014-10-29 10:31:28 +01:00
|
|
|
return QmlProfilerTimelineModel::accepted(event) &&
|
2014-10-10 18:10:15 +02:00
|
|
|
(event.detailType == QmlDebug::Mouse || event.detailType == QmlDebug::Key);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-23 17:49:11 +02:00
|
|
|
InputEventsModel::InputEvent::InputEvent(QmlDebug::InputEventType type, int a, int b) :
|
|
|
|
|
type(type), a(a), b(b)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-08 18:33:02 +02:00
|
|
|
}
|
|
|
|
|
}
|