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.cpp545
1 files changed, 433 insertions, 112 deletions
diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
index 2367d56dad..be185c1e7a 100644
--- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
+++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
@@ -1,33 +1,8 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+
+#include <QTest>
#include <QtTest/private/qtesthelpers_p.h>
#include "qlineedit.h"
#include "qapplication.h"
@@ -43,6 +18,9 @@
#include "qstylehints.h"
#include <private/qapplication_p.h>
#include "qclipboard.h"
+#include <QSignalSpy>
+#include <QRandomGenerator>
+#include <QTimer>
#include <qlineedit.h>
#include <private/qlineedit_p.h>
@@ -250,6 +228,8 @@ private slots:
void textMargin_data();
void textMargin();
+ void returnKeyClearsEditedFlag();
+
// task-specific tests:
void task180999_focus();
void task174640_editingFinished();
@@ -287,6 +267,8 @@ private slots:
void inputMethodQueryImHints_data();
void inputMethodQueryImHints();
+ void inputMethodQueryEnterKeyType();
+
void inputMethodUpdate();
void undoRedoAndEchoModes_data();
@@ -296,6 +278,7 @@ private slots:
void clearButtonVisibleAfterSettingText_QTBUG_45518();
void sideWidgets();
void sideWidgetsActionEvents();
+ void sideWidgetsEffectiveMargins();
void shouldShowPlaceholderText_data();
void shouldShowPlaceholderText();
@@ -309,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();
@@ -671,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());
}
@@ -902,11 +892,11 @@ static const int chars = 8;
class ValidatorWithFixup : public QValidator
{
public:
- ValidatorWithFixup(QWidget *parent = 0)
+ ValidatorWithFixup(QWidget *parent = nullptr)
: QValidator(parent)
{}
- QValidator::State validate(QString &str, int &) const
+ QValidator::State validate(QString &str, int &) const override
{
const int s = str.size();
if (s < chars) {
@@ -917,7 +907,7 @@ public:
return Acceptable;
}
- void fixup(QString &str) const
+ void fixup(QString &str) const override
{
str = str.leftJustified(chars, 'X', true);
}
@@ -938,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);
}
@@ -1611,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"));
}
@@ -1677,11 +1667,13 @@ void tst_QLineEdit::displayText_data()
m << bool(use_setText);
s = key_mode_str + "Password";
m = QLineEdit::Password;
- QChar passChar = qApp->style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, 0, m_testWidget);
+ const int passwordCharacter = qApp->style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, 0, m_testWidget);
+ QVERIFY(passwordCharacter <= 0xFFFF);
+ const QChar passChar(passwordCharacter);
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("") <<
@@ -1689,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);
}
@@ -1723,7 +1715,9 @@ void tst_QLineEdit::passwordEchoOnEdit()
QStyleOptionFrame opt;
QLineEdit *testWidget = ensureTestWidget();
- QChar fillChar = testWidget->style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, testWidget);
+ const int passwordCharacter = testWidget->style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, testWidget);
+ QVERIFY(passwordCharacter <= 0xFFFF);
+ const QChar fillChar(passwordCharacter);
testWidget->setEchoMode(QLineEdit::PasswordEchoOnEdit);
testWidget->setFocus();
@@ -1770,7 +1764,9 @@ void tst_QLineEdit::passwordEchoDelay()
QSKIP("Platform not defining echo delay and overriding only possible in internal build");
QStyleOptionFrame opt;
- QChar fillChar = testWidget->style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, testWidget);
+ const int passwordCharacter = testWidget->style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, testWidget);
+ QVERIFY(passwordCharacter <= 0xFFFF);
+ const QChar fillChar(passwordCharacter);
testWidget->setEchoMode(QLineEdit::Password);
testWidget->setFocus();
@@ -1930,7 +1926,7 @@ void tst_QLineEdit::isReadOnly()
class BlinkTestLineEdit : public QLineEdit
{
public:
- void paintEvent(QPaintEvent *e)
+ void paintEvent(QPaintEvent *e) override
{
++updates;
QLineEdit::paintEvent(e);
@@ -2007,7 +2003,8 @@ void tst_QLineEdit::addKeySequenceStandardKey(QTestEventList &keys, QKeySequence
{
QKeySequence keyseq = QKeySequence(key);
for (int i = 0; i < keyseq.count(); ++i)
- keys.addKeyClick( Qt::Key( keyseq[i] & ~Qt::KeyboardModifierMask), Qt::KeyboardModifier(keyseq[i] & Qt::KeyboardModifierMask) );
+ keys.addKeyClick( Qt::Key( keyseq[i].toCombined() & ~Qt::KeyboardModifierMask),
+ Qt::KeyboardModifier(keyseq[i].toCombined() & Qt::KeyboardModifierMask) );
}
#endif // QT_CONFIG(shortcut)
@@ -2237,6 +2234,11 @@ void tst_QLineEdit::cursorPositionChanged()
input.simulate(testWidget);
QCOMPARE(lastCursorPos, lastPos);
QCOMPARE(newCursorPos, newPos);
+
+ QInputMethodQueryEvent queryEvent(Qt::ImCursorPosition | Qt::ImAbsolutePosition);
+ QApplication::sendEvent(testWidget, &queryEvent);
+ QCOMPARE(queryEvent.value(Qt::ImCursorPosition).toInt(), newPos);
+ QCOMPARE(queryEvent.value(Qt::ImAbsolutePosition).toInt(), newPos);
}
void tst_QLineEdit::selectedText()
@@ -2299,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
@@ -2431,8 +2433,8 @@ void tst_QLineEdit::returnPressed()
class QIntFixValidator : public QIntValidator {
public:
QIntFixValidator(int min, int max, QObject *parent) : QIntValidator(min, max, parent) {}
- void fixup (QString &input) const {
- for (int i=0; i<input.length(); ++i)
+ void fixup (QString &input) const override {
+ for (int i=0; i<input.size(); ++i)
if (!input.at(i).isNumber()) {
input[(int)i] = QChar('0');
}
@@ -2998,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;
@@ -3018,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;
}
@@ -3148,8 +3150,8 @@ void tst_QLineEdit::cutWithoutSelection()
class InputMaskValidator : public QValidator
{
public:
- InputMaskValidator(QObject *parent, const char *name = 0) : QValidator(parent) { setObjectName(name); }
- State validate(QString &text, int &pos) const
+ InputMaskValidator(QObject *parent, const char *name = nullptr) : QValidator(parent) { setObjectName(name); }
+ State validate(QString &text, int &pos) const override
{
InputMaskValidator *that = (InputMaskValidator *)this;
that->validateText = text;
@@ -3219,7 +3221,7 @@ class LineEdit : public QLineEdit
public:
LineEdit() { state = Other; }
- void keyPressEvent(QKeyEvent *e)
+ void keyPressEvent(QKeyEvent *e) override
{
QLineEdit::keyPressEvent(e);
if (e->key() == Qt::Key_Enter) {
@@ -3310,12 +3312,12 @@ void tst_QLineEdit::validateOnFocusOut()
QLineEdit *testWidget = ensureTestWidget();
QSignalSpy editingFinishedSpy(testWidget, SIGNAL(editingFinished()));
- testWidget->setValidator(new QIntValidator(100, 999, 0));
+ testWidget->setValidator(new QIntValidator(100, 999, testWidget));
QTest::keyPress(testWidget, '1');
QTest::keyPress(testWidget, '0');
QCOMPARE(testWidget->text(), QString("10"));
testWidget->clearFocus();
- QCOMPARE(editingFinishedSpy.count(), 0);
+ QCOMPARE(editingFinishedSpy.size(), 0);
testWidget->setFocus();
centerOnScreen(testWidget);
@@ -3328,14 +3330,14 @@ void tst_QLineEdit::validateOnFocusOut()
QTRY_COMPARE(testWidget->text(), QString("100"));
testWidget->clearFocus();
- QCOMPARE(editingFinishedSpy.count(), 1);
+ QCOMPARE(editingFinishedSpy.size(), 1);
}
void tst_QLineEdit::editInvalidText()
{
QLineEdit *testWidget = ensureTestWidget();
testWidget->clear();
- testWidget->setValidator(new QIntValidator(0, 12, 0));
+ testWidget->setValidator(new QIntValidator(0, 12, testWidget));
testWidget->setText("1234");
QVERIFY(!testWidget->hasAcceptableInput());
@@ -3412,6 +3414,9 @@ void tst_QLineEdit::leftKeyOnSelectedText()
void tst_QLineEdit::inlineCompletion()
{
+#ifdef Q_OS_ANDROID
+ QSKIP("QCompleter does not work on Android, see QTBUG-77174");
+#endif
if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
QSKIP("Wayland: This fails. Figure out why.");
@@ -3503,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()
@@ -3519,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;
@@ -3586,6 +3592,72 @@ void tst_QLineEdit::textMargin()
QTRY_COMPARE(testWidget.cursorPosition(), cursorPosition);
}
+void tst_QLineEdit::returnKeyClearsEditedFlag()
+{
+ /* Tests that pressing enter within the line edit correctly clears
+ the "edited" flag, preventing a redundant emission of
+ editingFinished() when its focus is dropped after no further
+ edits */
+ QLineEdit testWidget;
+ QSignalSpy leSpy(&testWidget, &QLineEdit::editingFinished);
+ QVERIFY(leSpy.isValid());
+
+ // Prepare widget for testing
+ testWidget.setFocus();
+ centerOnScreen(&testWidget);
+ testWidget.show();
+ testWidget.raise();
+ QVERIFY(QTest::qWaitForWindowExposed(&testWidget));
+ QTRY_VERIFY(testWidget.hasFocus());
+
+ // Focus drop with no edits shouldn't emit signal, edited flag == false
+ testWidget.clearFocus(); // Signal not emitted
+ QVERIFY(!testWidget.hasFocus());
+ QCOMPARE(leSpy.size(), 0);
+
+ // Focus drop after edits should emit signal, edited flag == true
+ testWidget.setFocus();
+ QTRY_VERIFY(testWidget.hasFocus());
+ QTest::keyClicks(&testWidget, "edit1 "); // edited flag set
+ testWidget.clearFocus(); // edited flag cleared, signal emitted
+ QVERIFY(!testWidget.hasFocus());
+ QCOMPARE(leSpy.size(), 1);
+
+ // Only text related keys should set edited flag
+ testWidget.setFocus();
+ QTRY_VERIFY(testWidget.hasFocus());
+ QTest::keyClick(&testWidget, Qt::Key_Left);
+ QTest::keyClick(&testWidget, Qt::Key_Alt);
+ QTest::keyClick(&testWidget, Qt::Key_PageUp);
+ testWidget.clearFocus(); // Signal not emitted
+ QVERIFY(!testWidget.hasFocus());
+ QCOMPARE(leSpy.size(), 1); // No change
+
+ // Return should always emit signal
+ testWidget.setFocus();
+ QTRY_VERIFY(testWidget.hasFocus());
+ QTest::keyClick(&testWidget, Qt::Key_Return); /* Without edits,
+ signal emitted,
+ edited flag cleared */
+ 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.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
+ clears the edited flag */
+ QTest::keyClicks(&testWidget, "edit3 "); // edited flag set
+ QTest::keyClick(&testWidget, Qt::Key_Return); /* signal emitted,
+ edited flag cleared */
+ QCOMPARE(leSpy.size(), 4);
+ testWidget.clearFocus(); // Signal not emitted since edited == false
+ QVERIFY(!testWidget.hasFocus());
+ QCOMPARE(leSpy.size(), 4); // No change
+}
+
#ifndef QT_NO_CURSOR
void tst_QLineEdit::cursor()
{
@@ -3602,7 +3674,7 @@ void tst_QLineEdit::cursor()
class task180999_Widget : public QWidget
{
public:
- task180999_Widget(QWidget *parent = 0) : QWidget(parent)
+ task180999_Widget(QWidget *parent = nullptr) : QWidget(parent)
{
QHBoxLayout *layout = new QHBoxLayout(this);
lineEdit1.setText("some text 1 ...");
@@ -3650,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());
@@ -3659,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();
@@ -3686,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);
@@ -3699,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)
@@ -3707,7 +3779,7 @@ class task198789_Widget : public QWidget
{
Q_OBJECT
public:
- task198789_Widget(QWidget *parent = 0) : QWidget(parent)
+ task198789_Widget(QWidget *parent = nullptr) : QWidget(parent)
{
QStringList wordList;
wordList << "alpha" << "omega" << "omicron" << "zeta";
@@ -3743,6 +3815,9 @@ void tst_QLineEdit::task198789_currentCompletion()
void tst_QLineEdit::task210502_caseInsensitiveInlineCompletion()
{
+#ifdef Q_OS_ANDROID
+ QSKIP("QCompleter does not work on Android, see QTBUG-77174");
+#endif
if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
QSKIP("Wayland: This fails. Figure out why.");
@@ -3755,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());
@@ -3781,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()
@@ -3848,13 +3923,15 @@ void tst_QLineEdit::task241436_passwordEchoOnEditRestoreEchoMode()
QStyleOptionFrame opt;
QLineEdit *testWidget = ensureTestWidget();
- QChar fillChar = testWidget->style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, testWidget);
+ const int passwordCharacter = testWidget->style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, testWidget);
+ QVERIFY(passwordCharacter <= 0xFFFF);
+ const QChar fillChar(passwordCharacter);
testWidget->setEchoMode(QLineEdit::PasswordEchoOnEdit);
testWidget->setFocus();
centerOnScreen(testWidget);
testWidget->show();
- QApplication::setActiveWindow(testWidget);
+ QApplicationPrivate::setActiveWindow(testWidget);
QVERIFY(QTest::qWaitForWindowActive(testWidget));
QVERIFY(testWidget->hasFocus());
@@ -3905,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);
@@ -3961,7 +4038,8 @@ void tst_QLineEdit::taskQTBUG_7902_contextMenuCrash()
w->connect(&ti, SIGNAL(timeout()), w, SLOT(deleteLater()));
ti.start(200);
- QContextMenuEvent *cme = new QContextMenuEvent(QContextMenuEvent::Mouse, w->rect().center());
+ QContextMenuEvent *cme = new QContextMenuEvent(QContextMenuEvent::Mouse, w->rect().center(),
+ w->mapToGlobal(w->rect().center()));
qApp->postEvent(w, cme);
QTest::qWait(300);
@@ -3987,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()
@@ -4009,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());
@@ -4034,13 +4112,18 @@ void tst_QLineEdit::QTBUG13520_textNotVisible()
le.setAlignment( Qt::AlignRight | Qt::AlignVCenter);
le.show();
QVERIFY(QTest::qWaitForWindowExposed(&le));
- le.setText("01-ST16-01SIL-MPL001wfgsdfgsdgsdfgsdfgsdfgsdfgsdfg");
+ QString sometext("01-ST16-01SIL-MPL001wfgsdfgsdgsdfgsdfgsdfgsdfgsdfg");
+ le.setText(sometext);
le.setCursorPosition(0);
- QTest::qWait(100); //just make sure we get he lineedit correcly painted
-
- QVERIFY(le.cursorRect().center().x() < le.width() / 2);
+ 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:
+ if (expectedCursorCoordinate < 0)
+ expectedCursorCoordinate = 0;
+ // compare with some tolerance for margins
+ QVERIFY(qAbs(le.cursorRect().center().x() - expectedCursorCoordinate) < 10);
}
class UpdateRegionLineEdit : public QLineEdit
@@ -4048,7 +4131,7 @@ class UpdateRegionLineEdit : public QLineEdit
public:
QRegion updateRegion;
protected:
- void paintEvent(QPaintEvent *event)
+ void paintEvent(QPaintEvent *event) override
{
updateRegion = event->region();
}
@@ -4275,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);
@@ -4296,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);
@@ -4309,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);
@@ -4336,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))
@@ -4472,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);
@@ -4497,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());
@@ -4583,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;
@@ -4598,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;
}
@@ -4652,6 +4764,71 @@ void tst_QLineEdit::sideWidgetsActionEvents()
QCOMPARE(toolButton2->x(), toolButton1X);
}
+/*!
+ Verify that side widgets are positioned correctly and result in
+ correct effective text margins.
+*/
+void tst_QLineEdit::sideWidgetsEffectiveMargins()
+{
+#ifndef QT_BUILD_INTERNAL
+ QSKIP("This test requires a developer build.");
+#else
+ QLineEdit edit;
+ edit.setPlaceholderText("placeholder");
+ edit.setClearButtonEnabled(true);
+ edit.show();
+ QLineEditPrivate *priv = QLineEditPrivate::get(&edit);
+ const auto sideWidgetParameters = priv->sideWidgetParameters();
+ const int sideWidgetWidth = sideWidgetParameters.widgetWidth + sideWidgetParameters.margin;
+ QVERIFY(QTest::qWaitForWindowExposed(&edit));
+
+ QCOMPARE(priv->effectiveTextMargins().left(), 0);
+ QCOMPARE(priv->effectiveTextMargins().right(), 0);
+
+ edit.setText("Left to right"); // clear button fades in on the right
+ QCOMPARE(priv->effectiveTextMargins().left(), 0);
+ QCOMPARE(priv->effectiveTextMargins().right(), sideWidgetWidth);
+ edit.clear();
+ QCOMPARE(priv->effectiveTextMargins().left(), 0);
+ QCOMPARE(priv->effectiveTextMargins().right(), 0);
+
+ edit.setLayoutDirection(Qt::RightToLeft);
+ edit.setText("ئۇيغۇر تىلى"); // clear button fades in on the left
+ QCOMPARE(priv->effectiveTextMargins().left(), sideWidgetWidth);
+ QCOMPARE(priv->effectiveTextMargins().right(), 0);
+ edit.clear();
+ QCOMPARE(priv->effectiveTextMargins().left(), 0);
+ QCOMPARE(priv->effectiveTextMargins().right(), 0);
+
+ edit.setLayoutDirection(Qt::LeftToRight);
+
+ const QIcon leftIcon = edit.style()->standardIcon(QStyle::SP_FileIcon);
+ const QIcon rightIcon = edit.style()->standardIcon(QStyle::SP_DirIcon);
+ edit.addAction(leftIcon, QLineEdit::ActionPosition::LeadingPosition);
+ QCOMPARE(priv->effectiveTextMargins().left(), sideWidgetWidth);
+ QCOMPARE(priv->effectiveTextMargins().right(), 0);
+
+ edit.addAction(rightIcon, QLineEdit::ActionPosition::TrailingPosition);
+ QCOMPARE(priv->effectiveTextMargins().left(), sideWidgetWidth);
+ QCOMPARE(priv->effectiveTextMargins().right(), sideWidgetWidth);
+
+ edit.setText("Left to right"); // clear button on the right
+ QCOMPARE(priv->effectiveTextMargins().left(), sideWidgetWidth);
+ QCOMPARE(priv->effectiveTextMargins().right(), 2 * sideWidgetWidth);
+ edit.clear();
+ QCOMPARE(priv->effectiveTextMargins().left(), sideWidgetWidth);
+ QCOMPARE(priv->effectiveTextMargins().right(), sideWidgetWidth);
+
+ edit.setLayoutDirection(Qt::RightToLeft);
+ edit.setText("ئۇيغۇر تىلى"); // clear button fades in on the left
+ QCOMPARE(priv->effectiveTextMargins().left(), 2 * sideWidgetWidth);
+ QCOMPARE(priv->effectiveTextMargins().right(), sideWidgetWidth);
+ edit.clear();
+ QCOMPARE(priv->effectiveTextMargins().left(), sideWidgetWidth);
+ QCOMPARE(priv->effectiveTextMargins().right(), sideWidgetWidth);
+#endif
+}
+
Q_DECLARE_METATYPE(Qt::AlignmentFlag)
void tst_QLineEdit::shouldShowPlaceholderText_data()
{
@@ -4713,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)
@@ -4738,9 +4915,9 @@ void tst_QLineEdit::shortcutOverrideOnReadonlyLineEdit_data()
QTest::newRow("b") << QKeySequence(Qt::Key_B) << false;
QTest::newRow("c") << QKeySequence(Qt::Key_C) << false;
QTest::newRow("x") << QKeySequence(Qt::Key_X) << false;
- QTest::newRow("X") << QKeySequence(Qt::ShiftModifier + Qt::Key_X) << false;
+ QTest::newRow("X") << QKeySequence(Qt::ShiftModifier | Qt::Key_X) << false;
- QTest::newRow("Alt+Home") << QKeySequence(Qt::AltModifier + Qt::Key_Home) << false;
+ QTest::newRow("Alt+Home") << QKeySequence(Qt::AltModifier | Qt::Key_Home) << false;
}
void tst_QLineEdit::shortcutOverrideOnReadonlyLineEdit()
@@ -4767,14 +4944,14 @@ void tst_QLineEdit::shortcutOverrideOnReadonlyLineEdit()
const int keySequenceCount = keySequence.count();
for (int i = 0; i < keySequenceCount; ++i) {
- const uint key = keySequence[i];
+ const uint key = keySequence[i].toCombined();
QTest::keyClick(lineEdit,
Qt::Key(key & ~Qt::KeyboardModifierMask),
Qt::KeyboardModifier(key & Qt::KeyboardModifierMask));
}
const int activationCount = shouldBeHandledByQLineEdit ? 0 : 1;
- QCOMPARE(spy.count(), activationCount);
+ QCOMPARE(spy.size(), activationCount);
}
#endif // QT_CONFIG(shortcut)
@@ -4807,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
@@ -4827,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()
@@ -4900,7 +5077,7 @@ void tst_QLineEdit::testQuickSelectionWithMouse()
QVERIFY(lineEdit.selectedText().endsWith(suffix));
QTest::mouseMove(lineEdit.windowHandle(), center + QPoint(20, 0));
qCDebug(lcTests) << "Selected text:" << lineEdit.selectedText();
-#ifdef Q_PROCESSOR_ARM
+#ifdef Q_PROCESSOR_ARM_32
QEXPECT_FAIL("", "Currently fails on gcc-armv7, needs investigation.", Continue);
#endif
QCOMPARE(lineEdit.selectedText(), partialSelection);
@@ -4927,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();
@@ -4946,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);
@@ -4955,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();
@@ -4971,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"