Commit 10d942e2 authored by Ulf Hermann's avatar Ulf Hermann Committed by Ulf Hermann
Browse files

QmlProfiler: Split AbstractTimelineModel in two classes



We need a general purpose TimelineModel and a specialized
QmlProfilerTimelineModel.

Change-Id: I2da02d65efa11e160cab5fa9f8a21075beb0e2bf
Reviewed-by: default avatarKai Koehne <kai.koehne@theqtcompany.com>
parent af84726c
......@@ -5,7 +5,6 @@ QT += network qml quick
include(../../qtcreatorplugin.pri)
SOURCES += \
abstracttimelinemodel.cpp \
localqmlprofilerrunner.cpp \
qmlprofileranimationsmodel.cpp \
qmlprofilerattachdialog.cpp \
......@@ -23,6 +22,7 @@ SOURCES += \
qmlprofilerruncontrolfactory.cpp \
qmlprofilerstatemanager.cpp \
qmlprofilerstatewidget.cpp \
qmlprofilertimelinemodel.cpp \
qmlprofilertimelinemodelfactory.cpp \
qmlprofilertool.cpp \
qmlprofilertracefile.cpp \
......@@ -31,14 +31,13 @@ SOURCES += \
qmlprofilerviewmanager.cpp \
qv8profilerdatamodel.cpp \
qv8profilereventview.cpp \
timelinemodel.cpp \
timelinemodelaggregator.cpp \
timelinerenderer.cpp \
timelinezoomcontrol.cpp
HEADERS += \
abstractqmlprofilerrunner.h \
abstracttimelinemodel.h \
abstracttimelinemodel_p.h \
localqmlprofilerrunner.h \
qmlprofiler_global.h \
qmlprofileranimationsmodel.h \
......@@ -59,6 +58,7 @@ HEADERS += \
qmlprofilerruncontrolfactory.h \
qmlprofilerstatemanager.h \
qmlprofilerstatewidget.h \
qmlprofilertimelinemodel.h \
qmlprofilertimelinemodelfactory.h \
qmlprofilertool.h \
qmlprofilertracefile.h \
......@@ -67,6 +67,8 @@ HEADERS += \
qmlprofilerviewmanager.h \
qv8profilerdatamodel.h \
qv8profilereventview.h \
timelinemodel.h \
timelinemodel_p.h \
timelinemodelaggregator.h \
timelinerenderer.h \
timelinezoomcontrol.h
......
......@@ -21,7 +21,6 @@ QtcPlugin {
name: "General"
files: [
"abstractqmlprofilerrunner.h",
"abstracttimelinemodel.h", "abstracttimelinemodel_p.h", "abstracttimelinemodel.cpp",
"localqmlprofilerrunner.cpp", "localqmlprofilerrunner.h",
"qmlprofiler_global.h",
"qmlprofileranimationsmodel.h", "qmlprofileranimationsmodel.cpp",
......@@ -41,6 +40,7 @@ QtcPlugin {
"qmlprofilerstatemanager.cpp", "qmlprofilerstatemanager.h",
"qmlprofilerstatewidget.cpp", "qmlprofilerstatewidget.h",
"qmlprofilerrangemodel.cpp", "qmlprofilerrangemodel.h",
"qmlprofilertimelinemodel.cpp", "qmlprofilertimelinemodel.h",
"qmlprofilertimelinemodelfactory.cpp", "qmlprofilertimelinemodelfactory.h",
"qmlprofilertool.cpp", "qmlprofilertool.h",
"qmlprofilertracefile.cpp", "qmlprofilertracefile.h",
......@@ -49,6 +49,7 @@ QtcPlugin {
"qmlprofilerviewmanager.cpp", "qmlprofilerviewmanager.h",
"qv8profilerdatamodel.cpp", "qv8profilerdatamodel.h",
"qv8profilereventview.h", "qv8profilereventview.cpp",
"timelinemodel.cpp", "timelinemodel.h", "timelinemodel_p.h",
"timelinemodelaggregator.cpp", "timelinemodelaggregator.h",
"timelinerenderer.cpp", "timelinerenderer.h",
"timelinezoomcontrol.cpp", "timelinezoomcontrol.h"
......
......@@ -31,7 +31,6 @@
#include "qmlprofileranimationsmodel.h"
#include "qmlprofilermodelmanager.h"
#include "qmlprofilerdatamodel.h"
#include "abstracttimelinemodel_p.h"
#include <utils/qtcassert.h>
#include <QCoreApplication>
......@@ -47,8 +46,8 @@ namespace QmlProfiler {
namespace Internal {
QmlProfilerAnimationsModel::QmlProfilerAnimationsModel(QmlProfilerModelManager *manager,
QObject *parent)
: AbstractTimelineModel(manager,
QObject *parent) :
QmlProfilerTimelineModel(manager,
tr(QmlProfilerModelManager::featureName(QmlDebug::ProfileAnimations)),
QmlDebug::Event, QmlDebug::MaximumRangeType, parent)
{
......@@ -60,12 +59,12 @@ void QmlProfilerAnimationsModel::clear()
{
m_maxGuiThreadAnimations = m_maxRenderThreadAnimations = 0;
m_data.clear();
AbstractTimelineModel::clear();
QmlProfilerTimelineModel::clear();
}
bool QmlProfilerAnimationsModel::accepted(const QmlProfilerDataModel::QmlEventTypeData &event) const
{
return AbstractTimelineModel::accepted(event) &&
return QmlProfilerTimelineModel::accepted(event) &&
event.detailType== QmlDebug::AnimationFrame;
}
......@@ -149,7 +148,7 @@ int QmlProfilerAnimationsModel::rowMaxValue(int rowNumber) const
case 2:
return m_maxRenderThreadAnimations;
default:
return AbstractTimelineModel::rowMaxValue(rowNumber);
return QmlProfilerTimelineModel::rowMaxValue(rowNumber);
}
}
......
......@@ -33,7 +33,7 @@
#define QMLPROFILERANIMATIONSMODEL_H
#include <QObject>
#include "abstracttimelinemodel.h"
#include "qmlprofilertimelinemodel.h"
#include <qmldebug/qmlprofilereventtypes.h>
#include <qmldebug/qmlprofilereventlocation.h>
//#include <QHash>
......@@ -49,7 +49,7 @@ class QmlProfilerModelManager;
namespace Internal {
class QmlProfilerAnimationsModel : public AbstractTimelineModel
class QmlProfilerAnimationsModel : public QmlProfilerTimelineModel
{
Q_OBJECT
public:
......
......@@ -47,9 +47,9 @@ void QmlProfilerNotesModel::setModelManager(QmlProfilerModelManager *modelManage
m_modelManager = modelManager;
}
void QmlProfilerNotesModel::addTimelineModel(const AbstractTimelineModel *timelineModel)
void QmlProfilerNotesModel::addTimelineModel(const QmlProfilerTimelineModel *timelineModel)
{
connect(timelineModel, &AbstractTimelineModel::destroyed,
connect(timelineModel, &QmlProfilerTimelineModel::destroyed,
this, &QmlProfilerNotesModel::removeTimelineModel);
m_timelineModels.insert(timelineModel->modelId(), timelineModel);
}
......@@ -111,7 +111,7 @@ int QmlProfilerNotesModel::get(int timelineModel, int timelineIndex) const
int QmlProfilerNotesModel::add(int timelineModel, int timelineIndex, const QString &text)
{
const AbstractTimelineModel *model = m_timelineModels[timelineModel];
const QmlProfilerTimelineModel *model = m_timelineModels[timelineModel];
int typeId = model->typeId(timelineIndex);
Note note = { text, timelineModel, timelineIndex };
m_data << note;
......@@ -162,7 +162,7 @@ int QmlProfilerNotesModel::add(int typeId, qint64 start, qint64 duration, const
int timelineIndex = -1;
const QVector<QmlProfilerDataModel::QmlEventTypeData> &types =
m_modelManager->qmlModel()->getEventTypes();
foreach (const AbstractTimelineModel *model, m_timelineModels) {
foreach (const QmlProfilerTimelineModel *model, m_timelineModels) {
if (model->accepted(types[typeId])) {
for (int i = model->firstIndex(start); i <= model->lastIndex(start + duration); ++i) {
if (i < 0)
......@@ -237,7 +237,7 @@ void QmlProfilerNotesModel::saveData()
if (it == m_timelineModels.end())
continue;
const AbstractTimelineModel *model = it.value();
const QmlProfilerTimelineModel *model = it.value();
QmlProfilerDataModel::QmlEventNoteData save = {
model->typeId(note.timelineIndex), model->startTime(note.timelineIndex),
model->duration(note.timelineIndex), note.text
......
......@@ -31,7 +31,7 @@
#ifndef NOTESMODEL_H
#define NOTESMODEL_H
#include "abstracttimelinemodel.h"
#include "qmlprofilertimelinemodel.h"
#include "qmlprofilermodelmanager.h"
#include <QList>
#include <QHash>
......@@ -54,7 +54,7 @@ public:
int count() const;
void setModelManager(QmlProfilerModelManager *modelManager);
void addTimelineModel(const AbstractTimelineModel *timelineModel);
void addTimelineModel(const QmlProfilerTimelineModel *timelineModel);
Q_INVOKABLE int typeId(int index) const;
Q_INVOKABLE QString text(int index) const;
......@@ -86,7 +86,7 @@ private slots:
protected:
QmlProfilerModelManager *m_modelManager;
QList<Note> m_data;
QHash<int, const AbstractTimelineModel *> m_timelineModels;
QHash<int, const QmlProfilerTimelineModel *> m_timelineModels;
bool m_modified;
int add(int typeId, qint64 startTime, qint64 duration, const QString &text);
......
......@@ -32,7 +32,7 @@
#include "qmlprofilerruncontrolfactory.h"
#include "qmlprofilertool.h"
#include "abstracttimelinemodel.h"
#include "qmlprofilertimelinemodel.h"
#include <analyzerbase/analyzermanager.h>
#include <extensionsystem/pluginmanager.h>
......@@ -103,7 +103,7 @@ ExtensionSystem::IPlugin::ShutdownFlag QmlProfilerPlugin::aboutToShutdown()
return SynchronousShutdown;
}
QList<AbstractTimelineModel *> QmlProfilerPlugin::getModels(QmlProfilerModelManager *manager) const
QList<QmlProfilerTimelineModel *> QmlProfilerPlugin::getModels(QmlProfilerModelManager *manager) const
{
return factory->create(manager);
}
......
......@@ -35,7 +35,7 @@
#include "qmlprofilertimelinemodelfactory.h"
#include <extensionsystem/iplugin.h>
#include "abstracttimelinemodel.h"
#include "qmlprofilertimelinemodel.h"
namespace QmlProfiler {
namespace Internal {
......@@ -55,7 +55,7 @@ public:
static bool debugOutput;
static QmlProfilerPlugin *instance;
QList<AbstractTimelineModel *> getModels(QmlProfilerModelManager *manager) const;
QList<QmlProfilerTimelineModel *> getModels(QmlProfilerModelManager *manager) const;
private:
QmlProfilerTimelineModelFactory *factory;
......
......@@ -46,8 +46,8 @@ namespace Internal {
QmlProfilerRangeModel::QmlProfilerRangeModel(QmlProfilerModelManager *manager,
QmlDebug::RangeType range, QObject *parent)
: AbstractTimelineModel(manager, categoryLabel(range), QmlDebug::MaximumMessage, range, parent)
QmlDebug::RangeType range, QObject *parent) :
QmlProfilerTimelineModel(manager, categoryLabel(range), QmlDebug::MaximumMessage, range, parent)
{
m_expandedRowTypes << -1;
announceFeatures(1ULL << QmlDebug::featureFromRangeType(rangeType()));
......@@ -58,7 +58,7 @@ void QmlProfilerRangeModel::clear()
m_expandedRowTypes.clear();
m_expandedRowTypes << -1;
m_data.clear();
AbstractTimelineModel::clear();
QmlProfilerTimelineModel::clear();
}
void QmlProfilerRangeModel::loadData()
......
......@@ -32,7 +32,7 @@
#ifndef QMLPROFILERRANGEMODEL_H
#define QMLPROFILERRANGEMODEL_H
#include "abstracttimelinemodel.h"
#include "qmlprofilertimelinemodel.h"
#include <qmldebug/qmlprofilereventtypes.h>
#include <qmldebug/qmlprofilereventlocation.h>
#include <QVariantList>
......@@ -44,7 +44,7 @@ class QmlProfilerModelManager;
namespace Internal {
class QmlProfilerRangeModel : public AbstractTimelineModel
class QmlProfilerRangeModel : public QmlProfilerTimelineModel
{
Q_OBJECT
public:
......
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://www.qt.io/licensing. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "qmlprofilertimelinemodel.h"
namespace QmlProfiler {
QmlProfilerTimelineModel::QmlProfilerTimelineModel(QmlProfilerModelManager *modelManager,
const QString &displayName,
QmlDebug::Message message,
QmlDebug::RangeType rangeType, QObject *parent) :
TimelineModel(modelManager->registerModelProxy(), displayName, parent), m_message(message),
m_rangeType(rangeType), m_modelManager(modelManager)
{
connect(modelManager->qmlModel(), &QmlProfilerDataModel::changed,
this, &QmlProfilerTimelineModel::dataChanged);
}
QmlDebug::RangeType QmlProfilerTimelineModel::rangeType() const
{
return m_rangeType;
}
QmlDebug::Message QmlProfilerTimelineModel::message() const
{
return m_message;
}
bool QmlProfilerTimelineModel::accepted(const QmlProfilerDataModel::QmlEventTypeData &event) const
{
return (event.rangeType == m_rangeType && event.message == m_message);
}
bool QmlProfilerTimelineModel::handlesTypeId(int typeIndex) const
{
if (typeIndex < 0)
return false;
return accepted(modelManager()->qmlModel()->getEventTypes().at(typeIndex));
}
void QmlProfilerTimelineModel::clear()
{
TimelineModel::clear();
updateProgress(0, 1);
}
QmlProfilerModelManager *QmlProfilerTimelineModel::modelManager() const
{
return m_modelManager;
}
void QmlProfilerTimelineModel::updateProgress(qint64 count, qint64 max) const
{
m_modelManager->modelProxyCountUpdated(modelId(), count, max);
}
void QmlProfilerTimelineModel::announceFeatures(quint64 features) const
{
m_modelManager->announceFeatures(modelId(), features);
}
void QmlProfilerTimelineModel::dataChanged()
{
switch (m_modelManager->state()) {
case QmlProfilerDataState::ProcessingData:
loadData();
emit emptyChanged();
break;
case QmlProfilerDataState::ClearingData:
clear();
break;
default:
break;
}
}
int QmlProfilerTimelineModel::bindingLoopDest(int index) const
{
Q_UNUSED(index);
return -1;
}
}
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://www.qt.io/licensing. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef QMLPROFILERTIMELINEMODEL_H
#define QMLPROFILERTIMELINEMODEL_H
#include "timelinemodel.h"
namespace QmlProfiler {
class QMLPROFILER_EXPORT QmlProfilerTimelineModel : public TimelineModel {
Q_OBJECT
Q_PROPERTY(QmlDebug::RangeType rangeType READ rangeType CONSTANT)
Q_PROPERTY(QmlDebug::Message message READ message CONSTANT)
Q_PROPERTY(QmlProfilerModelManager *modelManager READ modelManager CONSTANT)
public:
QmlProfilerTimelineModel(QmlProfilerModelManager *modelManager, const QString &displayName,
QmlDebug::Message message, QmlDebug::RangeType rangeType,
QObject *parent);
QmlProfilerModelManager *modelManager() const;
QmlDebug::RangeType rangeType() const;
QmlDebug::Message message() const;
virtual bool accepted(const QmlProfilerDataModel::QmlEventTypeData &event) const;
bool handlesTypeId(int typeId) const;
Q_INVOKABLE virtual int bindingLoopDest(int index) const;
virtual void loadData() = 0;
void clear();
private slots:
void dataChanged();
protected:
void updateProgress(qint64 count, qint64 max) const;
void announceFeatures(quint64 features) const;
private:
const QmlDebug::Message m_message;
const QmlDebug::RangeType m_rangeType;
QmlProfilerModelManager *const m_modelManager;
};
}
#endif // QMLPROFILERTIMELINEMODEL_H
......@@ -31,7 +31,7 @@
#ifndef QMLPROFILERTIMELINEMODELFACTORY_H
#define QMLPROFILERTIMELINEMODELFACTORY_H
#include "abstracttimelinemodel.h"
#include "qmlprofilertimelinemodel.h"
#include "qmlprofilermodelmanager.h"
namespace QmlProfiler {
......@@ -40,7 +40,7 @@ class QMLPROFILER_EXPORT QmlProfilerTimelineModelFactory : public QObject
{
Q_OBJECT
public:
virtual QList<AbstractTimelineModel *> create(QmlProfilerModelManager *manager) = 0;
virtual QList<QmlProfilerTimelineModel *> create(QmlProfilerModelManager *manager) = 0;
};
}
......
......@@ -28,8 +28,8 @@
**
****************************************************************************/
#ifndef ABSTRACTTIMELINEMODEL_H
#define ABSTRACTTIMELINEMODEL_H
#ifndef TIMELINEMODEL_H
#define TIMELINEMODEL_H
#include "qmlprofiler_global.h"
......@@ -40,30 +40,24 @@
namespace QmlProfiler {
class QMLPROFILER_EXPORT AbstractTimelineModel : public QObject
class QMLPROFILER_EXPORT TimelineModel : public QObject
{
Q_OBJECT
Q_PROPERTY(int modelId READ modelId CONSTANT)
Q_PROPERTY(QString displayName READ displayName CONSTANT)
Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged)
Q_PROPERTY(bool hidden READ hidden WRITE setHidden NOTIFY hiddenChanged)
Q_PROPERTY(int height READ height NOTIFY heightChanged)
Q_PROPERTY(QmlProfilerModelManager *modelManager READ modelManager)
public:
class AbstractTimelineModelPrivate;
class TimelineModelPrivate;
AbstractTimelineModel(QmlProfilerModelManager *manager, const QString &displayName,
QmlDebug::Message message, QmlDebug::RangeType rangeType,
QObject *parent);
~AbstractTimelineModel();
// Trivial methods implemented by the abstract model itself
QmlProfilerModelManager *modelManager() const;
TimelineModel(int modelId, const QString &displayName, QObject *parent);
~TimelineModel();
// Methods implemented by the abstract model itself
bool isEmpty() const;
int modelId() const;
// Methods are directly passed on to the private model and relying on its virtual methods.
int rowHeight(int rowNumber) const;
int rowOffset(int rowNumber) const;
void setRowHeight(int rowNumber, int height);
......@@ -96,9 +90,7 @@ public:
virtual QVariantMap location(int index) const;
virtual int typeId(int index) const;
virtual bool handlesTypeId(int typeId) const;
virtual bool accepted(const QmlProfilerDataModel::QmlEventTypeData &event) const;
virtual int selectionIdForLocation(const QString &filename, int line, int column) const;
virtual int bindingLoopDest(int index) const;
virtual float relativeHeight(int index) const;
virtual int rowMinValue(int rowNumber) const;
virtual int rowMaxValue(int rowNumber) const;
......@@ -128,26 +120,15 @@ protected:
int expandedRowCount() const;
void setExpandedRowCount(int rows);
QmlDebug::RangeType rangeType() const;
QmlDebug::Message message() const;
void updateProgress(qint64 count, qint64 max) const;
void announceFeatures(quint64 features) const;
explicit AbstractTimelineModel(AbstractTimelineModelPrivate *dd,
QmlProfilerModelManager *manager, const QString &displayName,
QmlDebug::Message message, QmlDebug::RangeType rangeType,
QObject *parent);
AbstractTimelineModelPrivate *d_ptr;
virtual void loadData() = 0;
virtual void clear();
explicit TimelineModel(TimelineModelPrivate &dd, QObject *parent);
TimelineModelPrivate *d_ptr;
private:
Q_DECLARE_PRIVATE(AbstractTimelineModel)
Q_PRIVATE_SLOT(d_func(), void _q_dataChanged())
Q_DECLARE_PRIVATE(TimelineModel)
};
}
#endif // ABSTRACTTIMELINEMODEL_H
#endif // TIMELINEMODEL_H
......@@ -28,14 +28,14 @@
**
****************************************************************************/
#ifndef ABSTRACTTIMELINEMODEL_P_H
#define ABSTRACTTIMELINEMODEL_P_H
#ifndef TIMELINEMODEL_P_H
#define TIMELINEMODEL_P_H
#include "abstracttimelinemodel.h"
#include "timelinemodel.h"
namespace QmlProfiler {
class QMLPROFILER_EXPORT AbstractTimelineModel::AbstractTimelineModelPrivate {
class QMLPROFILER_EXPORT TimelineModel::TimelineModelPrivate {
public:
static const int DefaultRowHeight = 30;
......@@ -67,11 +67,10 @@ public:
inline qint64 timestamp() const {return end;}
};
void init(AbstractTimelineModel *q, QmlProfilerModelManager *manager,
const QString &displayName, QmlDebug::Message message, QmlDebug::RangeType rangeType);
TimelineModelPrivate(int modelId, const QString &displayName);
void init(TimelineModel *q);
inline qint64 lastEndTime() const { return endTimes.last().end; }
inline qint64 firstStartTime() const { return ranges.first().start; }