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();
d->cursor->setHeight(QFontMetrics(d->font).height());
moveCursorDelegate();
}else{
+ delete object;
qmlInfo(this) << "Error loading cursor delegate.";
}
}
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;
}
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
}
}
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);
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
}
}
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);