diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2011-09-30 17:17:49 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-10-12 04:38:36 +0200 |
commit | b3f9f53ff12d7fd5fc5b667c6a58169d5de06939 (patch) | |
tree | f7a4cd5e3ad60e23955ecea351fa99bebd6c1173 | |
parent | fee823ed6adc77db563468539b47b9d10e02e5c8 (diff) |
Provide a context when constructing a TextInput cursor delegate.
Without a context the delegate won't be able to refer to any external
properties.
Task-number: QTBUG-21780
Change-Id: I7171787e677ce67466b311796693ed88bcacb718
Reviewed-on: http://codereview.qt-project.org/5837
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
6 files changed, 15 insertions, 5 deletions
diff --git a/src/declarative/items/qsgtextedit.cpp b/src/declarative/items/qsgtextedit.cpp index 6dd3908c9c..cec3bd8b20 100644 --- a/src/declarative/items/qsgtextedit.cpp +++ b/src/declarative/items/qsgtextedit.cpp @@ -891,7 +891,9 @@ void QSGTextEdit::loadCursorDelegate() Q_D(QSGTextEdit); if(d->cursorComponent->isLoading()) return; - d->cursor = qobject_cast<QSGItem*>(d->cursorComponent->create(qmlContext(this))); + QDeclarativeContext *creationContext = d->cursorComponent->creationContext(); + QObject *object = d->cursorComponent->create(creationContext ? creationContext : qmlContext(this)); + d->cursor = qobject_cast<QSGItem*>(object); if(d->cursor){ d->control->setCursorWidth(0); updateCursor(); @@ -900,6 +902,7 @@ void QSGTextEdit::loadCursorDelegate() d->cursor->setHeight(QFontMetrics(d->font).height()); moveCursorDelegate(); }else{ + delete object; qmlInfo(this) << "Error loading cursor delegate."; } } diff --git a/src/declarative/items/qsgtextinput.cpp b/src/declarative/items/qsgtextinput.cpp index 71c414fe02..3f1d95a4fc 100644 --- a/src/declarative/items/qsgtextinput.cpp +++ b/src/declarative/items/qsgtextinput.cpp @@ -971,8 +971,11 @@ void QSGTextInput::createCursor() if(d->cursorItem) delete d->cursorItem; - d->cursorItem = qobject_cast<QSGItem*>(d->cursorComponent->create()); + QDeclarativeContext *creationContext = d->cursorComponent->creationContext(); + QObject *object = d->cursorComponent->create(creationContext ? creationContext : qmlContext(this)); + d->cursorItem = qobject_cast<QSGItem*>(object); if(!d->cursorItem){ + delete object; qmlInfo(this, d->cursorComponent->errors()) << tr("Could not instantiate cursor delegate"); return; } diff --git a/tests/auto/declarative/qsgtextedit/data/cursorTest.qml b/tests/auto/declarative/qsgtextedit/data/cursorTest.qml index e734fc141c..7bfc869403 100644 --- a/tests/auto/declarative/qsgtextedit/data/cursorTest.qml +++ b/tests/auto/declarative/qsgtextedit/data/cursorTest.qml @@ -1,8 +1,9 @@ import QtQuick 2.0 Rectangle { width: 300; height: 300; color: "white" + property string contextualProperty: "Hello" TextEdit { text: "Hello world!"; id: textEditObject; objectName: "textEditObject" - resources: [ Component { id:cursor; Item { id:cursorInstance; objectName: "cursorInstance" } } ] + resources: [ Component { id:cursor; Item { id:cursorInstance; objectName: "cursorInstance"; property string localProperty: contextualProperty } } ] cursorDelegate: cursor } } diff --git a/tests/auto/declarative/qsgtextedit/tst_qsgtextedit.cpp b/tests/auto/declarative/qsgtextedit/tst_qsgtextedit.cpp index 1a9372b1e5..874522941d 100644 --- a/tests/auto/declarative/qsgtextedit/tst_qsgtextedit.cpp +++ b/tests/auto/declarative/qsgtextedit/tst_qsgtextedit.cpp @@ -1589,6 +1589,7 @@ void tst_qsgtextedit::cursorDelegate() textEditObject->setFocus(true); QSGItem* delegateObject = textEditObject->findChild<QSGItem*>("cursorInstance"); QVERIFY(delegateObject); + QCOMPARE(delegateObject->property("localProperty").toString(), QString("Hello")); //Test Delegate gets moved for(int i=0; i<= textEditObject->text().length(); i++){ textEditObject->setCursorPosition(i); diff --git a/tests/auto/declarative/qsgtextinput/data/cursorTest.qml b/tests/auto/declarative/qsgtextinput/data/cursorTest.qml index 01858fba77..71a420ee7c 100644 --- a/tests/auto/declarative/qsgtextinput/data/cursorTest.qml +++ b/tests/auto/declarative/qsgtextinput/data/cursorTest.qml @@ -1,8 +1,9 @@ import QtQuick 2.0 -Rectangle { width: 300; height: 300; color: "white" +Rectangle { id:rect; width: 300; height: 300; color: "white" + property string contextualProperty: "Hello" TextInput { text: "Hello world!"; id: textInputObject; objectName: "textInputObject" - resources: [ Component { id:cursor; Item { id:cursorInstance; objectName: "cursorInstance";} } ] + resources: [ Component { id:cursor; Item { id:cursorInstance; objectName: "cursorInstance"; property string localProperty: contextualProperty } } ] cursorDelegate: cursor } } diff --git a/tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp b/tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp index 26638c14aa..b2960dd4c4 100644 --- a/tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp +++ b/tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp @@ -1742,6 +1742,7 @@ void tst_qsgtextinput::cursorDelegate() textInputObject->setFocus(true); QSGItem* delegateObject = textInputObject->findChild<QSGItem*>("cursorInstance"); QVERIFY(delegateObject); + QCOMPARE(delegateObject->property("localProperty").toString(), QString("Hello")); //Test Delegate gets moved for(int i=0; i<= textInputObject->text().length(); i++){ textInputObject->setCursorPosition(i); |