aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2012-05-04 16:07:32 +1000
committerQt by Nokia <qt-info@nokia.com>2012-05-14 00:51:15 +0200
commitbd5e23a00e97603c1cc73328c508a044f1528802 (patch)
tree8ffe4145ec6d62c5d9e0798af9d48c29d66ff176 /tests
parent6f9b3893c8c7bc0b6663acb34c17c120852ef7b7 (diff)
Defer construction of TextEdit/TextInput delegates.
Don't create instances of the delegate components until the item gains focus, or the cursorVisible property is set to true. Cursor delegates are typically small and relatively fast to create and so won't have a significant cost during a one off focus in event, but that cost can still add up when creating a number of TextInputs or TextEdits at once. If a delegate that is instantiated immeditately is required it is possible to instead create a child item and bind to the cursorRectangle and cursorVisible properties. Change-Id: I5ec2b5b6a30e534aee3dd5a58c6a5ac0686f5ce2 Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qquicktextedit/data/http/cursorHttpTest.qml4
-rw-r--r--tests/auto/quick/qquicktextedit/data/http/cursorHttpTestFail1.qml3
-rw-r--r--tests/auto/quick/qquicktextedit/data/http/cursorHttpTestFail2.qml3
-rw-r--r--tests/auto/quick/qquicktextedit/data/http/cursorHttpTestPass.qml2
-rw-r--r--tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp7
-rw-r--r--tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp9
6 files changed, 25 insertions, 3 deletions
diff --git a/tests/auto/quick/qquicktextedit/data/http/cursorHttpTest.qml b/tests/auto/quick/qquicktextedit/data/http/cursorHttpTest.qml
index be4526e22b..043304d027 100644
--- a/tests/auto/quick/qquicktextedit/data/http/cursorHttpTest.qml
+++ b/tests/auto/quick/qquicktextedit/data/http/cursorHttpTest.qml
@@ -9,14 +9,18 @@ Rectangle { width: 300; height: 300; color: "white"
]
TextEdit {
cursorDelegate: cursorFail
+ cursorVisible: true
}
TextEdit {
cursorDelegate: cursorWait
+ cursorVisible: true
}
TextEdit {
cursorDelegate: cursorNorm
+ cursorVisible: true
}
TextEdit {
cursorDelegate: cursorErr
+ cursorVisible: true
}
}
diff --git a/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestFail1.qml b/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestFail1.qml
index 1d7763f913..a6556454fe 100644
--- a/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestFail1.qml
+++ b/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestFail1.qml
@@ -8,11 +8,14 @@ Rectangle { width: 300; height: 300; color: "white"
]
TextEdit {
cursorDelegate: cursorFail
+ cursorVisible: true
}
TextEdit {
cursorDelegate: cursorWait
+ cursorVisible: true
}
TextEdit {
cursorDelegate: cursorNorm
+ cursorVisible: true
}
}
diff --git a/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestFail2.qml b/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestFail2.qml
index c82ec02e68..9429779a87 100644
--- a/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestFail2.qml
+++ b/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestFail2.qml
@@ -8,11 +8,14 @@ Rectangle { width: 300; height: 300; color: "white"
]
TextEdit {
cursorDelegate: cursorWait
+ cursorVisible: true
}
TextEdit {
cursorDelegate: cursorNorm
+ cursorVisible: true
}
TextEdit {
cursorDelegate: cursorErr
+ cursorVisible: true
}
}
diff --git a/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestPass.qml b/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestPass.qml
index 96d582c95d..69e498ef8d 100644
--- a/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestPass.qml
+++ b/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestPass.qml
@@ -8,10 +8,12 @@ Rectangle { width: 300; height: 300; color: "white"
TextEdit {
cursorDelegate: cursorWait
text: "Hello"
+ cursorVisible: true
}
TextEdit {
objectName: "textEditObject"
cursorDelegate: cursorNorm
+ cursorVisible: true
focus: true;
text: "Hello"
}
diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
index 1b21fcc2b4..c7bf6af6ee 100644
--- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
+++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
@@ -1952,9 +1952,12 @@ void tst_qquicktextedit::cursorDelegate()
view.requestActivateWindow();
QQuickTextEdit *textEditObject = view.rootObject()->findChild<QQuickTextEdit*>("textEditObject");
QVERIFY(textEditObject != 0);
- QVERIFY(textEditObject->findChild<QQuickItem*>("cursorInstance"));
+ // Delegate creation is deferred until focus in or cursor visiblity is forced.
+ QVERIFY(!textEditObject->findChild<QQuickItem*>("cursorInstance"));
+ QVERIFY(!textEditObject->isCursorVisible());
//Test Delegate gets created
textEditObject->setFocus(true);
+ QVERIFY(textEditObject->isCursorVisible());
QQuickItem* delegateObject = textEditObject->findChild<QQuickItem*>("cursorInstance");
QVERIFY(delegateObject);
QCOMPARE(delegateObject->property("localProperty").toString(), QString("Hello"));
@@ -2716,6 +2719,7 @@ void tst_qquicktextedit::clipRect()
cursorComponent.setData("import QtQuick 2.0\nRectangle { height: 20; width: 8 }", QUrl());
edit->setCursorDelegate(&cursorComponent);
+ edit->setCursorVisible(true);
// If a cursor delegate is used it's size should determine the excess width.
QCOMPARE(edit->clipRect().x(), qreal(0));
@@ -2797,6 +2801,7 @@ void tst_qquicktextedit::boundingRect()
cursorComponent.setData("import QtQuick 2.0\nRectangle { height: 20; width: 8 }", QUrl());
edit->setCursorDelegate(&cursorComponent);
+ edit->setCursorVisible(true);
// Don't include the size of a cursor delegate as it has its own bounding rect.
QCOMPARE(edit->boundingRect().x(), qreal(0));
diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
index e80808badf..5397b6ce9f 100644
--- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
+++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
@@ -1509,6 +1509,7 @@ void tst_qquicktextinput::clipRect()
cursorComponent.setData("import QtQuick 2.0\nRectangle { height: 20; width: 8 }", QUrl());
input->setCursorDelegate(&cursorComponent);
+ input->setCursorVisible(true);
// If a cursor delegate is used it's size should determine the excess width.
QCOMPARE(input->clipRect().x(), qreal(0));
@@ -1596,6 +1597,7 @@ void tst_qquicktextinput::boundingRect()
cursorComponent.setData("import QtQuick 2.0\nRectangle { height: 20; width: 8 }", QUrl());
input->setCursorDelegate(&cursorComponent);
+ input->setCursorVisible(true);
// Don't include the size of a cursor delegate as it has its own bounding rect.
QCOMPARE(input->boundingRect().x(), input->width() - line.naturalTextWidth());
@@ -2481,9 +2483,13 @@ void tst_qquicktextinput::cursorDelegate()
view.requestActivateWindow();
QQuickTextInput *textInputObject = view.rootObject()->findChild<QQuickTextInput*>("textInputObject");
QVERIFY(textInputObject != 0);
- QVERIFY(textInputObject->findChild<QQuickItem*>("cursorInstance"));
+ // Delegate is created on demand, and so won't be available immediately. Focus in or
+ // setCursorVisible(true) will trigger creation.
+ QTRY_VERIFY(!textInputObject->findChild<QQuickItem*>("cursorInstance"));
+ QVERIFY(!textInputObject->isCursorVisible());
//Test Delegate gets created
textInputObject->setFocus(true);
+ QVERIFY(textInputObject->isCursorVisible());
QQuickItem* delegateObject = textInputObject->findChild<QQuickItem*>("cursorInstance");
QVERIFY(delegateObject);
QCOMPARE(delegateObject->property("localProperty").toString(), QString("Hello"));
@@ -2497,7 +2503,6 @@ void tst_qquicktextinput::cursorDelegate()
QCOMPARE(textInputObject->cursorRectangle().x(), delegateObject->x());
QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y());
-
// Test delegate gets moved on mouse press.
textInputObject->setSelectByMouse(true);
textInputObject->setCursorPosition(0);