Make setting twice the very same model on QComboBox a no-op

Basically, introduce a small check for this corner-case situation.
Setting a model doesn't just store a pointer, but also resets the current
index, changes the line edit completion model, and so on, and seems silly
to trigger changes in such cases.

[ChangeLog][QtWidgets][QComboBox] A QComboBox does not reset itself any
more when setting the same model more than once.

Change-Id: If028b36cdfaa5552c156dd900e123ca9a04d4e3d
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
Giuseppe D'Angelo 2014-12-18 16:07:27 +01:00
parent ebd33883e7
commit 95092e2011
2 changed files with 9 additions and 0 deletions

View File

@ -1931,6 +1931,9 @@ void QComboBox::setModel(QAbstractItemModel *model)
return;
}
if (model == d->model)
return;
#ifndef QT_NO_COMPLETER
if (d->lineEdit && d->lineEdit->completer()
&& d->lineEdit->completer() == d->completer)

View File

@ -1576,6 +1576,12 @@ void tst_QComboBox::setModel()
box.setModel(new QStandardItemModel(2,1, &box));
QCOMPARE(box.currentIndex(), 0);
QVERIFY(box.model() != oldModel);
// check that setting the very same model doesn't move the current item
box.setCurrentIndex(1);
QCOMPARE(box.currentIndex(), 1);
box.setModel(box.model());
QCOMPARE(box.currentIndex(), 1);
}
void tst_QComboBox::setCustomModelAndView()