summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2013-07-02 15:49:50 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-08 05:58:31 +0200
commit737abb8a5e51d75c0f2f93d5f7b42b05400034a9 (patch)
tree28eb60b253fb6b90b4b8793bb8ba1bdb3cf5e45d /src/widgets/widgets
parentd0c8fc3b2831de809bdb562db0924673c1abcc84 (diff)
QComboBox: fix item activation via completer
Task-number: QTBUG-31146 Change-Id: I64291f397d80bf934152f63e629810540abf466e Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com> Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Diffstat (limited to 'src/widgets/widgets')
-rw-r--r--src/widgets/widgets/qcombobox.cpp31
-rw-r--r--src/widgets/widgets/qcombobox.h4
-rw-r--r--src/widgets/widgets/qcombobox_p.h4
3 files changed, 30 insertions, 9 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index c59edf295c..afe8f1c3f4 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -59,6 +59,7 @@
#include <qheaderview.h>
#include <qmath.h>
#include <qmetaobject.h>
+#include <qabstractproxymodel.h>
#include <private/qguiapplication_p.h>
#include <private/qapplication_p.h>
#include <private/qcombobox_p.h>
@@ -173,18 +174,28 @@ QStyleOptionMenuItem QComboMenuDelegate::getStyleOption(const QStyleOptionViewIt
return menuOption;
}
-#ifdef QT_KEYPAD_NAVIGATION
-void QComboBoxPrivate::_q_completerActivated()
+#ifndef QT_NO_COMPLETER
+void QComboBoxPrivate::_q_completerActivated(const QModelIndex &index)
{
Q_Q(QComboBox);
+ if (index.isValid() && q->completer()) {
+ QAbstractProxyModel *proxy = qobject_cast<QAbstractProxyModel *>(q->completer()->completionModel());
+ if (proxy) {
+ q->setCurrentIndex(proxy->mapToSource(index).row());
+ emitActivated(currentIndex);
+ }
+ }
+
+# ifdef QT_KEYPAD_NAVIGATION
if ( QApplication::keypadNavigationEnabled()
&& q->isEditable()
&& q->completer()
&& q->completer()->completionMode() == QCompleter::UnfilteredPopupCompletion ) {
q->setEditFocus(false);
}
+# endif // QT_KEYPAD_NAVIGATION
}
-#endif
+#endif // !QT_NO_COMPLETER
void QComboBoxPrivate::updateArrow(QStyle::StateFlag state)
{
@@ -1149,6 +1160,14 @@ void QComboBoxPrivate::_q_editingFinished()
void QComboBoxPrivate::_q_returnPressed()
{
Q_Q(QComboBox);
+
+ // The insertion code below does not apply when the policy is QComboBox::NoInsert.
+ // In case a completer is installed, item activation via the completer is handled
+ // in _q_completerActivated(). Otherwise _q_editingFinished() updates the current
+ // index as appropriate.
+ if (insertPolicy == QComboBox::NoInsert)
+ return;
+
if (lineEdit && !lineEdit->text().isEmpty()) {
if (q->count() >= maxCount && !(this->insertPolicy == QComboBox::InsertAtCurrent))
return;
@@ -1191,7 +1210,6 @@ void QComboBoxPrivate::_q_returnPressed()
break;
}
break;
- case QComboBox::NoInsert:
default:
break;
}
@@ -1393,6 +1411,7 @@ void QComboBox::setAutoCompletion(bool enable)
if (d->lineEdit->completer())
return;
d->completer = new QCompleter(d->model, d->lineEdit);
+ connect(d->completer, SIGNAL(activated(QModelIndex)), this, SLOT(_q_completerActivated(QModelIndex)));
d->completer->setCaseSensitivity(d->autoCompletionCaseSensitivity);
d->completer->setCompletionMode(QCompleter::InlineCompletion);
d->completer->setCompletionColumn(d->modelColumn);
@@ -1805,8 +1824,10 @@ void QComboBox::setCompleter(QCompleter *c)
if (!d->lineEdit)
return;
d->lineEdit->setCompleter(c);
- if (c)
+ if (c) {
+ connect(c, SIGNAL(activated(QModelIndex)), this, SLOT(_q_completerActivated(QModelIndex)));
c->setWidget(this);
+ }
}
/*!
diff --git a/src/widgets/widgets/qcombobox.h b/src/widgets/widgets/qcombobox.h
index d167ac7d11..2fafe79f7a 100644
--- a/src/widgets/widgets/qcombobox.h
+++ b/src/widgets/widgets/qcombobox.h
@@ -259,8 +259,8 @@ private:
Q_PRIVATE_SLOT(d_func(), void _q_rowsRemoved(const QModelIndex & parent, int start, int end))
Q_PRIVATE_SLOT(d_func(), void _q_modelDestroyed())
Q_PRIVATE_SLOT(d_func(), void _q_modelReset())
-#ifdef QT_KEYPAD_NAVIGATION
- Q_PRIVATE_SLOT(d_func(), void _q_completerActivated())
+#ifndef QT_NO_COMPLETER
+ Q_PRIVATE_SLOT(d_func(), void _q_completerActivated(const QModelIndex &index))
#endif
};
diff --git a/src/widgets/widgets/qcombobox_p.h b/src/widgets/widgets/qcombobox_p.h
index 14cf9e7925..07ba9b0925 100644
--- a/src/widgets/widgets/qcombobox_p.h
+++ b/src/widgets/widgets/qcombobox_p.h
@@ -348,8 +348,8 @@ public:
void _q_emitCurrentIndexChanged(const QModelIndex &index);
void _q_modelDestroyed();
void _q_modelReset();
-#ifdef QT_KEYPAD_NAVIGATION
- void _q_completerActivated();
+#ifndef QT_NO_COMPLETER
+ void _q_completerActivated(const QModelIndex &index);
#endif
void _q_resetButton();
void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);