QComboBox - optimize (improve stupid code at enter-key)

There is no need to do a search for an item if we already
have the correct index.

Change-Id: Iac0e7df7573b71b82aa491acb8e289fe02fb3285
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
This commit is contained in:
Thorbjørn Martsum 2013-07-07 14:59:27 +02:00 committed by The Qt Project
parent e08aca15ec
commit 6dec40628b

View File

@ -1136,10 +1136,9 @@ Qt::MatchFlags QComboBoxPrivate::matchFlags() const
void QComboBoxPrivate::_q_editingFinished() void QComboBoxPrivate::_q_editingFinished()
{ {
Q_Q(QComboBox); Q_Q(QComboBox);
if (lineEdit && !lineEdit->text().isEmpty()) { if (lineEdit && !lineEdit->text().isEmpty() && itemText(currentIndex) != lineEdit->text()) {
//here we just check if the current item was entered
const int index = q_func()->findText(lineEdit->text(), matchFlags()); const int index = q_func()->findText(lineEdit->text(), matchFlags());
if (index != -1 && itemText(currentIndex) != lineEdit->text()) { if (index != -1) {
q->setCurrentIndex(index); q->setCurrentIndex(index);
emitActivated(currentIndex); emitActivated(currentIndex);
} }