From 0f97a4fbcab5972f47a8a6cc3b501446df94bedb Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Thu, 15 Oct 2009 14:07:24 +1000 Subject: Add cursorDelegate test to QFxTextInput autotests Also cleaned up the QFxTextEdit version, and fixed a bug the new test uncovered. --- src/declarative/fx/qfxtextinput.cpp | 14 ++++++------ .../declarative/qfxtextedit/tst_qfxtextedit.cpp | 6 +++--- .../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("textEditObject"); QVERIFY(textEditObject != 0); QVERIFY(textEditObject->findChild("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("textInputObject"); + QVERIFY(textInputObject != 0); + QVERIFY(textInputObject->findChild("cursorInstance")); + //Test Delegate gets created + textInputObject->setFocus(true); + QFxItem* delegateObject = textInputObject->findChild("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("cursorInstance")); } void tst_qfxtextinput::simulateKey(QmlView *view, int key) -- cgit v0.12