diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2012-05-04 16:07:32 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-14 00:51:15 +0200 |
commit | bd5e23a00e97603c1cc73328c508a044f1528802 (patch) | |
tree | 8ffe4145ec6d62c5d9e0798af9d48c29d66ff176 /tests/auto/quick/qquicktextinput | |
parent | 6f9b3893c8c7bc0b6663acb34c17c120852ef7b7 (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/auto/quick/qquicktextinput')
-rw-r--r-- | tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
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); |