From 780d4c6a434c84c7bfdd6b2cf0020891481f7b76 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 28 Mar 2018 15:40:13 +0200 Subject: [PATCH] Timeline: Move modelId generation into aggregator The way the notes model works requires every timeline model to have a different ID. Conversely no other kind of model actually needs an ID. Therefore it makes sense to have the TimelineModelAggregator manage the IDs as every timeline model will sooner or later be associated with an aggregator. Change-Id: Ib8b2c88ed883351d4e3e156dd13e1dd113c21808 Reviewed-by: Tobias Hunger --- src/libs/timeline/timelinemodel.cpp | 5 +- src/libs/timeline/timelinemodel.h | 3 +- src/libs/timeline/timelinemodelaggregator.cpp | 7 ++ src/libs/timeline/timelinemodelaggregator.h | 3 +- .../qmlprofiler/debugmessagesmodel.cpp | 3 +- src/plugins/qmlprofiler/debugmessagesmodel.h | 2 +- src/plugins/qmlprofiler/flamegraphmodel.cpp | 1 - src/plugins/qmlprofiler/inputeventsmodel.cpp | 3 +- src/plugins/qmlprofiler/inputeventsmodel.h | 2 +- src/plugins/qmlprofiler/memoryusagemodel.cpp | 3 +- src/plugins/qmlprofiler/memoryusagemodel.h | 2 +- src/plugins/qmlprofiler/pixmapcachemodel.cpp | 3 +- src/plugins/qmlprofiler/pixmapcachemodel.h | 2 +- .../qmlprofileranimationsmodel.cpp | 2 +- .../qmlprofiler/qmlprofileranimationsmodel.h | 3 +- .../qmlprofiler/qmlprofilermodelmanager.cpp | 6 -- .../qmlprofiler/qmlprofilermodelmanager.h | 1 - .../qmlprofiler/qmlprofilerrangemodel.cpp | 2 +- .../qmlprofiler/qmlprofilerrangemodel.h | 3 +- .../qmlprofilerstatisticsmodel.cpp | 1 - .../qmlprofiler/qmlprofilertimelinemodel.cpp | 6 +- .../qmlprofiler/qmlprofilertimelinemodel.h | 4 +- .../qmlprofiler/scenegraphtimelinemodel.cpp | 2 +- .../qmlprofiler/scenegraphtimelinemodel.h | 3 +- .../tests/debugmessagesmodel_test.cpp | 2 +- .../tests/debugmessagesmodel_test.h | 1 + .../tests/flamegraphmodel_test.cpp | 7 +- .../qmlprofiler/tests/flamegraphmodel_test.h | 7 +- .../qmlprofiler/tests/flamegraphview_test.cpp | 5 +- .../qmlprofiler/tests/flamegraphview_test.h | 4 ++ .../tests/inputeventsmodel_test.cpp | 2 +- .../qmlprofiler/tests/inputeventsmodel_test.h | 1 + .../tests/memoryusagemodel_test.cpp | 2 +- .../qmlprofiler/tests/memoryusagemodel_test.h | 1 + .../tests/pixmapcachemodel_test.cpp | 2 +- .../qmlprofiler/tests/pixmapcachemodel_test.h | 1 + .../tests/qmlprofileranimationsmodel_test.cpp | 2 +- .../tests/qmlprofileranimationsmodel_test.h | 1 + ...qmlprofilerbindingloopsrenderpass_test.cpp | 12 ++-- .../tst_timelineabstractrenderer.cpp | 4 +- .../tst_timelineitemsrenderpass.cpp | 8 ++- .../timelinemodel/tst_timelinemodel.cpp | 70 +++++++++---------- .../tst_timelinemodelaggregator.cpp | 33 ++++----- .../tst_timelinenotesmodel.cpp | 50 +++++++------ .../tst_timelinenotesrenderpass.cpp | 16 +++-- .../tst_timelineoverviewrenderer.cpp | 6 +- .../timelinerenderer/tst_timelinerenderer.cpp | 8 ++- .../tst_timelinerenderstate.cpp | 4 +- .../tst_timelineselectionrenderpass.cpp | 8 ++- 49 files changed, 188 insertions(+), 141 deletions(-) diff --git a/src/libs/timeline/timelinemodel.cpp b/src/libs/timeline/timelinemodel.cpp index 8bb6f14142d..e2f28e18497 100644 --- a/src/libs/timeline/timelinemodel.cpp +++ b/src/libs/timeline/timelinemodel.cpp @@ -25,6 +25,7 @@ #include "timelinemodel.h" #include "timelinemodel_p.h" +#include "timelinemodelaggregator.h" #include "timelineitemsrenderpass.h" #include "timelineselectionrenderpass.h" #include "timelinenotesrenderpass.h" @@ -157,8 +158,8 @@ TimelineModel::TimelineModelPrivate::TimelineModelPrivate(int modelId) : { } -TimelineModel::TimelineModel(int modelId, QObject *parent) : - QObject(parent), d_ptr(new TimelineModelPrivate(modelId)) +TimelineModel::TimelineModel(TimelineModelAggregator *parent) : + QObject(parent), d_ptr(new TimelineModelPrivate(parent->generateModelId())) { connect(this, &TimelineModel::contentChanged, this, &TimelineModel::labelsChanged); connect(this, &TimelineModel::contentChanged, this, &TimelineModel::detailsChanged); diff --git a/src/libs/timeline/timelinemodel.h b/src/libs/timeline/timelinemodel.h index 2bb2031dd53..010a4f2aef6 100644 --- a/src/libs/timeline/timelinemodel.h +++ b/src/libs/timeline/timelinemodel.h @@ -31,6 +31,7 @@ #include namespace Timeline { +class TimelineModelAggregator; class TIMELINE_EXPORT TimelineModel : public QObject { @@ -51,7 +52,7 @@ class TIMELINE_EXPORT TimelineModel : public QObject public: class TimelineModelPrivate; - TimelineModel(int modelId, QObject *parent = 0); + TimelineModel(TimelineModelAggregator *parent); ~TimelineModel(); // Methods implemented by the abstract model itself diff --git a/src/libs/timeline/timelinemodelaggregator.cpp b/src/libs/timeline/timelinemodelaggregator.cpp index b8c4bbd41a9..30636356aec 100644 --- a/src/libs/timeline/timelinemodelaggregator.cpp +++ b/src/libs/timeline/timelinemodelaggregator.cpp @@ -39,6 +39,7 @@ class TimelineModelAggregator::TimelineModelAggregatorPrivate { public: QList modelList; TimelineNotesModel *notesModel; + int currentModelId = 0; }; TimelineModelAggregator::TimelineModelAggregator(TimelineNotesModel *notes, QObject *parent) @@ -60,6 +61,12 @@ int TimelineModelAggregator::height() const return modelOffset(d->modelList.length()); } +int TimelineModelAggregator::generateModelId() +{ + Q_D(TimelineModelAggregator); + return d->currentModelId++; +} + void TimelineModelAggregator::addModel(TimelineModel *m) { Q_D(TimelineModelAggregator); diff --git a/src/libs/timeline/timelinemodelaggregator.h b/src/libs/timeline/timelinemodelaggregator.h index b0173543303..e1f7a01cab7 100644 --- a/src/libs/timeline/timelinemodelaggregator.h +++ b/src/libs/timeline/timelinemodelaggregator.h @@ -37,10 +37,11 @@ class TIMELINE_EXPORT TimelineModelAggregator : public QObject Q_PROPERTY(QVariantList models READ models WRITE setModels NOTIFY modelsChanged) Q_PROPERTY(Timeline::TimelineNotesModel *notes READ notes CONSTANT) public: - TimelineModelAggregator(TimelineNotesModel *notes, QObject *parent = 0); + TimelineModelAggregator(TimelineNotesModel *notes = nullptr, QObject *parent = nullptr); ~TimelineModelAggregator(); int height() const; + int generateModelId(); void addModel(TimelineModel *m); const TimelineModel *model(int modelIndex) const; diff --git a/src/plugins/qmlprofiler/debugmessagesmodel.cpp b/src/plugins/qmlprofiler/debugmessagesmodel.cpp index b0217bf68d1..82578df8ec4 100644 --- a/src/plugins/qmlprofiler/debugmessagesmodel.cpp +++ b/src/plugins/qmlprofiler/debugmessagesmodel.cpp @@ -30,7 +30,8 @@ namespace QmlProfiler { namespace Internal { -DebugMessagesModel::DebugMessagesModel(QmlProfilerModelManager *manager, QObject *parent) : +DebugMessagesModel::DebugMessagesModel(QmlProfilerModelManager *manager, + Timeline::TimelineModelAggregator *parent) : QmlProfilerTimelineModel(manager, DebugMessage, MaximumRangeType, ProfileDebugMessages, parent), m_maximumMsgType(-1) { diff --git a/src/plugins/qmlprofiler/debugmessagesmodel.h b/src/plugins/qmlprofiler/debugmessagesmodel.h index 4cb49e4e276..6af88796fb2 100644 --- a/src/plugins/qmlprofiler/debugmessagesmodel.h +++ b/src/plugins/qmlprofiler/debugmessagesmodel.h @@ -35,7 +35,7 @@ class DebugMessagesModel : public QmlProfilerTimelineModel Q_OBJECT public: - DebugMessagesModel(QmlProfilerModelManager *manager, QObject *parent = 0); + DebugMessagesModel(QmlProfilerModelManager *manager, Timeline::TimelineModelAggregator *parent); int typeId(int index) const override; QRgb color(int index) const override; diff --git a/src/plugins/qmlprofiler/flamegraphmodel.cpp b/src/plugins/qmlprofiler/flamegraphmodel.cpp index 7b2e26d2524..41e0b141558 100644 --- a/src/plugins/qmlprofiler/flamegraphmodel.cpp +++ b/src/plugins/qmlprofiler/flamegraphmodel.cpp @@ -57,7 +57,6 @@ FlameGraphModel::FlameGraphModel(QmlProfilerModelManager *modelManager, this, &FlameGraphModel::onTypeDetailsFinished); connect(modelManager->notesModel(), &Timeline::TimelineNotesModel::changed, this, [this](int typeId, int, int){loadNotes(typeId, true);}); - m_modelId = modelManager->registerModelProxy(); m_acceptedFeatures = supportedFeatures(); modelManager->announceFeatures(m_acceptedFeatures, diff --git a/src/plugins/qmlprofiler/inputeventsmodel.cpp b/src/plugins/qmlprofiler/inputeventsmodel.cpp index e89d0ae5963..ae8e46f405d 100644 --- a/src/plugins/qmlprofiler/inputeventsmodel.cpp +++ b/src/plugins/qmlprofiler/inputeventsmodel.cpp @@ -36,7 +36,8 @@ namespace QmlProfiler { namespace Internal { -InputEventsModel::InputEventsModel(QmlProfilerModelManager *manager, QObject *parent) : +InputEventsModel::InputEventsModel(QmlProfilerModelManager *manager, + Timeline::TimelineModelAggregator *parent) : QmlProfilerTimelineModel(manager, Event, MaximumRangeType, ProfileInputEvents, parent), m_keyTypeId(-1), m_mouseTypeId(-1) { diff --git a/src/plugins/qmlprofiler/inputeventsmodel.h b/src/plugins/qmlprofiler/inputeventsmodel.h index 0e77893a17b..d38350777a1 100644 --- a/src/plugins/qmlprofiler/inputeventsmodel.h +++ b/src/plugins/qmlprofiler/inputeventsmodel.h @@ -42,7 +42,7 @@ public: int b; }; - InputEventsModel(QmlProfilerModelManager *manager, QObject *parent = 0); + InputEventsModel(QmlProfilerModelManager *manager, Timeline::TimelineModelAggregator *parent); bool accepted(const QmlEventType &type) const override; void loadEvent(const QmlEvent &event, const QmlEventType &type) override; diff --git a/src/plugins/qmlprofiler/memoryusagemodel.cpp b/src/plugins/qmlprofiler/memoryusagemodel.cpp index b379e7455bc..5c878a0410a 100644 --- a/src/plugins/qmlprofiler/memoryusagemodel.cpp +++ b/src/plugins/qmlprofiler/memoryusagemodel.cpp @@ -32,7 +32,8 @@ namespace QmlProfiler { namespace Internal { -MemoryUsageModel::MemoryUsageModel(QmlProfilerModelManager *manager, QObject *parent) : +MemoryUsageModel::MemoryUsageModel(QmlProfilerModelManager *manager, + Timeline::TimelineModelAggregator *parent) : QmlProfilerTimelineModel(manager, MemoryAllocation, MaximumRangeType, ProfileMemory, parent) { // Announce additional features. The base class already announces the main feature. diff --git a/src/plugins/qmlprofiler/memoryusagemodel.h b/src/plugins/qmlprofiler/memoryusagemodel.h index 98ec40f4d5e..65c0d7a528b 100644 --- a/src/plugins/qmlprofiler/memoryusagemodel.h +++ b/src/plugins/qmlprofiler/memoryusagemodel.h @@ -51,7 +51,7 @@ public: void update(qint64 amount); }; - MemoryUsageModel(QmlProfilerModelManager *manager, QObject *parent = 0); + MemoryUsageModel(QmlProfilerModelManager *manager, Timeline::TimelineModelAggregator *parent); qint64 rowMaxValue(int rowNumber) const override; diff --git a/src/plugins/qmlprofiler/pixmapcachemodel.cpp b/src/plugins/qmlprofiler/pixmapcachemodel.cpp index 1e47dbe4207..b21e2f7cfff 100644 --- a/src/plugins/qmlprofiler/pixmapcachemodel.cpp +++ b/src/plugins/qmlprofiler/pixmapcachemodel.cpp @@ -32,7 +32,8 @@ namespace QmlProfiler { namespace Internal { -PixmapCacheModel::PixmapCacheModel(QmlProfilerModelManager *manager, QObject *parent) : +PixmapCacheModel::PixmapCacheModel(QmlProfilerModelManager *manager, + Timeline::TimelineModelAggregator *parent) : QmlProfilerTimelineModel(manager, PixmapCacheEvent, MaximumRangeType, ProfilePixmapCache, parent) { diff --git a/src/plugins/qmlprofiler/pixmapcachemodel.h b/src/plugins/qmlprofiler/pixmapcachemodel.h index c645c53deaa..ebd08e131f3 100644 --- a/src/plugins/qmlprofiler/pixmapcachemodel.h +++ b/src/plugins/qmlprofiler/pixmapcachemodel.h @@ -94,7 +94,7 @@ public: qint64 cacheSize = 0; }; - PixmapCacheModel(QmlProfilerModelManager *manager, QObject *parent = 0); + PixmapCacheModel(QmlProfilerModelManager *manager, Timeline::TimelineModelAggregator *parent); qint64 rowMaxValue(int rowNumber) const override; diff --git a/src/plugins/qmlprofiler/qmlprofileranimationsmodel.cpp b/src/plugins/qmlprofiler/qmlprofileranimationsmodel.cpp index 337da28feda..f743d2a5100 100644 --- a/src/plugins/qmlprofiler/qmlprofileranimationsmodel.cpp +++ b/src/plugins/qmlprofiler/qmlprofileranimationsmodel.cpp @@ -41,7 +41,7 @@ namespace QmlProfiler { namespace Internal { QmlProfilerAnimationsModel::QmlProfilerAnimationsModel(QmlProfilerModelManager *manager, - QObject *parent) : + Timeline::TimelineModelAggregator *parent) : QmlProfilerTimelineModel(manager, Event, MaximumRangeType, ProfileAnimations, parent) { m_minNextStartTimes[0] = m_minNextStartTimes[1] = 0; diff --git a/src/plugins/qmlprofiler/qmlprofileranimationsmodel.h b/src/plugins/qmlprofiler/qmlprofileranimationsmodel.h index 8d109698338..7364db61e33 100644 --- a/src/plugins/qmlprofiler/qmlprofileranimationsmodel.h +++ b/src/plugins/qmlprofiler/qmlprofileranimationsmodel.h @@ -49,7 +49,8 @@ public: int typeId; }; - QmlProfilerAnimationsModel(QmlProfilerModelManager *manager, QObject *parent = 0); + QmlProfilerAnimationsModel(QmlProfilerModelManager *manager, + Timeline::TimelineModelAggregator *parent); qint64 rowMaxValue(int rowNumber) const override; diff --git a/src/plugins/qmlprofiler/qmlprofilermodelmanager.cpp b/src/plugins/qmlprofiler/qmlprofilermodelmanager.cpp index 7dbb10ba4ad..2f5afbd8acd 100644 --- a/src/plugins/qmlprofiler/qmlprofilermodelmanager.cpp +++ b/src/plugins/qmlprofiler/qmlprofilermodelmanager.cpp @@ -76,7 +76,6 @@ public: QmlProfilerModelManager::State state = Empty; - int numRegisteredModels = 0; int numFinishedFinalizers = 0; int numLoadedEvents = 0; @@ -193,11 +192,6 @@ int QmlProfilerModelManager::numEventTypes() const return d->eventTypes.count(); } -int QmlProfilerModelManager::registerModelProxy() -{ - return d->numRegisteredModels++; -} - int QmlProfilerModelManager::numFinishedFinalizers() const { return d->numFinishedFinalizers; diff --git a/src/plugins/qmlprofiler/qmlprofilermodelmanager.h b/src/plugins/qmlprofiler/qmlprofilermodelmanager.h index dd04e841a6a..00b525cbf30 100644 --- a/src/plugins/qmlprofiler/qmlprofilermodelmanager.h +++ b/src/plugins/qmlprofiler/qmlprofilermodelmanager.h @@ -76,7 +76,6 @@ public: int numEvents() const; int numEventTypes() const; - int registerModelProxy(); void announceFeatures(quint64 features, EventLoader eventLoader, Finalizer finalizer); int numFinishedFinalizers() const; diff --git a/src/plugins/qmlprofiler/qmlprofilerrangemodel.cpp b/src/plugins/qmlprofiler/qmlprofilerrangemodel.cpp index 243e07a0c02..07a5d20e0d9 100644 --- a/src/plugins/qmlprofiler/qmlprofilerrangemodel.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerrangemodel.cpp @@ -43,7 +43,7 @@ namespace QmlProfiler { namespace Internal { QmlProfilerRangeModel::QmlProfilerRangeModel(QmlProfilerModelManager *manager, RangeType range, - QObject *parent) : + Timeline::TimelineModelAggregator *parent) : QmlProfilerTimelineModel(manager, MaximumMessage, range, featureFromRangeType(range), parent) { m_expandedRowTypes << -1; diff --git a/src/plugins/qmlprofiler/qmlprofilerrangemodel.h b/src/plugins/qmlprofiler/qmlprofilerrangemodel.h index 7e93b67adfb..1ca4af7fcaa 100644 --- a/src/plugins/qmlprofiler/qmlprofilerrangemodel.h +++ b/src/plugins/qmlprofiler/qmlprofilerrangemodel.h @@ -56,7 +56,8 @@ public: int bindingLoopHead; }; - QmlProfilerRangeModel(QmlProfilerModelManager *manager, RangeType range, QObject *parent = 0); + QmlProfilerRangeModel(QmlProfilerModelManager *manager, RangeType range, + Timeline::TimelineModelAggregator *parent); Q_INVOKABLE int expandedRow(int index) const override; Q_INVOKABLE int collapsedRow(int index) const override; diff --git a/src/plugins/qmlprofiler/qmlprofilerstatisticsmodel.cpp b/src/plugins/qmlprofiler/qmlprofilerstatisticsmodel.cpp index 13b6064eb46..ef8a1ac882a 100644 --- a/src/plugins/qmlprofiler/qmlprofilerstatisticsmodel.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerstatisticsmodel.cpp @@ -70,7 +70,6 @@ QmlProfilerStatisticsModel::QmlProfilerStatisticsModel(QmlProfilerModelManager * this, &QmlProfilerStatisticsModel::modelManagerStateChanged); connect(modelManager->notesModel(), &Timeline::TimelineNotesModel::changed, this, &QmlProfilerStatisticsModel::notesChanged); - modelManager->registerModelProxy(); m_acceptedTypes << Compiling << Creating << Binding << HandlingSignal << Javascript; diff --git a/src/plugins/qmlprofiler/qmlprofilertimelinemodel.cpp b/src/plugins/qmlprofiler/qmlprofilertimelinemodel.cpp index 2aeb0883ef2..8cc9ffc0707 100644 --- a/src/plugins/qmlprofiler/qmlprofilertimelinemodel.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertimelinemodel.cpp @@ -29,9 +29,9 @@ namespace QmlProfiler { QmlProfilerTimelineModel::QmlProfilerTimelineModel(QmlProfilerModelManager *modelManager, Message message, RangeType rangeType, - ProfileFeature mainFeature, QObject *parent) : - TimelineModel(modelManager->registerModelProxy(), parent), - m_message(message), m_rangeType(rangeType), m_mainFeature(mainFeature), + ProfileFeature mainFeature, + Timeline::TimelineModelAggregator *parent) : + TimelineModel(parent), m_message(message), m_rangeType(rangeType), m_mainFeature(mainFeature), m_modelManager(modelManager) { setDisplayName(tr(QmlProfilerModelManager::featureName(mainFeature))); diff --git a/src/plugins/qmlprofiler/qmlprofilertimelinemodel.h b/src/plugins/qmlprofiler/qmlprofilertimelinemodel.h index 742bec73b4b..12d2229586e 100644 --- a/src/plugins/qmlprofiler/qmlprofilertimelinemodel.h +++ b/src/plugins/qmlprofiler/qmlprofilertimelinemodel.h @@ -28,6 +28,7 @@ #include "qmlprofiler_global.h" #include "qmlprofilermodelmanager.h" #include "timeline/timelinemodel.h" +#include "timeline/timelinemodelaggregator.h" namespace QmlProfiler { @@ -39,7 +40,8 @@ class QMLPROFILER_EXPORT QmlProfilerTimelineModel : public Timeline::TimelineMod public: QmlProfilerTimelineModel(QmlProfilerModelManager *modelManager, Message message, - RangeType rangeType, ProfileFeature mainFeature, QObject *parent); + RangeType rangeType, ProfileFeature mainFeature, + Timeline::TimelineModelAggregator *parent); QmlProfilerModelManager *modelManager() const; diff --git a/src/plugins/qmlprofiler/scenegraphtimelinemodel.cpp b/src/plugins/qmlprofiler/scenegraphtimelinemodel.cpp index 18342e7b6b2..ab14fbae118 100644 --- a/src/plugins/qmlprofiler/scenegraphtimelinemodel.cpp +++ b/src/plugins/qmlprofiler/scenegraphtimelinemodel.cpp @@ -76,7 +76,7 @@ Q_STATIC_ASSERT(sizeof(StageLabels) == SceneGraphTimelineModel::MaximumSceneGraphStage * sizeof(const char *)); SceneGraphTimelineModel::SceneGraphTimelineModel(QmlProfilerModelManager *manager, - QObject *parent) : + Timeline::TimelineModelAggregator *parent) : QmlProfilerTimelineModel(manager, SceneGraphFrame, MaximumRangeType, ProfileSceneGraph, parent) { } diff --git a/src/plugins/qmlprofiler/scenegraphtimelinemodel.h b/src/plugins/qmlprofiler/scenegraphtimelinemodel.h index 0dd0e6d5108..a4338738aa6 100644 --- a/src/plugins/qmlprofiler/scenegraphtimelinemodel.h +++ b/src/plugins/qmlprofiler/scenegraphtimelinemodel.h @@ -82,7 +82,8 @@ public: int glyphCount; // only used for one event type }; - SceneGraphTimelineModel(QmlProfilerModelManager *manager, QObject *parent = 0); + SceneGraphTimelineModel(QmlProfilerModelManager *manager, + Timeline::TimelineModelAggregator *parent); int expandedRow(int index) const override; int collapsedRow(int index) const override; diff --git a/src/plugins/qmlprofiler/tests/debugmessagesmodel_test.cpp b/src/plugins/qmlprofiler/tests/debugmessagesmodel_test.cpp index 85103758a66..71a68ded907 100644 --- a/src/plugins/qmlprofiler/tests/debugmessagesmodel_test.cpp +++ b/src/plugins/qmlprofiler/tests/debugmessagesmodel_test.cpp @@ -33,7 +33,7 @@ namespace QmlProfiler { namespace Internal { DebugMessagesModelTest::DebugMessagesModelTest(QObject *parent) : - QObject(parent), manager(nullptr), model(&manager) + QObject(parent), model(&manager, &aggregator) { } diff --git a/src/plugins/qmlprofiler/tests/debugmessagesmodel_test.h b/src/plugins/qmlprofiler/tests/debugmessagesmodel_test.h index 581908e55bd..23dcf277d48 100644 --- a/src/plugins/qmlprofiler/tests/debugmessagesmodel_test.h +++ b/src/plugins/qmlprofiler/tests/debugmessagesmodel_test.h @@ -51,6 +51,7 @@ private slots: private: QmlProfilerModelManager manager; + Timeline::TimelineModelAggregator aggregator; DebugMessagesModel model; }; diff --git a/src/plugins/qmlprofiler/tests/flamegraphmodel_test.cpp b/src/plugins/qmlprofiler/tests/flamegraphmodel_test.cpp index c2db0182451..c4abc490849 100644 --- a/src/plugins/qmlprofiler/tests/flamegraphmodel_test.cpp +++ b/src/plugins/qmlprofiler/tests/flamegraphmodel_test.cpp @@ -37,10 +37,11 @@ FlameGraphModelTest::FlameGraphModelTest(QObject *parent) : { } -int FlameGraphModelTest::generateData(QmlProfilerModelManager *manager) +int FlameGraphModelTest::generateData(QmlProfilerModelManager *manager, + Timeline::TimelineModelAggregator *aggregator) { // Notes only work with timeline models - QmlProfilerRangeModel *rangeModel = new QmlProfilerRangeModel(manager, Javascript, manager); + QmlProfilerRangeModel *rangeModel = new QmlProfilerRangeModel(manager, Javascript, aggregator); int rangeModelId = rangeModel->modelId(); manager->notesModel()->addTimelineModel(rangeModel); @@ -95,7 +96,7 @@ int FlameGraphModelTest::generateData(QmlProfilerModelManager *manager) void FlameGraphModelTest::initTestCase() { QCOMPARE(model.modelManager(), &manager); - rangeModelId = generateData(&manager); + rangeModelId = generateData(&manager, &aggregator); QCOMPARE(manager.state(), QmlProfilerModelManager::Done); } diff --git a/src/plugins/qmlprofiler/tests/flamegraphmodel_test.h b/src/plugins/qmlprofiler/tests/flamegraphmodel_test.h index 1099ee62007..627a217d20c 100644 --- a/src/plugins/qmlprofiler/tests/flamegraphmodel_test.h +++ b/src/plugins/qmlprofiler/tests/flamegraphmodel_test.h @@ -27,6 +27,9 @@ #include #include + +#include + #include namespace QmlProfiler { @@ -37,7 +40,8 @@ class FlameGraphModelTest : public QObject Q_OBJECT public: FlameGraphModelTest(QObject *parent = nullptr); - static int generateData(QmlProfilerModelManager *manager); + static int generateData(QmlProfilerModelManager *manager, + Timeline::TimelineModelAggregator *aggregator); private slots: void initTestCase(); @@ -50,6 +54,7 @@ private slots: private: QmlProfilerModelManager manager; + Timeline::TimelineModelAggregator aggregator; FlameGraphModel model; int rangeModelId = -1; }; diff --git a/src/plugins/qmlprofiler/tests/flamegraphview_test.cpp b/src/plugins/qmlprofiler/tests/flamegraphview_test.cpp index e371bf584d1..732128ab5a5 100644 --- a/src/plugins/qmlprofiler/tests/flamegraphview_test.cpp +++ b/src/plugins/qmlprofiler/tests/flamegraphview_test.cpp @@ -34,7 +34,8 @@ namespace QmlProfiler { namespace Internal { -FlameGraphViewTest::FlameGraphViewTest(QObject *parent) : QObject(parent), view(&manager) +FlameGraphViewTest::FlameGraphViewTest(QObject *parent) + : QObject(parent), view(&manager) { } @@ -42,7 +43,7 @@ void FlameGraphViewTest::initTestCase() { connect(&view, &QmlProfilerEventsView::showFullRange, this, [this](){ manager.restrictToRange(-1, -1); }); - FlameGraphModelTest::generateData(&manager); + FlameGraphModelTest::generateData(&manager, &aggregator); QCOMPARE(manager.state(), QmlProfilerModelManager::Done); view.resize(500, 500); view.show(); diff --git a/src/plugins/qmlprofiler/tests/flamegraphview_test.h b/src/plugins/qmlprofiler/tests/flamegraphview_test.h index c99a2177d2b..2729306412f 100644 --- a/src/plugins/qmlprofiler/tests/flamegraphview_test.h +++ b/src/plugins/qmlprofiler/tests/flamegraphview_test.h @@ -27,6 +27,9 @@ #include #include + +#include + #include namespace QmlProfiler { @@ -46,6 +49,7 @@ private slots: private: QmlProfilerModelManager manager; + Timeline::TimelineModelAggregator aggregator; FlameGraphView view; }; diff --git a/src/plugins/qmlprofiler/tests/inputeventsmodel_test.cpp b/src/plugins/qmlprofiler/tests/inputeventsmodel_test.cpp index fb6896e6f11..b92eca9f931 100644 --- a/src/plugins/qmlprofiler/tests/inputeventsmodel_test.cpp +++ b/src/plugins/qmlprofiler/tests/inputeventsmodel_test.cpp @@ -38,7 +38,7 @@ static InputEventType inputType(int i) } InputEventsModelTest::InputEventsModelTest(QObject *parent) : - QObject(parent), manager(nullptr), model(&manager) + QObject(parent), model(&manager, &aggregator) { keyTypeId = manager.numEventTypes(); manager.addEventType(QmlEventType(Event, MaximumRangeType, Key)); diff --git a/src/plugins/qmlprofiler/tests/inputeventsmodel_test.h b/src/plugins/qmlprofiler/tests/inputeventsmodel_test.h index af8b4e39cbd..16c92d83bb4 100644 --- a/src/plugins/qmlprofiler/tests/inputeventsmodel_test.h +++ b/src/plugins/qmlprofiler/tests/inputeventsmodel_test.h @@ -51,6 +51,7 @@ private slots: private: QmlProfilerModelManager manager; + Timeline::TimelineModelAggregator aggregator; InputEventsModel model; int mouseTypeId = -1; diff --git a/src/plugins/qmlprofiler/tests/memoryusagemodel_test.cpp b/src/plugins/qmlprofiler/tests/memoryusagemodel_test.cpp index 92d17524613..8e7db17b7c0 100644 --- a/src/plugins/qmlprofiler/tests/memoryusagemodel_test.cpp +++ b/src/plugins/qmlprofiler/tests/memoryusagemodel_test.cpp @@ -30,7 +30,7 @@ namespace QmlProfiler { namespace Internal { MemoryUsageModelTest::MemoryUsageModelTest(QObject *parent) : QObject(parent), - manager(nullptr), model(&manager) + model(&manager, &aggregator) { } diff --git a/src/plugins/qmlprofiler/tests/memoryusagemodel_test.h b/src/plugins/qmlprofiler/tests/memoryusagemodel_test.h index c8b1c4b8c12..2bd40aa6a4a 100644 --- a/src/plugins/qmlprofiler/tests/memoryusagemodel_test.h +++ b/src/plugins/qmlprofiler/tests/memoryusagemodel_test.h @@ -54,6 +54,7 @@ private slots: private: QmlProfilerModelManager manager; + Timeline::TimelineModelAggregator aggregator; MemoryUsageModel model; int heapPageTypeId = -1; diff --git a/src/plugins/qmlprofiler/tests/pixmapcachemodel_test.cpp b/src/plugins/qmlprofiler/tests/pixmapcachemodel_test.cpp index c0148f2c83a..0f4a0079b75 100644 --- a/src/plugins/qmlprofiler/tests/pixmapcachemodel_test.cpp +++ b/src/plugins/qmlprofiler/tests/pixmapcachemodel_test.cpp @@ -31,7 +31,7 @@ namespace QmlProfiler { namespace Internal { PixmapCacheModelTest::PixmapCacheModelTest(QObject *parent) : QObject(parent), - manager(nullptr), model(&manager) + model(&manager, &aggregator) { } diff --git a/src/plugins/qmlprofiler/tests/pixmapcachemodel_test.h b/src/plugins/qmlprofiler/tests/pixmapcachemodel_test.h index 8a6448bb105..f4f5819f350 100644 --- a/src/plugins/qmlprofiler/tests/pixmapcachemodel_test.h +++ b/src/plugins/qmlprofiler/tests/pixmapcachemodel_test.h @@ -48,6 +48,7 @@ private slots: private: QmlProfilerModelManager manager; + Timeline::TimelineModelAggregator aggregator; PixmapCacheModel model; int eventTypeIndices[2 * MaximumPixmapEventType]; diff --git a/src/plugins/qmlprofiler/tests/qmlprofileranimationsmodel_test.cpp b/src/plugins/qmlprofiler/tests/qmlprofileranimationsmodel_test.cpp index 6b18fde64fb..98e3883c677 100644 --- a/src/plugins/qmlprofiler/tests/qmlprofileranimationsmodel_test.cpp +++ b/src/plugins/qmlprofiler/tests/qmlprofileranimationsmodel_test.cpp @@ -31,7 +31,7 @@ namespace QmlProfiler { namespace Internal { QmlProfilerAnimationsModelTest::QmlProfilerAnimationsModelTest(QObject *parent) : - QObject(parent), manager(nullptr), model(&manager) + QObject(parent), model(&manager, &aggregator) { } diff --git a/src/plugins/qmlprofiler/tests/qmlprofileranimationsmodel_test.h b/src/plugins/qmlprofiler/tests/qmlprofileranimationsmodel_test.h index c53515a2051..4ce91a93ac9 100644 --- a/src/plugins/qmlprofiler/tests/qmlprofileranimationsmodel_test.h +++ b/src/plugins/qmlprofiler/tests/qmlprofileranimationsmodel_test.h @@ -52,6 +52,7 @@ private slots: private: QmlProfilerModelManager manager; + Timeline::TimelineModelAggregator aggregator; QmlProfilerAnimationsModel model; }; diff --git a/src/plugins/qmlprofiler/tests/qmlprofilerbindingloopsrenderpass_test.cpp b/src/plugins/qmlprofiler/tests/qmlprofilerbindingloopsrenderpass_test.cpp index 54e1bb4c133..ab451e04e3c 100644 --- a/src/plugins/qmlprofiler/tests/qmlprofilerbindingloopsrenderpass_test.cpp +++ b/src/plugins/qmlprofiler/tests/qmlprofilerbindingloopsrenderpass_test.cpp @@ -37,12 +37,13 @@ namespace Internal { class DummyModel : public QmlProfilerRangeModel { public: - DummyModel(QmlProfilerModelManager *manager); + DummyModel(QmlProfilerModelManager *manager, Timeline::TimelineModelAggregator *aggregator); void loadData(); }; -DummyModel::DummyModel(QmlProfilerModelManager *manager) : - QmlProfilerRangeModel(manager, Binding) +DummyModel::DummyModel(QmlProfilerModelManager *manager, + Timeline::TimelineModelAggregator *aggregator) : + QmlProfilerRangeModel(manager, Binding, aggregator) { } @@ -90,8 +91,9 @@ void QmlProfilerBindingLoopsRenderPassTest::testUpdate() inst->update(&renderer, &parentState, 0, 0, 0, true, 1); QCOMPARE(result, nullState); - QmlProfilerModelManager manager(nullptr); - DummyModel model(&manager); + QmlProfilerModelManager manager; + Timeline::TimelineModelAggregator aggregator; + DummyModel model(&manager, &aggregator); renderer.setModel(&model); result = inst->update(&renderer, &parentState, 0, 0, 0, true, 1); QCOMPARE(result, nullState); diff --git a/tests/auto/timeline/timelineabstractrenderer/tst_timelineabstractrenderer.cpp b/tests/auto/timeline/timelineabstractrenderer/tst_timelineabstractrenderer.cpp index 10453ffcffe..b2aaab141d0 100644 --- a/tests/auto/timeline/timelineabstractrenderer/tst_timelineabstractrenderer.cpp +++ b/tests/auto/timeline/timelineabstractrenderer/tst_timelineabstractrenderer.cpp @@ -24,6 +24,7 @@ ****************************************************************************/ #include +#include #include using namespace Timeline; @@ -82,10 +83,11 @@ void tst_TimelineAbstractRenderer::selectedItem() void tst_TimelineAbstractRenderer::model() { TimelineAbstractRenderer renderer; + TimelineModelAggregator aggregator; QSignalSpy spy(&renderer, SIGNAL(modelChanged(TimelineModel*))); QVERIFY(!renderer.modelDirty()); QCOMPARE(spy.count(), 0); - TimelineModel model(0); + TimelineModel model(&aggregator); QCOMPARE(renderer.model(), static_cast(0)); renderer.setModel(&model); QVERIFY(renderer.modelDirty()); diff --git a/tests/auto/timeline/timelineitemsrenderpass/tst_timelineitemsrenderpass.cpp b/tests/auto/timeline/timelineitemsrenderpass/tst_timelineitemsrenderpass.cpp index 1f26877f4f5..6bf7f0d8905 100644 --- a/tests/auto/timeline/timelineitemsrenderpass/tst_timelineitemsrenderpass.cpp +++ b/tests/auto/timeline/timelineitemsrenderpass/tst_timelineitemsrenderpass.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -34,7 +35,7 @@ using namespace Timeline; class DummyModel : public TimelineModel { public: - DummyModel(); + DummyModel(TimelineModelAggregator *parent); void loadData(); float relativeHeight(int index) const; }; @@ -48,7 +49,7 @@ private slots: void update(); }; -DummyModel::DummyModel() : TimelineModel(12) +DummyModel::DummyModel(TimelineModelAggregator *parent) : TimelineModel(parent) { } @@ -77,13 +78,14 @@ void tst_TimelineItemsRenderPass::update() { const TimelineItemsRenderPass *inst = TimelineItemsRenderPass::instance(); TimelineAbstractRenderer renderer; + TimelineModelAggregator aggregator; TimelineRenderState parentState(0, 8, 1, 1); TimelineRenderPass::State *nullState = 0; QSGNode *nullNode = 0; TimelineRenderPass::State *result = inst->update(&renderer, &parentState, 0, 0, 0, true, 1); QCOMPARE(result, nullState); - DummyModel model; + DummyModel model(&aggregator); renderer.setModel(&model); result = inst->update(&renderer, &parentState, 0, 0, 0, true, 1); QCOMPARE(result, nullState); diff --git a/tests/auto/timeline/timelinemodel/tst_timelinemodel.cpp b/tests/auto/timeline/timelinemodel/tst_timelinemodel.cpp index eb24474bd44..01a00d02567 100644 --- a/tests/auto/timeline/timelinemodel/tst_timelinemodel.cpp +++ b/tests/auto/timeline/timelinemodel/tst_timelinemodel.cpp @@ -26,6 +26,7 @@ #include #include #include +#include static const int NumItems = 32; static const qint64 ItemDuration = 1 << 19; @@ -36,8 +37,8 @@ class DummyModel : public Timeline::TimelineModel Q_OBJECT friend class tst_TimelineModel; public: - DummyModel(int modelId); - DummyModel(QString displayName = tr("dummy"), QObject *parent = 0); + DummyModel(Timeline::TimelineModelAggregator *parent); + DummyModel(QString displayName, Timeline::TimelineModelAggregator *parent); int expandedRow(int) const { return 2; } int collapsedRow(int) const { return 1; } @@ -54,7 +55,6 @@ public: tst_TimelineModel(); private slots: - void privateModel(); void isEmpty(); void modelId(); void rowHeight(); @@ -77,15 +77,18 @@ private slots: void rowCount(); void prevNext(); void parentingOfEqualStarts(); + +private: + Timeline::TimelineModelAggregator aggregator; }; -DummyModel::DummyModel(int modelId) : - Timeline::TimelineModel(modelId, 0) +DummyModel::DummyModel(Timeline::TimelineModelAggregator *parent) : + Timeline::TimelineModel(parent) { } -DummyModel::DummyModel(QString displayName, QObject *parent) : - TimelineModel(12, parent) +DummyModel::DummyModel(QString displayName, Timeline::TimelineModelAggregator *parent) : + TimelineModel(parent) { setDisplayName(displayName); } @@ -112,15 +115,9 @@ tst_TimelineModel::tst_TimelineModel() : { } -void tst_TimelineModel::privateModel() -{ - DummyModel dummy(15); - QCOMPARE(dummy.modelId(), 15); -} - void tst_TimelineModel::isEmpty() { - DummyModel dummy; + DummyModel dummy(&aggregator); QVERIFY(dummy.isEmpty()); dummy.loadData(); QVERIFY(!dummy.isEmpty()); @@ -130,13 +127,13 @@ void tst_TimelineModel::isEmpty() void tst_TimelineModel::modelId() { - DummyModel dummy; - QCOMPARE(dummy.modelId(), 12); + DummyModel dummy(&aggregator); + QCOMPARE(dummy.modelId(), aggregator.generateModelId() - 1); } void tst_TimelineModel::rowHeight() { - DummyModel dummy; + DummyModel dummy(&aggregator); QCOMPARE(dummy.rowHeight(0), DefaultRowHeight); QCOMPARE(dummy.collapsedRowHeight(0), DefaultRowHeight); QCOMPARE(dummy.expandedRowHeight(0), DefaultRowHeight); @@ -178,7 +175,7 @@ void tst_TimelineModel::rowHeight() void tst_TimelineModel::rowOffset() { - DummyModel dummy; + DummyModel dummy(&aggregator); QCOMPARE(dummy.rowOffset(0), 0); dummy.loadData(); @@ -215,7 +212,7 @@ void tst_TimelineModel::rowOffset() void tst_TimelineModel::height() { - DummyModel dummy; + DummyModel dummy(&aggregator); int heightAfterLastSignal = 0; int heightChangedSignals = 0; connect(&dummy, &Timeline::TimelineModel::heightChanged, [&](){ @@ -258,7 +255,7 @@ void tst_TimelineModel::height() void tst_TimelineModel::count() { - DummyModel dummy; + DummyModel dummy(&aggregator); QCOMPARE(dummy.count(), 0); dummy.loadData(); QCOMPARE(dummy.count(), NumItems); @@ -270,7 +267,7 @@ void tst_TimelineModel::count() void tst_TimelineModel::times() { - DummyModel dummy; + DummyModel dummy(&aggregator); dummy.loadData(); QCOMPARE(dummy.startTime(0), 0); QCOMPARE(dummy.duration(0), ItemDuration * 3 + 2); @@ -280,14 +277,14 @@ void tst_TimelineModel::times() void tst_TimelineModel::selectionId() { - DummyModel dummy; + DummyModel dummy(&aggregator); dummy.loadData(); QCOMPARE(dummy.selectionId(0), 4); } void tst_TimelineModel::firstLast() { - DummyModel dummy; + DummyModel dummy(&aggregator); QCOMPARE(dummy.firstIndex(0), -1); QCOMPARE(dummy.firstIndex(ItemSpacing), -1); QCOMPARE(dummy.lastIndex(0), -1); @@ -307,7 +304,7 @@ void tst_TimelineModel::firstLast() void tst_TimelineModel::expand() { - DummyModel dummy; + DummyModel dummy(&aggregator); QSignalSpy spy(&dummy, SIGNAL(expandedChanged())); QVERIFY(!dummy.expanded()); dummy.setExpanded(true); @@ -326,7 +323,7 @@ void tst_TimelineModel::expand() void tst_TimelineModel::hide() { - DummyModel dummy; + DummyModel dummy(&aggregator); QSignalSpy spy(&dummy, SIGNAL(hiddenChanged())); QVERIFY(!dummy.hidden()); dummy.setHidden(true); @@ -346,7 +343,7 @@ void tst_TimelineModel::hide() void tst_TimelineModel::displayName() { QLatin1String name("testest"); - DummyModel dummy(name); + DummyModel dummy(name, &aggregator); QSignalSpy spy(&dummy, SIGNAL(displayNameChanged())); QCOMPARE(dummy.displayName(), name); QCOMPARE(spy.count(), 0); @@ -361,7 +358,7 @@ void tst_TimelineModel::displayName() void tst_TimelineModel::defaultValues() { - Timeline::TimelineModel dummy(12); + Timeline::TimelineModel dummy(&aggregator); QCOMPARE(dummy.location(0), QVariantMap()); QCOMPARE(dummy.handlesTypeId(0), false); QCOMPARE(dummy.relativeHeight(0), 1.0); @@ -377,7 +374,7 @@ void tst_TimelineModel::defaultValues() void tst_TimelineModel::row() { - DummyModel dummy; + DummyModel dummy(&aggregator); dummy.loadData(); QCOMPARE(dummy.row(0), 1); dummy.setExpanded(true); @@ -386,33 +383,34 @@ void tst_TimelineModel::row() void tst_TimelineModel::colorByHue() { - DummyModel dummy; + Timeline::TimelineModelAggregator aggregator; + DummyModel dummy(&aggregator); QCOMPARE(dummy.colorByHue(10), QColor::fromHsl(10, 150, 166).rgb()); QCOMPARE(dummy.colorByHue(500), QColor::fromHsl(140, 150, 166).rgb()); } void tst_TimelineModel::colorBySelectionId() { - DummyModel dummy; + DummyModel dummy(&aggregator); dummy.loadData(); QCOMPARE(dummy.colorBySelectionId(5), QColor::fromHsl(6 * 25, 150, 166).rgb()); } void tst_TimelineModel::colorByFraction() { - DummyModel dummy; + DummyModel dummy(&aggregator); QCOMPARE(dummy.colorByFraction(0.5), QColor::fromHsl(0.5 * 96 + 10, 150, 166).rgb()); } void tst_TimelineModel::supportedRenderPasses() { - DummyModel dummy; + DummyModel dummy(&aggregator); QVERIFY(!dummy.supportedRenderPasses().isEmpty()); } void tst_TimelineModel::insertStartEnd() { - DummyModel dummy; + DummyModel dummy(&aggregator); int id = dummy.insertStart(10, 0); dummy.insertEnd(id, 10); QCOMPARE(dummy.startTime(id), 10); @@ -433,7 +431,7 @@ void tst_TimelineModel::insertStartEnd() void tst_TimelineModel::rowCount() { - DummyModel dummy; + DummyModel dummy(&aggregator); QSignalSpy expandedSpy(&dummy, SIGNAL(expandedRowCountChanged())); QSignalSpy collapsedSpy(&dummy, SIGNAL(collapsedRowCountChanged())); QCOMPARE(dummy.rowCount(), 1); @@ -453,7 +451,7 @@ void tst_TimelineModel::rowCount() void tst_TimelineModel::prevNext() { - DummyModel dummy; + DummyModel dummy(&aggregator); QCOMPARE(dummy.nextItemBySelectionId(5, 10, 5), -1); QCOMPARE(dummy.prevItemBySelectionId(5, 10, 5), -1); @@ -474,7 +472,7 @@ void tst_TimelineModel::prevNext() void tst_TimelineModel::parentingOfEqualStarts() { - DummyModel dummy; + DummyModel dummy(&aggregator); // Trick it so that it cannot reorder the events and has to parent them in the "wrong" way ... QCOMPARE(dummy.insert(1, 10, 998), 0); QCOMPARE(dummy.insertStart(1, 999), 1); diff --git a/tests/auto/timeline/timelinemodelaggregator/tst_timelinemodelaggregator.cpp b/tests/auto/timeline/timelinemodelaggregator/tst_timelinemodelaggregator.cpp index 5776e387522..70ca024f70d 100644 --- a/tests/auto/timeline/timelinemodelaggregator/tst_timelinemodelaggregator.cpp +++ b/tests/auto/timeline/timelinemodelaggregator/tst_timelinemodelaggregator.cpp @@ -38,7 +38,7 @@ private slots: class HeightTestModel : public Timeline::TimelineModel { public: - HeightTestModel() : TimelineModel(2) + HeightTestModel(Timeline::TimelineModelAggregator *parent) : TimelineModel(parent) { insert(0, 1, 1); } @@ -46,15 +46,15 @@ public: void tst_TimelineModelAggregator::height() { - Timeline::TimelineModelAggregator aggregator(0); + Timeline::TimelineModelAggregator aggregator; QCOMPARE(aggregator.height(), 0); QSignalSpy heightSpy(&aggregator, SIGNAL(heightChanged())); - Timeline::TimelineModel *model = new Timeline::TimelineModel(25); + Timeline::TimelineModel *model = new Timeline::TimelineModel(&aggregator); aggregator.addModel(model); QCOMPARE(aggregator.height(), 0); QCOMPARE(heightSpy.count(), 0); - aggregator.addModel(new HeightTestModel); + aggregator.addModel(new HeightTestModel(&aggregator)); QVERIFY(aggregator.height() > 0); QCOMPARE(heightSpy.count(), 1); aggregator.clear(); @@ -70,8 +70,8 @@ void tst_TimelineModelAggregator::addRemoveModel() QCOMPARE(aggregator.notes(), ¬es); - Timeline::TimelineModel *model1 = new Timeline::TimelineModel(25); - Timeline::TimelineModel *model2 = new Timeline::TimelineModel(26); + Timeline::TimelineModel *model1 = new Timeline::TimelineModel(&aggregator); + Timeline::TimelineModel *model2 = new Timeline::TimelineModel(&aggregator); aggregator.addModel(model1); QCOMPARE(spy.count(), 1); QCOMPARE(aggregator.modelCount(), 1); @@ -84,9 +84,9 @@ void tst_TimelineModelAggregator::addRemoveModel() QCOMPARE(aggregator.model(1), model2); QCOMPARE(aggregator.models().count(), 2); - QCOMPARE(aggregator.modelIndexById(25), 0); - QCOMPARE(aggregator.modelIndexById(26), 1); - QCOMPARE(aggregator.modelIndexById(27), -1); + QCOMPARE(aggregator.modelIndexById(model1->modelId()), 0); + QCOMPARE(aggregator.modelIndexById(model2->modelId()), 1); + QCOMPARE(aggregator.modelIndexById(aggregator.generateModelId()), -1); QCOMPARE(aggregator.modelOffset(0), 0); QCOMPARE(aggregator.modelOffset(1), 0); @@ -99,22 +99,23 @@ void tst_TimelineModelAggregator::addRemoveModel() class PrevNextTestModel : public Timeline::TimelineModel { public: - PrevNextTestModel(int x) : TimelineModel(x) + PrevNextTestModel(Timeline::TimelineModelAggregator *parent) : TimelineModel(parent) { for (int i = 0; i < 20; ++i) - insert(i + x, i * x, x); + insert(i + modelId(), i * modelId(), modelId()); } }; void tst_TimelineModelAggregator::prevNext() { - Timeline::TimelineModelAggregator aggregator(0); - aggregator.addModel(new PrevNextTestModel(1)); - aggregator.addModel(new PrevNextTestModel(2)); - aggregator.addModel(new PrevNextTestModel(3)); + Timeline::TimelineModelAggregator aggregator; + aggregator.generateModelId(); // start modelIds at 1 + aggregator.addModel(new PrevNextTestModel(&aggregator)); + aggregator.addModel(new PrevNextTestModel(&aggregator)); + aggregator.addModel(new PrevNextTestModel(&aggregator)); // Add an empty model to trigger the special code paths that skip it - aggregator.addModel(new Timeline::TimelineModel(4)); + aggregator.addModel(new Timeline::TimelineModel(&aggregator)); QLatin1String item("item"); QLatin1String model("model"); QVariantMap result; diff --git a/tests/auto/timeline/timelinenotesmodel/tst_timelinenotesmodel.cpp b/tests/auto/timeline/timelinenotesmodel/tst_timelinenotesmodel.cpp index df0f977cdee..125f9ad995e 100644 --- a/tests/auto/timeline/timelinenotesmodel/tst_timelinenotesmodel.cpp +++ b/tests/auto/timeline/timelinenotesmodel/tst_timelinenotesmodel.cpp @@ -25,6 +25,7 @@ #include #include +#include #include class tst_TimelineNotesModel : public QObject @@ -37,11 +38,14 @@ private slots: void properties(); void selection(); void modify(); + +private: + Timeline::TimelineModelAggregator aggregator; }; class TestModel : public Timeline::TimelineModel { public: - TestModel(int modelId = 10) : TimelineModel(modelId) + TestModel(Timeline::TimelineModelAggregator *parent) : TimelineModel(parent) { insert(0, 10, 10); } @@ -59,11 +63,11 @@ class TestNotesModel : public Timeline::TimelineNotesModel { void tst_TimelineNotesModel::timelineModel() { TestNotesModel notes; - TestModel *model = new TestModel; - TestModel *model2 = new TestModel(2); + TestModel *model = new TestModel(&aggregator); + TestModel *model2 = new TestModel(&aggregator); notes.addTimelineModel(model); notes.addTimelineModel(model2); - QCOMPARE(notes.timelineModelByModelId(10), model); + QCOMPARE(notes.timelineModelByModelId(model->modelId()), model); QCOMPARE(notes.timelineModels().count(), 2); QVERIFY(notes.timelineModels().contains(model)); QVERIFY(notes.timelineModels().contains(model2)); @@ -78,11 +82,11 @@ void tst_TimelineNotesModel::timelineModel() void tst_TimelineNotesModel::addRemove() { TestNotesModel notes; - TestModel model; + TestModel model(&aggregator); notes.addTimelineModel(&model); QSignalSpy spy(¬es, SIGNAL(changed(int,int,int))); - int id = notes.add(10, 0, QLatin1String("xyz")); + int id = notes.add(model.modelId(), 0, QLatin1String("xyz")); QCOMPARE(spy.count(), 1); QCOMPARE(notes.isModified(), true); QCOMPARE(notes.count(), 1); @@ -99,32 +103,34 @@ void tst_TimelineNotesModel::properties() TestNotesModel notes; int id = -1; + int modelId = -1; { - TestModel model; + TestModel model(&aggregator); + modelId = model.modelId(); notes.addTimelineModel(&model); - id = notes.add(10, 0, QLatin1String("xyz")); + id = notes.add(model.modelId(), 0, QLatin1String("xyz")); QVERIFY(id >= 0); QCOMPARE(notes.typeId(id), 7); QCOMPARE(notes.timelineIndex(id), 0); - QCOMPARE(notes.timelineModel(id), 10); + QCOMPARE(notes.timelineModel(id), modelId); QCOMPARE(notes.text(id), QLatin1String("xyz")); } QCOMPARE(notes.typeId(id), -1); // cannot ask the model anymore QCOMPARE(notes.timelineIndex(id), 0); - QCOMPARE(notes.timelineModel(id), 10); + QCOMPARE(notes.timelineModel(id), modelId); QCOMPARE(notes.text(id), QLatin1String("xyz")); } void tst_TimelineNotesModel::selection() { TestNotesModel notes; - TestModel model; + TestModel model(&aggregator); notes.addTimelineModel(&model); - int id1 = notes.add(10, 0, QLatin1String("blablub")); - int id2 = notes.add(10, 0, QLatin1String("xyz")); - QVariantList ids = notes.byTimelineModel(10); + int id1 = notes.add(model.modelId(), 0, QLatin1String("blablub")); + int id2 = notes.add(model.modelId(), 0, QLatin1String("xyz")); + QVariantList ids = notes.byTimelineModel(model.modelId()); QCOMPARE(ids.length(), 2); QVERIFY(ids.contains(id1)); QVERIFY(ids.contains(id2)); @@ -134,19 +140,19 @@ void tst_TimelineNotesModel::selection() QVERIFY(ids.contains(id1)); QVERIFY(ids.contains(id2)); - int got = notes.get(10, 0); + int got = notes.get(model.modelId(), 0); QVERIFY(got == id1 || got == id2); - QCOMPARE(notes.get(10, 20), -1); - QCOMPARE(notes.get(20, 10), -1); + QCOMPARE(notes.get(model.modelId(), 20), -1); + QCOMPARE(notes.get(model.modelId() + 10, 10), -1); } void tst_TimelineNotesModel::modify() { TestNotesModel notes; - TestModel model; + TestModel model(&aggregator); notes.addTimelineModel(&model); QSignalSpy spy(¬es, SIGNAL(changed(int,int,int))); - int id = notes.add(10, 0, QLatin1String("a")); + int id = notes.add(model.modelId(), 0, QLatin1String("a")); QCOMPARE(spy.count(), 1); notes.resetModified(); notes.update(id, QLatin1String("b")); @@ -165,15 +171,15 @@ void tst_TimelineNotesModel::modify() QCOMPARE(notes.text(id), QLatin1String("a")); notes.resetModified(); - notes.setText(10, 0, QLatin1String("x")); + notes.setText(model.modelId(), 0, QLatin1String("x")); QVERIFY(notes.isModified()); QCOMPARE(spy.count(), 4); QCOMPARE(notes.text(id), QLatin1String("x")); notes.resetModified(); - TestModel model2(9); + TestModel model2(&aggregator); notes.addTimelineModel(&model2); - notes.setText(9, 0, QLatin1String("hh")); + notes.setText(model2.modelId(), 0, QLatin1String("hh")); QVERIFY(notes.isModified()); QCOMPARE(spy.count(), 5); QCOMPARE(notes.count(), 2); diff --git a/tests/auto/timeline/timelinenotesrenderpass/tst_timelinenotesrenderpass.cpp b/tests/auto/timeline/timelinenotesrenderpass/tst_timelinenotesrenderpass.cpp index b67d10536a4..9e238a1e429 100644 --- a/tests/auto/timeline/timelinenotesrenderpass/tst_timelinenotesrenderpass.cpp +++ b/tests/auto/timeline/timelinenotesrenderpass/tst_timelinenotesrenderpass.cpp @@ -24,6 +24,7 @@ ****************************************************************************/ #include +#include #include #include #include @@ -35,7 +36,7 @@ using namespace Timeline; class DummyModel : public TimelineModel { public: - DummyModel(int id = 12); + DummyModel(TimelineModelAggregator *parent); void loadData(); }; @@ -48,7 +49,7 @@ private slots: void update(); }; -DummyModel::DummyModel(int id) : TimelineModel(id) +DummyModel::DummyModel(TimelineModelAggregator *parent) : TimelineModel(parent) { } @@ -70,14 +71,15 @@ void tst_TimelineNotesRenderPass::update() { const TimelineNotesRenderPass *inst = TimelineNotesRenderPass::instance(); TimelineAbstractRenderer renderer; + TimelineModelAggregator aggregator; TimelineRenderState parentState(0, 8, 1, 1); TimelineRenderPass::State *nullState = 0; QSGNode *nullNode = 0; TimelineRenderPass::State *result = inst->update(&renderer, &parentState, 0, 0, 0, true, 1); QCOMPARE(result, nullState); - DummyModel model; - DummyModel otherModel(13); + DummyModel model(&aggregator); + DummyModel otherModel(&aggregator); TimelineNotesModel notes; notes.addTimelineModel(&model); @@ -104,9 +106,9 @@ void tst_TimelineNotesRenderPass::update() 1); QCOMPARE(result2, result); - notes.add(12, 0, QLatin1String("x")); - notes.add(12, 9, QLatin1String("xx")); - notes.add(13, 0, QLatin1String("y")); + notes.add(model.modelId(), 0, QLatin1String("x")); + notes.add(model.modelId(), 9, QLatin1String("xx")); + notes.add(otherModel.modelId(), 0, QLatin1String("y")); QVERIFY(renderer.notesDirty()); result = inst->update(&renderer, &parentState, result, 0, 0, true, 1); QVERIFY(result != nullState); diff --git a/tests/auto/timeline/timelineoverviewrenderer/tst_timelineoverviewrenderer.cpp b/tests/auto/timeline/timelineoverviewrenderer/tst_timelineoverviewrenderer.cpp index c7049c27bc2..97371c4de62 100644 --- a/tests/auto/timeline/timelineoverviewrenderer/tst_timelineoverviewrenderer.cpp +++ b/tests/auto/timeline/timelineoverviewrenderer/tst_timelineoverviewrenderer.cpp @@ -24,6 +24,7 @@ ****************************************************************************/ #include +#include #include using namespace Timeline; @@ -34,7 +35,7 @@ class DummyRenderer : public TimelineOverviewRenderer { class DummyModel : public TimelineModel { public: - DummyModel() : TimelineModel(0) {} + DummyModel(TimelineModelAggregator *parent) : TimelineModel(parent) {} void loadData() { @@ -57,8 +58,9 @@ private slots: void tst_TimelineOverviewRenderer::updatePaintNode() { DummyRenderer renderer; + TimelineModelAggregator aggregator; QCOMPARE(renderer.updatePaintNode(0, 0), static_cast(0)); - DummyModel model; + DummyModel model(&aggregator); renderer.setModel(&model); QCOMPARE(renderer.updatePaintNode(0, 0), static_cast(0)); model.loadData(); diff --git a/tests/auto/timeline/timelinerenderer/tst_timelinerenderer.cpp b/tests/auto/timeline/timelinerenderer/tst_timelinerenderer.cpp index b657cb0649b..a18886b551a 100644 --- a/tests/auto/timeline/timelinerenderer/tst_timelinerenderer.cpp +++ b/tests/auto/timeline/timelinerenderer/tst_timelinerenderer.cpp @@ -24,6 +24,7 @@ ****************************************************************************/ #include +#include #include using namespace Timeline; @@ -34,7 +35,7 @@ class DummyRenderer : public TimelineRenderer { class DummyModel : public TimelineModel { public: - DummyModel() : TimelineModel(0) {} + DummyModel(TimelineModelAggregator *parent) : TimelineModel(parent) {} void loadData() { @@ -55,6 +56,7 @@ class tst_TimelineRenderer : public QObject private: void testMouseEvents(DummyRenderer *renderer, int x, int y); + TimelineModelAggregator aggregator; private slots: void updatePaintNode(); @@ -65,7 +67,7 @@ void tst_TimelineRenderer::updatePaintNode() { DummyRenderer renderer; QCOMPARE(renderer.updatePaintNode(0, 0), static_cast(0)); - DummyModel model; + DummyModel model(&aggregator); renderer.setModel(&model); QCOMPARE(renderer.updatePaintNode(0, 0), static_cast(0)); model.loadData(); @@ -124,7 +126,7 @@ void tst_TimelineRenderer::mouseEvents() QCOMPARE(renderer.selectedItem(), -1); QCOMPARE(renderer.selectionLocked(), true); - DummyModel model; + DummyModel model(&aggregator); renderer.setModel(&model); testMouseEvents(&renderer, 1, 1); QCOMPARE(renderer.selectedItem(), -1); diff --git a/tests/auto/timeline/timelinerenderstate/tst_timelinerenderstate.cpp b/tests/auto/timeline/timelinerenderstate/tst_timelinerenderstate.cpp index 647c7f32e42..6c033a19165 100644 --- a/tests/auto/timeline/timelinerenderstate/tst_timelinerenderstate.cpp +++ b/tests/auto/timeline/timelinerenderstate/tst_timelinerenderstate.cpp @@ -23,6 +23,7 @@ ** ****************************************************************************/ +#include #include #include #include @@ -140,7 +141,8 @@ void tst_TimelineRenderState::emptyRoots() void tst_TimelineRenderState::assembleNodeTree() { - TimelineModel model(3); + TimelineModelAggregator aggregator; + TimelineModel model(&aggregator); TimelineRenderState state1(1, 2, 0.5, 3); state1.assembleNodeTree(&model, 30, 30); QSGTransformNode *node = state1.finalize(0, true, QMatrix4x4()); diff --git a/tests/auto/timeline/timelineselectionrenderpass/tst_timelineselectionrenderpass.cpp b/tests/auto/timeline/timelineselectionrenderpass/tst_timelineselectionrenderpass.cpp index b718dacdf86..85192bffe4c 100644 --- a/tests/auto/timeline/timelineselectionrenderpass/tst_timelineselectionrenderpass.cpp +++ b/tests/auto/timeline/timelineselectionrenderpass/tst_timelineselectionrenderpass.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -37,7 +38,7 @@ using namespace Timeline; class DummyModel : public TimelineModel { public: - DummyModel(int id = 12); + DummyModel(TimelineModelAggregator *parent); void loadData(); float relativeHeight(int index) const; }; @@ -51,7 +52,7 @@ private slots: void update(); }; -DummyModel::DummyModel(int id) : TimelineModel(id) +DummyModel::DummyModel(TimelineModelAggregator *parent) : TimelineModel(parent) { } @@ -112,13 +113,14 @@ void tst_TimelineSelectionRenderPass::update() { const TimelineSelectionRenderPass *inst = TimelineSelectionRenderPass::instance(); TimelineAbstractRenderer renderer; + TimelineModelAggregator aggregator; TimelineRenderState parentState(0, 400, 1, 1); TimelineRenderPass::State *nullState = 0; QSGNode *nullNode = 0; TimelineRenderPass::State *result = inst->update(&renderer, &parentState, 0, 0, 10, true, 1); QCOMPARE(result, nullState); - DummyModel model; + DummyModel model(&aggregator); result = inst->update(&renderer, &parentState, 0, 0, 10, true, 1); QCOMPARE(result, nullState);