forked from qt-creator/qt-creator
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 <kai.koehne@theqtcompany.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user