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>
This commit is contained in:
Ulf Hermann
2015-04-09 15:38:59 +02:00
parent 7b1a421fbf
commit 171d16c6fb
2 changed files with 9 additions and 4 deletions

View File

@@ -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

View File

@@ -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()