summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2012-02-14 12:55:38 +1000
committerQt by Nokia <qt-info@nokia.com>2012-02-14 07:48:38 +0100
commita4b0ac2af03f4a78469a3dc0e04f785cde4ab381 (patch)
treee67320e3e6f8bf215965c843c7c6838463b28b72
parent452be83f43f190cce04b8dc6b4b5f2e797c5886b (diff)
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>
-rw-r--r--src/quick/items/qquicktextedit.cpp5
-rw-r--r--tests/auto/qtquick2/qquicktextedit/data/Cursor.qml5
-rw-r--r--tests/auto/qtquick2/qquicktextedit/data/cursorTestExternal.qml15
-rw-r--r--tests/auto/qtquick2/qquicktextedit/data/cursorTestInline.qml15
-rw-r--r--tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp12
-rw-r--r--tests/auto/qtquick2/qquicktextinput/data/Cursor.qml5
-rw-r--r--tests/auto/qtquick2/qquicktextinput/data/cursorTestExternal.qml15
-rw-r--r--tests/auto/qtquick2/qquicktextinput/data/cursorTestInline.qml15
-rw-r--r--tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp12
9 files changed, 95 insertions, 4 deletions
diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp
index 5343715c3a..b9ff18e3d3 100644
--- a/src/quick/items/qquicktextedit.cpp
+++ b/src/quick/items/qquicktextedit.cpp
@@ -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));
@@ -1164,7 +1164,8 @@ void QQuickTextEdit::componentComplete()
updateSize();
d->dirty = false;
}
-
+ if (d->cursorComponent && d->cursorComponent->isReady())
+ loadCursorDelegate();
}
/*!
\qmlproperty bool QtQuick2::TextEdit::selectByMouse
diff --git a/tests/auto/qtquick2/qquicktextedit/data/Cursor.qml b/tests/auto/qtquick2/qquicktextedit/data/Cursor.qml
new file mode 100644
index 0000000000..e5c1853fc5
--- /dev/null
+++ b/tests/auto/qtquick2/qquicktextedit/data/Cursor.qml
@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+Rectangle {
+ property string localProperty
+}
diff --git a/tests/auto/qtquick2/qquicktextedit/data/cursorTestExternal.qml b/tests/auto/qtquick2/qquicktextedit/data/cursorTestExternal.qml
new file mode 100644
index 0000000000..7e916ec818
--- /dev/null
+++ b/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;
+ }
+ }
+}
diff --git a/tests/auto/qtquick2/qquicktextedit/data/cursorTestInline.qml b/tests/auto/qtquick2/qquicktextedit/data/cursorTestInline.qml
new file mode 100644
index 0000000000..786f39113c
--- /dev/null
+++ b/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
+ }
+ }
+}
diff --git a/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp
index 77d17d99d6..eb8e711e6a 100644
--- a/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp
+++ b/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp
@@ -134,6 +134,7 @@ private slots:
void linkActivated();
+ void cursorDelegate_data();
void cursorDelegate();
void cursorVisible();
void delegateLoading_data();
@@ -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");
diff --git a/tests/auto/qtquick2/qquicktextinput/data/Cursor.qml b/tests/auto/qtquick2/qquicktextinput/data/Cursor.qml
new file mode 100644
index 0000000000..e5c1853fc5
--- /dev/null
+++ b/tests/auto/qtquick2/qquicktextinput/data/Cursor.qml
@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+Rectangle {
+ property string localProperty
+}
diff --git a/tests/auto/qtquick2/qquicktextinput/data/cursorTestExternal.qml b/tests/auto/qtquick2/qquicktextinput/data/cursorTestExternal.qml
new file mode 100644
index 0000000000..9277dcc518
--- /dev/null
+++ b/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;
+ }
+ }
+}
diff --git a/tests/auto/qtquick2/qquicktextinput/data/cursorTestInline.qml b/tests/auto/qtquick2/qquicktextinput/data/cursorTestInline.qml
new file mode 100644
index 0000000000..efc4b191da
--- /dev/null
+++ b/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
+ }
+ }
+}
diff --git a/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp
index dd86d03b74..16577376f0 100644
--- a/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp
+++ b/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp
@@ -136,6 +136,7 @@ private slots:
void inputMethods();
void passwordCharacter();
+ void cursorDelegate_data();
void cursorDelegate();
void cursorVisible();
void cursorRectangle();
@@ -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");