From 4fe568ffb7a59909b0c72bed7da959fd36702f19 Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Wed, 26 May 2010 12:42:36 +1000 Subject: Add a way to control when software input panels are shown in TextInput and TextEdit elements Task-number: QTBUG-10841 Reviewed-by: Warwick Allison --- .../tst_qdeclarativetextedit.cpp | 85 +++++++++++++++++---- .../tst_qdeclarativetextinput.cpp | 86 ++++++++++++++++++---- 2 files changed, 140 insertions(+), 31 deletions(-) (limited to 'tests') diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index b07849dc59..2b6f2aa1c3 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ #include +#include #include "../../../shared/util.h" #include "../shared/testhttpserver.h" #include @@ -811,7 +812,7 @@ QDeclarativeView *tst_qdeclarativetextedit::createView(const QString &filename) class MyInputContext : public QInputContext { public: - MyInputContext() : softwareInputPanelEventReceived(false) {} + MyInputContext() : openInputPanelReceived(false), closeInputPanelReceived(false) {} ~MyInputContext() {} QString identifierName() { return QString(); } @@ -824,10 +825,13 @@ public: bool filterEvent( const QEvent *event ) { if (event->type() == QEvent::RequestSoftwareInputPanel) - softwareInputPanelEventReceived = true; + openInputPanelReceived = true; + if (event->type() == QEvent::CloseSoftwareInputPanel) + closeInputPanelReceived = true; return QInputContext::filterEvent(event); } - bool softwareInputPanelEventReceived; + bool openInputPanelReceived; + bool closeInputPanelReceived; }; void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent() @@ -835,10 +839,9 @@ void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent() QGraphicsScene scene; QGraphicsView view(&scene); MyInputContext ic; - view.viewport()->setInputContext(&ic); - QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel( - view.style()->styleHint(QStyle::SH_RequestSoftwareInputPanel)); + view.setInputContext(&ic); QDeclarativeTextEdit edit; + QSignalSpy inputPanelonFocusSpy(&edit, SIGNAL(showInputPanelOnFocusChanged(bool))); edit.setText("Hello world"); edit.setPos(0, 0); scene.addItem(&edit); @@ -847,16 +850,68 @@ void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent() QApplication::setActiveWindow(&view); QTest::qWaitForWindowShown(&view); QTRY_COMPARE(QApplication::activeWindow(), static_cast(&view)); - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); + + QVERIFY(edit.showInputPanelOnFocus()); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, false); + + // focus on press, input panel on focus + QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); QApplication::processEvents(); - if (behavior == QStyle::RSIP_OnMouseClickAndAlreadyFocused) { - QCOMPARE(ic.softwareInputPanelEventReceived, false); - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); - QApplication::processEvents(); - QCOMPARE(ic.softwareInputPanelEventReceived, true); - } else if (behavior == QStyle::RSIP_OnMouseClick) { - QCOMPARE(ic.softwareInputPanelEventReceived, true); - } + QCOMPARE(ic.openInputPanelReceived, true); + QCOMPARE(ic.closeInputPanelReceived, false); + ic.openInputPanelReceived = false; + + // no events on release + QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, false); + ic.openInputPanelReceived = false; + + // input panel closed on focus lost + edit.setFocus(false); + QApplication::processEvents(); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, true); + ic.closeInputPanelReceived = false; + + // no input panel events if showInputPanelOnFocus is false + edit.setShowInputPanelOnFocus(false); + QCOMPARE(inputPanelonFocusSpy.count(),1); + QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); + QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); + edit.setFocus(false); + edit.setFocus(true); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, false); + + edit.setShowInputPanelOnFocus(false); + QCOMPARE(inputPanelonFocusSpy.count(),1); + + // one show input panel event when openSoftwareInputPanel is called + edit.openSoftwareInputPanel(); + QCOMPARE(ic.openInputPanelReceived, true); + QCOMPARE(ic.closeInputPanelReceived, false); + ic.openInputPanelReceived = false; + + // one close input panel event when closeSoftwareInputPanel is called + edit.closeSoftwareInputPanel(); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, true); + ic.openInputPanelReceived = false; + + // set showInputPanelOnFocus back to true + edit.setShowInputPanelOnFocus(true); + QCOMPARE(inputPanelonFocusSpy.count(),2); + edit.setFocus(false); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, true); + edit.setFocus(true); + QCOMPARE(ic.openInputPanelReceived, true); + QCOMPARE(ic.closeInputPanelReceived, true); + + edit.setShowInputPanelOnFocus(true); + QCOMPARE(inputPanelonFocusSpy.count(),2); } void tst_qdeclarativetextedit::geometrySignals() diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index ac80edb464..b3e16c49c7 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ #include +#include #include "../../../shared/util.h" #include #include @@ -712,11 +713,10 @@ QDeclarativeView *tst_qdeclarativetextinput::createView(const QString &filename) return canvas; } - class MyInputContext : public QInputContext { public: - MyInputContext() : softwareInputPanelEventReceived(false) {} + MyInputContext() : openInputPanelReceived(false), closeInputPanelReceived(false) {} ~MyInputContext() {} QString identifierName() { return QString(); } @@ -729,10 +729,13 @@ public: bool filterEvent( const QEvent *event ) { if (event->type() == QEvent::RequestSoftwareInputPanel) - softwareInputPanelEventReceived = true; + openInputPanelReceived = true; + if (event->type() == QEvent::CloseSoftwareInputPanel) + closeInputPanelReceived = true; return QInputContext::filterEvent(event); } - bool softwareInputPanelEventReceived; + bool openInputPanelReceived; + bool closeInputPanelReceived; }; void tst_qdeclarativetextinput::sendRequestSoftwareInputPanelEvent() @@ -740,10 +743,9 @@ void tst_qdeclarativetextinput::sendRequestSoftwareInputPanelEvent() QGraphicsScene scene; QGraphicsView view(&scene); MyInputContext ic; - view.viewport()->setInputContext(&ic); - QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel( - view.style()->styleHint(QStyle::SH_RequestSoftwareInputPanel)); + view.setInputContext(&ic); QDeclarativeTextInput input; + QSignalSpy inputPanelonFocusSpy(&input, SIGNAL(showInputPanelOnFocusChanged(bool))); input.setText("Hello world"); input.setPos(0, 0); scene.addItem(&input); @@ -752,16 +754,68 @@ void tst_qdeclarativetextinput::sendRequestSoftwareInputPanelEvent() QApplication::setActiveWindow(&view); QTest::qWaitForWindowShown(&view); QTRY_COMPARE(QApplication::activeWindow(), static_cast(&view)); - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); + + QVERIFY(input.showInputPanelOnFocus()); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, false); + + // focus on press, input panel on focus + QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); QApplication::processEvents(); - if (behavior == QStyle::RSIP_OnMouseClickAndAlreadyFocused) { - QCOMPARE(ic.softwareInputPanelEventReceived, false); - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); - QApplication::processEvents(); - QCOMPARE(ic.softwareInputPanelEventReceived, true); - } else if (behavior == QStyle::RSIP_OnMouseClick) { - QCOMPARE(ic.softwareInputPanelEventReceived, true); - } + QCOMPARE(ic.openInputPanelReceived, true); + QCOMPARE(ic.closeInputPanelReceived, false); + ic.openInputPanelReceived = false; + + // no events on release + QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, false); + ic.openInputPanelReceived = false; + + // input panel closed on focus lost + input.setFocus(false); + QApplication::processEvents(); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, true); + ic.closeInputPanelReceived = false; + + // no input panel events if showInputPanelOnFocus is false + input.setShowInputPanelOnFocus(false); + QCOMPARE(inputPanelonFocusSpy.count(),1); + QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); + QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); + input.setFocus(false); + input.setFocus(true); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, false); + + input.setShowInputPanelOnFocus(false); + QCOMPARE(inputPanelonFocusSpy.count(),1); + + // one show input panel event when openSoftwareInputPanel is called + input.openSoftwareInputPanel(); + QCOMPARE(ic.openInputPanelReceived, true); + QCOMPARE(ic.closeInputPanelReceived, false); + ic.openInputPanelReceived = false; + + // one close input panel event when closeSoftwareInputPanel is called + input.closeSoftwareInputPanel(); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, true); + ic.openInputPanelReceived = false; + + // set showInputPanelOnFocus back to true + input.setShowInputPanelOnFocus(true); + QCOMPARE(inputPanelonFocusSpy.count(),2); + input.setFocus(false); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, true); + input.setFocus(true); + QCOMPARE(ic.openInputPanelReceived, true); + QCOMPARE(ic.closeInputPanelReceived, true); + + input.setShowInputPanelOnFocus(true); + QCOMPARE(inputPanelonFocusSpy.count(),2); } class MyTextInput : public QDeclarativeTextInput -- cgit v1.2.3 From e9a25332df933227c6b71a1654260d8421f56415 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 26 May 2010 15:15:45 +1000 Subject: Fix TextEdit clipping when not wrapped. Rename most-useful-wrap-mode to "Wrap". --- tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext.qml | 2 +- tests/auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml | 2 +- tests/auto/declarative/qmlvisual/qdeclarativetextedit/wrap.qml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext.qml b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext.qml index d948e4a494..73dd4d7844 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext.qml @@ -85,7 +85,7 @@ Rectangle { text: s.text + " thisisaverylongstringwithnospaces"; width: 150; wrapMode: Text.WrapAnywhere } Text { - text: s.text + " thisisaverylongstringwithnospaces"; width: 150; wrapMode: Text.WrapAtWordBoundaryOrAnywhere + text: s.text + " thisisaverylongstringwithnospaces"; width: 150; wrapMode: Text.Wrap } } } diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml index d10cfd3d1b..b41b93a31a 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml @@ -85,7 +85,7 @@ Rectangle { text: s.text + " thisisaverylongstringwithnospaces"; width: 150; wrapMode: Text.WrapAnywhere } Text { - text: s.text + " thisisaverylongstringwithnospaces"; width: 150; wrapMode: Text.WrapAtWordBoundaryOrAnywhere + text: s.text + " thisisaverylongstringwithnospaces"; width: 150; wrapMode: Text.Wrap } } } diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetextedit/wrap.qml b/tests/auto/declarative/qmlvisual/qdeclarativetextedit/wrap.qml index abb446423c..a1dc5bf17f 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativetextedit/wrap.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativetextedit/wrap.qml @@ -27,7 +27,7 @@ Item { TextEdit { width: 150 height: 100 - wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere + wrapMode: TextEdit.Wrap text: "This is a test that text edit wraps correctly. thisisaverylongstringwithnospaces" y:300 } -- cgit v1.2.3 From ef2bc487ab9b66e052920b671e947abc4a6d8ef4 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 26 May 2010 14:28:23 +1000 Subject: Fix horizontal/verticalCenter anchors bug. Task-number: QTBUG-10999 Reviewed-by: Michael Brasser --- .../auto/declarative/qdeclarativeanchors/data/hvCenter.qml | 11 +++++++++++ .../qdeclarativeanchors/tst_qdeclarativeanchors.cpp | 14 ++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativeanchors/data/hvCenter.qml (limited to 'tests') diff --git a/tests/auto/declarative/qdeclarativeanchors/data/hvCenter.qml b/tests/auto/declarative/qdeclarativeanchors/data/hvCenter.qml new file mode 100644 index 0000000000..7cd4f264f6 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeanchors/data/hvCenter.qml @@ -0,0 +1,11 @@ +import Qt 4.7 + +Rectangle { + width: 77; height: 95 + Rectangle { + objectName: "centered" + width: 57; height: 57; color: "blue" + anchors.verticalCenter: parent.verticalCenter + anchors.horizontalCenter: parent.horizontalCenter + } +} diff --git a/tests/auto/declarative/qdeclarativeanchors/tst_qdeclarativeanchors.cpp b/tests/auto/declarative/qdeclarativeanchors/tst_qdeclarativeanchors.cpp index e169fa2116..22f7966cf7 100644 --- a/tests/auto/declarative/qdeclarativeanchors/tst_qdeclarativeanchors.cpp +++ b/tests/auto/declarative/qdeclarativeanchors/tst_qdeclarativeanchors.cpp @@ -77,6 +77,7 @@ private slots: void nullItem_data(); void crash1(); void centerIn(); + void hvCenter(); void fill(); void margins(); }; @@ -526,6 +527,19 @@ void tst_qdeclarativeanchors::centerIn() delete view; } +void tst_qdeclarativeanchors::hvCenter() +{ + QDeclarativeView *view = new QDeclarativeView(QUrl::fromLocalFile(SRCDIR "/data/hvCenter.qml")); + + qApp->processEvents(); + QDeclarativeRectangle* rect = findItem(view->rootObject(), QLatin1String("centered")); + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); + // test QTBUG-10999 + QCOMPARE(rect->x(), 10.0); + QCOMPARE(rect->y(), 19.0); + delete view; +} + void tst_qdeclarativeanchors::margins() { QDeclarativeView *view = new QDeclarativeView(QUrl::fromLocalFile(SRCDIR "/data/margins.qml")); -- cgit v1.2.3 From 1256a212460438462367b48de086ab690f722be5 Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Wed, 26 May 2010 16:26:19 +1000 Subject: Open input panel on press if TextInput or TextEdit are already focused but panel has been closed Task-number: Reviewed-by: Martin Jones --- .../qdeclarativetextedit/tst_qdeclarativetextedit.cpp | 9 +++++++++ .../qdeclarativetextinput/tst_qdeclarativetextinput.cpp | 9 +++++++++ 2 files changed, 18 insertions(+) (limited to 'tests') diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index 2b6f2aa1c3..0df28d02e8 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -858,6 +858,7 @@ void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent() // focus on press, input panel on focus QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); QApplication::processEvents(); + QVERIFY(edit.hasFocus()); QCOMPARE(ic.openInputPanelReceived, true); QCOMPARE(ic.closeInputPanelReceived, false); ic.openInputPanelReceived = false; @@ -868,6 +869,14 @@ void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent() QCOMPARE(ic.closeInputPanelReceived, false); ic.openInputPanelReceived = false; + // Even with focus already gained, user needs + // to be able to open panel by pressing on the editor + QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); + QApplication::processEvents(); + QCOMPARE(ic.openInputPanelReceived, true); + QCOMPARE(ic.closeInputPanelReceived, false); + ic.openInputPanelReceived = false; + // input panel closed on focus lost edit.setFocus(false); QApplication::processEvents(); diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index b3e16c49c7..155223d9a7 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -762,6 +762,7 @@ void tst_qdeclarativetextinput::sendRequestSoftwareInputPanelEvent() // focus on press, input panel on focus QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); QApplication::processEvents(); + QVERIFY(input.hasFocus()); QCOMPARE(ic.openInputPanelReceived, true); QCOMPARE(ic.closeInputPanelReceived, false); ic.openInputPanelReceived = false; @@ -772,6 +773,14 @@ void tst_qdeclarativetextinput::sendRequestSoftwareInputPanelEvent() QCOMPARE(ic.closeInputPanelReceived, false); ic.openInputPanelReceived = false; + // Even with focus already gained, user needs + // to be able to open panel by pressing on the editor + QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); + QApplication::processEvents(); + QCOMPARE(ic.openInputPanelReceived, true); + QCOMPARE(ic.closeInputPanelReceived, false); + ic.openInputPanelReceived = false; + // input panel closed on focus lost input.setFocus(false); QApplication::processEvents(); -- cgit v1.2.3 From dc9602f6bb805751beb3b7963398679d12753e53 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Wed, 26 May 2010 14:47:11 +1000 Subject: Allow js files with '.pragma library' to be used from WorkerScript --- .../qdeclarativeworkerscript/data/BaseWorker.qml | 24 ++++++++++++ .../qdeclarativeworkerscript/data/script.js | 1 - .../data/script_fixed_return.js | 4 ++ .../qdeclarativeworkerscript/data/script_pragma.js | 6 +++ .../qdeclarativeworkerscript/data/worker.qml | 21 +---------- .../data/worker_pragma.qml | 6 +++ .../tst_qdeclarativeworkerscript.cpp | 43 ++++++++++++++++++---- 7 files changed, 76 insertions(+), 29 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeworkerscript/data/BaseWorker.qml create mode 100644 tests/auto/declarative/qdeclarativeworkerscript/data/script_fixed_return.js create mode 100644 tests/auto/declarative/qdeclarativeworkerscript/data/script_pragma.js create mode 100644 tests/auto/declarative/qdeclarativeworkerscript/data/worker_pragma.qml (limited to 'tests') diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/BaseWorker.qml b/tests/auto/declarative/qdeclarativeworkerscript/data/BaseWorker.qml new file mode 100644 index 0000000000..d275ca8511 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeworkerscript/data/BaseWorker.qml @@ -0,0 +1,24 @@ +import Qt 4.7 + +WorkerScript { + id: worker + + property variant response + + signal done() + + function testSend(value) { + worker.sendMessage(value) + } + + function compareLiteralResponse(expected) { + var e = eval('(' + expected + ')') + return worker.response == e + } + + onMessage: { + worker.response = messageObject + worker.done() + } +} + diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/script.js b/tests/auto/declarative/qdeclarativeworkerscript/data/script.js index 09199de9be..90aae263a1 100644 --- a/tests/auto/declarative/qdeclarativeworkerscript/data/script.js +++ b/tests/auto/declarative/qdeclarativeworkerscript/data/script.js @@ -2,4 +2,3 @@ WorkerScript.onMessage = function(msg) { WorkerScript.sendMessage(msg) } - diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/script_fixed_return.js b/tests/auto/declarative/qdeclarativeworkerscript/data/script_fixed_return.js new file mode 100644 index 0000000000..14f6f178ae --- /dev/null +++ b/tests/auto/declarative/qdeclarativeworkerscript/data/script_fixed_return.js @@ -0,0 +1,4 @@ +WorkerScript.onMessage = function(msg) { + WorkerScript.sendMessage('Hello_World') +} + diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/script_pragma.js b/tests/auto/declarative/qdeclarativeworkerscript/data/script_pragma.js new file mode 100644 index 0000000000..cb3b6d3398 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeworkerscript/data/script_pragma.js @@ -0,0 +1,6 @@ +.pragma library + +WorkerScript.onMessage = function(msg) { + WorkerScript.sendMessage(msg) +} + diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml b/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml index 5c7a5ff26e..1a20098ef7 100644 --- a/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml +++ b/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml @@ -1,24 +1,5 @@ import Qt 4.7 -WorkerScript { - id: worker +BaseWorker { source: "script.js" - - property variant response - - signal done() - - function testSend(value) { - worker.sendMessage(value) - } - - function compareLiteralResponse(expected) { - var e = eval('(' + expected + ')') - return worker.response == e - } - - onMessage: { - worker.response = messageObject - worker.done() - } } diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/worker_pragma.qml b/tests/auto/declarative/qdeclarativeworkerscript/data/worker_pragma.qml new file mode 100644 index 0000000000..3b720ef473 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeworkerscript/data/worker_pragma.qml @@ -0,0 +1,6 @@ +import Qt 4.7 + +BaseWorker { + source: "script_pragma.js" +} + diff --git a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp index a1dae24770..7a4315a050 100644 --- a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp +++ b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp @@ -64,6 +64,7 @@ private slots: void messaging_data(); void messaging_sendQObjectList(); void messaging_sendJsObject(); + void script_with_pragma(); private: void waitForEchoMessage(QDeclarativeWorkerScript *worker) { @@ -82,18 +83,25 @@ private: void tst_QDeclarativeWorkerScript::source() { - QUrl source = QUrl::fromLocalFile(SRCDIR "/data/worker.qml"); - - QDeclarativeComponent component(&m_engine); - component.setData("import Qt 4.7\nWorkerScript { source: '" + source.toString().toUtf8() + "'; }", QUrl()); + QDeclarativeComponent component(&m_engine, SRCDIR "/data/worker.qml"); + QDeclarativeWorkerScript *worker = qobject_cast(component.create()); + QVERIFY(worker != 0); + const QMetaObject *mo = worker->metaObject(); - QDeclarativeWorkerScript *item = qobject_cast(component.create()); - QVERIFY(item != 0); + QVariant value(100); + QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value))); + waitForEchoMessage(worker); + QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker).value(), value); - QCOMPARE(item->source(), source); + QUrl source = QUrl::fromLocalFile(SRCDIR "/data/script_fixed_return.js"); + worker->setSource(source); + QCOMPARE(worker->source(), source); + QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value))); + waitForEchoMessage(worker); + QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker).value(), qVariantFromValue(QString("Hello_World"))); qApp->processEvents(); - delete item; + delete worker; } void tst_QDeclarativeWorkerScript::messaging() @@ -177,6 +185,25 @@ void tst_QDeclarativeWorkerScript::messaging_sendJsObject() delete worker; } +void tst_QDeclarativeWorkerScript::script_with_pragma() +{ + QVariant value(100); + + QDeclarativeComponent component(&m_engine, SRCDIR "/data/worker_pragma.qml"); + QDeclarativeWorkerScript *worker = qobject_cast(component.create()); + QVERIFY(worker != 0); + + QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value))); + waitForEchoMessage(worker); + + const QMetaObject *mo = worker->metaObject(); + QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker).value(), value); + + qApp->processEvents(); + delete worker; +} + + QTEST_MAIN(tst_QDeclarativeWorkerScript) #include "tst_qdeclarativeworkerscript.moc" -- cgit v1.2.3 From e0dc3b88abc9c4bcd6c3710c458c4948e5b8a912 Mon Sep 17 00:00:00 2001 From: Jakub Wieczorek Date: Wed, 26 May 2010 11:50:57 +0200 Subject: QXmlStreamWriter: Auto-formatting does not behave properly with processing instructions. When writing a processing instruction with auto-formatting enabled, it should put it in a new line for readability and apply the indentation properly. Merge-request: 620 Reviewed-by: Olivier Goffart --- tests/auto/qxmlstream/tst_qxmlstream.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests') diff --git a/tests/auto/qxmlstream/tst_qxmlstream.cpp b/tests/auto/qxmlstream/tst_qxmlstream.cpp index 3c5358c36c..f93d4fc6d1 100644 --- a/tests/auto/qxmlstream/tst_qxmlstream.cpp +++ b/tests/auto/qxmlstream/tst_qxmlstream.cpp @@ -546,6 +546,7 @@ private slots: void writerHangs() const; void writerAutoFormattingWithComments() const; void writerAutoFormattingWithTabs() const; + void writerAutoFormattingWithProcessingInstructions() const; void writerAutoEmptyTags() const; void writeAttributesWithSpace() const; void addExtraNamespaceDeclarations(); @@ -1030,6 +1031,22 @@ void tst_QXmlStream::writerAutoFormattingWithTabs() const QCOMPARE(buffer.buffer().data(), str); } +void tst_QXmlStream::writerAutoFormattingWithProcessingInstructions() const +{ + QBuffer buffer; + buffer.open(QIODevice::WriteOnly); + + QXmlStreamWriter writer(&buffer); + writer.setAutoFormatting(true); + writer.writeStartDocument(); + writer.writeProcessingInstruction("B", "C"); + writer.writeStartElement("A"); + writer.writeEndElement(); + writer.writeEndDocument(); + const char *str = "\n\n\n"; + QCOMPARE(buffer.buffer().data(), str); +} + /*! Task 204822 */ -- cgit v1.2.3 From 2eedb392048fdebbb29615345ea3716cebabd451 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 26 May 2010 11:59:48 +0200 Subject: tst_qxmlstream: fix in shadowbuild --- tests/auto/qxmlstream/qxmlstream.pro | 5 ++++- tests/auto/qxmlstream/tst_qxmlstream.cpp | 9 ++++----- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/auto/qxmlstream/qxmlstream.pro b/tests/auto/qxmlstream/qxmlstream.pro index ac03d421d1..f82a7b3dba 100644 --- a/tests/auto/qxmlstream/qxmlstream.pro +++ b/tests/auto/qxmlstream/qxmlstream.pro @@ -1,5 +1,5 @@ load(qttest_p4) -SOURCES += tst_qxmlstream.cpp +SOURCES += tst_qxmlstream.cpp QT = core xml network @@ -8,4 +8,7 @@ wince*|symbian*: { addFiles.sources = data XML-Test-Suite addFiles.path = . DEPLOYMENT += addFiles + DEFINES += SRCDIR=\\\"\\\" +} else { + DEFINES += SRCDIR=\\\"$$PWD/\\\" } diff --git a/tests/auto/qxmlstream/tst_qxmlstream.cpp b/tests/auto/qxmlstream/tst_qxmlstream.cpp index f93d4fc6d1..7d5e3b7f8c 100644 --- a/tests/auto/qxmlstream/tst_qxmlstream.cpp +++ b/tests/auto/qxmlstream/tst_qxmlstream.cpp @@ -57,7 +57,7 @@ Q_DECLARE_METATYPE(QXmlStreamReader::ReadElementTextBehaviour) -static const char *const catalogFile = "XML-Test-Suite/xmlconf/finalCatalog.xml"; +static const char *const catalogFile = SRCDIR "XML-Test-Suite/xmlconf/finalCatalog.xml"; static const int expectedRunCount = 1646; static const int expectedSkipCount = 532; @@ -527,8 +527,7 @@ class tst_QXmlStream: public QObject { Q_OBJECT public: - tst_QXmlStream() : m_handler(QUrl::fromLocalFile(QDir::currentPath() + QLatin1Char('/')) - .resolved(QUrl(QLatin1String(catalogFile)))) + tst_QXmlStream() : m_handler(QUrl::fromLocalFile(QLatin1String(catalogFile))) { } @@ -806,7 +805,7 @@ void tst_QXmlStream::testReader_data() const QTest::addColumn("xml"); QTest::addColumn("ref"); QDir dir; - dir.cd("data/"); + dir.cd(SRCDIR "data/"); foreach(QString filename , dir.entryList(QStringList() << "*.xml")) { QString reference = QFileInfo(filename).baseName() + ".ref"; QTest::newRow(dir.filePath(filename).toLatin1().data()) << dir.filePath(filename) << dir.filePath(reference); @@ -1201,7 +1200,7 @@ void tst_QXmlStream::crashInUTF16Codec() const QEventLoop eventLoop; QNetworkAccessManager networkManager; - QNetworkRequest request(QUrl::fromLocalFile(QLatin1String("data/051reduced.xml"))); + QNetworkRequest request(QUrl::fromLocalFile(QLatin1String(SRCDIR "data/051reduced.xml"))); QNetworkReply *const reply = networkManager.get(request); eventLoop.connect(reply, SIGNAL(finished()), SLOT(quit())); -- cgit v1.2.3 From cf1e3150247d6694e8c00b924627c66e798f2382 Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Tue, 6 Apr 2010 19:59:08 +0200 Subject: Fixes a proxymodel sorting odity. Sort order was modified when sorted according to an empty column always in the same order Reviewed-by: Thierry --- .../tst_qsortfilterproxymodel.cpp | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'tests') diff --git a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index 992c95e4c0..53fefeedc8 100644 --- a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -127,6 +127,8 @@ private slots: void sortColumnTracking1(); void sortColumnTracking2(); + void sortStable(); + void task236755_hiddenColumns(); void task247867_insertRowsSort(); void task248868_staticSorting(); @@ -2442,6 +2444,40 @@ void tst_QSortFilterProxyModel::sortColumnTracking2() QCOMPARE(proxyModel.data(proxyModel.index(strings.count()-1,0)).toString(),QString::fromLatin1("zz")); } +void tst_QSortFilterProxyModel::sortStable() +{ + QStandardItemModel* model = new QStandardItemModel(5, 2); + for (int r=0; r<5; r++) { + for (int c=0; c<2; c++) { + QStandardItem* item = new QStandardItem( + QString("Row:%0, Column:%1").arg(r).arg(c) ); + for( int i=0; i<3; i++ ) { + QStandardItem* child = new QStandardItem( + QString("Item %0").arg(i) ); + item->appendRow( child ); + } + model->setItem(r, c, item); + } + } + model->setHorizontalHeaderItem( 0, new QStandardItem( "Name" )); + model->setHorizontalHeaderItem( 1, new QStandardItem( "Value" ) ); + + + QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(model); + filterModel->setSourceModel(model); + + QTreeView *view = new QTreeView; + view->setModel(filterModel); + QModelIndex firstRoot = filterModel->index(0,0); + view->expand(firstRoot); + view->setSortingEnabled(true); + + view->model()->sort(1, Qt::DescendingOrder); + QVariant lastItemData =filterModel->index(2,0, firstRoot).data(); + view->model()->sort(1, Qt::DescendingOrder); + QCOMPARE(lastItemData, filterModel->index(2,0, firstRoot).data()); +} + void tst_QSortFilterProxyModel::task236755_hiddenColumns() { class MyStandardItemModel : public QStandardItemModel -- cgit v1.2.3 From 11a8c52498e8dc74fdfef48e953055338c8f18d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Wed, 26 May 2010 15:53:06 +0200 Subject: Redraw issues when removing a fully transparent QGraphicsItem from the scene. This only happened with fully transparent ancestors (item's effectiveOpacity() == 0.0). Problem was that we didn't take into account the ancestors' opacity when removing an item from the scene. More specifically: The calculated effective opacity for the item was zero and we ignored update requests. We have to ignore the opacity if any of the ancestors' ignoreOpacity bit is 1, which means the opacity is set to 0 and the update request has not yet been processed. Auto test included. Task-number: QTBUG-10778 --- tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'tests') diff --git a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp index a15522263c..67a41ca81a 100644 --- a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp @@ -275,6 +275,7 @@ private slots: void polishItems2(); void isActive(); void siblingIndexAlwaysValid(); + void removeFullyTransparentItem(); // task specific tests below me void task139710_bspTreeCrash(); @@ -4333,6 +4334,48 @@ void tst_QGraphicsScene::siblingIndexAlwaysValid() } +void tst_QGraphicsScene::removeFullyTransparentItem() +{ + QGraphicsScene scene; + + QGraphicsItem *parent = scene.addRect(0, 0, 100, 100); + parent->setFlag(QGraphicsItem::ItemHasNoContents); + + QGraphicsItem *child = scene.addRect(0, 0, 100, 100); + child->setParentItem(parent); + + CustomView view; + view.setScene(&scene); + view.show(); + QTest::qWaitForWindowShown(&view); + + // NB! The parent has the ItemHasNoContents flag set, which means + // the parent itself doesn't generate any update requests, only the + // child can possibly trigger an update. Also note that the child + // is removed before processing events. + view.repaints = 0; + parent->setOpacity(0); + QVERIFY(qFuzzyIsNull(child->effectiveOpacity())); + scene.removeItem(child); + QVERIFY(!scene.items().contains(child)); + QTRY_VERIFY(view.repaints > 0); + + // Re-add child. There's nothing new to display (child is still + // effectively hidden), so it shouldn't trigger an update. + view.repaints = 0; + child->setParentItem(parent); + QVERIFY(scene.items().contains(child)); + QVERIFY(qFuzzyIsNull(child->effectiveOpacity())); + QApplication::processEvents(); + QCOMPARE(view.repaints, 0); + + // Nothing is visible on the screen, removing child item shouldn't trigger an update. + scene.removeItem(child); + QApplication::processEvents(); + QCOMPARE(view.repaints, 0); + delete child; +} + void tst_QGraphicsScene::taskQTBUG_5904_crashWithDeviceCoordinateCache() { QGraphicsScene scene; -- cgit v1.2.3