summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin C Meyer <benjamin.meyer@torchmobile.com>2009-07-30 14:59:02 (GMT)
committerEskil Abrahamsen Blomfeldt <eblomfel@trolltech.com>2009-07-30 14:59:02 (GMT)
commit4c3cc938ed17e9b98bbdfc9a7e4c5a5b7efd4a3b (patch)
tree544dedee9d860c12522cc280f288851249b942c9
parent2ebebeebd3dacc7192f2f998d324d16bc8cba9fa (diff)
downloadQt-4c3cc938ed17e9b98bbdfc9a7e4c5a5b7efd4a3b.zip
Qt-4c3cc938ed17e9b98bbdfc9a7e4c5a5b7efd4a3b.tar.gz
Qt-4c3cc938ed17e9b98bbdfc9a7e4c5a5b7efd4a3b.tar.bz2
Do not emit activated and close the popup when the item is not enabled.
Autotest: included Merge-request: 378 Reviewed-by: Eskil Abrahamsen Blomfeldt <eblomfel@trolltech.com>
-rw-r--r--src/gui/util/qcompleter.cpp6
-rw-r--r--tests/auto/qcompleter/tst_qcompleter.cpp27
2 files changed, 31 insertions, 2 deletions
diff --git a/src/gui/util/qcompleter.cpp b/src/gui/util/qcompleter.cpp
index bf1fa6a..a0a3756 100644
--- a/src/gui/util/qcompleter.cpp
+++ b/src/gui/util/qcompleter.cpp
@@ -824,6 +824,9 @@ void QCompleterPrivate::_q_complete(QModelIndex index, bool highlighted)
Q_Q(QCompleter);
QString completion;
+ if (!(index.flags() & Qt::ItemIsEnabled))
+ return;
+
if (!index.isValid() || (!proxy->showAll && (index.row() >= proxy->engine->matchCount()))) {
completion = prefix;
} else {
@@ -1102,7 +1105,8 @@ void QCompleter::setPopup(QAbstractItemView *popup)
QObject::connect(popup, SIGNAL(clicked(QModelIndex)),
this, SLOT(_q_complete(QModelIndex)));
- QObject::connect(popup, SIGNAL(clicked(QModelIndex)), popup, SLOT(hide()));
+ QObject::connect(this, SIGNAL(activated(QModelIndex)),
+ popup, SLOT(hide()));
QObject::connect(popup->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this, SLOT(_q_completionSelected(QItemSelection)));
diff --git a/tests/auto/qcompleter/tst_qcompleter.cpp b/tests/auto/qcompleter/tst_qcompleter.cpp
index 0a9c16a..a65490d 100644
--- a/tests/auto/qcompleter/tst_qcompleter.cpp
+++ b/tests/auto/qcompleter/tst_qcompleter.cpp
@@ -138,6 +138,7 @@ private slots:
void setters();
void dynamicSortOrder();
+ void disabledItems();
// task-specific tests below me
void task178797_activatedOnReturn();
@@ -147,7 +148,6 @@ private slots:
void task253125_lineEditCompletion_data();
void task253125_lineEditCompletion();
-
void task247560_keyboardNavigation();
private:
@@ -1106,6 +1106,31 @@ void tst_QCompleter::dynamicSortOrder()
QCOMPARE(completer.completionCount(), 12);
}
+void tst_QCompleter::disabledItems()
+{
+ QLineEdit lineEdit;
+ QStandardItemModel *model = new QStandardItemModel(&lineEdit);
+ QStandardItem *suggestions = new QStandardItem("suggestions");
+ suggestions->setEnabled(false);
+ model->appendRow(suggestions);
+ model->appendRow(new QStandardItem("suggestions Enabled"));
+ QCompleter *completer = new QCompleter(model, &lineEdit);
+ QSignalSpy spy(completer, SIGNAL(activated(const QString &)));
+ lineEdit.setCompleter(completer);
+ lineEdit.show();
+
+ QTest::keyPress(&lineEdit, Qt::Key_S);
+ QTest::keyPress(&lineEdit, Qt::Key_U);
+ QAbstractItemView *view = lineEdit.completer()->popup();
+ QVERIFY(view->isVisible());
+ QTest::mouseClick(view->viewport(), Qt::LeftButton, 0, view->visualRect(view->model()->index(0, 0)).center());
+ QCOMPARE(spy.count(), 0);
+ QVERIFY(view->isVisible());
+ QTest::mouseClick(view->viewport(), Qt::LeftButton, 0, view->visualRect(view->model()->index(1, 0)).center());
+ QCOMPARE(spy.count(), 1);
+ QVERIFY(!view->isVisible());
+}
+
void tst_QCompleter::task178797_activatedOnReturn()
{
QStringList words;