summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp')
-rw-r--r--tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp311
1 files changed, 247 insertions, 64 deletions
diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
index 8722b4602e..be185c1e7a 100644
--- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
+++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -267,6 +267,8 @@ private slots:
void inputMethodQueryImHints_data();
void inputMethodQueryImHints();
+ void inputMethodQueryEnterKeyType();
+
void inputMethodUpdate();
void undoRedoAndEchoModes_data();
@@ -290,6 +292,13 @@ private slots:
void QTBUG_60319_setInputMaskCheckImSurroundingText();
void testQuickSelectionWithMouse();
void inputRejected();
+ void keyReleasePropagates();
+
+#if QT_CONFIG(shortcut)
+ void deleteWordByKeySequence_data();
+ void deleteWordByKeySequence();
+#endif
+
protected slots:
void editingFinished();
@@ -652,7 +661,7 @@ void tst_QLineEdit::setInputMask()
testWidget->insert(input);
} else {
psKeyClick(testWidget, Qt::Key_Home);
- for (int i=0; i<input.length(); i++)
+ for (int i=0; i<input.size(); i++)
QTest::keyClick(testWidget, input.at(i).toLatin1());
}
@@ -919,8 +928,8 @@ void tst_QLineEdit::hasAcceptableInputValidator()
qApp->sendEvent(testWidget, &lostFocus);
QVERIFY(testWidget->hasAcceptableInput());
- QCOMPARE(spyChanged.count(), 2);
- QCOMPARE(spyEdited.count(), 0);
+ QCOMPARE(spyChanged.size(), 2);
+ QCOMPARE(spyEdited.size(), 0);
}
@@ -1592,7 +1601,7 @@ void tst_QLineEdit::setText()
QSignalSpy editedSpy(testWidget, SIGNAL(textEdited(QString)));
QSignalSpy changedSpy(testWidget, SIGNAL(textChanged(QString)));
testWidget->setText("hello");
- QCOMPARE(editedSpy.count(), 0);
+ QCOMPARE(editedSpy.size(), 0);
QCOMPARE(changedSpy.value(0).value(0).toString(), QString("hello"));
}
@@ -1664,7 +1673,7 @@ void tst_QLineEdit::displayText_data()
QString input;
QString pass;
input = "Hello World";
- pass.resize(input.length());
+ pass.resize(input.size());
pass.fill(passChar);
QTest::newRow(QString(s + " text0").toLatin1()) << input << pass << m << bool(use_setText);
QTest::newRow(QString(s + " text1").toLatin1()) << QString("") <<
@@ -1672,14 +1681,14 @@ void tst_QLineEdit::displayText_data()
m << bool(use_setText);
QTest::newRow(QString(s + " text2").toLatin1()) << QString("A") << QString(passChar) << m << bool(use_setText);
input = QString("ryyryryryryryryryryryryryryryryryryryryryryryryryryryrryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryrryryryryryryryryryryryryry");
- pass.resize(input.length());
+ pass.resize(input.size());
pass.fill(passChar);
QTest::newRow(QString(s + " text3").toLatin1()) << input << pass << m << bool(use_setText);
input = QString("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890`~!@#$%^&*()_-+={[}]|\\:;'?/>.<,\"");
- pass.fill(passChar, input.length());
+ pass.fill(passChar, input.size());
QTest::newRow(QString(s + " text4").toLatin1()) << input << pass << m << bool(use_setText);
input = QString("Hello") + QChar(0xa0) + "World";
- pass.resize(input.length());
+ pass.resize(input.size());
pass.fill(passChar);
QTest::newRow(QString(s + " text with nbsp").toLatin1()) << input << pass << m << bool(use_setText);
}
@@ -2292,7 +2301,7 @@ void tst_QLineEdit::deleteSelectedText()
#ifndef QT_NO_CONTEXTMENU
QMenu *menu = edit.createStandardContextMenu();
- for (int i = 0; i < menu->actions().count(); ++i) {
+ for (int i = 0; i < menu->actions().size(); ++i) {
QAction *current = menu->actions().at(i);
if (current->text() == QLineEdit::tr("Delete")) {
current->trigger(); //this will delete the whole text selected
@@ -2425,7 +2434,7 @@ class QIntFixValidator : public QIntValidator {
public:
QIntFixValidator(int min, int max, QObject *parent) : QIntValidator(min, max, parent) {}
void fixup (QString &input) const override {
- for (int i=0; i<input.length(); ++i)
+ for (int i=0; i<input.size(); ++i)
if (!input.at(i).isNumber()) {
input[(int)i] = QChar('0');
}
@@ -2991,7 +3000,7 @@ void tst_QLineEdit::setSelection_data()
QTest::newRow(selectionTestName(start, length).constData())
<< text << start << length << pos << QString("Abc ") << true;
- start = -1; length = 0; pos = text.length();
+ start = -1; length = 0; pos = text.size();
QTest::newRow(selectionTestName(start, length).constData())
<< text << start << length << pos << QString() << false;
@@ -3011,7 +3020,7 @@ void tst_QLineEdit::setSelection_data()
QTest::newRow(selectionTestName(start, length).constData())
<< text << start << length << pos << QString("A") << true;
- start = -1; length = -1; pos = text.length();
+ start = -1; length = -1; pos = text.size();
QTest::newRow(selectionTestName(start, length).constData())
<< text << start << length << pos << QString() << false;
}
@@ -3308,7 +3317,7 @@ void tst_QLineEdit::validateOnFocusOut()
QTest::keyPress(testWidget, '0');
QCOMPARE(testWidget->text(), QString("10"));
testWidget->clearFocus();
- QCOMPARE(editingFinishedSpy.count(), 0);
+ QCOMPARE(editingFinishedSpy.size(), 0);
testWidget->setFocus();
centerOnScreen(testWidget);
@@ -3321,7 +3330,7 @@ void tst_QLineEdit::validateOnFocusOut()
QTRY_COMPARE(testWidget->text(), QString("100"));
testWidget->clearFocus();
- QCOMPARE(editingFinishedSpy.count(), 1);
+ QCOMPARE(editingFinishedSpy.size(), 1);
}
void tst_QLineEdit::editInvalidText()
@@ -3499,7 +3508,7 @@ void tst_QLineEdit::noTextEditedOnClear()
testWidget->setText("Test");
QSignalSpy textEditedSpy(testWidget, SIGNAL(textEdited(QString)));
testWidget->clear();
- QCOMPARE(textEditedSpy.count(), 0);
+ QCOMPARE(textEditedSpy.size(), 0);
}
void tst_QLineEdit::textMargin_data()
@@ -3515,11 +3524,12 @@ void tst_QLineEdit::textMargin_data()
QLineEdit testWidget;
QFontMetrics metrics(testWidget.font());
const QString s = QLatin1String("MMM MMM MMM");
+ const int windows11StyleHorizontalOffset = qApp->style()->inherits("QWindows11Style") ? 8 : 0;
// Different styles generate different offsets, so
// calculate the width rather than hardcode it.
- const int pixelWidthOfM = metrics.horizontalAdvance(s, 1);
- const int pixelWidthOfMMM_MM = metrics.horizontalAdvance(s, 6);
+ const int pixelWidthOfM = windows11StyleHorizontalOffset + metrics.horizontalAdvance(s, 1);
+ const int pixelWidthOfMMM_MM = windows11StyleHorizontalOffset + metrics.horizontalAdvance(s, 6);
QTest::newRow("default-0") << 0 << 0 << 0 << 0 << QPoint(pixelWidthOfMMM_MM, 0) << 6;
QTest::newRow("default-1") << 0 << 0 << 0 << 0 << QPoint(1, 1) << 0;
@@ -3603,7 +3613,7 @@ void tst_QLineEdit::returnKeyClearsEditedFlag()
// Focus drop with no edits shouldn't emit signal, edited flag == false
testWidget.clearFocus(); // Signal not emitted
QVERIFY(!testWidget.hasFocus());
- QCOMPARE(leSpy.count(), 0);
+ QCOMPARE(leSpy.size(), 0);
// Focus drop after edits should emit signal, edited flag == true
testWidget.setFocus();
@@ -3611,7 +3621,7 @@ void tst_QLineEdit::returnKeyClearsEditedFlag()
QTest::keyClicks(&testWidget, "edit1 "); // edited flag set
testWidget.clearFocus(); // edited flag cleared, signal emitted
QVERIFY(!testWidget.hasFocus());
- QCOMPARE(leSpy.count(), 1);
+ QCOMPARE(leSpy.size(), 1);
// Only text related keys should set edited flag
testWidget.setFocus();
@@ -3621,7 +3631,7 @@ void tst_QLineEdit::returnKeyClearsEditedFlag()
QTest::keyClick(&testWidget, Qt::Key_PageUp);
testWidget.clearFocus(); // Signal not emitted
QVERIFY(!testWidget.hasFocus());
- QCOMPARE(leSpy.count(), 1); // No change
+ QCOMPARE(leSpy.size(), 1); // No change
// Return should always emit signal
testWidget.setFocus();
@@ -3629,12 +3639,12 @@ void tst_QLineEdit::returnKeyClearsEditedFlag()
QTest::keyClick(&testWidget, Qt::Key_Return); /* Without edits,
signal emitted,
edited flag cleared */
- QCOMPARE(leSpy.count(), 2);
+ QCOMPARE(leSpy.size(), 2);
QTest::keyClicks(&testWidget, "edit2 "); // edited flag set
QTest::keyClick(&testWidget, Qt::Key_Return); /* With edits,
signal emitted,
edited flag cleared */
- QCOMPARE(leSpy.count(), 3);
+ QCOMPARE(leSpy.size(), 3);
/* After editing the line edit following a Return key press with a
focus drop should not emit signal a second time since Return now
@@ -3642,10 +3652,10 @@ void tst_QLineEdit::returnKeyClearsEditedFlag()
QTest::keyClicks(&testWidget, "edit3 "); // edited flag set
QTest::keyClick(&testWidget, Qt::Key_Return); /* signal emitted,
edited flag cleared */
- QCOMPARE(leSpy.count(), 4);
+ QCOMPARE(leSpy.size(), 4);
testWidget.clearFocus(); // Signal not emitted since edited == false
QVERIFY(!testWidget.hasFocus());
- QCOMPARE(leSpy.count(), 4); // No change
+ QCOMPARE(leSpy.size(), 4); // No change
}
#ifndef QT_NO_CURSOR
@@ -3712,7 +3722,7 @@ void tst_QLineEdit::task174640_editingFinished()
layout->addWidget(le2);
mw.show();
- QApplication::setActiveWindow(&mw);
+ QApplicationPrivate::setActiveWindow(&mw);
mw.activateWindow();
QVERIFY(QTest::qWaitForWindowActive(&mw));
QCOMPARE(&mw, QApplication::activeWindow());
@@ -3721,19 +3731,19 @@ void tst_QLineEdit::task174640_editingFinished()
le1->setFocus();
QTRY_VERIFY(le1->hasFocus());
- QCOMPARE(editingFinishedSpy.count(), 0);
+ QCOMPARE(editingFinishedSpy.size(), 0);
le2->setFocus();
QTRY_VERIFY(le2->hasFocus());
// editingFinished will not be emitted anew because no editing happened
- QCOMPARE(editingFinishedSpy.count(), 0);
+ QCOMPARE(editingFinishedSpy.size(), 0);
le1->setFocus();
QTRY_VERIFY(le1->hasFocus());
QTest::keyPress(le1, Qt::Key_Plus);
le2->setFocus();
QTRY_VERIFY(le2->hasFocus());
- QCOMPARE(editingFinishedSpy.count(), 1);
+ QCOMPARE(editingFinishedSpy.size(), 1);
editingFinishedSpy.clear();
le1->setFocus();
@@ -3748,7 +3758,7 @@ void tst_QLineEdit::task174640_editingFinished()
mw.activateWindow();
delete testMenu1;
- QCOMPARE(editingFinishedSpy.count(), 0);
+ QCOMPARE(editingFinishedSpy.size(), 0);
QTRY_VERIFY(le1->hasFocus());
// Ensure le1 has been edited
QTest::keyPress(le1, Qt::Key_Plus);
@@ -3761,7 +3771,7 @@ void tst_QLineEdit::task174640_editingFinished()
QTest::qWait(20);
mw.activateWindow();
delete testMenu2;
- QCOMPARE(editingFinishedSpy.count(), 1);
+ QCOMPARE(editingFinishedSpy.size(), 1);
}
#if QT_CONFIG(completer)
@@ -3820,7 +3830,7 @@ void tst_QLineEdit::task210502_caseInsensitiveInlineCompletion()
completer.setCompletionMode(QCompleter::InlineCompletion);
lineEdit.setCompleter(&completer);
lineEdit.show();
- QApplication::setActiveWindow(&lineEdit);
+ QApplicationPrivate::setActiveWindow(&lineEdit);
QVERIFY(QTest::qWaitForWindowActive(&lineEdit));
lineEdit.setFocus();
QTRY_VERIFY(lineEdit.hasFocus());
@@ -3846,7 +3856,7 @@ void tst_QLineEdit::task229938_dontEmitChangedWhenTextIsNotChanged()
QTest::keyPress(&lineEdit, 'd');
QTest::keyPress(&lineEdit, 'e');
QTest::keyPress(&lineEdit, 'f');
- QCOMPARE(changedSpy.count(), 5);
+ QCOMPARE(changedSpy.size(), 5);
}
void tst_QLineEdit::task233101_cursorPosAfterInputMethod_data()
@@ -3921,7 +3931,7 @@ void tst_QLineEdit::task241436_passwordEchoOnEditRestoreEchoMode()
testWidget->setFocus();
centerOnScreen(testWidget);
testWidget->show();
- QApplication::setActiveWindow(testWidget);
+ QApplicationPrivate::setActiveWindow(testWidget);
QVERIFY(QTest::qWaitForWindowActive(testWidget));
QVERIFY(testWidget->hasFocus());
@@ -3972,7 +3982,7 @@ void tst_QLineEdit::taskQTBUG_4401_enterKeyClearsPassword()
testWidget->selectAll();
centerOnScreen(testWidget);
testWidget->show();
- QApplication::setActiveWindow(testWidget);
+ QApplicationPrivate::setActiveWindow(testWidget);
QVERIFY(QTest::qWaitForWindowActive(testWidget));
QTest::keyPress(testWidget, Qt::Key_Enter);
@@ -4055,13 +4065,13 @@ void tst_QLineEdit::taskQTBUG_7395_readOnlyShortcut()
le.show();
QVERIFY(QTest::qWaitForWindowExposed(&le));
- QApplication::setActiveWindow(&le);
+ QApplicationPrivate::setActiveWindow(&le);
QVERIFY(QTest::qWaitForWindowActive(&le));
le.setFocus();
QTRY_VERIFY(le.hasFocus());
QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_P);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
}
void tst_QLineEdit::QTBUG697_paletteCurrentColorGroup()
@@ -4077,7 +4087,7 @@ void tst_QLineEdit::QTBUG697_paletteCurrentColorGroup()
le.setPalette(p);
le.show();
- QApplication::setActiveWindow(&le);
+ QApplicationPrivate::setActiveWindow(&le);
QVERIFY(QTest::qWaitForWindowActive(&le));
le.setFocus();
QTRY_VERIFY(le.hasFocus());
@@ -4105,7 +4115,7 @@ void tst_QLineEdit::QTBUG13520_textNotVisible()
QString sometext("01-ST16-01SIL-MPL001wfgsdfgsdgsdfgsdfgsdfgsdfgsdfg");
le.setText(sometext);
le.setCursorPosition(0);
- QTest::qWait(100); //just make sure we get he lineedit correcly painted
+ QTest::qWait(100); //just make sure we get he lineedit correctly painted
auto expectedCursorCoordinate = le.width() - le.fontMetrics().horizontalAdvance(sometext);
// cursor does not leave widget to the left:
@@ -4348,14 +4358,14 @@ void tst_QLineEdit::inputMethodSelection()
testWidget->setSelection(0,0);
QSignalSpy selectionSpy(testWidget, SIGNAL(selectionChanged()));
- QCOMPARE(selectionSpy.count(), 0);
+ QCOMPARE(selectionSpy.size(), 0);
QCOMPARE(testWidget->selectionStart(), -1);
QCOMPARE(testWidget->selectionEnd(), -1);
QCOMPARE(testWidget->selectionLength(), 0);
testWidget->setSelection(0,5);
- QCOMPARE(selectionSpy.count(), 1);
+ QCOMPARE(selectionSpy.size(), 1);
QCOMPARE(testWidget->selectionStart(), 0);
QCOMPARE(testWidget->selectionEnd(), 5);
QCOMPARE(testWidget->selectionLength(), 5);
@@ -4369,7 +4379,7 @@ void tst_QLineEdit::inputMethodSelection()
QApplication::sendEvent(testWidget, &event);
}
- QCOMPARE(selectionSpy.count(), 2);
+ QCOMPARE(selectionSpy.size(), 2);
QCOMPARE(testWidget->selectionStart(), 12);
QCOMPARE(testWidget->selectionEnd(), 17);
QCOMPARE(testWidget->selectionLength(), 5);
@@ -4382,7 +4392,7 @@ void tst_QLineEdit::inputMethodSelection()
QApplication::sendEvent(testWidget, &event);
}
- QCOMPARE(selectionSpy.count(), 3);
+ QCOMPARE(selectionSpy.size(), 3);
QCOMPARE(testWidget->selectionStart(), -1);
QCOMPARE(testWidget->selectionEnd(), -1);
QCOMPARE(testWidget->selectionLength(), 0);
@@ -4409,6 +4419,33 @@ void tst_QLineEdit::inputMethodQueryImHints()
QCOMPARE(static_cast<Qt::InputMethodHints>(value.toInt()), hints);
}
+void tst_QLineEdit::inputMethodQueryEnterKeyType()
+{
+ QWidget mw;
+ QVBoxLayout layout(&mw);
+ QLineEdit le1(&mw);
+ layout.addWidget(&le1);
+ mw.show();
+ QVariant enterType = le1.inputMethodQuery(Qt::ImEnterKeyType);
+ QCOMPARE(enterType.value<Qt::EnterKeyType>(), Qt::EnterKeyDefault);
+
+ mw.hide();
+ QLineEdit le2(&mw);
+ layout.addWidget(&le2);
+ mw.show();
+
+ enterType = le1.inputMethodQuery(Qt::ImEnterKeyType);
+#ifdef Q_OS_ANDROID
+ // QTBUG-61652
+ // EnterKey is changed to EnterKeyNext if the focus can be moved to widget below
+ QCOMPARE(enterType.value<Qt::EnterKeyType>(), Qt::EnterKeyNext);
+#else
+ QCOMPARE(enterType.value<Qt::EnterKeyType>(), Qt::EnterKeyDefault);
+#endif
+ enterType = le2.inputMethodQuery(Qt::ImEnterKeyType);
+ QCOMPARE(enterType.value<Qt::EnterKeyType>(), Qt::EnterKeyDefault);
+}
+
void tst_QLineEdit::inputMethodUpdate()
{
if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
@@ -4545,7 +4582,7 @@ void tst_QLineEdit::clearButton()
l->addWidget(listView);
testWidget.move(300, 300);
testWidget.show();
- qApp->setActiveWindow(&testWidget);
+ QApplicationPrivate::setActiveWindow(&testWidget);
QVERIFY(QTest::qWaitForWindowActive(&testWidget));
// Flip the clear button on,off, trying to detect crashes.
filterLineEdit->setClearButtonEnabled(true);
@@ -4570,11 +4607,11 @@ void tst_QLineEdit::clearButton()
QSignalSpy spyEdited(filterLineEdit, &QLineEdit::textEdited);
const QPoint clearButtonCenterPos = QRect(QPoint(0, 0), clearButton->size()).center();
QTest::mouseClick(clearButton, Qt::LeftButton, {}, clearButtonCenterPos);
- QCOMPARE(spyEdited.count(), 1);
+ QCOMPARE(spyEdited.size(), 1);
QTRY_COMPARE(clearButton->cursor().shape(), filterLineEdit->cursor().shape());
QTRY_COMPARE(filterModel->rowCount(), 3);
QCoreApplication::processEvents();
- QCOMPARE(spyEdited.count(), 1);
+ QCOMPARE(spyEdited.size(), 1);
filterLineEdit->setReadOnly(true); // QTBUG-34315
QVERIFY(!clearButton->isEnabled());
@@ -4656,7 +4693,8 @@ void tst_QLineEdit::sideWidgets()
testWidget.move(300, 300);
testWidget.show();
QVERIFY(QTest::qWaitForWindowExposed(&testWidget));
- foreach (QToolButton *button, lineEdit->findChildren<QToolButton *>())
+ const auto buttons = lineEdit->findChildren<QToolButton *>();
+ for (QToolButton *button : buttons)
QCOMPARE(button->cursor().shape(), Qt::ArrowCursor);
// Arbitrarily add/remove actions, trying to detect crashes. Add QTRY_VERIFY(false) to view the result.
delete label3Action;
@@ -4671,7 +4709,8 @@ void tst_QLineEdit::sideWidgets()
template <class T> T *findAssociatedWidget(const QAction *a)
{
- foreach (QWidget *w, a->associatedWidgets()) {
+ const auto associatedObjects = a->associatedObjects();
+ for (QObject *w : associatedObjects) {
if (T *result = qobject_cast<T *>(w))
return result;
}
@@ -4851,7 +4890,7 @@ void tst_QLineEdit::QTBUG1266_setInputMaskEmittingTextEdited()
QSignalSpy spy(&lineEdit, SIGNAL(textEdited(QString)));
lineEdit.setInputMask("AAAA");
lineEdit.setInputMask(QString());
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
}
#if QT_CONFIG(shortcut)
@@ -4912,7 +4951,7 @@ void tst_QLineEdit::shortcutOverrideOnReadonlyLineEdit()
}
const int activationCount = shouldBeHandledByQLineEdit ? 0 : 1;
- QCOMPARE(spy.count(), activationCount);
+ QCOMPARE(spy.size(), activationCount);
}
#endif // QT_CONFIG(shortcut)
@@ -4945,7 +4984,7 @@ void tst_QLineEdit::QTBUG59957_clearButtonLeftmostAction()
bool tst_QLineEdit::unselectingWithLeftOrRightChangesCursorPosition()
{
-#if defined Q_OS_WIN || defined Q_OS_QNX //Windows and QNX do not jump to the beginning of the selection
+#if defined Q_OS_WIN || defined Q_OS_QNX || defined Q_OS_VXWORKS //Windows, QNX and VxWorks do not jump to the beginning of the selection
return true;
#endif
// Platforms minimal/offscreen also need left after unselecting with right
@@ -4965,10 +5004,10 @@ void tst_QLineEdit::QTBUG_60319_setInputMaskCheckImSurroundingText()
QLineEdit *testWidget = ensureTestWidget();
QString mask("+000(000)-000-00-00");
testWidget->setInputMask(mask);
- testWidget->setCursorPosition(mask.length());
+ testWidget->setCursorPosition(mask.size());
QString surroundingText = testWidget->inputMethodQuery(Qt::ImSurroundingText).toString();
int cursorPosition = testWidget->inputMethodQuery(Qt::ImCursorPosition).toInt();
- QCOMPARE(surroundingText.length(), cursorPosition);
+ QCOMPARE(surroundingText.size(), cursorPosition);
}
void tst_QLineEdit::testQuickSelectionWithMouse()
@@ -5065,18 +5104,18 @@ void tst_QLineEdit::inputRejected()
QSignalSpy spyInputRejected(testWidget, SIGNAL(inputRejected()));
QTest::keyClicks(testWidget, "abcde");
- QCOMPARE(spyInputRejected.count(), 0);
+ QCOMPARE(spyInputRejected.size(), 0);
testWidget->setText("fghij");
- QCOMPARE(spyInputRejected.count(), 0);
+ QCOMPARE(spyInputRejected.size(), 0);
testWidget->insert("k");
- QCOMPARE(spyInputRejected.count(), 0);
+ QCOMPARE(spyInputRejected.size(), 0);
testWidget->clear();
testWidget->setMaxLength(5);
QTest::keyClicks(testWidget, "abcde");
- QCOMPARE(spyInputRejected.count(), 0);
+ QCOMPARE(spyInputRejected.size(), 0);
QTest::keyClicks(testWidget, "fgh");
- QCOMPARE(spyInputRejected.count(), 3);
+ QCOMPARE(spyInputRejected.size(), 3);
#if QT_CONFIG(clipboard)
testWidget->clear();
spyInputRejected.clear();
@@ -5084,7 +5123,7 @@ void tst_QLineEdit::inputRejected()
testWidget->paste();
// The first 5 characters are accepted, but
// the last 2 are not.
- QCOMPARE(spyInputRejected.count(), 1);
+ QCOMPARE(spyInputRejected.size(), 1);
#endif
testWidget->setMaxLength(INT_MAX);
@@ -5093,15 +5132,15 @@ void tst_QLineEdit::inputRejected()
QIntValidator intValidator(1, 100);
testWidget->setValidator(&intValidator);
QTest::keyClicks(testWidget, "11");
- QCOMPARE(spyInputRejected.count(), 0);
+ QCOMPARE(spyInputRejected.size(), 0);
QTest::keyClicks(testWidget, "a#");
- QCOMPARE(spyInputRejected.count(), 2);
+ QCOMPARE(spyInputRejected.size(), 2);
#if QT_CONFIG(clipboard)
testWidget->clear();
spyInputRejected.clear();
QApplication::clipboard()->setText("a#");
testWidget->paste();
- QCOMPARE(spyInputRejected.count(), 1);
+ QCOMPARE(spyInputRejected.size(), 1);
#endif
testWidget->clear();
@@ -5109,10 +5148,154 @@ void tst_QLineEdit::inputRejected()
spyInputRejected.clear();
testWidget->setInputMask("999.999.999.999;_");
QTest::keyClicks(testWidget, "11");
- QCOMPARE(spyInputRejected.count(), 0);
+ QCOMPARE(spyInputRejected.size(), 0);
QTest::keyClicks(testWidget, "a#");
- QCOMPARE(spyInputRejected.count(), 2);
+ QCOMPARE(spyInputRejected.size(), 2);
+}
+
+void tst_QLineEdit::keyReleasePropagates()
+{
+ struct Dialog : QWidget
+ {
+ QLineEdit *lineEdit;
+ int releasedKey = {};
+
+ Dialog()
+ {
+ lineEdit = new QLineEdit;
+ QHBoxLayout *hbox = new QHBoxLayout;
+
+ hbox->addWidget(lineEdit);
+ setLayout(hbox);
+ }
+
+ protected:
+ void keyReleaseEvent(QKeyEvent *e) override
+ {
+ releasedKey = e->key();
+ }
+ } dialog;
+
+ dialog.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&dialog));
+
+ QTest::keyPress(dialog.lineEdit, Qt::Key_A);
+ QTest::keyRelease(dialog.lineEdit, Qt::Key_A);
+
+ QCOMPARE(dialog.releasedKey, Qt::Key_A);
+
+ QTest::keyPress(dialog.lineEdit, Qt::Key_Alt);
+ QTest::keyRelease(dialog.lineEdit, Qt::Key_Alt);
+
+ QCOMPARE(dialog.releasedKey, Qt::Key_Alt);
}
+#if QT_CONFIG(shortcut)
+
+void tst_QLineEdit::deleteWordByKeySequence_data()
+{
+ QTest::addColumn<QString>("startText");
+ QTest::addColumn<int>("selectionStart");
+ QTest::addColumn<int>("selectionEnd");
+ QTest::addColumn<int>("cursorPosition");
+ QTest::addColumn<QKeySequence::StandardKey>("key");
+ QTest::addColumn<QString>("expectedText");
+ QTest::addColumn<int>("expectedCursorPosition");
+
+ QTest::newRow("Delete start, no selection")
+ << QStringLiteral("Some Text") << 0 << 0 << 9 << QKeySequence::DeleteStartOfWord
+ << QStringLiteral("Some ") << 5;
+ QTest::newRow("Delete end, no selection")
+ << QStringLiteral("Some Text") << 0 << 0 << 5 << QKeySequence::DeleteEndOfWord
+ << QStringLiteral("Some ") << 5;
+ QTest::newRow("Delete start from middle, no selection")
+ << QStringLiteral("Some Text") << 0 << 0 << 7 << QKeySequence::DeleteStartOfWord
+ << QStringLiteral("Some xt") << 5;
+ QTest::newRow("Delete end from middle, no selection")
+ << QStringLiteral("Some Text") << 0 << 0 << 7 << QKeySequence::DeleteEndOfWord
+ << QStringLiteral("Some Te") << 7;
+ QTest::newRow("Delete end from first, no selection")
+ << QStringLiteral("Some Text") << 0 << 0 << 0 << QKeySequence::DeleteEndOfWord
+ << QStringLiteral("Text") << 0;
+
+ QTest::newRow("Delete start, full selection")
+ << QStringLiteral("Some Text") << 0 << 9 << 0 << QKeySequence::DeleteStartOfWord
+ << QStringLiteral("") << 0;
+ QTest::newRow("Delete end, full selection")
+ << QStringLiteral("Some Text") << 0 << 9 << 0 << QKeySequence::DeleteEndOfWord
+ << QStringLiteral("") << 0;
+ QTest::newRow("Delete start, full selection, single word")
+ << QStringLiteral("Some") << 0 << 4 << 0 << QKeySequence::DeleteStartOfWord
+ << QStringLiteral("") << 0;
+ QTest::newRow("Delete end, full selection, single word")
+ << QStringLiteral("Some") << 0 << 4 << 0 << QKeySequence::DeleteEndOfWord
+ << QStringLiteral("") << 0;
+
+ QTest::newRow("Delete start, word selection")
+ << QStringLiteral("Some Text") << 5 << 9 << 0 << QKeySequence::DeleteStartOfWord
+ << QStringLiteral("Some ") << 5;
+ QTest::newRow("Delete end, word selection")
+ << QStringLiteral("Some Text") << 5 << 9 << 0 << QKeySequence::DeleteEndOfWord
+ << QStringLiteral("Some ") << 5;
+ QTest::newRow("Delete start, partial word selection")
+ << QStringLiteral("Some Text") << 5 << 7 << 0 << QKeySequence::DeleteStartOfWord
+ << QStringLiteral("Some xt") << 5;
+ QTest::newRow("Delete end, partial word selection")
+ << QStringLiteral("Some Text") << 5 << 7 << 0 << QKeySequence::DeleteEndOfWord
+ << QStringLiteral("Some xt") << 5;
+ QTest::newRow("Delete start, partial inner word selection")
+ << QStringLiteral("Some Text") << 6 << 8 << 0 << QKeySequence::DeleteStartOfWord
+ << QStringLiteral("Some Tt") << 6;
+ QTest::newRow("Delete end, partial inner word selection")
+ << QStringLiteral("Some Text") << 6 << 8 << 0 << QKeySequence::DeleteEndOfWord
+ << QStringLiteral("Some Tt") << 6;
+ QTest::newRow("Delete start, selection with space")
+ << QStringLiteral("Some Text") << 3 << 9 << 0 << QKeySequence::DeleteStartOfWord
+ << QStringLiteral("Som") << 3;
+ QTest::newRow("Delete end, selection with space")
+ << QStringLiteral("Some Text") << 3 << 9 << 0 << QKeySequence::DeleteEndOfWord
+ << QStringLiteral("Som") << 3;
+ QTest::newRow("Delete start, partial word selection with space")
+ << QStringLiteral("Some Text") << 3 << 7 << 0 << QKeySequence::DeleteStartOfWord
+ << QStringLiteral("Somxt") << 3;
+ QTest::newRow("Delete end, partial selection with space")
+ << QStringLiteral("Some Text") << 3 << 7 << 0 << QKeySequence::DeleteEndOfWord
+ << QStringLiteral("Somxt") << 3;
+}
+
+void tst_QLineEdit::deleteWordByKeySequence()
+{
+ QFETCH(QString, startText);
+ QFETCH(int, selectionStart);
+ QFETCH(int, selectionEnd);
+ QFETCH(int, cursorPosition);
+ QFETCH(QKeySequence::StandardKey, key);
+ QFETCH(QString, expectedText);
+ QFETCH(int, expectedCursorPosition);
+
+ QWidget widget;
+
+ QLineEdit *lineEdit = new QLineEdit(startText, &widget);
+ lineEdit->setFocus();
+ lineEdit->setCursorPosition(cursorPosition);
+ if (selectionStart != selectionEnd)
+ lineEdit->setSelection(selectionStart, selectionEnd - selectionStart);
+
+ widget.show();
+
+ QVERIFY(QTest::qWaitForWindowActive(&widget));
+
+ QTestEventList keys;
+ addKeySequenceStandardKey(keys, key);
+ keys.simulate(lineEdit);
+
+ QCOMPARE(lineEdit->text(), expectedText);
+ QCOMPARE(lineEdit->selectionStart(), -1);
+ QCOMPARE(lineEdit->selectionEnd(), -1);
+ QCOMPARE(lineEdit->cursorPosition(), expectedCursorPosition);
+}
+
+#endif // QT_CONFIG(shortcut)
+
QTEST_MAIN(tst_QLineEdit)
#include "tst_qlineedit.moc"