diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2010-05-31 05:45:01 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2010-05-31 05:49:01 (GMT) |
commit | b8b1e9784583e3b5960b1966328299f8a1bec440 (patch) | |
tree | 26b147cdf82bde0b3d97610a8449fcc1599d2246 /tests/auto | |
parent | c00e6b499e89e4b872e9148c5f8a37f9050d9c84 (diff) | |
download | Qt-b8b1e9784583e3b5960b1966328299f8a1bec440.zip Qt-b8b1e9784583e3b5960b1966328299f8a1bec440.tar.gz Qt-b8b1e9784583e3b5960b1966328299f8a1bec440.tar.bz2 |
Simplify selection setting. Make TextInput more like TextEdit.
By making selectionStart/End read-only, and adding adding select().
Task-number: QTBUG-11056
Diffstat (limited to 'tests/auto')
4 files changed, 31 insertions, 69 deletions
diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index d3e3c3a..47c5b63 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -551,11 +551,11 @@ void tst_qdeclarativetextedit::selection() //Test selection for(int i=0; i<= testStr.size(); i++) { - textEditObject->setSelectionEnd(i); + textEditObject->select(0,i); QCOMPARE(testStr.mid(0,i), textEditObject->selectedText()); } for(int i=0; i<= testStr.size(); i++) { - textEditObject->setSelectionStart(i); + textEditObject->select(i,testStr.size()); QCOMPARE(testStr.mid(i,testStr.size()-i), textEditObject->selectedText()); } @@ -565,43 +565,26 @@ void tst_qdeclarativetextedit::selection() QVERIFY(textEditObject->selectionEnd() == 0); QVERIFY(textEditObject->selectedText().isNull()); - for(int i=0; i< testStr.size(); i++) { - textEditObject->setSelectionStart(i); - QCOMPARE(textEditObject->selectionEnd(), i); - QCOMPARE(testStr.mid(i,0), textEditObject->selectedText()); - textEditObject->setSelectionEnd(i+1); - QCOMPARE(textEditObject->selectionStart(), i); - QCOMPARE(testStr.mid(i,1), textEditObject->selectedText()); - } - - for(int i= testStr.size() - 1; i>0; i--) { - textEditObject->setSelectionEnd(i); - QCOMPARE(testStr.mid(i,0), textEditObject->selectedText()); - textEditObject->setSelectionStart(i-1); - QCOMPARE(testStr.mid(i-1,1), textEditObject->selectedText()); - } - //Test Error Ignoring behaviour textEditObject->setCursorPosition(0); QVERIFY(textEditObject->selectedText().isNull()); - textEditObject->setSelectionStart(-10); + textEditObject->select(-10,0); QVERIFY(textEditObject->selectedText().isNull()); - textEditObject->setSelectionStart(100); + textEditObject->select(100,101); QVERIFY(textEditObject->selectedText().isNull()); - textEditObject->setSelectionEnd(-10); + textEditObject->select(0,-10); QVERIFY(textEditObject->selectedText().isNull()); - textEditObject->setSelectionEnd(100); + textEditObject->select(0,100); QVERIFY(textEditObject->selectedText().isNull()); - textEditObject->setSelectionStart(0); - textEditObject->setSelectionEnd(10); + textEditObject->select(0,10); QVERIFY(textEditObject->selectedText().size() == 10); - textEditObject->setSelectionStart(-10); + textEditObject->select(-10,0); QVERIFY(textEditObject->selectedText().size() == 10); - textEditObject->setSelectionStart(100); + textEditObject->select(100,101); QVERIFY(textEditObject->selectedText().size() == 10); - textEditObject->setSelectionEnd(-10); + textEditObject->select(0,-10); QVERIFY(textEditObject->selectedText().size() == 10); - textEditObject->setSelectionEnd(100); + textEditObject->select(0,100); QVERIFY(textEditObject->selectedText().size() == 10); } diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index c01cfa5..54bb9c1 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -322,11 +322,11 @@ void tst_qdeclarativetextinput::selection() //Test selection for(int i=0; i<= testStr.size(); i++) { - textinputObject->setSelectionEnd(i); + textinputObject->select(0,i); QCOMPARE(testStr.mid(0,i), textinputObject->selectedText()); } for(int i=0; i<= testStr.size(); i++) { - textinputObject->setSelectionStart(i); + textinputObject->select(i,testStr.size()); QCOMPARE(testStr.mid(i,testStr.size()-i), textinputObject->selectedText()); } @@ -336,43 +336,26 @@ void tst_qdeclarativetextinput::selection() QVERIFY(textinputObject->selectionEnd() == 0); QVERIFY(textinputObject->selectedText().isNull()); - for(int i=0; i< testStr.size(); i++) { - textinputObject->setSelectionStart(i); - QCOMPARE(textinputObject->selectionEnd(), i); - QCOMPARE(testStr.mid(i,0), textinputObject->selectedText()); - textinputObject->setSelectionEnd(i+1); - QCOMPARE(textinputObject->selectionStart(), i); - QCOMPARE(testStr.mid(i,1), textinputObject->selectedText()); - } - - for(int i= testStr.size() - 1; i>0; i--) { - textinputObject->setSelectionEnd(i); - QCOMPARE(testStr.mid(i,0), textinputObject->selectedText()); - textinputObject->setSelectionStart(i-1); - QCOMPARE(testStr.mid(i-1,1), textinputObject->selectedText()); - } - //Test Error Ignoring behaviour textinputObject->setCursorPosition(0); QVERIFY(textinputObject->selectedText().isNull()); - textinputObject->setSelectionStart(-10); + textinputObject->select(-10,0); QVERIFY(textinputObject->selectedText().isNull()); - textinputObject->setSelectionStart(100); + textinputObject->select(100,110); QVERIFY(textinputObject->selectedText().isNull()); - textinputObject->setSelectionEnd(-10); + textinputObject->select(0,-10); QVERIFY(textinputObject->selectedText().isNull()); - textinputObject->setSelectionEnd(100); + textinputObject->select(0,100); QVERIFY(textinputObject->selectedText().isNull()); - textinputObject->setSelectionStart(0); - textinputObject->setSelectionEnd(10); + textinputObject->select(0,10); QVERIFY(textinputObject->selectedText().size() == 10); - textinputObject->setSelectionStart(-10); + textinputObject->select(-10,10); QVERIFY(textinputObject->selectedText().size() == 10); - textinputObject->setSelectionStart(100); + textinputObject->select(100,101); QVERIFY(textinputObject->selectedText().size() == 10); - textinputObject->setSelectionEnd(-10); + textinputObject->select(0,-10); QVERIFY(textinputObject->selectedText().size() == 10); - textinputObject->setSelectionEnd(100); + textinputObject->select(0,100); QVERIFY(textinputObject->selectedText().size() == 10); delete textinputObject; @@ -565,8 +548,7 @@ void tst_qdeclarativetextinput::navigation() QVERIFY(input->hasFocus() == true); //QT-2944: If text is selected, ensure we deselect upon cursor motion input->setCursorPosition(input->text().length()); - input->setSelectionStart(0); - input->setSelectionEnd(input->text().length()); + input->select(0,input->text().length()); QVERIFY(input->selectionStart() != input->selectionEnd()); simulateKey(canvas, Qt::Key_Right); QVERIFY(input->selectionStart() == input->selectionEnd()); @@ -603,13 +585,13 @@ void tst_qdeclarativetextinput::cursorDelegate() //Test Delegate gets moved for(int i=0; i<= textInputObject->text().length(); i++){ textInputObject->setCursorPosition(i); - //+5 is because the TextInput cursorRect is just a 10xHeight area centered on cursor position - QCOMPARE(textInputObject->cursorRect().x() + 5, qRound(delegateObject->x())); - QCOMPARE(textInputObject->cursorRect().y(), qRound(delegateObject->y())); + //+5 is because the TextInput cursorRectangle is just a 10xHeight area centered on cursor position + QCOMPARE(textInputObject->cursorRectangle().x() + 5, qRound(delegateObject->x())); + QCOMPARE(textInputObject->cursorRectangle().y(), qRound(delegateObject->y())); } textInputObject->setCursorPosition(0); - QCOMPARE(textInputObject->cursorRect().x()+5, qRound(delegateObject->x())); - QCOMPARE(textInputObject->cursorRect().y(), qRound(delegateObject->y())); + QCOMPARE(textInputObject->cursorRectangle().x()+5, qRound(delegateObject->x())); + QCOMPARE(textInputObject->cursorRectangle().y(), qRound(delegateObject->y())); //Test Delegate gets deleted textInputObject->setCursorDelegate(0); QVERIFY(!textInputObject->findChild<QDeclarativeItem*>("cursorInstance")); @@ -881,8 +863,7 @@ void tst_qdeclarativetextinput::focusOutClearSelection() view.show(); QApplication::setActiveWindow(&view); QTest::qWaitForWindowShown(&view); - input.setSelectionStart(2); - input.setSelectionEnd(5); + input.select(2,5); //The selection should work QTRY_COMPARE(input.selectedText(), QLatin1String("llo")); input2.setFocus(true); diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetextedit/MultilineEdit.qml b/tests/auto/declarative/qmlvisual/qdeclarativetextedit/MultilineEdit.qml index 0273282..53538cb 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativetextedit/MultilineEdit.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativetextedit/MultilineEdit.qml @@ -65,8 +65,7 @@ Item { onReleased: { } onDoubleClicked: { - textEdit.selectionStart=0; - textEdit.selectionEnd=textEdit.text.length; + textEdit.selectAll() } z: textEdit.z + 1 } diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetextinput/LineEdit.qml b/tests/auto/declarative/qmlvisual/qdeclarativetextinput/LineEdit.qml index cc0ad3c..69f57c6 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativetextinput/LineEdit.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativetextinput/LineEdit.qml @@ -58,8 +58,7 @@ Item { onReleased: { } onDoubleClicked: { - textInp.selectionStart=0; - textInp.selectionEnd=textInp.text.length; + textInp.selectAll() } z: textInp.z + 1 } |