diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2012-01-20 16:10:23 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-02 02:36:00 +0100 |
commit | 054a1e942f20e5b64626729f72023ac78dd0ce38 (patch) | |
tree | ec4ff0deb03f11989a1c40e1f07ad3c098346505 /tests | |
parent | c30a170bb0777e5d5ddc2d45a3ca98d3af0c62c4 (diff) |
Add a persistentSelection property to TextInput.
Improves feature parity with TextEdit.
Task-number: QTBUG-16355
Change-Id: I3919c71454a4f4574a1ee35ad38969459beb8363
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests')
4 files changed, 101 insertions, 16 deletions
diff --git a/tests/auto/qtquick2/qquicktextedit/data/persistentSelection.qml b/tests/auto/qtquick2/qquicktextedit/data/persistentSelection.qml new file mode 100644 index 0000000000..fb2fe0cd6c --- /dev/null +++ b/tests/auto/qtquick2/qquicktextedit/data/persistentSelection.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 + +TextEdit { + property string selected: selectedText + + text: "Hello World!" + focus: true +} diff --git a/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp index bcf4f60bf0..07b8f105fa 100644 --- a/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp @@ -946,23 +946,47 @@ void tst_qquicktextedit::textMargin() void tst_qquicktextedit::persistentSelection() { - { - QString componentStr = "import QtQuick 2.0\nTextEdit { persistentSelection: true; text: \"Hello World\" }"; - QDeclarativeComponent texteditComponent(&engine); - texteditComponent.setData(componentStr.toLatin1(), QUrl()); - QQuickTextEdit *textEditObject = qobject_cast<QQuickTextEdit*>(texteditComponent.create()); - QVERIFY(textEditObject != 0); - QCOMPARE(textEditObject->persistentSelection(), true); - } + QQuickView canvas(testFileUrl("persistentSelection.qml")); + canvas.show(); + canvas.requestActivateWindow(); + QTest::qWaitForWindowShown(&canvas); + QTRY_COMPARE(&canvas, qGuiApp->focusWindow()); + canvas.requestActivateWindow(); + + QQuickTextEdit *edit = qobject_cast<QQuickTextEdit *>(canvas.rootObject()); + QVERIFY(edit); + QVERIFY(edit->hasActiveFocus()); + + QSignalSpy spy(edit, SIGNAL(persistentSelectionChanged(bool))); + + QCOMPARE(edit->persistentSelection(), false); + + edit->setPersistentSelection(false); + QCOMPARE(edit->persistentSelection(), false); + QCOMPARE(spy.count(), 0); + + edit->select(1, 4); + QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); + + edit->setFocus(false); + QCOMPARE(edit->property("selected").toString(), QString()); + + edit->setFocus(true); + QCOMPARE(edit->property("selected").toString(), QString()); + + edit->setPersistentSelection(true); + QCOMPARE(edit->persistentSelection(), true); + QCOMPARE(spy.count(), 1); + + edit->select(1, 4); + QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); + + edit->setFocus(false); + QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); + + edit->setFocus(true); + QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); - { - QString componentStr = "import QtQuick 2.0\nTextEdit { persistentSelection: false; text: \"Hello World\" }"; - QDeclarativeComponent texteditComponent(&engine); - texteditComponent.setData(componentStr.toLatin1(), QUrl()); - QQuickTextEdit *textEditObject = qobject_cast<QQuickTextEdit*>(texteditComponent.create()); - QVERIFY(textEditObject != 0); - QCOMPARE(textEditObject->persistentSelection(), false); - } } void tst_qquicktextedit::focusOnPress() diff --git a/tests/auto/qtquick2/qquicktextinput/data/persistentSelection.qml b/tests/auto/qtquick2/qquicktextinput/data/persistentSelection.qml new file mode 100644 index 0000000000..dea6e48b08 --- /dev/null +++ b/tests/auto/qtquick2/qquicktextinput/data/persistentSelection.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 + +TextInput { + property string selected: selectedText + + text: "Hello World!" + focus: true +} diff --git a/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp index 13936d42cd..5e4521449e 100644 --- a/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp @@ -109,6 +109,7 @@ private slots: void color(); void wrap(); void selection(); + void persistentSelection(); void isRightToLeft_data(); void isRightToLeft(); void moveCursorSelection_data(); @@ -628,6 +629,50 @@ void tst_qquicktextinput::selection() delete textinputObject; } +void tst_qquicktextinput::persistentSelection() +{ + QQuickView canvas(testFileUrl("persistentSelection.qml")); + canvas.show(); + canvas.requestActivateWindow(); + QTest::qWaitForWindowShown(&canvas); + QTRY_COMPARE(&canvas, qGuiApp->focusWindow()); + canvas.requestActivateWindow(); + + QQuickTextInput *input = qobject_cast<QQuickTextInput *>(canvas.rootObject()); + QVERIFY(input); + QVERIFY(input->hasActiveFocus()); + + QSignalSpy spy(input, SIGNAL(persistentSelectionChanged())); + + QCOMPARE(input->persistentSelection(), false); + + input->setPersistentSelection(false); + QCOMPARE(input->persistentSelection(), false); + QCOMPARE(spy.count(), 0); + + input->select(1, 4); + QCOMPARE(input->property("selected").toString(), QLatin1String("ell")); + + input->setFocus(false); + QCOMPARE(input->property("selected").toString(), QString()); + + input->setFocus(true); + QCOMPARE(input->property("selected").toString(), QString()); + + input->setPersistentSelection(true); + QCOMPARE(input->persistentSelection(), true); + QCOMPARE(spy.count(), 1); + + input->select(1, 4); + QCOMPARE(input->property("selected").toString(), QLatin1String("ell")); + + input->setFocus(false); + QCOMPARE(input->property("selected").toString(), QLatin1String("ell")); + + input->setFocus(true); + QCOMPARE(input->property("selected").toString(), QLatin1String("ell")); +} + void tst_qquicktextinput::isRightToLeft_data() { QTest::addColumn<QString>("text"); |