2014-09-08 18:33:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-14 11:03:04 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-09-08 18:33:02 +02:00
|
|
|
**
|
2016-01-14 11:03:04 +01:00
|
|
|
** This file is part of Qt Creator.
|
2014-09-08 18:33:02 +02:00
|
|
|
**
|
2016-01-14 11:03:04 +01:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
2014-09-08 18:33:02 +02:00
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-14 11:03:04 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2014-09-08 18:33:02 +02:00
|
|
|
**
|
2016-01-14 11:03:04 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2014-09-08 18:33:02 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "inputeventsmodel.h"
|
2016-04-26 10:21:00 +02:00
|
|
|
#include "qmlprofilermodelmanager.h"
|
2014-09-08 18:33:02 +02:00
|
|
|
#include "qmldebug/qmlprofilereventtypes.h"
|
|
|
|
|
|
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 {
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-23 15:46:41 +01:00
|
|
|
QMetaEnum InputEventsModel::metaEnum(const char *name)
|
|
|
|
|
{
|
|
|
|
|
return staticQtMetaObject.enumerator(staticQtMetaObject.indexOfEnumerator(name));
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-10 18:10:15 +02:00
|
|
|
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-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;
|
|
|
|
|
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");
|
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;
|
|
|
|
|
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()) {
|
2015-11-13 15:38:56 +01:00
|
|
|
const QmlProfilerDataModel::QmlEventTypeData &type = types[event.typeIndex()];
|
2014-10-10 18:10:15 +02:00
|
|
|
if (!accepted(type))
|
|
|
|
|
continue;
|
2015-10-23 17:49:11 +02:00
|
|
|
|
2015-11-13 15:38:56 +01:00
|
|
|
m_data.insert(insert(event.startTime(), 0, type.detailType),
|
|
|
|
|
InputEvent(static_cast<QmlDebug::InputEventType>(event.numericData(0)),
|
|
|
|
|
event.numericData(1), event.numericData(2)));
|
2015-10-23 17:49:11 +02:00
|
|
|
|
2014-10-28 14:30:04 +01:00
|
|
|
if (type.detailType == QmlDebug::Mouse) {
|
|
|
|
|
if (m_mouseTypeId == -1)
|
2015-11-13 15:38:56 +01:00
|
|
|
m_mouseTypeId = event.typeIndex();
|
2014-10-28 14:30:04 +01:00
|
|
|
} else if (m_keyTypeId == -1) {
|
2015-11-13 15:38:56 +01:00
|
|
|
m_keyTypeId = event.typeIndex();
|
2014-10-28 14:30:04 +01:00
|
|
|
}
|
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;
|
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
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-26 10:21:00 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlProfiler
|