forked from qt-creator/qt-creator
Timeline: Be more exact about model height changes.
Emit the signal every time the height changes, but not if it doesn't. Change-Id: I3a3da737bc99ae99ac6d5690c55c21d94cf5b647 Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
This commit is contained in:
@@ -121,8 +121,10 @@ void TimelineModel::setCollapsedRowCount(int rows)
|
|||||||
if (d->collapsedRowCount != rows) {
|
if (d->collapsedRowCount != rows) {
|
||||||
d->collapsedRowCount = rows;
|
d->collapsedRowCount = rows;
|
||||||
emit collapsedRowCountChanged();
|
emit collapsedRowCountChanged();
|
||||||
if (!d->expanded)
|
if (!d->expanded) {
|
||||||
emit rowCountChanged();
|
emit rowCountChanged();
|
||||||
|
emit heightChanged(); // collapsed rows have a fixed size
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,12 +138,16 @@ void TimelineModel::setExpandedRowCount(int rows)
|
|||||||
{
|
{
|
||||||
Q_D(TimelineModel);
|
Q_D(TimelineModel);
|
||||||
if (d->expandedRowCount != rows) {
|
if (d->expandedRowCount != rows) {
|
||||||
|
int prevHeight = height();
|
||||||
if (d->rowOffsets.length() > rows)
|
if (d->rowOffsets.length() > rows)
|
||||||
d->rowOffsets.resize(rows);
|
d->rowOffsets.resize(rows);
|
||||||
d->expandedRowCount = rows;
|
d->expandedRowCount = rows;
|
||||||
emit expandedRowCountChanged();
|
emit expandedRowCountChanged();
|
||||||
if (d->expanded)
|
if (d->expanded) {
|
||||||
emit rowCountChanged();
|
emit rowCountChanged();
|
||||||
|
if (height() != prevHeight)
|
||||||
|
emit heightChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,25 +162,16 @@ TimelineModel::TimelineModelPrivate::TimelineModelPrivate(int modelId, const QSt
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimelineModel::TimelineModelPrivate::init(TimelineModel *q)
|
|
||||||
{
|
|
||||||
q_ptr = q;
|
|
||||||
connect(q,SIGNAL(expandedChanged()),q,SIGNAL(heightChanged()));
|
|
||||||
connect(q,SIGNAL(hiddenChanged()),q,SIGNAL(heightChanged()));
|
|
||||||
connect(q,SIGNAL(emptyChanged()),q,SIGNAL(heightChanged()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TimelineModel::TimelineModel(TimelineModelPrivate &dd, QObject *parent) :
|
TimelineModel::TimelineModel(TimelineModelPrivate &dd, QObject *parent) :
|
||||||
QObject(parent), d_ptr(&dd)
|
QObject(parent), d_ptr(&dd)
|
||||||
{
|
{
|
||||||
d_ptr->init(this);
|
d_ptr->q_ptr = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
TimelineModel::TimelineModel(int modelId, const QString &displayName, QObject *parent) :
|
TimelineModel::TimelineModel(int modelId, const QString &displayName, QObject *parent) :
|
||||||
QObject(parent), d_ptr(new TimelineModelPrivate(modelId, displayName))
|
QObject(parent), d_ptr(new TimelineModelPrivate(modelId, displayName))
|
||||||
{
|
{
|
||||||
d_ptr->init(this);
|
d_ptr->q_ptr = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
TimelineModel::~TimelineModel()
|
TimelineModel::~TimelineModel()
|
||||||
@@ -492,8 +489,11 @@ void TimelineModel::setExpanded(bool expanded)
|
|||||||
{
|
{
|
||||||
Q_D(TimelineModel);
|
Q_D(TimelineModel);
|
||||||
if (expanded != d->expanded) {
|
if (expanded != d->expanded) {
|
||||||
|
int prevHeight = height();
|
||||||
d->expanded = expanded;
|
d->expanded = expanded;
|
||||||
emit expandedChanged();
|
emit expandedChanged();
|
||||||
|
if (prevHeight != height())
|
||||||
|
emit heightChanged();
|
||||||
if (d->collapsedRowCount != d->expandedRowCount)
|
if (d->collapsedRowCount != d->expandedRowCount)
|
||||||
emit rowCountChanged();
|
emit rowCountChanged();
|
||||||
}
|
}
|
||||||
@@ -509,8 +509,11 @@ void TimelineModel::setHidden(bool hidden)
|
|||||||
{
|
{
|
||||||
Q_D(TimelineModel);
|
Q_D(TimelineModel);
|
||||||
if (hidden != d->hidden) {
|
if (hidden != d->hidden) {
|
||||||
|
int prevHeight = height();
|
||||||
d->hidden = hidden;
|
d->hidden = hidden;
|
||||||
emit hiddenChanged();
|
emit hiddenChanged();
|
||||||
|
if (height() != prevHeight)
|
||||||
|
emit heightChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -227,14 +227,23 @@ void tst_TimelineModel::rowOffset()
|
|||||||
void tst_TimelineModel::height()
|
void tst_TimelineModel::height()
|
||||||
{
|
{
|
||||||
DummyModel dummy;
|
DummyModel dummy;
|
||||||
|
QSignalSpy spy(&dummy, SIGNAL(heightChanged()));
|
||||||
QCOMPARE(dummy.height(), 0);
|
QCOMPARE(dummy.height(), 0);
|
||||||
dummy.loadData();
|
dummy.loadData();
|
||||||
|
QCOMPARE(spy.count(), 1);
|
||||||
QCOMPARE(dummy.height(), 2 * DefaultRowHeight);
|
QCOMPARE(dummy.height(), 2 * DefaultRowHeight);
|
||||||
dummy.setExpanded(true);
|
dummy.setExpanded(true);
|
||||||
|
QCOMPARE(spy.count(), 2);
|
||||||
QCOMPARE(dummy.height(), 3 * DefaultRowHeight);
|
QCOMPARE(dummy.height(), 3 * DefaultRowHeight);
|
||||||
dummy.setExpandedRowHeight(1, 80);
|
dummy.setExpandedRowHeight(1, 80);
|
||||||
|
QCOMPARE(spy.count(), 3);
|
||||||
QCOMPARE(dummy.height(), 2 * DefaultRowHeight + 80);
|
QCOMPARE(dummy.height(), 2 * DefaultRowHeight + 80);
|
||||||
|
dummy.setHidden(true);
|
||||||
|
QCOMPARE(spy.count(), 4);
|
||||||
|
QCOMPARE(dummy.height(), 0);
|
||||||
dummy.clear();
|
dummy.clear();
|
||||||
|
// When clearing the height can change several times in a row.
|
||||||
|
QVERIFY(spy.count() > 4);
|
||||||
dummy.loadData();
|
dummy.loadData();
|
||||||
dummy.setExpanded(true);
|
dummy.setExpanded(true);
|
||||||
QCOMPARE(dummy.rowHeight(1), DefaultRowHeight); // Make sure the row height gets reset.
|
QCOMPARE(dummy.rowHeight(1), DefaultRowHeight); // Make sure the row height gets reset.
|
||||||
|
Reference in New Issue
Block a user