diff options
Diffstat (limited to 'tests/auto/qcompleter/tst_qcompleter.cpp')
-rw-r--r-- | tests/auto/qcompleter/tst_qcompleter.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/auto/qcompleter/tst_qcompleter.cpp b/tests/auto/qcompleter/tst_qcompleter.cpp index 3daa3a0..f6f1a07 100644 --- a/tests/auto/qcompleter/tst_qcompleter.cpp +++ b/tests/auto/qcompleter/tst_qcompleter.cpp @@ -140,6 +140,8 @@ private slots: // task-specific tests below me void task178797_activatedOnReturn(); void task189564_omitNonSelectableItems(); + void task246056_setCompletionPrefix(); + void task250064_lostFocus(); private: void filter(); @@ -1096,5 +1098,94 @@ void tst_QCompleter::task189564_omitNonSelectableItems() QVERIFY(matches2.isEmpty()); } +class task246056_ComboBox : public QComboBox +{ + Q_OBJECT +public: + task246056_ComboBox() + { + setEditable(true); + setInsertPolicy(NoInsert); + Q_ASSERT(completer()); + completer()->setCompletionMode(QCompleter::PopupCompletion); + completer()->setCompletionRole(Qt::DisplayRole); + connect(lineEdit(), SIGNAL(editingFinished()), SLOT(setCompletionPrefix())); + } +private slots: + void setCompletionPrefix() { completer()->setCompletionPrefix(lineEdit()->text()); } +}; + +void tst_QCompleter::task246056_setCompletionPrefix() +{ + task246056_ComboBox *comboBox = new task246056_ComboBox; + comboBox->addItem(""); + comboBox->addItem("a1"); + comboBox->addItem("a2"); + comboBox->show(); + comboBox->setFocus(); + QTest::qWait(100); + QTest::keyPress(comboBox, 'a'); + QTest::keyPress(comboBox->completer()->popup(), Qt::Key_Down); + QTest::keyPress(comboBox->completer()->popup(), Qt::Key_Down); + QTest::keyPress(comboBox->completer()->popup(), Qt::Key_Enter); // don't crash! +} + +class task250064_TextEdit : public QTextEdit +{ +public: + QCompleter *completer; + + task250064_TextEdit() + { + completer = new QCompleter; + completer->setWidget(this); + } + + void keyPressEvent (QKeyEvent *e) + { + completer->popup(); + QTextEdit::keyPressEvent(e); + } +}; + +class task250064_Widget : public QWidget +{ + Q_OBJECT +public: + task250064_TextEdit *textEdit; + + task250064_Widget(task250064_TextEdit *textEdit) + : textEdit(textEdit) + { + QTabWidget *tabWidget = new QTabWidget; + tabWidget->setFocusPolicy(Qt::ClickFocus); + tabWidget->addTab(textEdit, "untitled"); + + QVBoxLayout *layout = new QVBoxLayout(this); + layout->addWidget(tabWidget); + + textEdit->setPlainText("bla bla bla"); + textEdit->setFocus(); + } + + void setCompletionModel() + { + textEdit->completer->setModel(0); + } +}; + +void tst_QCompleter::task250064_lostFocus() +{ + task250064_TextEdit *textEdit = new task250064_TextEdit; + task250064_Widget *widget = new task250064_Widget(textEdit); + widget->show(); + QTest::qWait(100); + QTest::keyPress(textEdit, 'a'); + Qt::FocusPolicy origPolicy = textEdit->focusPolicy(); + QVERIFY(origPolicy != Qt::NoFocus); + widget->setCompletionModel(); + QCOMPARE(textEdit->focusPolicy(), origPolicy); +} + QTEST_MAIN(tst_QCompleter) #include "tst_qcompleter.moc" |