diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2009-10-15 04:07:24 (GMT) |
---|---|---|
committer | Alan Alpert <alan.alpert@nokia.com> | 2009-10-15 04:07:24 (GMT) |
commit | 0f97a4fbcab5972f47a8a6cc3b501446df94bedb (patch) | |
tree | 2f481fb4dab033b42649c9453b0409d0825a1792 | |
parent | 25f5008d6bc6788e68e34f24af196f12de052567 (diff) | |
download | Qt-0f97a4fbcab5972f47a8a6cc3b501446df94bedb.zip Qt-0f97a4fbcab5972f47a8a6cc3b501446df94bedb.tar.gz Qt-0f97a4fbcab5972f47a8a6cc3b501446df94bedb.tar.bz2 |
Add cursorDelegate test to QFxTextInput autotests
Also cleaned up the QFxTextEdit version, and fixed a bug the new test
uncovered.
-rw-r--r-- | src/declarative/fx/qfxtextinput.cpp | 14 | ||||
-rw-r--r-- | tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp | 6 | ||||
-rw-r--r-- | tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp | 25 |
3 files changed, 35 insertions, 10 deletions
diff --git a/src/declarative/fx/qfxtextinput.cpp b/src/declarative/fx/qfxtextinput.cpp index c694133..e9ddd3f 100644 --- a/src/declarative/fx/qfxtextinput.cpp +++ b/src/declarative/fx/qfxtextinput.cpp @@ -501,17 +501,19 @@ void QFxTextInput::setCursorDelegate(QmlComponent* c) { Q_D(QFxTextInput); d->cursorComponent = c; - d->startCreatingCursor(); + if(!c){ + //note that the components are owned by something else + disconnect(d->control, SIGNAL(cursorPositionChanged(int, int)), + this, SLOT(moveCursor())); + delete d->cursorItem; + }else{ + d->startCreatingCursor(); + } } void QFxTextInputPrivate::startCreatingCursor() { Q_Q(QFxTextInput); - if(!cursorComponent){ - q->disconnect(control, SIGNAL(cursorPositionChanged(int, int)), - q, SLOT(moveCursor())); - return; - } q->connect(control, SIGNAL(cursorPositionChanged(int, int)), q, SLOT(moveCursor())); if(cursorComponent->isReady()){ diff --git a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp index 1433bf2..f78e564 100644 --- a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp +++ b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp @@ -433,10 +433,10 @@ void tst_qfxtextedit::selection() void tst_qfxtextedit::cursorDelegate() { - QmlView* view = new QmlView(0); - view->show(); - view->setUrl(QUrl("data/cursorTest.qml")); + QmlView* view = createView(SRCDIR "/data/cursorTest.qml"); view->execute(); + view->show(); + view->setFocus(); QFxTextEdit *textEditObject = view->root()->findChild<QFxTextEdit*>("textEditObject"); QVERIFY(textEditObject != 0); QVERIFY(textEditObject->findChild<QFxItem*>("cursorInstance")); diff --git a/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp b/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp index 81b4ac8..069574c 100644 --- a/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp +++ b/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp @@ -330,7 +330,30 @@ void tst_qfxtextinput::navigation() void tst_qfxtextinput::cursorDelegate() { - //TODO:Get the QFxTextEdit test passing first + QmlView* view = createView(SRCDIR "/data/cursorTest.qml"); + view->execute(); + view->show(); + view->setFocus(); + QFxTextInput *textInputObject = view->root()->findChild<QFxTextInput*>("textInputObject"); + QVERIFY(textInputObject != 0); + QVERIFY(textInputObject->findChild<QFxItem*>("cursorInstance")); + //Test Delegate gets created + textInputObject->setFocus(true); + QFxItem* delegateObject = textInputObject->findChild<QFxItem*>("cursorInstance"); + QVERIFY(delegateObject); + //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())); + } + textInputObject->setCursorPosition(0); + QCOMPARE(textInputObject->cursorRect().x()+5, qRound(delegateObject->x())); + QCOMPARE(textInputObject->cursorRect().y(), qRound(delegateObject->y())); + //Test Delegate gets deleted + textInputObject->setCursorDelegate(0); + QVERIFY(!textInputObject->findChild<QFxItem*>("cursorInstance")); } void tst_qfxtextinput::simulateKey(QmlView *view, int key) |