Commit 7e03cbd8 authored by Ulf Hermann's avatar Ulf Hermann
Browse files

Timeline: Allow setting the timeline model's displayName



This makes a lot of things easier. There is no real reason for it to be
const.

Change-Id: I426a2cbcfce6eae7cf7fabc28ab63098885324b8
Reviewed-by: default avatarJoerg Bornemann <joerg.bornemann@theqtcompany.com>
parent 5ab8440e
......@@ -151,8 +151,8 @@ int TimelineModel::row(int index) const
return expanded() ? expandedRow(index) : collapsedRow(index);
}
TimelineModel::TimelineModelPrivate::TimelineModelPrivate(int modelId, const QString &displayName) :
modelId(modelId), displayName(displayName), expanded(false), hidden(false),
TimelineModel::TimelineModelPrivate::TimelineModelPrivate(int modelId) :
modelId(modelId), expanded(false), hidden(false),
expandedRowCount(1), collapsedRowCount(1), q_ptr(0)
{
}
......@@ -163,8 +163,8 @@ TimelineModel::TimelineModel(TimelineModelPrivate &dd, QObject *parent) :
d_ptr->q_ptr = this;
}
TimelineModel::TimelineModel(int modelId, const QString &displayName, QObject *parent) :
QObject(parent), d_ptr(new TimelineModelPrivate(modelId, displayName))
TimelineModel::TimelineModel(int modelId, QObject *parent) :
QObject(parent), d_ptr(new TimelineModelPrivate(modelId))
{
d_ptr->q_ptr = this;
}
......@@ -512,6 +512,15 @@ void TimelineModel::setHidden(bool hidden)
}
}
void TimelineModel::setDisplayName(const QString &displayName)
{
Q_D(TimelineModel);
if (d->displayName != displayName) {
d->displayName = displayName;
emit displayNameChanged();
}
}
QString TimelineModel::displayName() const
{
Q_D(const TimelineModel);
......
......@@ -37,7 +37,7 @@ class TIMELINE_EXPORT TimelineModel : public QObject
{
Q_OBJECT
Q_PROPERTY(int modelId READ modelId CONSTANT)
Q_PROPERTY(QString displayName READ displayName CONSTANT)
Q_PROPERTY(QString displayName READ displayName WRITE setDisplayName NOTIFY displayNameChanged)
Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged)
Q_PROPERTY(bool hidden READ hidden WRITE setHidden NOTIFY hiddenChanged)
Q_PROPERTY(bool expanded READ expanded WRITE setExpanded NOTIFY expandedChanged)
......@@ -52,7 +52,7 @@ class TIMELINE_EXPORT TimelineModel : public QObject
public:
class TimelineModelPrivate;
TimelineModel(int modelId, const QString &displayName, QObject *parent = 0);
TimelineModel(int modelId, QObject *parent = 0);
~TimelineModel();
// Methods implemented by the abstract model itself
......@@ -82,6 +82,7 @@ public:
bool hidden() const;
void setExpanded(bool expanded);
void setHidden(bool hidden);
void setDisplayName(const QString &displayName);
QString displayName() const;
int expandedRowCount() const;
int collapsedRowCount() const;
......@@ -123,6 +124,7 @@ signals:
void collapsedRowCountChanged();
void rowCountChanged();
void labelsChanged();
void displayNameChanged();
protected:
QColor colorBySelectionId(int index) const;
......
......@@ -64,7 +64,7 @@ public:
inline qint64 timestamp() const {return end;}
};
TimelineModelPrivate(int modelId, const QString &displayName);
TimelineModelPrivate(int modelId);
void init(TimelineModel *q);
int firstIndexNoParents(qint64 startTime) const;
......@@ -131,7 +131,7 @@ public:
QVector<int> rowOffsets;
const int modelId;
const QString displayName;
QString displayName;
bool expanded;
bool hidden;
......
......@@ -32,11 +32,11 @@ QmlProfilerTimelineModel::QmlProfilerTimelineModel(QmlProfilerModelManager *mode
QmlDebug::RangeType rangeType,
QmlDebug::ProfileFeature mainFeature,
QObject *parent) :
TimelineModel(modelManager->registerModelProxy(),
tr(QmlProfilerModelManager::featureName(mainFeature)), parent),
TimelineModel(modelManager->registerModelProxy(), parent),
m_message(message), m_rangeType(rangeType), m_mainFeature(mainFeature),
m_modelManager(modelManager)
{
setDisplayName(tr(QmlProfilerModelManager::featureName(mainFeature)));
connect(modelManager, &QmlProfilerModelManager::stateChanged,
this, &QmlProfilerTimelineModel::dataChanged);
connect(modelManager, &QmlProfilerModelManager::visibleFeaturesChanged,
......
......@@ -85,7 +85,7 @@ void tst_TimelineAbstractRenderer::model()
QSignalSpy spy(&renderer, SIGNAL(modelChanged(TimelineModel*)));
QVERIFY(!renderer.modelDirty());
QCOMPARE(spy.count(), 0);
TimelineModel model(0, QLatin1String("model"));
TimelineModel model(0);
QCOMPARE(renderer.model(), static_cast<TimelineModel *>(0));
renderer.setModel(&model);
QVERIFY(renderer.modelDirty());
......
......@@ -49,7 +49,7 @@ private slots:
void update();
};
DummyModel::DummyModel() : TimelineModel(12, QLatin1String("dings"))
DummyModel::DummyModel() : TimelineModel(12)
{
}
......
......@@ -33,8 +33,7 @@ static const qint64 ItemSpacing = 1 << 20;
class DummyModelPrivate : public Timeline::TimelineModel::TimelineModelPrivate {
public:
DummyModelPrivate(int modelId) :
Timeline::TimelineModel::TimelineModelPrivate(modelId, QLatin1String("horst"))
DummyModelPrivate(int modelId) : Timeline::TimelineModel::TimelineModelPrivate(modelId)
{}
};
......@@ -92,8 +91,9 @@ DummyModel::DummyModel(int modelId) :
}
DummyModel::DummyModel(QString displayName, QObject *parent) :
TimelineModel(12, displayName, parent)
TimelineModel(12, parent)
{
setDisplayName(displayName);
}
void DummyModel::loadData()
......@@ -353,12 +353,21 @@ void tst_TimelineModel::displayName()
{
QLatin1String name("testest");
DummyModel dummy(name);
QSignalSpy spy(&dummy, SIGNAL(displayNameChanged()));
QCOMPARE(dummy.displayName(), name);
QCOMPARE(spy.count(), 0);
dummy.setDisplayName(name);
QCOMPARE(dummy.displayName(), name);
QCOMPARE(spy.count(), 0);
name = QLatin1String("testerei");
dummy.setDisplayName(name);
QCOMPARE(dummy.displayName(), name);
QCOMPARE(spy.count(), 1);
}
void tst_TimelineModel::defaultValues()
{
Timeline::TimelineModel dummy(12, QLatin1String("dings"));
Timeline::TimelineModel dummy(12);
QCOMPARE(dummy.location(0), QVariantMap());
QCOMPARE(dummy.handlesTypeId(0), false);
QCOMPARE(dummy.selectionIdForLocation(QString(), 0, 0), -1);
......
......@@ -38,7 +38,7 @@ private slots:
class HeightTestModel : public Timeline::TimelineModel {
public:
HeightTestModel() : TimelineModel(2, QString())
HeightTestModel() : TimelineModel(2)
{
insert(0, 1, 1);
}
......@@ -50,7 +50,7 @@ void tst_TimelineModelAggregator::height()
QCOMPARE(aggregator.height(), 0);
QSignalSpy heightSpy(&aggregator, SIGNAL(heightChanged()));
Timeline::TimelineModel *model = new Timeline::TimelineModel(25, QString());
Timeline::TimelineModel *model = new Timeline::TimelineModel(25);
aggregator.addModel(model);
QCOMPARE(aggregator.height(), 0);
QCOMPARE(heightSpy.count(), 0);
......@@ -70,8 +70,8 @@ void tst_TimelineModelAggregator::addRemoveModel()
QCOMPARE(aggregator.notes(), &notes);
Timeline::TimelineModel *model1 = new Timeline::TimelineModel(25, QString());
Timeline::TimelineModel *model2 = new Timeline::TimelineModel(26, QString());
Timeline::TimelineModel *model1 = new Timeline::TimelineModel(25);
Timeline::TimelineModel *model2 = new Timeline::TimelineModel(26);
aggregator.addModel(model1);
QCOMPARE(spy.count(), 1);
QCOMPARE(aggregator.modelCount(), 1);
......@@ -99,7 +99,7 @@ void tst_TimelineModelAggregator::addRemoveModel()
class PrevNextTestModel : public Timeline::TimelineModel
{
public:
PrevNextTestModel(int x) : TimelineModel(x, QString())
PrevNextTestModel(int x) : TimelineModel(x)
{
for (int i = 0; i < 20; ++i)
insert(i + x, i * x, x);
......@@ -114,7 +114,7 @@ void tst_TimelineModelAggregator::prevNext()
aggregator.addModel(new PrevNextTestModel(3));
// Add an empty model to trigger the special code paths that skip it
aggregator.addModel(new Timeline::TimelineModel(4, QString()));
aggregator.addModel(new Timeline::TimelineModel(4));
QLatin1String item("item");
QLatin1String model("model");
QVariantMap result;
......
......@@ -41,7 +41,7 @@ private slots:
class TestModel : public Timeline::TimelineModel {
public:
TestModel(int modelId = 10) : TimelineModel(modelId, QString())
TestModel(int modelId = 10) : TimelineModel(modelId)
{
insert(0, 10, 10);
}
......
......@@ -49,7 +49,7 @@ private slots:
void update();
};
DummyModel::DummyModel(int id) : TimelineModel(id, QLatin1String("dings"))
DummyModel::DummyModel(int id) : TimelineModel(id)
{
}
......
......@@ -34,7 +34,7 @@ class DummyRenderer : public TimelineOverviewRenderer {
class DummyModel : public TimelineModel {
public:
DummyModel() : TimelineModel(0, QLatin1String("x")) {}
DummyModel() : TimelineModel(0) {}
void loadData()
{
......
......@@ -34,7 +34,7 @@ class DummyRenderer : public TimelineRenderer {
class DummyModel : public TimelineModel {
public:
DummyModel() : TimelineModel(0, QLatin1String("x")) {}
DummyModel() : TimelineModel(0) {}
void loadData()
{
......
......@@ -140,7 +140,7 @@ void tst_TimelineRenderState::emptyRoots()
void tst_TimelineRenderState::assembleNodeTree()
{
TimelineModel model(3, QString());
TimelineModel model(3);
TimelineRenderState state1(1, 2, 0.5, 3);
state1.assembleNodeTree(&model, 30, 30);
QSGTransformNode *node = state1.finalize(0, true, QMatrix4x4());
......
......@@ -52,7 +52,7 @@ private slots:
void update();
};
DummyModel::DummyModel(int id) : TimelineModel(id, QLatin1String("dings"))
DummyModel::DummyModel(int id) : TimelineModel(id)
{
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment