From 3399066881c42d1dd6fda6b3ae8cf3fc8961929b Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Thu, 9 Jul 2009 17:06:22 +1000 Subject: Fix QFxTextEdit cursorDelegate auto test properly Also fixes the minor bug that it found. --- src/declarative/fx/qfxtextedit.cpp | 5 ++- .../declarative/qfxtextedit/data/cursorTest.qml | 6 +++ .../declarative/qfxtextedit/tst_qfxtextedit.cpp | 51 +++++----------------- 3 files changed, 19 insertions(+), 43 deletions(-) create mode 100644 tests/auto/declarative/qfxtextedit/data/cursorTest.qml diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp index ef56cc8..c2bda6f 100644 --- a/src/declarative/fx/qfxtextedit.cpp +++ b/src/declarative/fx/qfxtextedit.cpp @@ -521,8 +521,9 @@ void QFxTextEdit::setCursorDelegate(QmlComponent* c) if(c && c->isReady()){ loadCursorDelegate(); }else{ - connect(c, SIGNAL(statusChanged()), - this, SLOT(loadCursorDelegate())); + if(c) + connect(c, SIGNAL(statusChanged()), + this, SLOT(loadCursorDelegate())); } } diff --git a/tests/auto/declarative/qfxtextedit/data/cursorTest.qml b/tests/auto/declarative/qfxtextedit/data/cursorTest.qml new file mode 100644 index 0000000..10ac2fd --- /dev/null +++ b/tests/auto/declarative/qfxtextedit/data/cursorTest.qml @@ -0,0 +1,6 @@ +Rect { width: 300; height: 300; color: "white" + TextEdit { text: "Hello world!"; focusable: true; id: textEditObject + resources: [ Component { id:cursor; Item { id:cursorInstance } } ] + cursorDelegate: cursor + } +} diff --git a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp index 809ed5b..241dbad 100644 --- a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp +++ b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp @@ -43,38 +43,6 @@ private: QmlEngine engine; }; -/* - Find an item with the specified id. If index is supplied then the - item must also evaluate the {index} expression equal to index - - Copied from ListView test -*/ -template -T *findItem(QFxItem *parent, const QString &id, int index=0) -{ - const QMetaObject &mo = T::staticMetaObject; - qDebug() << parent->children()->count() << "children"; - for (int i = 0; i < parent->children()->count(); ++i) { - QFxItem *item = parent->children()->at(i); - qDebug() << "try" << item; - if (mo.cast(item) && (id.isEmpty() || item->id() == id)) { - if (index != -1) { - QmlExpression e(qmlContext(item), "index", item); - e.setTrackChange(false); - if (e.value().toInt() == index) - return static_cast(item); - } else { - return static_cast(item); - } - } - item = findItem(item, id, index); - if (item) - return static_cast(item); - } - - return 0; -} - tst_qfxtextedit::tst_qfxtextedit() { standard << "the quick brown fox jumped over the lazy dog" @@ -456,21 +424,22 @@ void tst_qfxtextedit::selection() QVERIFY(textEditObject->selectedText().size() == 10); } +#include void tst_qfxtextedit::cursorDelegate() { - QString componentStr = "TextEdit { text: \""+ standard[1] +"\"; focusable: true; resources: [ Component { id:cursor; Item { id:cursorInstance } } ] cursorDelegate: cursor}"; - QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); + QFxView* view = new QFxView(0); + view->show(); + view->setUrl(QUrl("data/cursorTest.qml")); + view->execute(); + QFxTextEdit *textEditObject = view->root()->findChild("textEditObject"); QVERIFY(textEditObject != 0); - QVERIFY(!findItem(textEditObject, "cursorInstance")); + QVERIFY(textEditObject->findChild("cursorInstance")); //Test Delegate gets created textEditObject->setFocus(true); - //TODO:To get focus you also need to be in a focused window - switch this to a QFxView - return; - QFxItem* delegateObject = findItem(textEditObject, "cursorInstance"); + QFxItem* delegateObject = textEditObject->findChild("cursorInstance"); QVERIFY(delegateObject); //Test Delegate gets moved - for(int i=0; i<= standard[1].size(); i++){ + for(int i=0; i<= textEditObject->text().length(); i++){ textEditObject->setCursorPosition(i); QCOMPARE(textEditObject->cursorRect().x(), qRound(delegateObject->x())); QCOMPARE(textEditObject->cursorRect().y(), qRound(delegateObject->y())); @@ -480,7 +449,7 @@ void tst_qfxtextedit::cursorDelegate() QCOMPARE(textEditObject->cursorRect().y(), qRound(delegateObject->y())); //Test Delegate gets deleted textEditObject->setCursorDelegate(0); - QVERIFY(!findItem(textEditObject, "cursorInstance")); + QVERIFY(!textEditObject->findChild("cursorInstance")); } QTEST_MAIN(tst_qfxtextedit) -- cgit v0.12