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 <tobias.hunger@qt.io>
This commit is contained in:
Ulf Hermann
2018-03-28 15:40:13 +02:00
parent 181ad6671c
commit 780d4c6a43
49 changed files with 188 additions and 141 deletions

View File

@@ -25,6 +25,7 @@
#include "timelinemodel.h" #include "timelinemodel.h"
#include "timelinemodel_p.h" #include "timelinemodel_p.h"
#include "timelinemodelaggregator.h"
#include "timelineitemsrenderpass.h" #include "timelineitemsrenderpass.h"
#include "timelineselectionrenderpass.h" #include "timelineselectionrenderpass.h"
#include "timelinenotesrenderpass.h" #include "timelinenotesrenderpass.h"
@@ -157,8 +158,8 @@ TimelineModel::TimelineModelPrivate::TimelineModelPrivate(int modelId) :
{ {
} }
TimelineModel::TimelineModel(int modelId, QObject *parent) : TimelineModel::TimelineModel(TimelineModelAggregator *parent) :
QObject(parent), d_ptr(new TimelineModelPrivate(modelId)) QObject(parent), d_ptr(new TimelineModelPrivate(parent->generateModelId()))
{ {
connect(this, &TimelineModel::contentChanged, this, &TimelineModel::labelsChanged); connect(this, &TimelineModel::contentChanged, this, &TimelineModel::labelsChanged);
connect(this, &TimelineModel::contentChanged, this, &TimelineModel::detailsChanged); connect(this, &TimelineModel::contentChanged, this, &TimelineModel::detailsChanged);

View File

@@ -31,6 +31,7 @@
#include <QColor> #include <QColor>
namespace Timeline { namespace Timeline {
class TimelineModelAggregator;
class TIMELINE_EXPORT TimelineModel : public QObject class TIMELINE_EXPORT TimelineModel : public QObject
{ {
@@ -51,7 +52,7 @@ class TIMELINE_EXPORT TimelineModel : public QObject
public: public:
class TimelineModelPrivate; class TimelineModelPrivate;
TimelineModel(int modelId, QObject *parent = 0); TimelineModel(TimelineModelAggregator *parent);
~TimelineModel(); ~TimelineModel();
// Methods implemented by the abstract model itself // Methods implemented by the abstract model itself

View File

@@ -39,6 +39,7 @@ class TimelineModelAggregator::TimelineModelAggregatorPrivate {
public: public:
QList <TimelineModel *> modelList; QList <TimelineModel *> modelList;
TimelineNotesModel *notesModel; TimelineNotesModel *notesModel;
int currentModelId = 0;
}; };
TimelineModelAggregator::TimelineModelAggregator(TimelineNotesModel *notes, QObject *parent) TimelineModelAggregator::TimelineModelAggregator(TimelineNotesModel *notes, QObject *parent)
@@ -60,6 +61,12 @@ int TimelineModelAggregator::height() const
return modelOffset(d->modelList.length()); return modelOffset(d->modelList.length());
} }
int TimelineModelAggregator::generateModelId()
{
Q_D(TimelineModelAggregator);
return d->currentModelId++;
}
void TimelineModelAggregator::addModel(TimelineModel *m) void TimelineModelAggregator::addModel(TimelineModel *m)
{ {
Q_D(TimelineModelAggregator); Q_D(TimelineModelAggregator);

View File

@@ -37,10 +37,11 @@ class TIMELINE_EXPORT TimelineModelAggregator : public QObject
Q_PROPERTY(QVariantList models READ models WRITE setModels NOTIFY modelsChanged) Q_PROPERTY(QVariantList models READ models WRITE setModels NOTIFY modelsChanged)
Q_PROPERTY(Timeline::TimelineNotesModel *notes READ notes CONSTANT) Q_PROPERTY(Timeline::TimelineNotesModel *notes READ notes CONSTANT)
public: public:
TimelineModelAggregator(TimelineNotesModel *notes, QObject *parent = 0); TimelineModelAggregator(TimelineNotesModel *notes = nullptr, QObject *parent = nullptr);
~TimelineModelAggregator(); ~TimelineModelAggregator();
int height() const; int height() const;
int generateModelId();
void addModel(TimelineModel *m); void addModel(TimelineModel *m);
const TimelineModel *model(int modelIndex) const; const TimelineModel *model(int modelIndex) const;

View File

@@ -30,7 +30,8 @@
namespace QmlProfiler { namespace QmlProfiler {
namespace Internal { namespace Internal {
DebugMessagesModel::DebugMessagesModel(QmlProfilerModelManager *manager, QObject *parent) : DebugMessagesModel::DebugMessagesModel(QmlProfilerModelManager *manager,
Timeline::TimelineModelAggregator *parent) :
QmlProfilerTimelineModel(manager, DebugMessage, MaximumRangeType, ProfileDebugMessages, parent), QmlProfilerTimelineModel(manager, DebugMessage, MaximumRangeType, ProfileDebugMessages, parent),
m_maximumMsgType(-1) m_maximumMsgType(-1)
{ {

View File

@@ -35,7 +35,7 @@ class DebugMessagesModel : public QmlProfilerTimelineModel
Q_OBJECT Q_OBJECT
public: public:
DebugMessagesModel(QmlProfilerModelManager *manager, QObject *parent = 0); DebugMessagesModel(QmlProfilerModelManager *manager, Timeline::TimelineModelAggregator *parent);
int typeId(int index) const override; int typeId(int index) const override;
QRgb color(int index) const override; QRgb color(int index) const override;

View File

@@ -57,7 +57,6 @@ FlameGraphModel::FlameGraphModel(QmlProfilerModelManager *modelManager,
this, &FlameGraphModel::onTypeDetailsFinished); this, &FlameGraphModel::onTypeDetailsFinished);
connect(modelManager->notesModel(), &Timeline::TimelineNotesModel::changed, connect(modelManager->notesModel(), &Timeline::TimelineNotesModel::changed,
this, [this](int typeId, int, int){loadNotes(typeId, true);}); this, [this](int typeId, int, int){loadNotes(typeId, true);});
m_modelId = modelManager->registerModelProxy();
m_acceptedFeatures = supportedFeatures(); m_acceptedFeatures = supportedFeatures();
modelManager->announceFeatures(m_acceptedFeatures, modelManager->announceFeatures(m_acceptedFeatures,

View File

@@ -36,7 +36,8 @@
namespace QmlProfiler { namespace QmlProfiler {
namespace Internal { namespace Internal {
InputEventsModel::InputEventsModel(QmlProfilerModelManager *manager, QObject *parent) : InputEventsModel::InputEventsModel(QmlProfilerModelManager *manager,
Timeline::TimelineModelAggregator *parent) :
QmlProfilerTimelineModel(manager, Event, MaximumRangeType, ProfileInputEvents, parent), QmlProfilerTimelineModel(manager, Event, MaximumRangeType, ProfileInputEvents, parent),
m_keyTypeId(-1), m_mouseTypeId(-1) m_keyTypeId(-1), m_mouseTypeId(-1)
{ {

View File

@@ -42,7 +42,7 @@ public:
int b; int b;
}; };
InputEventsModel(QmlProfilerModelManager *manager, QObject *parent = 0); InputEventsModel(QmlProfilerModelManager *manager, Timeline::TimelineModelAggregator *parent);
bool accepted(const QmlEventType &type) const override; bool accepted(const QmlEventType &type) const override;
void loadEvent(const QmlEvent &event, const QmlEventType &type) override; void loadEvent(const QmlEvent &event, const QmlEventType &type) override;

View File

@@ -32,7 +32,8 @@
namespace QmlProfiler { namespace QmlProfiler {
namespace Internal { namespace Internal {
MemoryUsageModel::MemoryUsageModel(QmlProfilerModelManager *manager, QObject *parent) : MemoryUsageModel::MemoryUsageModel(QmlProfilerModelManager *manager,
Timeline::TimelineModelAggregator *parent) :
QmlProfilerTimelineModel(manager, MemoryAllocation, MaximumRangeType, ProfileMemory, parent) QmlProfilerTimelineModel(manager, MemoryAllocation, MaximumRangeType, ProfileMemory, parent)
{ {
// Announce additional features. The base class already announces the main feature. // Announce additional features. The base class already announces the main feature.

View File

@@ -51,7 +51,7 @@ public:
void update(qint64 amount); void update(qint64 amount);
}; };
MemoryUsageModel(QmlProfilerModelManager *manager, QObject *parent = 0); MemoryUsageModel(QmlProfilerModelManager *manager, Timeline::TimelineModelAggregator *parent);
qint64 rowMaxValue(int rowNumber) const override; qint64 rowMaxValue(int rowNumber) const override;

View File

@@ -32,7 +32,8 @@
namespace QmlProfiler { namespace QmlProfiler {
namespace Internal { namespace Internal {
PixmapCacheModel::PixmapCacheModel(QmlProfilerModelManager *manager, QObject *parent) : PixmapCacheModel::PixmapCacheModel(QmlProfilerModelManager *manager,
Timeline::TimelineModelAggregator *parent) :
QmlProfilerTimelineModel(manager, PixmapCacheEvent, MaximumRangeType, ProfilePixmapCache, QmlProfilerTimelineModel(manager, PixmapCacheEvent, MaximumRangeType, ProfilePixmapCache,
parent) parent)
{ {

View File

@@ -94,7 +94,7 @@ public:
qint64 cacheSize = 0; qint64 cacheSize = 0;
}; };
PixmapCacheModel(QmlProfilerModelManager *manager, QObject *parent = 0); PixmapCacheModel(QmlProfilerModelManager *manager, Timeline::TimelineModelAggregator *parent);
qint64 rowMaxValue(int rowNumber) const override; qint64 rowMaxValue(int rowNumber) const override;

View File

@@ -41,7 +41,7 @@ namespace QmlProfiler {
namespace Internal { namespace Internal {
QmlProfilerAnimationsModel::QmlProfilerAnimationsModel(QmlProfilerModelManager *manager, QmlProfilerAnimationsModel::QmlProfilerAnimationsModel(QmlProfilerModelManager *manager,
QObject *parent) : Timeline::TimelineModelAggregator *parent) :
QmlProfilerTimelineModel(manager, Event, MaximumRangeType, ProfileAnimations, parent) QmlProfilerTimelineModel(manager, Event, MaximumRangeType, ProfileAnimations, parent)
{ {
m_minNextStartTimes[0] = m_minNextStartTimes[1] = 0; m_minNextStartTimes[0] = m_minNextStartTimes[1] = 0;

View File

@@ -49,7 +49,8 @@ public:
int typeId; int typeId;
}; };
QmlProfilerAnimationsModel(QmlProfilerModelManager *manager, QObject *parent = 0); QmlProfilerAnimationsModel(QmlProfilerModelManager *manager,
Timeline::TimelineModelAggregator *parent);
qint64 rowMaxValue(int rowNumber) const override; qint64 rowMaxValue(int rowNumber) const override;

View File

@@ -76,7 +76,6 @@ public:
QmlProfilerModelManager::State state = Empty; QmlProfilerModelManager::State state = Empty;
int numRegisteredModels = 0;
int numFinishedFinalizers = 0; int numFinishedFinalizers = 0;
int numLoadedEvents = 0; int numLoadedEvents = 0;
@@ -193,11 +192,6 @@ int QmlProfilerModelManager::numEventTypes() const
return d->eventTypes.count(); return d->eventTypes.count();
} }
int QmlProfilerModelManager::registerModelProxy()
{
return d->numRegisteredModels++;
}
int QmlProfilerModelManager::numFinishedFinalizers() const int QmlProfilerModelManager::numFinishedFinalizers() const
{ {
return d->numFinishedFinalizers; return d->numFinishedFinalizers;

View File

@@ -76,7 +76,6 @@ public:
int numEvents() const; int numEvents() const;
int numEventTypes() const; int numEventTypes() const;
int registerModelProxy();
void announceFeatures(quint64 features, EventLoader eventLoader, Finalizer finalizer); void announceFeatures(quint64 features, EventLoader eventLoader, Finalizer finalizer);
int numFinishedFinalizers() const; int numFinishedFinalizers() const;

View File

@@ -43,7 +43,7 @@ namespace QmlProfiler {
namespace Internal { namespace Internal {
QmlProfilerRangeModel::QmlProfilerRangeModel(QmlProfilerModelManager *manager, RangeType range, QmlProfilerRangeModel::QmlProfilerRangeModel(QmlProfilerModelManager *manager, RangeType range,
QObject *parent) : Timeline::TimelineModelAggregator *parent) :
QmlProfilerTimelineModel(manager, MaximumMessage, range, featureFromRangeType(range), parent) QmlProfilerTimelineModel(manager, MaximumMessage, range, featureFromRangeType(range), parent)
{ {
m_expandedRowTypes << -1; m_expandedRowTypes << -1;

View File

@@ -56,7 +56,8 @@ public:
int bindingLoopHead; 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 expandedRow(int index) const override;
Q_INVOKABLE int collapsedRow(int index) const override; Q_INVOKABLE int collapsedRow(int index) const override;

View File

@@ -70,7 +70,6 @@ QmlProfilerStatisticsModel::QmlProfilerStatisticsModel(QmlProfilerModelManager *
this, &QmlProfilerStatisticsModel::modelManagerStateChanged); this, &QmlProfilerStatisticsModel::modelManagerStateChanged);
connect(modelManager->notesModel(), &Timeline::TimelineNotesModel::changed, connect(modelManager->notesModel(), &Timeline::TimelineNotesModel::changed,
this, &QmlProfilerStatisticsModel::notesChanged); this, &QmlProfilerStatisticsModel::notesChanged);
modelManager->registerModelProxy();
m_acceptedTypes << Compiling << Creating << Binding << HandlingSignal << Javascript; m_acceptedTypes << Compiling << Creating << Binding << HandlingSignal << Javascript;

View File

@@ -29,9 +29,9 @@ namespace QmlProfiler {
QmlProfilerTimelineModel::QmlProfilerTimelineModel(QmlProfilerModelManager *modelManager, QmlProfilerTimelineModel::QmlProfilerTimelineModel(QmlProfilerModelManager *modelManager,
Message message, RangeType rangeType, Message message, RangeType rangeType,
ProfileFeature mainFeature, QObject *parent) : ProfileFeature mainFeature,
TimelineModel(modelManager->registerModelProxy(), parent), Timeline::TimelineModelAggregator *parent) :
m_message(message), m_rangeType(rangeType), m_mainFeature(mainFeature), TimelineModel(parent), m_message(message), m_rangeType(rangeType), m_mainFeature(mainFeature),
m_modelManager(modelManager) m_modelManager(modelManager)
{ {
setDisplayName(tr(QmlProfilerModelManager::featureName(mainFeature))); setDisplayName(tr(QmlProfilerModelManager::featureName(mainFeature)));

View File

@@ -28,6 +28,7 @@
#include "qmlprofiler_global.h" #include "qmlprofiler_global.h"
#include "qmlprofilermodelmanager.h" #include "qmlprofilermodelmanager.h"
#include "timeline/timelinemodel.h" #include "timeline/timelinemodel.h"
#include "timeline/timelinemodelaggregator.h"
namespace QmlProfiler { namespace QmlProfiler {
@@ -39,7 +40,8 @@ class QMLPROFILER_EXPORT QmlProfilerTimelineModel : public Timeline::TimelineMod
public: public:
QmlProfilerTimelineModel(QmlProfilerModelManager *modelManager, Message message, QmlProfilerTimelineModel(QmlProfilerModelManager *modelManager, Message message,
RangeType rangeType, ProfileFeature mainFeature, QObject *parent); RangeType rangeType, ProfileFeature mainFeature,
Timeline::TimelineModelAggregator *parent);
QmlProfilerModelManager *modelManager() const; QmlProfilerModelManager *modelManager() const;

View File

@@ -76,7 +76,7 @@ Q_STATIC_ASSERT(sizeof(StageLabels) ==
SceneGraphTimelineModel::MaximumSceneGraphStage * sizeof(const char *)); SceneGraphTimelineModel::MaximumSceneGraphStage * sizeof(const char *));
SceneGraphTimelineModel::SceneGraphTimelineModel(QmlProfilerModelManager *manager, SceneGraphTimelineModel::SceneGraphTimelineModel(QmlProfilerModelManager *manager,
QObject *parent) : Timeline::TimelineModelAggregator *parent) :
QmlProfilerTimelineModel(manager, SceneGraphFrame, MaximumRangeType, ProfileSceneGraph, parent) QmlProfilerTimelineModel(manager, SceneGraphFrame, MaximumRangeType, ProfileSceneGraph, parent)
{ {
} }

View File

@@ -82,7 +82,8 @@ public:
int glyphCount; // only used for one event type 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 expandedRow(int index) const override;
int collapsedRow(int index) const override; int collapsedRow(int index) const override;

View File

@@ -33,7 +33,7 @@ namespace QmlProfiler {
namespace Internal { namespace Internal {
DebugMessagesModelTest::DebugMessagesModelTest(QObject *parent) : DebugMessagesModelTest::DebugMessagesModelTest(QObject *parent) :
QObject(parent), manager(nullptr), model(&manager) QObject(parent), model(&manager, &aggregator)
{ {
} }

View File

@@ -51,6 +51,7 @@ private slots:
private: private:
QmlProfilerModelManager manager; QmlProfilerModelManager manager;
Timeline::TimelineModelAggregator aggregator;
DebugMessagesModel model; DebugMessagesModel model;
}; };

View File

@@ -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 // Notes only work with timeline models
QmlProfilerRangeModel *rangeModel = new QmlProfilerRangeModel(manager, Javascript, manager); QmlProfilerRangeModel *rangeModel = new QmlProfilerRangeModel(manager, Javascript, aggregator);
int rangeModelId = rangeModel->modelId(); int rangeModelId = rangeModel->modelId();
manager->notesModel()->addTimelineModel(rangeModel); manager->notesModel()->addTimelineModel(rangeModel);
@@ -95,7 +96,7 @@ int FlameGraphModelTest::generateData(QmlProfilerModelManager *manager)
void FlameGraphModelTest::initTestCase() void FlameGraphModelTest::initTestCase()
{ {
QCOMPARE(model.modelManager(), &manager); QCOMPARE(model.modelManager(), &manager);
rangeModelId = generateData(&manager); rangeModelId = generateData(&manager, &aggregator);
QCOMPARE(manager.state(), QmlProfilerModelManager::Done); QCOMPARE(manager.state(), QmlProfilerModelManager::Done);
} }

View File

@@ -27,6 +27,9 @@
#include <qmlprofiler/flamegraphmodel.h> #include <qmlprofiler/flamegraphmodel.h>
#include <qmlprofiler/qmlprofilermodelmanager.h> #include <qmlprofiler/qmlprofilermodelmanager.h>
#include <timeline/timelinemodelaggregator.h>
#include <QObject> #include <QObject>
namespace QmlProfiler { namespace QmlProfiler {
@@ -37,7 +40,8 @@ class FlameGraphModelTest : public QObject
Q_OBJECT Q_OBJECT
public: public:
FlameGraphModelTest(QObject *parent = nullptr); FlameGraphModelTest(QObject *parent = nullptr);
static int generateData(QmlProfilerModelManager *manager); static int generateData(QmlProfilerModelManager *manager,
Timeline::TimelineModelAggregator *aggregator);
private slots: private slots:
void initTestCase(); void initTestCase();
@@ -50,6 +54,7 @@ private slots:
private: private:
QmlProfilerModelManager manager; QmlProfilerModelManager manager;
Timeline::TimelineModelAggregator aggregator;
FlameGraphModel model; FlameGraphModel model;
int rangeModelId = -1; int rangeModelId = -1;
}; };

View File

@@ -34,7 +34,8 @@
namespace QmlProfiler { namespace QmlProfiler {
namespace Internal { 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, connect(&view, &QmlProfilerEventsView::showFullRange,
this, [this](){ manager.restrictToRange(-1, -1); }); this, [this](){ manager.restrictToRange(-1, -1); });
FlameGraphModelTest::generateData(&manager); FlameGraphModelTest::generateData(&manager, &aggregator);
QCOMPARE(manager.state(), QmlProfilerModelManager::Done); QCOMPARE(manager.state(), QmlProfilerModelManager::Done);
view.resize(500, 500); view.resize(500, 500);
view.show(); view.show();

View File

@@ -27,6 +27,9 @@
#include <qmlprofiler/flamegraphview.h> #include <qmlprofiler/flamegraphview.h>
#include <qmlprofiler/qmlprofilermodelmanager.h> #include <qmlprofiler/qmlprofilermodelmanager.h>
#include <timeline/timelinemodelaggregator.h>
#include <QObject> #include <QObject>
namespace QmlProfiler { namespace QmlProfiler {
@@ -46,6 +49,7 @@ private slots:
private: private:
QmlProfilerModelManager manager; QmlProfilerModelManager manager;
Timeline::TimelineModelAggregator aggregator;
FlameGraphView view; FlameGraphView view;
}; };

View File

@@ -38,7 +38,7 @@ static InputEventType inputType(int i)
} }
InputEventsModelTest::InputEventsModelTest(QObject *parent) : InputEventsModelTest::InputEventsModelTest(QObject *parent) :
QObject(parent), manager(nullptr), model(&manager) QObject(parent), model(&manager, &aggregator)
{ {
keyTypeId = manager.numEventTypes(); keyTypeId = manager.numEventTypes();
manager.addEventType(QmlEventType(Event, MaximumRangeType, Key)); manager.addEventType(QmlEventType(Event, MaximumRangeType, Key));

View File

@@ -51,6 +51,7 @@ private slots:
private: private:
QmlProfilerModelManager manager; QmlProfilerModelManager manager;
Timeline::TimelineModelAggregator aggregator;
InputEventsModel model; InputEventsModel model;
int mouseTypeId = -1; int mouseTypeId = -1;

View File

@@ -30,7 +30,7 @@ namespace QmlProfiler {
namespace Internal { namespace Internal {
MemoryUsageModelTest::MemoryUsageModelTest(QObject *parent) : QObject(parent), MemoryUsageModelTest::MemoryUsageModelTest(QObject *parent) : QObject(parent),
manager(nullptr), model(&manager) model(&manager, &aggregator)
{ {
} }

View File

@@ -54,6 +54,7 @@ private slots:
private: private:
QmlProfilerModelManager manager; QmlProfilerModelManager manager;
Timeline::TimelineModelAggregator aggregator;
MemoryUsageModel model; MemoryUsageModel model;
int heapPageTypeId = -1; int heapPageTypeId = -1;

View File

@@ -31,7 +31,7 @@ namespace QmlProfiler {
namespace Internal { namespace Internal {
PixmapCacheModelTest::PixmapCacheModelTest(QObject *parent) : QObject(parent), PixmapCacheModelTest::PixmapCacheModelTest(QObject *parent) : QObject(parent),
manager(nullptr), model(&manager) model(&manager, &aggregator)
{ {
} }

View File

@@ -48,6 +48,7 @@ private slots:
private: private:
QmlProfilerModelManager manager; QmlProfilerModelManager manager;
Timeline::TimelineModelAggregator aggregator;
PixmapCacheModel model; PixmapCacheModel model;
int eventTypeIndices[2 * MaximumPixmapEventType]; int eventTypeIndices[2 * MaximumPixmapEventType];

View File

@@ -31,7 +31,7 @@ namespace QmlProfiler {
namespace Internal { namespace Internal {
QmlProfilerAnimationsModelTest::QmlProfilerAnimationsModelTest(QObject *parent) : QmlProfilerAnimationsModelTest::QmlProfilerAnimationsModelTest(QObject *parent) :
QObject(parent), manager(nullptr), model(&manager) QObject(parent), model(&manager, &aggregator)
{ {
} }

View File

@@ -52,6 +52,7 @@ private slots:
private: private:
QmlProfilerModelManager manager; QmlProfilerModelManager manager;
Timeline::TimelineModelAggregator aggregator;
QmlProfilerAnimationsModel model; QmlProfilerAnimationsModel model;
}; };

View File

@@ -37,12 +37,13 @@ namespace Internal {
class DummyModel : public QmlProfilerRangeModel { class DummyModel : public QmlProfilerRangeModel {
public: public:
DummyModel(QmlProfilerModelManager *manager); DummyModel(QmlProfilerModelManager *manager, Timeline::TimelineModelAggregator *aggregator);
void loadData(); void loadData();
}; };
DummyModel::DummyModel(QmlProfilerModelManager *manager) : DummyModel::DummyModel(QmlProfilerModelManager *manager,
QmlProfilerRangeModel(manager, Binding) Timeline::TimelineModelAggregator *aggregator) :
QmlProfilerRangeModel(manager, Binding, aggregator)
{ {
} }
@@ -90,8 +91,9 @@ void QmlProfilerBindingLoopsRenderPassTest::testUpdate()
inst->update(&renderer, &parentState, 0, 0, 0, true, 1); inst->update(&renderer, &parentState, 0, 0, 0, true, 1);
QCOMPARE(result, nullState); QCOMPARE(result, nullState);
QmlProfilerModelManager manager(nullptr); QmlProfilerModelManager manager;
DummyModel model(&manager); Timeline::TimelineModelAggregator aggregator;
DummyModel model(&manager, &aggregator);
renderer.setModel(&model); renderer.setModel(&model);
result = inst->update(&renderer, &parentState, 0, 0, 0, true, 1); result = inst->update(&renderer, &parentState, 0, 0, 0, true, 1);
QCOMPARE(result, nullState); QCOMPARE(result, nullState);

View File

@@ -24,6 +24,7 @@
****************************************************************************/ ****************************************************************************/
#include <QtTest> #include <QtTest>
#include <timeline/timelinemodelaggregator.h>
#include <timeline/timelineabstractrenderer_p.h> #include <timeline/timelineabstractrenderer_p.h>
using namespace Timeline; using namespace Timeline;
@@ -82,10 +83,11 @@ void tst_TimelineAbstractRenderer::selectedItem()
void tst_TimelineAbstractRenderer::model() void tst_TimelineAbstractRenderer::model()
{ {
TimelineAbstractRenderer renderer; TimelineAbstractRenderer renderer;
TimelineModelAggregator aggregator;
QSignalSpy spy(&renderer, SIGNAL(modelChanged(TimelineModel*))); QSignalSpy spy(&renderer, SIGNAL(modelChanged(TimelineModel*)));
QVERIFY(!renderer.modelDirty()); QVERIFY(!renderer.modelDirty());
QCOMPARE(spy.count(), 0); QCOMPARE(spy.count(), 0);
TimelineModel model(0); TimelineModel model(&aggregator);
QCOMPARE(renderer.model(), static_cast<TimelineModel *>(0)); QCOMPARE(renderer.model(), static_cast<TimelineModel *>(0));
renderer.setModel(&model); renderer.setModel(&model);
QVERIFY(renderer.modelDirty()); QVERIFY(renderer.modelDirty());

View File

@@ -25,6 +25,7 @@
#include <timeline/runscenegraphtest.h> #include <timeline/runscenegraphtest.h>
#include <timeline/timelineitemsrenderpass.h> #include <timeline/timelineitemsrenderpass.h>
#include <timeline/timelinemodelaggregator.h>
#include <timeline/timelinerenderstate.h> #include <timeline/timelinerenderstate.h>
#include <QtTest> #include <QtTest>
@@ -34,7 +35,7 @@ using namespace Timeline;
class DummyModel : public TimelineModel { class DummyModel : public TimelineModel {
public: public:
DummyModel(); DummyModel(TimelineModelAggregator *parent);
void loadData(); void loadData();
float relativeHeight(int index) const; float relativeHeight(int index) const;
}; };
@@ -48,7 +49,7 @@ private slots:
void update(); 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(); const TimelineItemsRenderPass *inst = TimelineItemsRenderPass::instance();
TimelineAbstractRenderer renderer; TimelineAbstractRenderer renderer;
TimelineModelAggregator aggregator;
TimelineRenderState parentState(0, 8, 1, 1); TimelineRenderState parentState(0, 8, 1, 1);
TimelineRenderPass::State *nullState = 0; TimelineRenderPass::State *nullState = 0;
QSGNode *nullNode = 0; QSGNode *nullNode = 0;
TimelineRenderPass::State *result = inst->update(&renderer, &parentState, 0, 0, 0, true, 1); TimelineRenderPass::State *result = inst->update(&renderer, &parentState, 0, 0, 0, true, 1);
QCOMPARE(result, nullState); QCOMPARE(result, nullState);
DummyModel model; DummyModel model(&aggregator);
renderer.setModel(&model); renderer.setModel(&model);
result = inst->update(&renderer, &parentState, 0, 0, 0, true, 1); result = inst->update(&renderer, &parentState, 0, 0, 0, true, 1);
QCOMPARE(result, nullState); QCOMPARE(result, nullState);

View File

@@ -26,6 +26,7 @@
#include <QtTest> #include <QtTest>
#include <QColor> #include <QColor>
#include <timeline/timelinemodel_p.h> #include <timeline/timelinemodel_p.h>
#include <timeline/timelinemodelaggregator.h>
static const int NumItems = 32; static const int NumItems = 32;
static const qint64 ItemDuration = 1 << 19; static const qint64 ItemDuration = 1 << 19;
@@ -36,8 +37,8 @@ class DummyModel : public Timeline::TimelineModel
Q_OBJECT Q_OBJECT
friend class tst_TimelineModel; friend class tst_TimelineModel;
public: public:
DummyModel(int modelId); DummyModel(Timeline::TimelineModelAggregator *parent);
DummyModel(QString displayName = tr("dummy"), QObject *parent = 0); DummyModel(QString displayName, Timeline::TimelineModelAggregator *parent);
int expandedRow(int) const { return 2; } int expandedRow(int) const { return 2; }
int collapsedRow(int) const { return 1; } int collapsedRow(int) const { return 1; }
@@ -54,7 +55,6 @@ public:
tst_TimelineModel(); tst_TimelineModel();
private slots: private slots:
void privateModel();
void isEmpty(); void isEmpty();
void modelId(); void modelId();
void rowHeight(); void rowHeight();
@@ -77,15 +77,18 @@ private slots:
void rowCount(); void rowCount();
void prevNext(); void prevNext();
void parentingOfEqualStarts(); void parentingOfEqualStarts();
private:
Timeline::TimelineModelAggregator aggregator;
}; };
DummyModel::DummyModel(int modelId) : DummyModel::DummyModel(Timeline::TimelineModelAggregator *parent) :
Timeline::TimelineModel(modelId, 0) Timeline::TimelineModel(parent)
{ {
} }
DummyModel::DummyModel(QString displayName, QObject *parent) : DummyModel::DummyModel(QString displayName, Timeline::TimelineModelAggregator *parent) :
TimelineModel(12, parent) TimelineModel(parent)
{ {
setDisplayName(displayName); 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() void tst_TimelineModel::isEmpty()
{ {
DummyModel dummy; DummyModel dummy(&aggregator);
QVERIFY(dummy.isEmpty()); QVERIFY(dummy.isEmpty());
dummy.loadData(); dummy.loadData();
QVERIFY(!dummy.isEmpty()); QVERIFY(!dummy.isEmpty());
@@ -130,13 +127,13 @@ void tst_TimelineModel::isEmpty()
void tst_TimelineModel::modelId() void tst_TimelineModel::modelId()
{ {
DummyModel dummy; DummyModel dummy(&aggregator);
QCOMPARE(dummy.modelId(), 12); QCOMPARE(dummy.modelId(), aggregator.generateModelId() - 1);
} }
void tst_TimelineModel::rowHeight() void tst_TimelineModel::rowHeight()
{ {
DummyModel dummy; DummyModel dummy(&aggregator);
QCOMPARE(dummy.rowHeight(0), DefaultRowHeight); QCOMPARE(dummy.rowHeight(0), DefaultRowHeight);
QCOMPARE(dummy.collapsedRowHeight(0), DefaultRowHeight); QCOMPARE(dummy.collapsedRowHeight(0), DefaultRowHeight);
QCOMPARE(dummy.expandedRowHeight(0), DefaultRowHeight); QCOMPARE(dummy.expandedRowHeight(0), DefaultRowHeight);
@@ -178,7 +175,7 @@ void tst_TimelineModel::rowHeight()
void tst_TimelineModel::rowOffset() void tst_TimelineModel::rowOffset()
{ {
DummyModel dummy; DummyModel dummy(&aggregator);
QCOMPARE(dummy.rowOffset(0), 0); QCOMPARE(dummy.rowOffset(0), 0);
dummy.loadData(); dummy.loadData();
@@ -215,7 +212,7 @@ void tst_TimelineModel::rowOffset()
void tst_TimelineModel::height() void tst_TimelineModel::height()
{ {
DummyModel dummy; DummyModel dummy(&aggregator);
int heightAfterLastSignal = 0; int heightAfterLastSignal = 0;
int heightChangedSignals = 0; int heightChangedSignals = 0;
connect(&dummy, &Timeline::TimelineModel::heightChanged, [&](){ connect(&dummy, &Timeline::TimelineModel::heightChanged, [&](){
@@ -258,7 +255,7 @@ void tst_TimelineModel::height()
void tst_TimelineModel::count() void tst_TimelineModel::count()
{ {
DummyModel dummy; DummyModel dummy(&aggregator);
QCOMPARE(dummy.count(), 0); QCOMPARE(dummy.count(), 0);
dummy.loadData(); dummy.loadData();
QCOMPARE(dummy.count(), NumItems); QCOMPARE(dummy.count(), NumItems);
@@ -270,7 +267,7 @@ void tst_TimelineModel::count()
void tst_TimelineModel::times() void tst_TimelineModel::times()
{ {
DummyModel dummy; DummyModel dummy(&aggregator);
dummy.loadData(); dummy.loadData();
QCOMPARE(dummy.startTime(0), 0); QCOMPARE(dummy.startTime(0), 0);
QCOMPARE(dummy.duration(0), ItemDuration * 3 + 2); QCOMPARE(dummy.duration(0), ItemDuration * 3 + 2);
@@ -280,14 +277,14 @@ void tst_TimelineModel::times()
void tst_TimelineModel::selectionId() void tst_TimelineModel::selectionId()
{ {
DummyModel dummy; DummyModel dummy(&aggregator);
dummy.loadData(); dummy.loadData();
QCOMPARE(dummy.selectionId(0), 4); QCOMPARE(dummy.selectionId(0), 4);
} }
void tst_TimelineModel::firstLast() void tst_TimelineModel::firstLast()
{ {
DummyModel dummy; DummyModel dummy(&aggregator);
QCOMPARE(dummy.firstIndex(0), -1); QCOMPARE(dummy.firstIndex(0), -1);
QCOMPARE(dummy.firstIndex(ItemSpacing), -1); QCOMPARE(dummy.firstIndex(ItemSpacing), -1);
QCOMPARE(dummy.lastIndex(0), -1); QCOMPARE(dummy.lastIndex(0), -1);
@@ -307,7 +304,7 @@ void tst_TimelineModel::firstLast()
void tst_TimelineModel::expand() void tst_TimelineModel::expand()
{ {
DummyModel dummy; DummyModel dummy(&aggregator);
QSignalSpy spy(&dummy, SIGNAL(expandedChanged())); QSignalSpy spy(&dummy, SIGNAL(expandedChanged()));
QVERIFY(!dummy.expanded()); QVERIFY(!dummy.expanded());
dummy.setExpanded(true); dummy.setExpanded(true);
@@ -326,7 +323,7 @@ void tst_TimelineModel::expand()
void tst_TimelineModel::hide() void tst_TimelineModel::hide()
{ {
DummyModel dummy; DummyModel dummy(&aggregator);
QSignalSpy spy(&dummy, SIGNAL(hiddenChanged())); QSignalSpy spy(&dummy, SIGNAL(hiddenChanged()));
QVERIFY(!dummy.hidden()); QVERIFY(!dummy.hidden());
dummy.setHidden(true); dummy.setHidden(true);
@@ -346,7 +343,7 @@ void tst_TimelineModel::hide()
void tst_TimelineModel::displayName() void tst_TimelineModel::displayName()
{ {
QLatin1String name("testest"); QLatin1String name("testest");
DummyModel dummy(name); DummyModel dummy(name, &aggregator);
QSignalSpy spy(&dummy, SIGNAL(displayNameChanged())); QSignalSpy spy(&dummy, SIGNAL(displayNameChanged()));
QCOMPARE(dummy.displayName(), name); QCOMPARE(dummy.displayName(), name);
QCOMPARE(spy.count(), 0); QCOMPARE(spy.count(), 0);
@@ -361,7 +358,7 @@ void tst_TimelineModel::displayName()
void tst_TimelineModel::defaultValues() void tst_TimelineModel::defaultValues()
{ {
Timeline::TimelineModel dummy(12); Timeline::TimelineModel dummy(&aggregator);
QCOMPARE(dummy.location(0), QVariantMap()); QCOMPARE(dummy.location(0), QVariantMap());
QCOMPARE(dummy.handlesTypeId(0), false); QCOMPARE(dummy.handlesTypeId(0), false);
QCOMPARE(dummy.relativeHeight(0), 1.0); QCOMPARE(dummy.relativeHeight(0), 1.0);
@@ -377,7 +374,7 @@ void tst_TimelineModel::defaultValues()
void tst_TimelineModel::row() void tst_TimelineModel::row()
{ {
DummyModel dummy; DummyModel dummy(&aggregator);
dummy.loadData(); dummy.loadData();
QCOMPARE(dummy.row(0), 1); QCOMPARE(dummy.row(0), 1);
dummy.setExpanded(true); dummy.setExpanded(true);
@@ -386,33 +383,34 @@ void tst_TimelineModel::row()
void tst_TimelineModel::colorByHue() 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(10), QColor::fromHsl(10, 150, 166).rgb());
QCOMPARE(dummy.colorByHue(500), QColor::fromHsl(140, 150, 166).rgb()); QCOMPARE(dummy.colorByHue(500), QColor::fromHsl(140, 150, 166).rgb());
} }
void tst_TimelineModel::colorBySelectionId() void tst_TimelineModel::colorBySelectionId()
{ {
DummyModel dummy; DummyModel dummy(&aggregator);
dummy.loadData(); dummy.loadData();
QCOMPARE(dummy.colorBySelectionId(5), QColor::fromHsl(6 * 25, 150, 166).rgb()); QCOMPARE(dummy.colorBySelectionId(5), QColor::fromHsl(6 * 25, 150, 166).rgb());
} }
void tst_TimelineModel::colorByFraction() void tst_TimelineModel::colorByFraction()
{ {
DummyModel dummy; DummyModel dummy(&aggregator);
QCOMPARE(dummy.colorByFraction(0.5), QColor::fromHsl(0.5 * 96 + 10, 150, 166).rgb()); QCOMPARE(dummy.colorByFraction(0.5), QColor::fromHsl(0.5 * 96 + 10, 150, 166).rgb());
} }
void tst_TimelineModel::supportedRenderPasses() void tst_TimelineModel::supportedRenderPasses()
{ {
DummyModel dummy; DummyModel dummy(&aggregator);
QVERIFY(!dummy.supportedRenderPasses().isEmpty()); QVERIFY(!dummy.supportedRenderPasses().isEmpty());
} }
void tst_TimelineModel::insertStartEnd() void tst_TimelineModel::insertStartEnd()
{ {
DummyModel dummy; DummyModel dummy(&aggregator);
int id = dummy.insertStart(10, 0); int id = dummy.insertStart(10, 0);
dummy.insertEnd(id, 10); dummy.insertEnd(id, 10);
QCOMPARE(dummy.startTime(id), 10); QCOMPARE(dummy.startTime(id), 10);
@@ -433,7 +431,7 @@ void tst_TimelineModel::insertStartEnd()
void tst_TimelineModel::rowCount() void tst_TimelineModel::rowCount()
{ {
DummyModel dummy; DummyModel dummy(&aggregator);
QSignalSpy expandedSpy(&dummy, SIGNAL(expandedRowCountChanged())); QSignalSpy expandedSpy(&dummy, SIGNAL(expandedRowCountChanged()));
QSignalSpy collapsedSpy(&dummy, SIGNAL(collapsedRowCountChanged())); QSignalSpy collapsedSpy(&dummy, SIGNAL(collapsedRowCountChanged()));
QCOMPARE(dummy.rowCount(), 1); QCOMPARE(dummy.rowCount(), 1);
@@ -453,7 +451,7 @@ void tst_TimelineModel::rowCount()
void tst_TimelineModel::prevNext() void tst_TimelineModel::prevNext()
{ {
DummyModel dummy; DummyModel dummy(&aggregator);
QCOMPARE(dummy.nextItemBySelectionId(5, 10, 5), -1); QCOMPARE(dummy.nextItemBySelectionId(5, 10, 5), -1);
QCOMPARE(dummy.prevItemBySelectionId(5, 10, 5), -1); QCOMPARE(dummy.prevItemBySelectionId(5, 10, 5), -1);
@@ -474,7 +472,7 @@ void tst_TimelineModel::prevNext()
void tst_TimelineModel::parentingOfEqualStarts() 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 ... // 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.insert(1, 10, 998), 0);
QCOMPARE(dummy.insertStart(1, 999), 1); QCOMPARE(dummy.insertStart(1, 999), 1);

View File

@@ -38,7 +38,7 @@ private slots:
class HeightTestModel : public Timeline::TimelineModel { class HeightTestModel : public Timeline::TimelineModel {
public: public:
HeightTestModel() : TimelineModel(2) HeightTestModel(Timeline::TimelineModelAggregator *parent) : TimelineModel(parent)
{ {
insert(0, 1, 1); insert(0, 1, 1);
} }
@@ -46,15 +46,15 @@ public:
void tst_TimelineModelAggregator::height() void tst_TimelineModelAggregator::height()
{ {
Timeline::TimelineModelAggregator aggregator(0); Timeline::TimelineModelAggregator aggregator;
QCOMPARE(aggregator.height(), 0); QCOMPARE(aggregator.height(), 0);
QSignalSpy heightSpy(&aggregator, SIGNAL(heightChanged())); QSignalSpy heightSpy(&aggregator, SIGNAL(heightChanged()));
Timeline::TimelineModel *model = new Timeline::TimelineModel(25); Timeline::TimelineModel *model = new Timeline::TimelineModel(&aggregator);
aggregator.addModel(model); aggregator.addModel(model);
QCOMPARE(aggregator.height(), 0); QCOMPARE(aggregator.height(), 0);
QCOMPARE(heightSpy.count(), 0); QCOMPARE(heightSpy.count(), 0);
aggregator.addModel(new HeightTestModel); aggregator.addModel(new HeightTestModel(&aggregator));
QVERIFY(aggregator.height() > 0); QVERIFY(aggregator.height() > 0);
QCOMPARE(heightSpy.count(), 1); QCOMPARE(heightSpy.count(), 1);
aggregator.clear(); aggregator.clear();
@@ -70,8 +70,8 @@ void tst_TimelineModelAggregator::addRemoveModel()
QCOMPARE(aggregator.notes(), &notes); QCOMPARE(aggregator.notes(), &notes);
Timeline::TimelineModel *model1 = new Timeline::TimelineModel(25); Timeline::TimelineModel *model1 = new Timeline::TimelineModel(&aggregator);
Timeline::TimelineModel *model2 = new Timeline::TimelineModel(26); Timeline::TimelineModel *model2 = new Timeline::TimelineModel(&aggregator);
aggregator.addModel(model1); aggregator.addModel(model1);
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
QCOMPARE(aggregator.modelCount(), 1); QCOMPARE(aggregator.modelCount(), 1);
@@ -84,9 +84,9 @@ void tst_TimelineModelAggregator::addRemoveModel()
QCOMPARE(aggregator.model(1), model2); QCOMPARE(aggregator.model(1), model2);
QCOMPARE(aggregator.models().count(), 2); QCOMPARE(aggregator.models().count(), 2);
QCOMPARE(aggregator.modelIndexById(25), 0); QCOMPARE(aggregator.modelIndexById(model1->modelId()), 0);
QCOMPARE(aggregator.modelIndexById(26), 1); QCOMPARE(aggregator.modelIndexById(model2->modelId()), 1);
QCOMPARE(aggregator.modelIndexById(27), -1); QCOMPARE(aggregator.modelIndexById(aggregator.generateModelId()), -1);
QCOMPARE(aggregator.modelOffset(0), 0); QCOMPARE(aggregator.modelOffset(0), 0);
QCOMPARE(aggregator.modelOffset(1), 0); QCOMPARE(aggregator.modelOffset(1), 0);
@@ -99,22 +99,23 @@ void tst_TimelineModelAggregator::addRemoveModel()
class PrevNextTestModel : public Timeline::TimelineModel class PrevNextTestModel : public Timeline::TimelineModel
{ {
public: public:
PrevNextTestModel(int x) : TimelineModel(x) PrevNextTestModel(Timeline::TimelineModelAggregator *parent) : TimelineModel(parent)
{ {
for (int i = 0; i < 20; ++i) for (int i = 0; i < 20; ++i)
insert(i + x, i * x, x); insert(i + modelId(), i * modelId(), modelId());
} }
}; };
void tst_TimelineModelAggregator::prevNext() void tst_TimelineModelAggregator::prevNext()
{ {
Timeline::TimelineModelAggregator aggregator(0); Timeline::TimelineModelAggregator aggregator;
aggregator.addModel(new PrevNextTestModel(1)); aggregator.generateModelId(); // start modelIds at 1
aggregator.addModel(new PrevNextTestModel(2)); aggregator.addModel(new PrevNextTestModel(&aggregator));
aggregator.addModel(new PrevNextTestModel(3)); aggregator.addModel(new PrevNextTestModel(&aggregator));
aggregator.addModel(new PrevNextTestModel(&aggregator));
// Add an empty model to trigger the special code paths that skip it // 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 item("item");
QLatin1String model("model"); QLatin1String model("model");
QVariantMap result; QVariantMap result;

View File

@@ -25,6 +25,7 @@
#include <QtTest> #include <QtTest>
#include <QColor> #include <QColor>
#include <timeline/timelinemodelaggregator.h>
#include <timeline/timelinenotesmodel.h> #include <timeline/timelinenotesmodel.h>
class tst_TimelineNotesModel : public QObject class tst_TimelineNotesModel : public QObject
@@ -37,11 +38,14 @@ private slots:
void properties(); void properties();
void selection(); void selection();
void modify(); void modify();
private:
Timeline::TimelineModelAggregator aggregator;
}; };
class TestModel : public Timeline::TimelineModel { class TestModel : public Timeline::TimelineModel {
public: public:
TestModel(int modelId = 10) : TimelineModel(modelId) TestModel(Timeline::TimelineModelAggregator *parent) : TimelineModel(parent)
{ {
insert(0, 10, 10); insert(0, 10, 10);
} }
@@ -59,11 +63,11 @@ class TestNotesModel : public Timeline::TimelineNotesModel {
void tst_TimelineNotesModel::timelineModel() void tst_TimelineNotesModel::timelineModel()
{ {
TestNotesModel notes; TestNotesModel notes;
TestModel *model = new TestModel; TestModel *model = new TestModel(&aggregator);
TestModel *model2 = new TestModel(2); TestModel *model2 = new TestModel(&aggregator);
notes.addTimelineModel(model); notes.addTimelineModel(model);
notes.addTimelineModel(model2); notes.addTimelineModel(model2);
QCOMPARE(notes.timelineModelByModelId(10), model); QCOMPARE(notes.timelineModelByModelId(model->modelId()), model);
QCOMPARE(notes.timelineModels().count(), 2); QCOMPARE(notes.timelineModels().count(), 2);
QVERIFY(notes.timelineModels().contains(model)); QVERIFY(notes.timelineModels().contains(model));
QVERIFY(notes.timelineModels().contains(model2)); QVERIFY(notes.timelineModels().contains(model2));
@@ -78,11 +82,11 @@ void tst_TimelineNotesModel::timelineModel()
void tst_TimelineNotesModel::addRemove() void tst_TimelineNotesModel::addRemove()
{ {
TestNotesModel notes; TestNotesModel notes;
TestModel model; TestModel model(&aggregator);
notes.addTimelineModel(&model); notes.addTimelineModel(&model);
QSignalSpy spy(&notes, SIGNAL(changed(int,int,int))); QSignalSpy spy(&notes, 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(spy.count(), 1);
QCOMPARE(notes.isModified(), true); QCOMPARE(notes.isModified(), true);
QCOMPARE(notes.count(), 1); QCOMPARE(notes.count(), 1);
@@ -99,32 +103,34 @@ void tst_TimelineNotesModel::properties()
TestNotesModel notes; TestNotesModel notes;
int id = -1; int id = -1;
int modelId = -1;
{ {
TestModel model; TestModel model(&aggregator);
modelId = model.modelId();
notes.addTimelineModel(&model); notes.addTimelineModel(&model);
id = notes.add(10, 0, QLatin1String("xyz")); id = notes.add(model.modelId(), 0, QLatin1String("xyz"));
QVERIFY(id >= 0); QVERIFY(id >= 0);
QCOMPARE(notes.typeId(id), 7); QCOMPARE(notes.typeId(id), 7);
QCOMPARE(notes.timelineIndex(id), 0); QCOMPARE(notes.timelineIndex(id), 0);
QCOMPARE(notes.timelineModel(id), 10); QCOMPARE(notes.timelineModel(id), modelId);
QCOMPARE(notes.text(id), QLatin1String("xyz")); QCOMPARE(notes.text(id), QLatin1String("xyz"));
} }
QCOMPARE(notes.typeId(id), -1); // cannot ask the model anymore QCOMPARE(notes.typeId(id), -1); // cannot ask the model anymore
QCOMPARE(notes.timelineIndex(id), 0); QCOMPARE(notes.timelineIndex(id), 0);
QCOMPARE(notes.timelineModel(id), 10); QCOMPARE(notes.timelineModel(id), modelId);
QCOMPARE(notes.text(id), QLatin1String("xyz")); QCOMPARE(notes.text(id), QLatin1String("xyz"));
} }
void tst_TimelineNotesModel::selection() void tst_TimelineNotesModel::selection()
{ {
TestNotesModel notes; TestNotesModel notes;
TestModel model; TestModel model(&aggregator);
notes.addTimelineModel(&model); notes.addTimelineModel(&model);
int id1 = notes.add(10, 0, QLatin1String("blablub")); int id1 = notes.add(model.modelId(), 0, QLatin1String("blablub"));
int id2 = notes.add(10, 0, QLatin1String("xyz")); int id2 = notes.add(model.modelId(), 0, QLatin1String("xyz"));
QVariantList ids = notes.byTimelineModel(10); QVariantList ids = notes.byTimelineModel(model.modelId());
QCOMPARE(ids.length(), 2); QCOMPARE(ids.length(), 2);
QVERIFY(ids.contains(id1)); QVERIFY(ids.contains(id1));
QVERIFY(ids.contains(id2)); QVERIFY(ids.contains(id2));
@@ -134,19 +140,19 @@ void tst_TimelineNotesModel::selection()
QVERIFY(ids.contains(id1)); QVERIFY(ids.contains(id1));
QVERIFY(ids.contains(id2)); QVERIFY(ids.contains(id2));
int got = notes.get(10, 0); int got = notes.get(model.modelId(), 0);
QVERIFY(got == id1 || got == id2); QVERIFY(got == id1 || got == id2);
QCOMPARE(notes.get(10, 20), -1); QCOMPARE(notes.get(model.modelId(), 20), -1);
QCOMPARE(notes.get(20, 10), -1); QCOMPARE(notes.get(model.modelId() + 10, 10), -1);
} }
void tst_TimelineNotesModel::modify() void tst_TimelineNotesModel::modify()
{ {
TestNotesModel notes; TestNotesModel notes;
TestModel model; TestModel model(&aggregator);
notes.addTimelineModel(&model); notes.addTimelineModel(&model);
QSignalSpy spy(&notes, SIGNAL(changed(int,int,int))); QSignalSpy spy(&notes, 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); QCOMPARE(spy.count(), 1);
notes.resetModified(); notes.resetModified();
notes.update(id, QLatin1String("b")); notes.update(id, QLatin1String("b"));
@@ -165,15 +171,15 @@ void tst_TimelineNotesModel::modify()
QCOMPARE(notes.text(id), QLatin1String("a")); QCOMPARE(notes.text(id), QLatin1String("a"));
notes.resetModified(); notes.resetModified();
notes.setText(10, 0, QLatin1String("x")); notes.setText(model.modelId(), 0, QLatin1String("x"));
QVERIFY(notes.isModified()); QVERIFY(notes.isModified());
QCOMPARE(spy.count(), 4); QCOMPARE(spy.count(), 4);
QCOMPARE(notes.text(id), QLatin1String("x")); QCOMPARE(notes.text(id), QLatin1String("x"));
notes.resetModified(); notes.resetModified();
TestModel model2(9); TestModel model2(&aggregator);
notes.addTimelineModel(&model2); notes.addTimelineModel(&model2);
notes.setText(9, 0, QLatin1String("hh")); notes.setText(model2.modelId(), 0, QLatin1String("hh"));
QVERIFY(notes.isModified()); QVERIFY(notes.isModified());
QCOMPARE(spy.count(), 5); QCOMPARE(spy.count(), 5);
QCOMPARE(notes.count(), 2); QCOMPARE(notes.count(), 2);

View File

@@ -24,6 +24,7 @@
****************************************************************************/ ****************************************************************************/
#include <timeline/runscenegraphtest.h> #include <timeline/runscenegraphtest.h>
#include <timeline/timelinemodelaggregator.h>
#include <timeline/timelinenotesrenderpass.h> #include <timeline/timelinenotesrenderpass.h>
#include <timeline/timelinerenderstate.h> #include <timeline/timelinerenderstate.h>
#include <timeline/timelineabstractrenderer_p.h> #include <timeline/timelineabstractrenderer_p.h>
@@ -35,7 +36,7 @@ using namespace Timeline;
class DummyModel : public TimelineModel { class DummyModel : public TimelineModel {
public: public:
DummyModel(int id = 12); DummyModel(TimelineModelAggregator *parent);
void loadData(); void loadData();
}; };
@@ -48,7 +49,7 @@ private slots:
void update(); 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(); const TimelineNotesRenderPass *inst = TimelineNotesRenderPass::instance();
TimelineAbstractRenderer renderer; TimelineAbstractRenderer renderer;
TimelineModelAggregator aggregator;
TimelineRenderState parentState(0, 8, 1, 1); TimelineRenderState parentState(0, 8, 1, 1);
TimelineRenderPass::State *nullState = 0; TimelineRenderPass::State *nullState = 0;
QSGNode *nullNode = 0; QSGNode *nullNode = 0;
TimelineRenderPass::State *result = inst->update(&renderer, &parentState, 0, 0, 0, true, 1); TimelineRenderPass::State *result = inst->update(&renderer, &parentState, 0, 0, 0, true, 1);
QCOMPARE(result, nullState); QCOMPARE(result, nullState);
DummyModel model; DummyModel model(&aggregator);
DummyModel otherModel(13); DummyModel otherModel(&aggregator);
TimelineNotesModel notes; TimelineNotesModel notes;
notes.addTimelineModel(&model); notes.addTimelineModel(&model);
@@ -104,9 +106,9 @@ void tst_TimelineNotesRenderPass::update()
1); 1);
QCOMPARE(result2, result); QCOMPARE(result2, result);
notes.add(12, 0, QLatin1String("x")); notes.add(model.modelId(), 0, QLatin1String("x"));
notes.add(12, 9, QLatin1String("xx")); notes.add(model.modelId(), 9, QLatin1String("xx"));
notes.add(13, 0, QLatin1String("y")); notes.add(otherModel.modelId(), 0, QLatin1String("y"));
QVERIFY(renderer.notesDirty()); QVERIFY(renderer.notesDirty());
result = inst->update(&renderer, &parentState, result, 0, 0, true, 1); result = inst->update(&renderer, &parentState, result, 0, 0, true, 1);
QVERIFY(result != nullState); QVERIFY(result != nullState);

View File

@@ -24,6 +24,7 @@
****************************************************************************/ ****************************************************************************/
#include <QtTest> #include <QtTest>
#include <timeline/timelinemodelaggregator.h>
#include <timeline/timelineoverviewrenderer_p.h> #include <timeline/timelineoverviewrenderer_p.h>
using namespace Timeline; using namespace Timeline;
@@ -34,7 +35,7 @@ class DummyRenderer : public TimelineOverviewRenderer {
class DummyModel : public TimelineModel { class DummyModel : public TimelineModel {
public: public:
DummyModel() : TimelineModel(0) {} DummyModel(TimelineModelAggregator *parent) : TimelineModel(parent) {}
void loadData() void loadData()
{ {
@@ -57,8 +58,9 @@ private slots:
void tst_TimelineOverviewRenderer::updatePaintNode() void tst_TimelineOverviewRenderer::updatePaintNode()
{ {
DummyRenderer renderer; DummyRenderer renderer;
TimelineModelAggregator aggregator;
QCOMPARE(renderer.updatePaintNode(0, 0), static_cast<QSGNode *>(0)); QCOMPARE(renderer.updatePaintNode(0, 0), static_cast<QSGNode *>(0));
DummyModel model; DummyModel model(&aggregator);
renderer.setModel(&model); renderer.setModel(&model);
QCOMPARE(renderer.updatePaintNode(0, 0), static_cast<QSGNode *>(0)); QCOMPARE(renderer.updatePaintNode(0, 0), static_cast<QSGNode *>(0));
model.loadData(); model.loadData();

View File

@@ -24,6 +24,7 @@
****************************************************************************/ ****************************************************************************/
#include <QtTest> #include <QtTest>
#include <timeline/timelinemodelaggregator.h>
#include <timeline/timelinerenderer_p.h> #include <timeline/timelinerenderer_p.h>
using namespace Timeline; using namespace Timeline;
@@ -34,7 +35,7 @@ class DummyRenderer : public TimelineRenderer {
class DummyModel : public TimelineModel { class DummyModel : public TimelineModel {
public: public:
DummyModel() : TimelineModel(0) {} DummyModel(TimelineModelAggregator *parent) : TimelineModel(parent) {}
void loadData() void loadData()
{ {
@@ -55,6 +56,7 @@ class tst_TimelineRenderer : public QObject
private: private:
void testMouseEvents(DummyRenderer *renderer, int x, int y); void testMouseEvents(DummyRenderer *renderer, int x, int y);
TimelineModelAggregator aggregator;
private slots: private slots:
void updatePaintNode(); void updatePaintNode();
@@ -65,7 +67,7 @@ void tst_TimelineRenderer::updatePaintNode()
{ {
DummyRenderer renderer; DummyRenderer renderer;
QCOMPARE(renderer.updatePaintNode(0, 0), static_cast<QSGNode *>(0)); QCOMPARE(renderer.updatePaintNode(0, 0), static_cast<QSGNode *>(0));
DummyModel model; DummyModel model(&aggregator);
renderer.setModel(&model); renderer.setModel(&model);
QCOMPARE(renderer.updatePaintNode(0, 0), static_cast<QSGNode *>(0)); QCOMPARE(renderer.updatePaintNode(0, 0), static_cast<QSGNode *>(0));
model.loadData(); model.loadData();
@@ -124,7 +126,7 @@ void tst_TimelineRenderer::mouseEvents()
QCOMPARE(renderer.selectedItem(), -1); QCOMPARE(renderer.selectedItem(), -1);
QCOMPARE(renderer.selectionLocked(), true); QCOMPARE(renderer.selectionLocked(), true);
DummyModel model; DummyModel model(&aggregator);
renderer.setModel(&model); renderer.setModel(&model);
testMouseEvents(&renderer, 1, 1); testMouseEvents(&renderer, 1, 1);
QCOMPARE(renderer.selectedItem(), -1); QCOMPARE(renderer.selectedItem(), -1);

View File

@@ -23,6 +23,7 @@
** **
****************************************************************************/ ****************************************************************************/
#include <timeline/timelinemodelaggregator.h>
#include <timeline/timelinerenderstate.h> #include <timeline/timelinerenderstate.h>
#include <QtTest> #include <QtTest>
#include <QSGSimpleRectNode> #include <QSGSimpleRectNode>
@@ -140,7 +141,8 @@ void tst_TimelineRenderState::emptyRoots()
void tst_TimelineRenderState::assembleNodeTree() void tst_TimelineRenderState::assembleNodeTree()
{ {
TimelineModel model(3); TimelineModelAggregator aggregator;
TimelineModel model(&aggregator);
TimelineRenderState state1(1, 2, 0.5, 3); TimelineRenderState state1(1, 2, 0.5, 3);
state1.assembleNodeTree(&model, 30, 30); state1.assembleNodeTree(&model, 30, 30);
QSGTransformNode *node = state1.finalize(0, true, QMatrix4x4()); QSGTransformNode *node = state1.finalize(0, true, QMatrix4x4());

View File

@@ -28,6 +28,7 @@
#include <timeline/timelinerenderstate.h> #include <timeline/timelinerenderstate.h>
#include <timeline/timelineabstractrenderer_p.h> #include <timeline/timelineabstractrenderer_p.h>
#include <timeline/timelineitemsrenderpass.h> #include <timeline/timelineitemsrenderpass.h>
#include <timeline/timelinemodelaggregator.h>
#include <QtTest> #include <QtTest>
#include <QSGMaterialShader> #include <QSGMaterialShader>
@@ -37,7 +38,7 @@ using namespace Timeline;
class DummyModel : public TimelineModel { class DummyModel : public TimelineModel {
public: public:
DummyModel(int id = 12); DummyModel(TimelineModelAggregator *parent);
void loadData(); void loadData();
float relativeHeight(int index) const; float relativeHeight(int index) const;
}; };
@@ -51,7 +52,7 @@ private slots:
void update(); 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(); const TimelineSelectionRenderPass *inst = TimelineSelectionRenderPass::instance();
TimelineAbstractRenderer renderer; TimelineAbstractRenderer renderer;
TimelineModelAggregator aggregator;
TimelineRenderState parentState(0, 400, 1, 1); TimelineRenderState parentState(0, 400, 1, 1);
TimelineRenderPass::State *nullState = 0; TimelineRenderPass::State *nullState = 0;
QSGNode *nullNode = 0; QSGNode *nullNode = 0;
TimelineRenderPass::State *result = inst->update(&renderer, &parentState, 0, 0, 10, true, 1); TimelineRenderPass::State *result = inst->update(&renderer, &parentState, 0, 0, 10, true, 1);
QCOMPARE(result, nullState); QCOMPARE(result, nullState);
DummyModel model; DummyModel model(&aggregator);
result = inst->update(&renderer, &parentState, 0, 0, 10, true, 1); result = inst->update(&renderer, &parentState, 0, 0, 10, true, 1);
QCOMPARE(result, nullState); QCOMPARE(result, nullState);