From f0da74d35daebd6ed70d6c1022052722245cf51e Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 16 Dec 2014 12:32:17 +0100 Subject: [PATCH] Timeline: Streamline model implementations Allow models to be created without a parent and provide default implementations for virtual methods. It's actually fine to have all ranges in row 0 and in black by default. Having default implementations makes things easier to test. Change-Id: Ibb842ef295cdcfa13d8ca4be3489906af72e9699 Reviewed-by: Kai Koehne --- src/libs/timeline/timelinemodel.cpp | 29 +++++++++++++++++++ src/libs/timeline/timelinemodel.h | 15 +++++----- src/libs/timeline/timelinenotesmodel.h | 2 +- .../timelinemodel/tst_timelinemodel.cpp | 11 +++---- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/libs/timeline/timelinemodel.cpp b/src/libs/timeline/timelinemodel.cpp index 5fb463a3ded..0391e55f4dd 100644 --- a/src/libs/timeline/timelinemodel.cpp +++ b/src/libs/timeline/timelinemodel.cpp @@ -512,6 +512,35 @@ int TimelineModel::rowCount() const return d->expanded ? d->expandedRowCount : d->collapsedRowCount; } +QColor TimelineModel::color(int index) const +{ + Q_UNUSED(index); + return QColor(); +} + +QVariantList TimelineModel::labels() const +{ + return QVariantList(); +} + +QVariantMap TimelineModel::details(int index) const +{ + Q_UNUSED(index); + return QVariantMap(); +} + +int TimelineModel::expandedRow(int index) const +{ + Q_UNUSED(index); + return 0; +} + +int TimelineModel::collapsedRow(int index) const +{ + Q_UNUSED(index); + return 0; +} + /*! Returns the ID of the selection group the event with event ID \a index belongs to. Selection groups are local to the model and the model can arbitrarily assign events to selection groups diff --git a/src/libs/timeline/timelinemodel.h b/src/libs/timeline/timelinemodel.h index 9731648e605..cc5b56f08d6 100644 --- a/src/libs/timeline/timelinemodel.h +++ b/src/libs/timeline/timelinemodel.h @@ -57,7 +57,7 @@ class TIMELINE_EXPORT TimelineModel : public QObject public: class TimelineModelPrivate; - TimelineModel(int modelId, const QString &displayName, QObject *parent); + TimelineModel(int modelId, const QString &displayName, QObject *parent = 0); ~TimelineModel(); // Methods implemented by the abstract model itself @@ -92,15 +92,14 @@ public: int collapsedRowCount() const; int rowCount() const; - // Methods that have to be implemented by child models - Q_INVOKABLE virtual QColor color(int index) const = 0; - virtual QVariantList labels() const = 0; - Q_INVOKABLE virtual QVariantMap details(int index) const = 0; - Q_INVOKABLE virtual int expandedRow(int index) const = 0; - Q_INVOKABLE virtual int collapsedRow(int index) const = 0; + // Methods which can optionally be implemented by child models. + Q_INVOKABLE virtual QColor color(int index) const; + virtual QVariantList labels() const; + Q_INVOKABLE virtual QVariantMap details(int index) const; + Q_INVOKABLE virtual int expandedRow(int index) const; + Q_INVOKABLE virtual int collapsedRow(int index) const; Q_INVOKABLE int row(int index) const; - // Methods which can optionally be implemented by child models. // returned map should contain "file", "line", "column" properties, or be empty Q_INVOKABLE virtual QVariantMap location(int index) const; Q_INVOKABLE virtual int typeId(int index) const; diff --git a/src/libs/timeline/timelinenotesmodel.h b/src/libs/timeline/timelinenotesmodel.h index c270b084672..4a220927ecc 100644 --- a/src/libs/timeline/timelinenotesmodel.h +++ b/src/libs/timeline/timelinenotesmodel.h @@ -40,7 +40,7 @@ class TIMELINE_EXPORT TimelineNotesModel : public QObject Q_OBJECT Q_PROPERTY(int count READ count NOTIFY changed) public: - TimelineNotesModel(QObject *parent); + TimelineNotesModel(QObject *parent = 0); ~TimelineNotesModel(); int count() const; diff --git a/tests/auto/timeline/timelinemodel/tst_timelinemodel.cpp b/tests/auto/timeline/timelinemodel/tst_timelinemodel.cpp index 427cbdcd63b..a316c64d805 100644 --- a/tests/auto/timeline/timelinemodel/tst_timelinemodel.cpp +++ b/tests/auto/timeline/timelinemodel/tst_timelinemodel.cpp @@ -50,9 +50,6 @@ class DummyModel : public Timeline::TimelineModel public: DummyModel(int modelId); DummyModel(QString displayName = tr("dummy"), QObject *parent = 0); - QColor color(int) const { return QColor(); } - QVariantList labels() const { return QVariantList(); } - QVariantMap details(int) const { return QVariantMap(); } int expandedRow(int) const { return 2; } int collapsedRow(int) const { return 1; } @@ -330,8 +327,7 @@ void tst_TimelineModel::displayName() void tst_TimelineModel::defaultValues() { - DummyModel dummy; - dummy.loadData(); + Timeline::TimelineModel dummy(12, QLatin1String("dings")); QCOMPARE(dummy.location(0), QVariantMap()); QCOMPARE(dummy.handlesTypeId(0), false); QCOMPARE(dummy.selectionIdForLocation(QString(), 0, 0), -1); @@ -339,6 +335,11 @@ void tst_TimelineModel::defaultValues() QCOMPARE(dummy.rowMinValue(0), 0); QCOMPARE(dummy.rowMaxValue(0), 0); QCOMPARE(dummy.typeId(0), -1); + QCOMPARE(dummy.color(0), QColor()); + QCOMPARE(dummy.labels(), QVariantList()); + QCOMPARE(dummy.details(0), QVariantMap()); + QCOMPARE(dummy.collapsedRow(0), 0); + QCOMPARE(dummy.expandedRow(0), 0); } void tst_TimelineModel::row()