Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix access to context properties within TextEdit.cursorDelegate
Don't create the cursorDelegate instance before componentComplete as
the context may not be fully populated prior to that.

Task-number: QTBUG-21780

Change-Id: I6ca8a24989bc28e5c5ca06d61a85e32ff630ce7c
Reviewed-by: Martin Jones <martin.jones@nokia.com>
  • Loading branch information
Andrew den Exter authored and Qt by Nokia committed Feb 14, 2012
1 parent 452be83 commit a4b0ac2
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/quick/items/qquicktextedit.cpp
Expand Up @@ -960,7 +960,7 @@ void QQuickTextEdit::setCursorDelegate(QDeclarativeComponent* c)
void QQuickTextEdit::loadCursorDelegate()
{
Q_D(QQuickTextEdit);
if (d->cursorComponent->isLoading())
if (d->cursorComponent->isLoading() || !isComponentComplete())
return;
QDeclarativeContext *creationContext = d->cursorComponent->creationContext();
QObject *object = d->cursorComponent->create(creationContext ? creationContext : qmlContext(this));
Expand Down Expand Up @@ -1164,7 +1164,8 @@ void QQuickTextEdit::componentComplete()
updateSize();
d->dirty = false;
}

if (d->cursorComponent && d->cursorComponent->isReady())
loadCursorDelegate();
}
/*!
\qmlproperty bool QtQuick2::TextEdit::selectByMouse
Expand Down
5 changes: 5 additions & 0 deletions tests/auto/qtquick2/qquicktextedit/data/Cursor.qml
@@ -0,0 +1,5 @@
import QtQuick 2.0

Rectangle {
property string localProperty
}
15 changes: 15 additions & 0 deletions tests/auto/qtquick2/qquicktextedit/data/cursorTestExternal.qml
@@ -0,0 +1,15 @@
import QtQuick 2.0

Rectangle { width: 300; height: 300; color: "white"
property string contextualProperty: "Hello"
TextEdit {
text: "Hello world!"
id: textEditObject;
objectName: "textEditObject"
cursorDelegate: Cursor {
id:cursorInstance;
objectName: "cursorInstance";
localProperty: contextualProperty;
}
}
}
15 changes: 15 additions & 0 deletions tests/auto/qtquick2/qquicktextedit/data/cursorTestInline.qml
@@ -0,0 +1,15 @@
import QtQuick 2.0

Rectangle { width: 300; height: 300; color: "white"
property string contextualProperty: "Hello"
TextEdit {
text: "Hello world!"
id: textEditObject
objectName: "textEditObject"
cursorDelegate: Item {
id:cursorInstance
objectName: "cursorInstance"
property string localProperty: contextualProperty
}
}
}
12 changes: 11 additions & 1 deletion tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp
Expand Up @@ -134,6 +134,7 @@ private slots:

void linkActivated();

void cursorDelegate_data();
void cursorDelegate();
void cursorVisible();
void delegateLoading_data();
Expand Down Expand Up @@ -1813,9 +1814,18 @@ void tst_qquicktextedit::linkActivated()
QCOMPARE(spy.count(), 2);
}

void tst_qquicktextedit::cursorDelegate_data()
{
QTest::addColumn<QUrl>("source");
QTest::newRow("out of line") << testFileUrl("cursorTest.qml");
QTest::newRow("in line") << testFileUrl("cursorTestInline.qml");
QTest::newRow("external") << testFileUrl("cursorTestExternal.qml");
}

void tst_qquicktextedit::cursorDelegate()
{
QQuickView view(testFileUrl("cursorTest.qml"));
QFETCH(QUrl, source);
QQuickView view(source);
view.show();
view.requestActivateWindow();
QQuickTextEdit *textEditObject = view.rootObject()->findChild<QQuickTextEdit*>("textEditObject");
Expand Down
5 changes: 5 additions & 0 deletions tests/auto/qtquick2/qquicktextinput/data/Cursor.qml
@@ -0,0 +1,5 @@
import QtQuick 2.0

Rectangle {
property string localProperty
}
15 changes: 15 additions & 0 deletions tests/auto/qtquick2/qquicktextinput/data/cursorTestExternal.qml
@@ -0,0 +1,15 @@
import QtQuick 2.0

Rectangle { width: 300; height: 300; color: "white"
property string contextualProperty: "Hello"
TextInput {
text: "Hello world!"
id: textInputObject;
objectName: "textInputObject"
cursorDelegate: Cursor {
id:cursorInstance;
objectName: "cursorInstance";
localProperty: contextualProperty;
}
}
}
15 changes: 15 additions & 0 deletions tests/auto/qtquick2/qquicktextinput/data/cursorTestInline.qml
@@ -0,0 +1,15 @@
import QtQuick 2.0

Rectangle { width: 300; height: 300; color: "white"
property string contextualProperty: "Hello"
TextInput {
text: "Hello world!"
id: textInputObject
objectName: "textInputObject"
cursorDelegate: Item {
id:cursorInstance
objectName: "cursorInstance"
property string localProperty: contextualProperty
}
}
}
12 changes: 11 additions & 1 deletion tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp
Expand Up @@ -136,6 +136,7 @@ private slots:
void inputMethods();

void passwordCharacter();
void cursorDelegate_data();
void cursorDelegate();
void cursorVisible();
void cursorRectangle();
Expand Down Expand Up @@ -2306,9 +2307,18 @@ void tst_qquicktextinput::passwordCharacter()
delete textInput;
}

void tst_qquicktextinput::cursorDelegate_data()
{
QTest::addColumn<QUrl>("source");
QTest::newRow("out of line") << testFileUrl("cursorTest.qml");
QTest::newRow("in line") << testFileUrl("cursorTestInline.qml");
QTest::newRow("external") << testFileUrl("cursorTestExternal.qml");
}

void tst_qquicktextinput::cursorDelegate()
{
QQuickView view(testFileUrl("cursorTest.qml"));
QFETCH(QUrl, source);
QQuickView view(source);
view.show();
view.requestActivateWindow();
QQuickTextInput *textInputObject = view.rootObject()->findChild<QQuickTextInput*>("textInputObject");
Expand Down

0 comments on commit a4b0ac2

Please sign in to comment.