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"
|
2016-05-02 12:18:57 +02:00
|
|
|
#include "qmlprofilereventtypes.h"
|
2014-09-08 18:33:02 +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 {
|
|
|
|
|
|
2014-10-29 10:31:28 +01:00
|
|
|
InputEventsModel::InputEventsModel(QmlProfilerModelManager *manager, QObject *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)
|
|
|
|
|
{
|
|
|
|
|
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) {
|
2016-05-02 12:18:57 +02:00
|
|
|
case InputKeyPress:
|
2015-11-13 15:34:57 +01:00
|
|
|
type = tr("Key Press");
|
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");
|
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");
|
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:
|
|
|
|
|
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
|
|
|
{
|
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()),
|
2016-04-26 13:23:35 +02:00
|
|
|
InputEvent(static_cast<InputEventType>(event.number<qint32>(0)),
|
|
|
|
|
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);
|
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
|
|
|
}
|
|
|
|
|
|
2016-06-02 14:56:32 +02:00
|
|
|
bool InputEventsModel::accepted(const QmlEventType &type) const
|
2014-10-10 18:10:15 +02:00
|
|
|
{
|
2016-06-02 14:56:32 +02:00
|
|
|
return QmlProfilerTimelineModel::accepted(type) &&
|
2016-06-06 19:51:55 +02:00
|
|
|
(type.detailType() == Mouse || type.detailType() == Key);
|
2014-10-10 18:10:15 +02:00
|
|
|
}
|
|
|
|
|
|
2016-05-02 12:18:57 +02:00
|
|
|
InputEventsModel::InputEvent::InputEvent(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
|