diff --git a/src/plugins/qmlprofiler/abstracttimelinemodel.cpp b/src/plugins/qmlprofiler/abstracttimelinemodel.cpp index 4449f1f2456..38251620c5e 100644 --- a/src/plugins/qmlprofiler/abstracttimelinemodel.cpp +++ b/src/plugins/qmlprofiler/abstracttimelinemodel.cpp @@ -28,21 +28,33 @@ ****************************************************************************/ #include "abstracttimelinemodel.h" +#include "abstracttimelinemodel_p.h" namespace QmlProfiler { -AbstractTimelineModel::AbstractTimelineModel(const QString &name, QObject *parent) : - QObject(parent), m_name(name), m_modelManager(0) -{} +AbstractTimelineModel::AbstractTimelineModel(AbstractTimelineModelPrivate *dd, const QString &name, + QObject *parent) : + QObject(parent), d_ptr(dd) +{ + Q_D(AbstractTimelineModel); + d->q_ptr = this; + d->name = name; + d->modelId = 0; + d->modelManager = 0; +} AbstractTimelineModel::~AbstractTimelineModel() -{} +{ + Q_D(AbstractTimelineModel); + delete d; +} void AbstractTimelineModel::setModelManager(QmlProfilerModelManager *modelManager) { - m_modelManager = modelManager; - connect(modelManager->simpleModel(),SIGNAL(changed()),this,SLOT(dataChanged())); - m_modelId = modelManager->registerModelProxy(); + Q_D(AbstractTimelineModel); + d->modelManager = modelManager; + connect(d->modelManager->simpleModel(),SIGNAL(changed()),this,SLOT(dataChanged())); + d->modelId = d->modelManager->registerModelProxy(); } QStringList AbstractTimelineModel::categoryTitles() const @@ -55,7 +67,56 @@ QStringList AbstractTimelineModel::categoryTitles() const QString AbstractTimelineModel::name() const { - return m_name; + Q_D(const AbstractTimelineModel); + return d->name; +} + +int AbstractTimelineModel::count() const +{ + Q_D(const AbstractTimelineModel); + return d->count(); +} + +qint64 AbstractTimelineModel::lastTimeMark() const +{ + Q_D(const AbstractTimelineModel); + return d->lastEndTime(); +} + +int AbstractTimelineModel::findFirstIndex(qint64 startTime) const +{ + Q_D(const AbstractTimelineModel); + return d->findFirstIndex(startTime); +} + +int AbstractTimelineModel::findFirstIndexNoParents(qint64 startTime) const +{ + Q_D(const AbstractTimelineModel); + return d->findFirstIndexNoParents(startTime); +} + +int AbstractTimelineModel::findLastIndex(qint64 endTime) const +{ + Q_D(const AbstractTimelineModel); + return d->findLastIndex(endTime); +} + +qint64 AbstractTimelineModel::getDuration(int index) const +{ + Q_D(const AbstractTimelineModel); + return d->duration(index); +} + +qint64 AbstractTimelineModel::getStartTime(int index) const +{ + Q_D(const AbstractTimelineModel); + return d->startTime(index); +} + +qint64 AbstractTimelineModel::getEndTime(int index) const +{ + Q_D(const AbstractTimelineModel); + return d->startTime(index) + d->duration(index); } bool AbstractTimelineModel::isEmpty() const @@ -65,22 +126,47 @@ bool AbstractTimelineModel::isEmpty() const qint64 AbstractTimelineModel::traceStartTime() const { - return m_modelManager->traceTime()->startTime(); + Q_D(const AbstractTimelineModel); + return d->modelManager->traceTime()->startTime(); } qint64 AbstractTimelineModel::traceEndTime() const { - return m_modelManager->traceTime()->endTime(); + Q_D(const AbstractTimelineModel); + return d->modelManager->traceTime()->endTime(); } qint64 AbstractTimelineModel::traceDuration() const { - return m_modelManager->traceTime()->duration(); + Q_D(const AbstractTimelineModel); + return d->modelManager->traceTime()->duration(); } int AbstractTimelineModel::getState() const { - return (int)m_modelManager->state(); + Q_D(const AbstractTimelineModel); + return (int)d->modelManager->state(); +} + +const QVariantMap AbstractTimelineModel::getEventLocation(int index) const +{ + Q_UNUSED(index); + QVariantMap map; + return map; +} + +int AbstractTimelineModel::getEventIdForHash(const QString &eventHash) const +{ + Q_UNUSED(eventHash); + return -1; +} + +int AbstractTimelineModel::getEventIdForLocation(const QString &filename, int line, int column) const +{ + Q_UNUSED(filename); + Q_UNUSED(line); + Q_UNUSED(column); + return -1; } int AbstractTimelineModel::rowCount() const @@ -97,9 +183,16 @@ int AbstractTimelineModel::getBindingLoopDest(int index) const return -1; } +float AbstractTimelineModel::getHeight(int index) const +{ + Q_UNUSED(index); + return 1.0f; +} + void AbstractTimelineModel::dataChanged() { - switch (m_modelManager->state()) { + Q_D(AbstractTimelineModel); + switch (d->modelManager->state()) { case QmlProfilerDataState::ProcessingData: loadData(); break; diff --git a/src/plugins/qmlprofiler/abstracttimelinemodel.h b/src/plugins/qmlprofiler/abstracttimelinemodel.h index 9414378cd4b..99d95ea8609 100644 --- a/src/plugins/qmlprofiler/abstracttimelinemodel.h +++ b/src/plugins/qmlprofiler/abstracttimelinemodel.h @@ -45,59 +45,54 @@ class QMLPROFILER_EXPORT AbstractTimelineModel : public QObject Q_OBJECT public: - explicit AbstractTimelineModel(const QString &name, QObject *parent = 0); + class AbstractTimelineModelPrivate; ~AbstractTimelineModel(); + // Trivial methods implemented by the abstract model itself void setModelManager(QmlProfilerModelManager *modelManager); - QStringList categoryTitles() const; QString name() const; - virtual int count() const = 0; - bool isEmpty() const; - virtual bool eventAccepted(const QmlProfilerSimpleModel::QmlEventData &event) const = 0; - - Q_INVOKABLE virtual qint64 lastTimeMark() const = 0; + // Methods are directly passed on to the private model and relying on its virtual methods. + Q_INVOKABLE qint64 lastTimeMark() const; Q_INVOKABLE qint64 traceStartTime() const; Q_INVOKABLE qint64 traceEndTime() const; Q_INVOKABLE qint64 traceDuration() const; Q_INVOKABLE int getState() const; + Q_INVOKABLE int rowCount() const; + Q_INVOKABLE qint64 getDuration(int index) const; + Q_INVOKABLE qint64 getStartTime(int index) const; + Q_INVOKABLE qint64 getEndTime(int index) const; + int findFirstIndex(qint64 startTime) const; + int findFirstIndexNoParents(qint64 startTime) const; + int findLastIndex(qint64 endTime) const; + int count() const; + // Methods that have to be implemented by child models Q_INVOKABLE virtual bool expanded(int category) const = 0; Q_INVOKABLE virtual void setExpanded(int category, bool expanded) = 0; Q_INVOKABLE virtual int categoryDepth(int categoryIndex) const = 0; Q_INVOKABLE virtual int categoryCount() const = 0; - Q_INVOKABLE virtual int rowCount() const; Q_INVOKABLE virtual const QString categoryLabel(int categoryIndex) const = 0; - - virtual int findFirstIndex(qint64 startTime) const = 0; - virtual int findFirstIndexNoParents(qint64 startTime) const = 0; - virtual int findLastIndex(qint64 endTime) const = 0; - + Q_INVOKABLE virtual int getEventId(int index) const = 0; + Q_INVOKABLE virtual QColor getColor(int index) const = 0; + Q_INVOKABLE virtual const QVariantList getLabelsForCategory(int category) const = 0; + Q_INVOKABLE virtual const QVariantList getEventDetails(int index) const = 0; + virtual bool eventAccepted(const QmlProfilerSimpleModel::QmlEventData &event) const = 0; virtual int getEventType(int index) const = 0; virtual int getEventCategory(int index) const = 0; virtual int getEventRow(int index) const = 0; - virtual void loadData() = 0; virtual void clear() = 0; - Q_INVOKABLE virtual qint64 getDuration(int index) const = 0; - Q_INVOKABLE virtual qint64 getStartTime(int index) const = 0; - Q_INVOKABLE virtual qint64 getEndTime(int index) const = 0; - Q_INVOKABLE virtual int getEventId(int index) const = 0; - Q_INVOKABLE virtual int getBindingLoopDest(int index) const; - Q_INVOKABLE virtual QColor getColor(int index) const = 0; - Q_INVOKABLE virtual float getHeight(int index) const = 0; - - Q_INVOKABLE virtual const QVariantList getLabelsForCategory(int category) const = 0; - - Q_INVOKABLE virtual const QVariantList getEventDetails(int index) const = 0; - + // Methods which can optionally be implemented by child models. // returned map should contain "file", "line", "column" properties, or be empty - Q_INVOKABLE virtual const QVariantMap getEventLocation(int index) const = 0; - Q_INVOKABLE virtual int getEventIdForHash(const QString &eventHash) const = 0; - Q_INVOKABLE virtual int getEventIdForLocation(const QString &filename, int line, int column) const = 0; + Q_INVOKABLE virtual const QVariantMap getEventLocation(int index) const; + Q_INVOKABLE virtual int getEventIdForHash(const QString &eventHash) const; + Q_INVOKABLE virtual int getEventIdForLocation(const QString &filename, int line, int column) const; + Q_INVOKABLE virtual int getBindingLoopDest(int index) const; + Q_INVOKABLE virtual float getHeight(int index) const; signals: void dataAvailable(); @@ -106,12 +101,15 @@ signals: void expandedChanged(); protected: - QString m_name; - QmlProfilerModelManager *m_modelManager; - int m_modelId; + explicit AbstractTimelineModel(AbstractTimelineModelPrivate *dd, const QString &name, + QObject *parent = 0); + AbstractTimelineModelPrivate *d_ptr; protected slots: void dataChanged(); + +private: + Q_DECLARE_PRIVATE(AbstractTimelineModel) }; } diff --git a/src/plugins/qmlprofiler/abstracttimelinemodel_p.h b/src/plugins/qmlprofiler/abstracttimelinemodel_p.h new file mode 100644 index 00000000000..4ef663ad1c0 --- /dev/null +++ b/src/plugins/qmlprofiler/abstracttimelinemodel_p.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** 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://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: 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 ABSTRACTTIMELINEMODEL_P_H +#define ABSTRACTTIMELINEMODEL_P_H + +#include "abstracttimelinemodel.h" + +namespace QmlProfiler { + +class QMLPROFILER_EXPORT AbstractTimelineModel::AbstractTimelineModelPrivate { +public: + virtual ~AbstractTimelineModelPrivate() {} + + virtual int count() const = 0; + virtual qint64 duration(int index) const = 0; + virtual qint64 startTime(int index) const = 0; + virtual qint64 lastEndTime() const = 0; + virtual qint64 firstStartTime() const = 0; + virtual int findFirstIndex(qint64 startTime) const = 0; + virtual int findFirstIndexNoParents(qint64 startTime) const = 0; + virtual int findLastIndex(qint64 endTime) const = 0; + + QString name; + QmlProfilerModelManager *modelManager; + int modelId; + +protected: + AbstractTimelineModel *q_ptr; + +private: + Q_DECLARE_PUBLIC(AbstractTimelineModel) +}; + +} +#endif // ABSTRACTTIMELINEMODEL_P_H diff --git a/src/plugins/qmlprofiler/qmlprofiler.pro b/src/plugins/qmlprofiler/qmlprofiler.pro index 3b5d8d54922..34f8bc9b5f6 100644 --- a/src/plugins/qmlprofiler/qmlprofiler.pro +++ b/src/plugins/qmlprofiler/qmlprofiler.pro @@ -32,7 +32,8 @@ SOURCES += \ timelinemodelaggregator.cpp \ qmlprofilerpainteventsmodelproxy.cpp \ sortedtimelinemodel.cpp \ - qmlprofilerbasemodel.cpp + qmlprofilerbasemodel.cpp \ + singlecategorytimelinemodel.cpp HEADERS += \ qmlprofilerconstants.h \ @@ -65,7 +66,10 @@ HEADERS += \ timelinemodelaggregator.h \ qmlprofilerpainteventsmodelproxy.h \ sortedtimelinemodel.h \ - qmlprofilerbasemodel.h + qmlprofilerbasemodel.h \ + abstracttimelinemodel_p.h \ + singlecategorytimelinemodel.h \ + singlecategorytimelinemodel_p.h RESOURCES += \ qml/qmlprofiler.qrc diff --git a/src/plugins/qmlprofiler/qmlprofiler.qbs b/src/plugins/qmlprofiler/qmlprofiler.qbs index 40fcc0354ef..364e56f3cc2 100644 --- a/src/plugins/qmlprofiler/qmlprofiler.qbs +++ b/src/plugins/qmlprofiler/qmlprofiler.qbs @@ -24,7 +24,7 @@ QtcPlugin { name: "General" files: [ "abstractqmlprofilerrunner.h", - "abstracttimelinemodel.h", "abstracttimelinemodel.cpp", + "abstracttimelinemodel.h", "abstracttimelinemodel_p.h", "abstracttimelinemodel.cpp", "localqmlprofilerrunner.cpp", "localqmlprofilerrunner.h", "qmlprofiler_global.h", "qmlprofilerattachdialog.cpp", "qmlprofilerattachdialog.h", @@ -51,6 +51,8 @@ QtcPlugin { "qmlprofilerviewmanager.cpp", "qmlprofilerviewmanager.h", "qv8profilerdatamodel.cpp", "qv8profilerdatamodel.h", "qv8profilereventview.h", "qv8profilereventview.cpp", + "singlecategorytimelinemodel.h", "singlecategorytimelinemodel_p.h", + "singlecategorytimelinemodel.cpp", "sortedtimelinemodel.h", "sortedtimelinemodel.cpp", "timelinemodelaggregator.cpp", "timelinemodelaggregator.h", "timelinerenderer.cpp", "timelinerenderer.h", diff --git a/src/plugins/qmlprofiler/qmlprofilerpainteventsmodelproxy.cpp b/src/plugins/qmlprofiler/qmlprofilerpainteventsmodelproxy.cpp index 2c2a9c048b9..96478bcfde5 100644 --- a/src/plugins/qmlprofiler/qmlprofilerpainteventsmodelproxy.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerpainteventsmodelproxy.cpp @@ -31,6 +31,7 @@ #include "qmlprofilermodelmanager.h" #include "qmlprofilersimplemodel.h" #include "sortedtimelinemodel.h" +#include "singlecategorytimelinemodel_p.h" #include #include @@ -50,52 +51,51 @@ struct CategorySpan { int contractedRows; }; -class PaintEventsModelProxy::PaintEventsModelProxyPrivate : public SortedTimelineModel +class PaintEventsModelProxy::PaintEventsModelProxyPrivate : + public SortedTimelineModel { public: - PaintEventsModelProxyPrivate(PaintEventsModelProxy *qq) : q(qq) {} - ~PaintEventsModelProxyPrivate() {} - void computeAnimationCountLimit(); int minAnimationCount; int maxAnimationCount; - bool expanded; bool seenForeignPaintEvent; - PaintEventsModelProxy *q; +private: + Q_DECLARE_PUBLIC(PaintEventsModelProxy) }; PaintEventsModelProxy::PaintEventsModelProxy(QObject *parent) - : AbstractTimelineModel(QLatin1String("PaintEventsModelProxy"), parent), - d(new PaintEventsModelProxyPrivate(this)) + : SingleCategoryTimelineModel(new PaintEventsModelProxyPrivate, + QLatin1String("PaintEventsModelProxy"), tr("Painting"), + QmlDebug::Painting, parent) { } -PaintEventsModelProxy::~PaintEventsModelProxy() -{ - delete d; -} void PaintEventsModelProxy::clear() { + Q_D(PaintEventsModelProxy); d->SortedTimelineModel::clear(); d->minAnimationCount = 1; d->maxAnimationCount = 1; d->expanded = false; d->seenForeignPaintEvent = false; - m_modelManager->modelProxyCountUpdated(m_modelId, 0, 1); + d->modelManager->modelProxyCountUpdated(d->modelId, 0, 1); } bool PaintEventsModelProxy::eventAccepted(const QmlProfilerSimpleModel::QmlEventData &event) const { - return (event.eventType == QmlDebug::Painting && event.bindingType == QmlDebug::AnimationFrame); + return SingleCategoryTimelineModel::eventAccepted(event) && + event.bindingType == QmlDebug::AnimationFrame; } void PaintEventsModelProxy::loadData() { + Q_D(PaintEventsModelProxy); clear(); - QmlProfilerSimpleModel *simpleModel = m_modelManager->simpleModel(); + QmlProfilerSimpleModel *simpleModel = d->modelManager->simpleModel(); if (simpleModel->isEmpty()) return; @@ -133,41 +133,20 @@ void PaintEventsModelProxy::loadData() minNextStartTime = event.startTime + 1; - m_modelManager->modelProxyCountUpdated(m_modelId, d->count(), referenceList.count()); + d->modelManager->modelProxyCountUpdated(d->modelId, d->count(), referenceList.count()); } d->computeAnimationCountLimit(); d->computeNesting(); - m_modelManager->modelProxyCountUpdated(m_modelId, 1, 1); + d->modelManager->modelProxyCountUpdated(d->modelId, 1, 1); } /////////////////// QML interface -int PaintEventsModelProxy::count() const -{ - return d->count(); -} - -qint64 PaintEventsModelProxy::lastTimeMark() const -{ - return d->lastEndTime(); -} - -bool PaintEventsModelProxy::expanded(int ) const -{ - return d->expanded; -} - -void PaintEventsModelProxy::setExpanded(int category, bool expanded) -{ - Q_UNUSED(category); - d->expanded = expanded; - emit expandedChanged(); -} - int PaintEventsModelProxy::categoryDepth(int categoryIndex) const { + Q_D(const PaintEventsModelProxy); Q_UNUSED(categoryIndex); if (isEmpty()) return d->seenForeignPaintEvent ? 0 : 1; @@ -175,67 +154,12 @@ int PaintEventsModelProxy::categoryDepth(int categoryIndex) const return 2; } -int PaintEventsModelProxy::categoryCount() const -{ - return 1; -} - -const QString PaintEventsModelProxy::categoryLabel(int categoryIndex) const -{ - Q_UNUSED(categoryIndex); - return tr("Painting"); -} - - -int PaintEventsModelProxy::findFirstIndex(qint64 startTime) const -{ - return d->findFirstIndex(startTime); -} - -int PaintEventsModelProxy::findFirstIndexNoParents(qint64 startTime) const -{ - return d->findFirstIndexNoParents(startTime); -} - -int PaintEventsModelProxy::findLastIndex(qint64 endTime) const -{ - return d->findLastIndex(endTime); -} - -int PaintEventsModelProxy::getEventType(int index) const -{ - Q_UNUSED(index); - return (int)QmlDebug::Painting; -} - -int PaintEventsModelProxy::getEventCategory(int index) const -{ - Q_UNUSED(index); - // there is only one category, all events belong to it - return 0; -} - int PaintEventsModelProxy::getEventRow(int index) const { Q_UNUSED(index); return 1; } -qint64 PaintEventsModelProxy::getDuration(int index) const -{ - return d->range(index).duration; -} - -qint64 PaintEventsModelProxy::getStartTime(int index) const -{ - return d->range(index).start; -} - -qint64 PaintEventsModelProxy::getEndTime(int index) const -{ - return d->range(index).start + d->range(index).duration; -} - int PaintEventsModelProxy::getEventId(int index) const { // there is only one event Id for all painting events @@ -245,6 +169,7 @@ int PaintEventsModelProxy::getEventId(int index) const QColor PaintEventsModelProxy::getColor(int index) const { + Q_D(const PaintEventsModelProxy); double fpsFraction = d->range(index).framerate / 60.0; if (fpsFraction > 1.0) fpsFraction = 1.0; @@ -255,6 +180,7 @@ QColor PaintEventsModelProxy::getColor(int index) const float PaintEventsModelProxy::getHeight(int index) const { + Q_D(const PaintEventsModelProxy); float scale = d->maxAnimationCount - d->minAnimationCount; float fraction = 1.0f; if (scale > 1) @@ -297,6 +223,7 @@ void PaintEventsModelProxy::PaintEventsModelProxyPrivate::computeAnimationCountL const QVariantList PaintEventsModelProxy::getEventDetails(int index) const { + Q_D(const PaintEventsModelProxy); QVariantList result; // int eventId = getEventId(index); @@ -332,24 +259,5 @@ const QVariantList PaintEventsModelProxy::getEventDetails(int index) const return result; } -const QVariantMap PaintEventsModelProxy::getEventLocation(int /*index*/) const -{ - QVariantMap map; - return map; -} - -int PaintEventsModelProxy::getEventIdForHash(const QString &/*eventHash*/) const -{ - // paint events do not have an eventHash - return -1; -} - -int PaintEventsModelProxy::getEventIdForLocation(const QString &/*filename*/, int /*line*/, int /*column*/) const -{ - // paint events do not have a defined location - return -1; -} - } } - diff --git a/src/plugins/qmlprofiler/qmlprofilerpainteventsmodelproxy.h b/src/plugins/qmlprofiler/qmlprofilerpainteventsmodelproxy.h index a9671c2abc0..fcff44826de 100644 --- a/src/plugins/qmlprofiler/qmlprofilerpainteventsmodelproxy.h +++ b/src/plugins/qmlprofiler/qmlprofilerpainteventsmodelproxy.h @@ -32,7 +32,7 @@ #define QMLPROFILERPAINTEVENTSMODELPROXY_H #include -#include "abstracttimelinemodel.h" +#include "singlecategorytimelinemodel.h" #include #include //#include @@ -48,7 +48,7 @@ class QmlProfilerModelManager; namespace Internal { -class PaintEventsModelProxy : public AbstractTimelineModel +class PaintEventsModelProxy : public SingleCategoryTimelineModel { // Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged) @@ -61,47 +61,26 @@ public: }; PaintEventsModelProxy(QObject *parent = 0); - ~PaintEventsModelProxy(); void loadData(); - Q_INVOKABLE int count() const; void clear(); - Q_INVOKABLE qint64 lastTimeMark() const; - - Q_INVOKABLE bool expanded(int category) const; - Q_INVOKABLE void setExpanded(int category, bool expanded); Q_INVOKABLE int categoryDepth(int categoryIndex) const; - Q_INVOKABLE int categoryCount() const; - Q_INVOKABLE const QString categoryLabel(int categoryIndex) const; - - int findFirstIndex(qint64 startTime) const; - int findFirstIndexNoParents(qint64 startTime) const; - int findLastIndex(qint64 endTime) const; - - int getEventType(int index) const; - Q_INVOKABLE int getEventCategory(int index) const; - int getEventRow(int index) const; - Q_INVOKABLE qint64 getDuration(int index) const; - Q_INVOKABLE qint64 getStartTime(int index) const; - Q_INVOKABLE qint64 getEndTime(int index) const; Q_INVOKABLE int getEventId(int index) const; + int getEventRow(int index) const; + Q_INVOKABLE QColor getColor(int index) const; Q_INVOKABLE float getHeight(int index) const; Q_INVOKABLE const QVariantList getLabelsForCategory(int category) const; Q_INVOKABLE const QVariantList getEventDetails(int index) const; - Q_INVOKABLE const QVariantMap getEventLocation(int index) const; - Q_INVOKABLE int getEventIdForHash(const QString &eventHash) const; - Q_INVOKABLE int getEventIdForLocation(const QString &filename, int line, int column) const; private slots: bool eventAccepted(const QmlProfilerSimpleModel::QmlEventData &event) const; private: class PaintEventsModelProxyPrivate; - PaintEventsModelProxyPrivate *d; - + Q_DECLARE_PRIVATE(PaintEventsModelProxy) }; } diff --git a/src/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.cpp b/src/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.cpp index 2aadbeb453d..99eaaa5ba6e 100644 --- a/src/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.cpp @@ -54,9 +54,6 @@ struct CategorySpan { class BasicTimelineModel::BasicTimelineModelPrivate : public SortedTimelineModel { public: - BasicTimelineModelPrivate(BasicTimelineModel *qq) : q(qq) {} - ~BasicTimelineModelPrivate() {} - // convenience functions void prepare(); void computeNestingContracted(); @@ -68,30 +65,26 @@ public: QVector eventHashes; QVector categorySpan; bool seenPaintEvent; - - BasicTimelineModel *q; +private: + Q_DECLARE_PUBLIC(BasicTimelineModel) }; BasicTimelineModel::BasicTimelineModel(QObject *parent) - : AbstractTimelineModel(QLatin1String("BasicTimelineModel"), parent), - d(new BasicTimelineModelPrivate(this)) + : AbstractTimelineModel(new BasicTimelineModelPrivate, QLatin1String("BasicTimelineModel"), + parent) { } -BasicTimelineModel::~BasicTimelineModel() -{ - delete d; -} - void BasicTimelineModel::clear() { + Q_D(BasicTimelineModel); d->SortedTimelineModel::clear(); d->eventDict.clear(); d->eventHashes.clear(); d->categorySpan.clear(); d->seenPaintEvent = false; - m_modelManager->modelProxyCountUpdated(m_modelId, 0, 1); + d->modelManager->modelProxyCountUpdated(d->modelId, 0, 1); } void BasicTimelineModel::BasicTimelineModelPrivate::prepare() @@ -114,8 +107,9 @@ bool BasicTimelineModel::eventAccepted(const QmlProfilerSimpleModel::QmlEventDat void BasicTimelineModel::loadData() { + Q_D(BasicTimelineModel); clear(); - QmlProfilerSimpleModel *simpleModel = m_modelManager->simpleModel(); + QmlProfilerSimpleModel *simpleModel = d->modelManager->simpleModel(); if (simpleModel->isEmpty()) return; @@ -149,10 +143,10 @@ void BasicTimelineModel::loadData() // store starttime-based instance d->insert(event.startTime, event.duration, QmlRangeEventStartInstance(d->eventHashes.indexOf(eventHash))); - m_modelManager->modelProxyCountUpdated(m_modelId, d->count(), eventList.count() * 6); + d->modelManager->modelProxyCountUpdated(d->modelId, d->count(), eventList.count() * 6); } - m_modelManager->modelProxyCountUpdated(m_modelId, 2, 6); + d->modelManager->modelProxyCountUpdated(d->modelId, 2, 6); // compute range nesting d->computeNesting(); @@ -160,25 +154,26 @@ void BasicTimelineModel::loadData() // compute nestingLevel - nonexpanded d->computeNestingContracted(); - m_modelManager->modelProxyCountUpdated(m_modelId, 3, 6); + d->modelManager->modelProxyCountUpdated(d->modelId, 3, 6); // compute nestingLevel - expanded d->computeExpandedLevels(); - m_modelManager->modelProxyCountUpdated(m_modelId, 4, 6); + d->modelManager->modelProxyCountUpdated(d->modelId, 4, 6); d->findBindingLoops(); - m_modelManager->modelProxyCountUpdated(m_modelId, 5, 6); + d->modelManager->modelProxyCountUpdated(d->modelId, 5, 6); d->computeRowStarts(); - m_modelManager->modelProxyCountUpdated(m_modelId, 1, 1); + d->modelManager->modelProxyCountUpdated(d->modelId, 1, 1); } void BasicTimelineModel::BasicTimelineModelPrivate::computeNestingContracted() { + Q_Q(BasicTimelineModel); int i; int eventCount = count(); @@ -276,6 +271,7 @@ void BasicTimelineModel::BasicTimelineModelPrivate::findBindingLoops() void BasicTimelineModel::BasicTimelineModelPrivate::computeRowStarts() { + Q_Q(BasicTimelineModel); int rowStart = 0; for (int i = 0; i < categorySpan.count(); i++) { categorySpan[i].rowStart = rowStart; @@ -285,18 +281,9 @@ void BasicTimelineModel::BasicTimelineModelPrivate::computeRowStarts() /////////////////// QML interface -int BasicTimelineModel::count() const -{ - return d->count(); -} - -qint64 BasicTimelineModel::lastTimeMark() const -{ - return d->lastEndTime(); -} - bool BasicTimelineModel::expanded(int category) const { + Q_D(const BasicTimelineModel); if (d->categorySpan.count() <= category) return false; return d->categorySpan[category].expanded; @@ -304,6 +291,7 @@ bool BasicTimelineModel::expanded(int category) const void BasicTimelineModel::setExpanded(int category, bool expanded) { + Q_D(BasicTimelineModel); if (d->categorySpan.count() <= category) return; @@ -314,6 +302,7 @@ void BasicTimelineModel::setExpanded(int category, bool expanded) int BasicTimelineModel::categoryDepth(int categoryIndex) const { + Q_D(const BasicTimelineModel); // special for paint events: show only when empty model or there's actual events if (categoryIndex == QmlDebug::Painting && !d->seenPaintEvent) return 0; @@ -343,29 +332,15 @@ const QString BasicTimelineModel::categoryLabel(int categoryIndex) const } } - -int BasicTimelineModel::findFirstIndex(qint64 startTime) const -{ - return d->findFirstIndex(startTime); -} - -int BasicTimelineModel::findFirstIndexNoParents(qint64 startTime) const -{ - return d->findFirstIndexNoParents(startTime); -} - -int BasicTimelineModel::findLastIndex(qint64 endTime) const -{ - return d->findLastIndex(endTime); -} - int BasicTimelineModel::getEventType(int index) const { + Q_D(const BasicTimelineModel); return d->eventDict[d->range(index).eventId].eventType; } int BasicTimelineModel::getEventCategory(int index) const { + Q_D(const BasicTimelineModel); int evTy = getEventType(index); // special: paint events shown? if (!d->seenPaintEvent) @@ -375,34 +350,22 @@ int BasicTimelineModel::getEventCategory(int index) const int BasicTimelineModel::getEventRow(int index) const { + Q_D(const BasicTimelineModel); if (d->categorySpan[getEventType(index)].expanded) return d->range(index).displayRowExpanded + d->categorySpan[getEventType(index)].rowStart; else return d->range(index).displayRowCollapsed + d->categorySpan[getEventType(index)].rowStart; } -qint64 BasicTimelineModel::getDuration(int index) const -{ - return d->range(index).duration; -} - -qint64 BasicTimelineModel::getStartTime(int index) const -{ - return d->range(index).start; -} - -qint64 BasicTimelineModel::getEndTime(int index) const -{ - return d->range(index).start + d->range(index).duration; -} - int BasicTimelineModel::getEventId(int index) const { + Q_D(const BasicTimelineModel); return d->range(index).eventId; } int BasicTimelineModel::getBindingLoopDest(int index) const { + Q_D(const BasicTimelineModel); return d->range(index).bindingLoopHead; } @@ -412,15 +375,9 @@ QColor BasicTimelineModel::getColor(int index) const return QColor::fromHsl((ndx*25)%360, 76, 166); } -float BasicTimelineModel::getHeight(int index) const -{ - Q_UNUSED(index); - // 100% height for regular events - return 1.0f; -} - const QVariantList BasicTimelineModel::getLabelsForCategory(int category) const { + Q_D(const BasicTimelineModel); QVariantList result; if (d->categorySpan.count() > category && d->categorySpan[category].expanded) { @@ -441,6 +398,7 @@ const QVariantList BasicTimelineModel::getLabelsForCategory(int category) const const QVariantList BasicTimelineModel::getEventDetails(int index) const { + Q_D(const BasicTimelineModel); QVariantList result; int eventId = getEventId(index); @@ -485,6 +443,7 @@ const QVariantList BasicTimelineModel::getEventDetails(int index) const const QVariantMap BasicTimelineModel::getEventLocation(int index) const { + Q_D(const BasicTimelineModel); QVariantMap result; int eventId = getEventId(index); @@ -500,11 +459,13 @@ const QVariantMap BasicTimelineModel::getEventLocation(int index) const int BasicTimelineModel::getEventIdForHash(const QString &eventHash) const { + Q_D(const BasicTimelineModel); return d->eventHashes.indexOf(eventHash); } int BasicTimelineModel::getEventIdForLocation(const QString &filename, int line, int column) const { + Q_D(const BasicTimelineModel); // if this is called from v8 view, we don't have the column number, it will be -1 foreach (const QmlRangeEventData &eventData, d->eventDict) { if (eventData.location.filename == filename && diff --git a/src/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.h b/src/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.h index 4bdb69f75ce..d255c89d19e 100644 --- a/src/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.h +++ b/src/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.h @@ -80,15 +80,12 @@ public: }; BasicTimelineModel(QObject *parent = 0); - ~BasicTimelineModel(); void loadData(); - Q_INVOKABLE int count() const; void clear(); // QML interface - Q_INVOKABLE qint64 lastTimeMark() const; Q_INVOKABLE bool expanded(int category) const; Q_INVOKABLE void setExpanded(int category, bool expanded); @@ -96,20 +93,12 @@ public: Q_INVOKABLE int categoryCount() const; Q_INVOKABLE const QString categoryLabel(int categoryIndex) const; - int findFirstIndex(qint64 startTime) const; - int findFirstIndexNoParents(qint64 startTime) const; - int findLastIndex(qint64 endTime) const; - int getEventType(int index) const; int getEventCategory(int index) const; int getEventRow(int index) const; - Q_INVOKABLE qint64 getDuration(int index) const; - Q_INVOKABLE qint64 getStartTime(int index) const; - Q_INVOKABLE qint64 getEndTime(int index) const; Q_INVOKABLE int getEventId(int index) const; int getBindingLoopDest(int index) const; Q_INVOKABLE QColor getColor(int index) const; - Q_INVOKABLE float getHeight(int index) const; Q_INVOKABLE const QVariantList getLabelsForCategory(int category) const; Q_INVOKABLE const QVariantList getEventDetails(int index) const; @@ -123,8 +112,7 @@ private slots: private: class BasicTimelineModelPrivate; - BasicTimelineModelPrivate *d; - + Q_DECLARE_PRIVATE(BasicTimelineModel) }; } diff --git a/src/plugins/qmlprofiler/singlecategorytimelinemodel.cpp b/src/plugins/qmlprofiler/singlecategorytimelinemodel.cpp new file mode 100644 index 00000000000..604e299cc78 --- /dev/null +++ b/src/plugins/qmlprofiler/singlecategorytimelinemodel.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** 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://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: 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 "singlecategorytimelinemodel.h" +#include "singlecategorytimelinemodel_p.h" + +namespace QmlProfiler { + +SingleCategoryTimelineModel::SingleCategoryTimelineModel(SingleCategoryTimelineModelPrivate *dd, + const QString &name, const QString &label, QmlDebug::QmlEventType eventType, + QObject *parent) : + AbstractTimelineModel(dd, name, parent) +{ + Q_D(SingleCategoryTimelineModel); + d->expanded = false; + d->label = label; + d->eventType = eventType; +} + +/////////////////// QML interface + +bool SingleCategoryTimelineModel::eventAccepted(const QmlProfilerSimpleModel::QmlEventData &event) const +{ + Q_D(const SingleCategoryTimelineModel); + return (event.eventType == d->eventType); +} + +bool SingleCategoryTimelineModel::expanded(int categoryIndex) const +{ + Q_D(const SingleCategoryTimelineModel); + Q_UNUSED(categoryIndex); + return d->expanded; +} + +void SingleCategoryTimelineModel::setExpanded(int categoryIndex, bool expanded) +{ + Q_D(SingleCategoryTimelineModel); + Q_UNUSED(categoryIndex); + if (expanded != d->expanded) { + d->expanded = expanded; + emit expandedChanged(); + } +} + +int SingleCategoryTimelineModel::categoryCount() const +{ + return 1; +} + +const QString SingleCategoryTimelineModel::categoryLabel(int categoryIndex) const +{ + Q_D(const SingleCategoryTimelineModel); + Q_UNUSED(categoryIndex); + return d->label; +} + +int SingleCategoryTimelineModel::getEventType(int index) const +{ + Q_D(const SingleCategoryTimelineModel); + Q_UNUSED(index); + return (int)d->eventType; +} + +int SingleCategoryTimelineModel::getEventCategory(int index) const +{ + Q_UNUSED(index); + return 0; +} + +} diff --git a/src/plugins/qmlprofiler/singlecategorytimelinemodel.h b/src/plugins/qmlprofiler/singlecategorytimelinemodel.h new file mode 100644 index 00000000000..e14ab7e818d --- /dev/null +++ b/src/plugins/qmlprofiler/singlecategorytimelinemodel.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** 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://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: 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 SINGLECATEGORYTIMELINEMODEL_H +#define SINGLECATEGORYTIMELINEMODEL_H + +#include +#include "abstracttimelinemodel.h" + +namespace QmlProfiler { + +class QMLPROFILER_EXPORT SingleCategoryTimelineModel : public AbstractTimelineModel +{ + Q_OBJECT +public: + bool eventAccepted(const QmlProfilerSimpleModel::QmlEventData &event) const; + Q_INVOKABLE bool expanded(int) const; + Q_INVOKABLE void setExpanded(int, bool expanded); + + Q_INVOKABLE int categoryCount() const; + + int getEventType(int index) const; + Q_INVOKABLE int getEventCategory(int index) const; + Q_INVOKABLE const QString categoryLabel(int categoryIndex) const; + +protected: + class SingleCategoryTimelineModelPrivate; + SingleCategoryTimelineModel(SingleCategoryTimelineModelPrivate *dd, const QString &name, + const QString &label, QmlDebug::QmlEventType eventType, + QObject *parent); + Q_DECLARE_PRIVATE(SingleCategoryTimelineModel) +}; + +} + +#endif // SINGLECATEGORYTIMELINEMODEL_H diff --git a/src/plugins/qmlprofiler/singlecategorytimelinemodel_p.h b/src/plugins/qmlprofiler/singlecategorytimelinemodel_p.h new file mode 100644 index 00000000000..b0045c23522 --- /dev/null +++ b/src/plugins/qmlprofiler/singlecategorytimelinemodel_p.h @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** 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://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: 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 SINGLECATEGORYTIMELINEMODEL_P_H +#define SINGLECATEGORYTIMELINEMODEL_P_H + +#include "singlecategorytimelinemodel.h" +#include "abstracttimelinemodel_p.h" + +namespace QmlProfiler { + +class SingleCategoryTimelineModel::SingleCategoryTimelineModelPrivate : + public AbstractTimelineModel::AbstractTimelineModelPrivate { +public: + bool expanded; + QString label; + QmlDebug::QmlEventType eventType; +}; +} + +#endif // SINGLECATEGORYTIMELINEMODEL_P_H diff --git a/src/plugins/qmlprofiler/sortedtimelinemodel.h b/src/plugins/qmlprofiler/sortedtimelinemodel.h index 29a5697fd37..fb7ccb08dd6 100644 --- a/src/plugins/qmlprofiler/sortedtimelinemodel.h +++ b/src/plugins/qmlprofiler/sortedtimelinemodel.h @@ -30,13 +30,17 @@ #ifndef SORTEDTIMELINEMODEL_H #define SORTEDTIMELINEMODEL_H +#include "abstracttimelinemodel_p.h" #include #include namespace QmlProfiler { -template -class SortedTimelineModel { +// The template has to be inserted into the hierarchy of public/private classes when Data is known. +// Otherwise we'd have to add implementation details to the public headers. This is why the class to +// be derived from is given as template parameter. +template +class SortedTimelineModel : public Base { public: struct Range : public Data { Range() : Data(), start(-1), duration(-1), parent(-1) {} @@ -65,10 +69,13 @@ public: inline int count() const { return ranges.count(); } + qint64 duration(int index) const { return range(index).duration; } + qint64 startTime(int index) const { return range(index).start; } + inline qint64 lastEndTime() const { return endTimes.last().end; } inline qint64 firstStartTime() const { return ranges.first().start; } - inline const Range &range(int index) { return ranges[index]; } + inline const Range &range(int index) const { return ranges[index]; } inline Data &data(int index) { return ranges[index]; } inline int insert(qint64 startTime, qint64 duration, const Data &item)