From 171d16c6fb56c202efb7a3e79e7121dadac85265 Mon Sep 17 00:00:00 2001 From: Ulf Hermann <ulf.hermann@theqtcompany.com> Date: Thu, 9 Apr 2015 15:38:59 +0200 Subject: [PATCH] Timeline: Be more exact about height of model aggregator Only emit the change signal if the height has actually changed. Change-Id: Ic4bf67f25cb4a7f204815b4e6b0c6bd88c71944a Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com> --- src/libs/timeline/timelinemodelaggregator.cpp | 9 +++++---- .../tst_timelinemodelaggregator.cpp | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libs/timeline/timelinemodelaggregator.cpp b/src/libs/timeline/timelinemodelaggregator.cpp index bad5462fc5e..b363752058a 100644 --- a/src/libs/timeline/timelinemodelaggregator.cpp +++ b/src/libs/timeline/timelinemodelaggregator.cpp @@ -53,10 +53,6 @@ TimelineModelAggregator::TimelineModelAggregator(TimelineNotesModel *notes, QObj : QObject(parent), d(new TimelineModelAggregatorPrivate(this)) { d->notesModel = notes; - connect(this, &TimelineModelAggregator::modelsChanged, - this, &TimelineModelAggregator::heightChanged); - connect(this, &TimelineModelAggregator::stateChanged, - this, &TimelineModelAggregator::heightChanged); } TimelineModelAggregator::~TimelineModelAggregator() @@ -76,6 +72,8 @@ void TimelineModelAggregator::addModel(TimelineModel *m) if (d->notesModel) d->notesModel->addTimelineModel(m); emit modelsChanged(); + if (m->height() != 0) + emit heightChanged(); } const TimelineModel *TimelineModelAggregator::model(int modelIndex) const @@ -98,10 +96,13 @@ TimelineNotesModel *TimelineModelAggregator::notes() const void TimelineModelAggregator::clear() { + int prevHeight = height(); d->modelList.clear(); if (d->notesModel) d->notesModel->clear(); emit modelsChanged(); + if (height() != prevHeight) + emit heightChanged(); } int TimelineModelAggregator::modelOffset(int modelIndex) const diff --git a/tests/auto/timeline/timelinemodelaggregator/tst_timelinemodelaggregator.cpp b/tests/auto/timeline/timelinemodelaggregator/tst_timelinemodelaggregator.cpp index 5eb229c7df7..5de05069d1c 100644 --- a/tests/auto/timeline/timelinemodelaggregator/tst_timelinemodelaggregator.cpp +++ b/tests/auto/timeline/timelinemodelaggregator/tst_timelinemodelaggregator.cpp @@ -54,13 +54,17 @@ void tst_TimelineModelAggregator::height() Timeline::TimelineModelAggregator aggregator(0); QCOMPARE(aggregator.height(), 0); + QSignalSpy heightSpy(&aggregator, SIGNAL(heightChanged())); Timeline::TimelineModel *model = new Timeline::TimelineModel(25, QString()); aggregator.addModel(model); QCOMPARE(aggregator.height(), 0); + QCOMPARE(heightSpy.count(), 0); aggregator.addModel(new HeightTestModel); QVERIFY(aggregator.height() > 0); + QCOMPARE(heightSpy.count(), 1); aggregator.clear(); QCOMPARE(aggregator.height(), 0); + QCOMPARE(heightSpy.count(), 2); } void tst_TimelineModelAggregator::addRemoveModel() -- GitLab