summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/compilerwarnings/tst_compilerwarnings.cpp1
-rw-r--r--tests/auto/networkselftest/.gitattributes1
-rw-r--r--tests/auto/q3table/tst_q3table.cpp2
-rw-r--r--tests/auto/qaudioinput/tst_qaudioinput.cpp3
-rw-r--r--tests/auto/qaudiooutput/tst_qaudiooutput.cpp3
-rw-r--r--tests/auto/qbuttongroup/tst_qbuttongroup.cpp3
-rw-r--r--tests/auto/qdom/tst_qdom.cpp3
-rw-r--r--tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp5
-rw-r--r--tests/auto/qgl/tst_qgl.cpp150
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp1028
-rw-r--r--tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp19
-rw-r--r--tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp198
-rw-r--r--tests/auto/qgraphicsview/tst_qgraphicsview.cpp4
-rw-r--r--tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp2
-rw-r--r--tests/auto/qgridlayout/tst_qgridlayout.cpp3
-rw-r--r--tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp59
-rw-r--r--tests/auto/qicon/image.tgabin51708 -> 0 bytes
-rw-r--r--tests/auto/qicon/qicon.pro4
-rw-r--r--tests/auto/qicon/tst_qicon.cpp2
-rw-r--r--tests/auto/qitemdelegate/tst_qitemdelegate.cpp2
-rw-r--r--tests/auto/qmdiarea/tst_qmdiarea.cpp1
-rw-r--r--tests/auto/qmdisubwindow/tst_qmdisubwindow.cpp1
-rw-r--r--tests/auto/qmessagebox/tst_qmessagebox.cpp3
-rw-r--r--tests/auto/qpixmap/qpixmap.pro15
-rw-r--r--tests/auto/qpixmap/tst_qpixmap.cpp38
-rw-r--r--tests/auto/qprinterinfo/tst_qprinterinfo.cpp21
-rw-r--r--tests/auto/qscriptengine/tst_qscriptengine.cpp33
-rw-r--r--tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp9
-rw-r--r--tests/auto/qscriptjstestsuite/tst_qscriptjstestsuite.cpp2
-rw-r--r--tests/auto/qstatusbar/tst_qstatusbar.cpp9
-rw-r--r--tests/auto/qtableview/tst_qtableview.cpp9
-rw-r--r--tests/auto/qtreeview/tst_qtreeview.cpp4
-rw-r--r--tests/auto/qwidget/qwidget.pro4
-rw-r--r--tests/auto/qwidget/tst_qwidget.cpp166
-rw-r--r--tests/auto/qwindowsurface/tst_qwindowsurface.cpp34
35 files changed, 1609 insertions, 232 deletions
diff --git a/tests/auto/compilerwarnings/tst_compilerwarnings.cpp b/tests/auto/compilerwarnings/tst_compilerwarnings.cpp
index 907aade..0be5cb0 100644
--- a/tests/auto/compilerwarnings/tst_compilerwarnings.cpp
+++ b/tests/auto/compilerwarnings/tst_compilerwarnings.cpp
@@ -179,7 +179,6 @@ void tst_CompilerWarnings::warnings()
<< "-Wno-long-long" << "-Wshadow" << "-Wpacked" << "-Wunreachable-code"
<< "-Wundef" << "-Wchar-subscripts" << "-Wformat-nonliteral" << "-Wformat-security"
<< "-Wcast-align"
- << "-Wfloat-equal"
<< "-o" << tmpFile
<< tmpSourceFile;
#elif defined(Q_CC_XLC)
diff --git a/tests/auto/networkselftest/.gitattributes b/tests/auto/networkselftest/.gitattributes
new file mode 100644
index 0000000..e04709a
--- /dev/null
+++ b/tests/auto/networkselftest/.gitattributes
@@ -0,0 +1 @@
+rfc3252.txt -crlf
diff --git a/tests/auto/q3table/tst_q3table.cpp b/tests/auto/q3table/tst_q3table.cpp
index 770bf4d..bffb118 100644
--- a/tests/auto/q3table/tst_q3table.cpp
+++ b/tests/auto/q3table/tst_q3table.cpp
@@ -1200,7 +1200,7 @@ protected:
void tst_Q3Table::editCheck()
{
// Test for task 28086
-#if 0
+#if 1
QSKIP("This test currently fails on all versions", SkipAll);
#endif
diff --git a/tests/auto/qaudioinput/tst_qaudioinput.cpp b/tests/auto/qaudioinput/tst_qaudioinput.cpp
index 69b507d..3945364 100644
--- a/tests/auto/qaudioinput/tst_qaudioinput.cpp
+++ b/tests/auto/qaudioinput/tst_qaudioinput.cpp
@@ -139,12 +139,14 @@ void tst_QAudioInput::pullFile()
// Always have default states, before start
QVERIFY(audio->state() == QAudio::StopState);
QVERIFY(audio->error() == QAudio::NoError);
+ QVERIFY(audio->clock() == 0);
audio->start(&filename);
QTest::qWait(20);
// Check state and periodSize() are valid non-zero values.
QVERIFY(audio->state() == QAudio::ActiveState);
QVERIFY(audio->error() == QAudio::NoError);
+ QVERIFY(audio->clock() > 0);
QVERIFY(audio->periodSize() > 0);
QVERIFY(stateSignal.count() == 1); // State changed to QAudio::ActiveState
@@ -157,6 +159,7 @@ void tst_QAudioInput::pullFile()
audio->stop();
QTest::qWait(20);
QVERIFY(audio->state() == QAudio::StopState);
+ QVERIFY(audio->clock() == 0);
// Can only check to make sure we got at least 1 more signal, but can be more.
QVERIFY(stateSignal.count() > 1);
diff --git a/tests/auto/qaudiooutput/tst_qaudiooutput.cpp b/tests/auto/qaudiooutput/tst_qaudiooutput.cpp
index f1c75dc..b90873e 100644
--- a/tests/auto/qaudiooutput/tst_qaudiooutput.cpp
+++ b/tests/auto/qaudiooutput/tst_qaudiooutput.cpp
@@ -142,6 +142,7 @@ void tst_QAudioOutput::pullFile()
// Always have default states, before start
QVERIFY(audio->state() == QAudio::StopState);
QVERIFY(audio->error() == QAudio::NoError);
+ QVERIFY(audio->clock() == 0);
audio->start(&file);
QTest::qWait(20); // wait 20ms
@@ -149,6 +150,7 @@ void tst_QAudioOutput::pullFile()
QVERIFY(audio->state() == QAudio::ActiveState);
QVERIFY(audio->error() == QAudio::NoError);
QVERIFY(audio->periodSize() > 0);
+ QVERIFY(audio->clock() > 0);
QVERIFY(stateSignal.count() == 1); // State changed to QAudio::ActiveState
// Wait until finished...
@@ -160,6 +162,7 @@ void tst_QAudioOutput::pullFile()
audio->stop();
QTest::qWait(20); // wait 20ms
QVERIFY(audio->state() == QAudio::StopState);
+ QVERIFY(audio->clock() == 0);
// Can only check to make sure we got at least 1 more signal, but can be more.
QVERIFY(stateSignal.count() > 1);
diff --git a/tests/auto/qbuttongroup/tst_qbuttongroup.cpp b/tests/auto/qbuttongroup/tst_qbuttongroup.cpp
index 502c2d1..11c1f47 100644
--- a/tests/auto/qbuttongroup/tst_qbuttongroup.cpp
+++ b/tests/auto/qbuttongroup/tst_qbuttongroup.cpp
@@ -173,10 +173,11 @@ void tst_QButtonGroup::arrowKeyNavigation()
dlg.show();
qApp->setActiveWindow(&dlg);
+ QTest::qWaitForWindowShown(&dlg);
bt1.setFocus();
- QVERIFY(bt1.hasFocus());
+ QTRY_VERIFY(bt1.hasFocus());
QTest::keyClick(&bt1, Qt::Key_Right);
QVERIFY(pb.hasFocus());
diff --git a/tests/auto/qdom/tst_qdom.cpp b/tests/auto/qdom/tst_qdom.cpp
index 6987186..6637202 100644
--- a/tests/auto/qdom/tst_qdom.cpp
+++ b/tests/auto/qdom/tst_qdom.cpp
@@ -1908,8 +1908,7 @@ void tst_QDom::taskQTBUG4595_dontAssertWhenDocumentSpecifiesUnknownEncoding() co
QDomDocument d;
QVERIFY(d.setContent(xmlWithUnknownEncoding));
- //QString dontAssert = d.toString(); // this should not assert
- QVERIFY2(false, "Line above crashes but we still want to run all tests.");
+ QString dontAssert = d.toString(); // this should not assert
QVERIFY(true);
}
diff --git a/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp
index ea9304d..2cc2558 100644
--- a/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp
+++ b/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp
@@ -806,7 +806,10 @@ void tst_QFileSystemModel::sort()
QDir dir(QDir::tempPath());
dir.mkdir("sortTemp");
dir.cd("sortTemp");
- QDirIterator it(dir);
+ QTRY_VERIFY(dir.exists());
+
+ //To be sure we clean the dir if it was there before
+ QDirIterator it(dir.absolutePath(), QDir::NoDotAndDotDot);
while(it.hasNext())
{
it.next();
diff --git a/tests/auto/qgl/tst_qgl.cpp b/tests/auto/qgl/tst_qgl.cpp
index 999d119..f15b249 100644
--- a/tests/auto/qgl/tst_qgl.cpp
+++ b/tests/auto/qgl/tst_qgl.cpp
@@ -54,6 +54,10 @@
#include <QGraphicsProxyWidget>
#include <QVBoxLayout>
+#ifdef QT_BUILD_INTERNAL
+#include <QtOpenGL/private/qgl_p.h>
+#endif
+
//TESTED_CLASS=
//TESTED_FILES=
@@ -84,6 +88,8 @@ private slots:
void testDontCrashOnDanglingResources();
void replaceClipping();
void clipTest();
+ void destroyFBOAfterContext();
+ void shareRegister();
};
tst_QGL::tst_QGL()
@@ -1720,6 +1726,150 @@ void tst_QGL::clipTest()
QCOMPARE(widgetFB, reference);
}
+void tst_QGL::destroyFBOAfterContext()
+{
+ if (!QGLFramebufferObject::hasOpenGLFramebufferObjects())
+ QSKIP("QGLFramebufferObject not supported on this platform", SkipSingle);
+
+ QGLWidget *glw = new QGLWidget();
+ glw->makeCurrent();
+
+ // No multisample with combined depth/stencil attachment:
+ QGLFramebufferObjectFormat fboFormat;
+ fboFormat.setAttachment(QGLFramebufferObject::CombinedDepthStencil);
+
+ // Don't complicate things by using NPOT:
+ QGLFramebufferObject *fbo = new QGLFramebufferObject(256, 128, fboFormat);
+
+ // The handle should be valid until the context is destroyed.
+ QVERIFY(fbo->handle() != 0);
+ QVERIFY(fbo->isValid());
+
+ delete glw;
+
+ // The handle should now be zero.
+ QVERIFY(fbo->handle() == 0);
+ QVERIFY(!fbo->isValid());
+
+ delete fbo;
+}
+
+void tst_QGL::shareRegister()
+{
+#ifdef QT_BUILD_INTERNAL
+ QGLShareRegister *shareReg = qgl_share_reg();
+ QVERIFY(shareReg != 0);
+
+ // Create a context.
+ QGLWidget *glw1 = new QGLWidget();
+ glw1->makeCurrent();
+
+ // Nothing should be sharing with glw1's context yet.
+ QList<const QGLContext *> list;
+ list = shareReg->shares(glw1->context());
+ QCOMPARE(list.size(), 0);
+
+ // Create a guard for the first context.
+ QGLSharedResourceGuard guard(glw1->context());
+ QVERIFY(guard.id() == 0);
+ guard.setId(3);
+ QVERIFY(guard.id() == 3);
+
+ // Create another context that shares with the first.
+ QGLWidget *glw2 = new QGLWidget(0, glw1);
+ if (!glw2->isSharing()) {
+ delete glw2;
+ delete glw1;
+ QSKIP("Context sharing is not supported", SkipSingle);
+ }
+ QVERIFY(glw1->context() != glw2->context());
+
+ // Guard should still be the same.
+ QVERIFY(guard.context() == glw1->context());
+ QVERIFY(guard.id() == 3);
+
+ // Now there are two items in the share lists.
+ list = shareReg->shares(glw1->context());
+ QCOMPARE(list.size(), 2);
+ QVERIFY(list.contains(glw1->context()));
+ QVERIFY(list.contains(glw2->context()));
+ list = shareReg->shares(glw2->context());
+ QCOMPARE(list.size(), 2);
+ QVERIFY(list.contains(glw1->context()));
+ QVERIFY(list.contains(glw2->context()));
+
+ // Check the sharing relationships.
+ QVERIFY(QGLContext::areSharing(glw1->context(), glw1->context()));
+ QVERIFY(QGLContext::areSharing(glw2->context(), glw2->context()));
+ QVERIFY(QGLContext::areSharing(glw1->context(), glw2->context()));
+ QVERIFY(QGLContext::areSharing(glw2->context(), glw1->context()));
+ QVERIFY(!QGLContext::areSharing(0, glw2->context()));
+ QVERIFY(!QGLContext::areSharing(glw1->context(), 0));
+ QVERIFY(!QGLContext::areSharing(0, 0));
+
+ // Create a third context, not sharing with the others.
+ QGLWidget *glw3 = new QGLWidget();
+
+ // Create a guard on the standalone context.
+ QGLSharedResourceGuard guard3(glw3->context());
+ guard3.setId(5);
+
+ // First two should still be sharing, but third is in its own list.
+ list = shareReg->shares(glw1->context());
+ QCOMPARE(list.size(), 2);
+ QVERIFY(list.contains(glw1->context()));
+ QVERIFY(list.contains(glw2->context()));
+ list = shareReg->shares(glw2->context());
+ QCOMPARE(list.size(), 2);
+ QVERIFY(list.contains(glw1->context()));
+ QVERIFY(list.contains(glw2->context()));
+ list = shareReg->shares(glw3->context());
+ QCOMPARE(list.size(), 0);
+
+ // Check the sharing relationships again.
+ QVERIFY(QGLContext::areSharing(glw1->context(), glw1->context()));
+ QVERIFY(QGLContext::areSharing(glw2->context(), glw2->context()));
+ QVERIFY(QGLContext::areSharing(glw1->context(), glw2->context()));
+ QVERIFY(QGLContext::areSharing(glw2->context(), glw1->context()));
+ QVERIFY(!QGLContext::areSharing(glw1->context(), glw3->context()));
+ QVERIFY(!QGLContext::areSharing(glw2->context(), glw3->context()));
+ QVERIFY(!QGLContext::areSharing(glw3->context(), glw1->context()));
+ QVERIFY(!QGLContext::areSharing(glw3->context(), glw2->context()));
+ QVERIFY(QGLContext::areSharing(glw3->context(), glw3->context()));
+ QVERIFY(!QGLContext::areSharing(0, glw2->context()));
+ QVERIFY(!QGLContext::areSharing(glw1->context(), 0));
+ QVERIFY(!QGLContext::areSharing(0, glw3->context()));
+ QVERIFY(!QGLContext::areSharing(glw3->context(), 0));
+ QVERIFY(!QGLContext::areSharing(0, 0));
+
+ // Shared guard should still be the same.
+ QVERIFY(guard.context() == glw1->context());
+ QVERIFY(guard.id() == 3);
+
+ // Delete the first context.
+ delete glw1;
+
+ // Shared guard should now be the second context, with the id the same.
+ QVERIFY(guard.context() == glw2->context());
+ QVERIFY(guard.id() == 3);
+ QVERIFY(guard3.context() == glw3->context());
+ QVERIFY(guard3.id() == 5);
+
+ // Re-check the share list for the second context (should be empty now).
+ list = shareReg->shares(glw2->context());
+ QCOMPARE(list.size(), 0);
+
+ // Clean up.
+ delete glw2;
+ delete glw3;
+
+ // Guards should now be null and the id zero.
+ QVERIFY(guard.context() == 0);
+ QVERIFY(guard.id() == 0);
+ QVERIFY(guard3.context() == 0);
+ QVERIFY(guard3.id() == 0);
+#endif
+}
QTEST_MAIN(tst_QGL)
#include "tst_qgl.moc"
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
index ef9fe9e..297b6d3 100644
--- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -80,6 +80,57 @@ Q_DECLARE_METATYPE(QRectF)
#define Q_CHECK_PAINTEVENTS
#endif
+static void sendMousePress(QGraphicsScene *scene, const QPointF &point, Qt::MouseButton button = Qt::LeftButton)
+{
+ QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress);
+ event.setScenePos(point);
+ event.setButton(button);
+ event.setButtons(button);
+ QApplication::sendEvent(scene, &event);
+}
+
+static void sendMouseMove(QGraphicsScene *scene, const QPointF &point,
+ Qt::MouseButton button = Qt::NoButton, Qt::MouseButtons buttons = 0)
+{
+ QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove);
+ event.setScenePos(point);
+ event.setButton(button);
+ event.setButtons(button);
+ QApplication::sendEvent(scene, &event);
+}
+
+static void sendMouseRelease(QGraphicsScene *scene, const QPointF &point, Qt::MouseButton button = Qt::LeftButton)
+{
+ QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease);
+ event.setScenePos(point);
+ event.setButton(button);
+ QApplication::sendEvent(scene, &event);
+}
+
+static void sendMouseClick(QGraphicsScene *scene, const QPointF &point, Qt::MouseButton button = Qt::LeftButton)
+{
+ sendMousePress(scene, point, button);
+ sendMouseRelease(scene, point, button);
+}
+
+static void sendKeyPress(QGraphicsScene *scene, Qt::Key key)
+{
+ QKeyEvent keyEvent(QEvent::KeyPress, key, Qt::NoModifier);
+ QApplication::sendEvent(scene, &keyEvent);
+}
+
+static void sendKeyRelease(QGraphicsScene *scene, Qt::Key key)
+{
+ QKeyEvent keyEvent(QEvent::KeyRelease, key, Qt::NoModifier);
+ QApplication::sendEvent(scene, &keyEvent);
+}
+
+static void sendKeyClick(QGraphicsScene *scene, Qt::Key key)
+{
+ sendKeyPress(scene, key);
+ sendKeyRelease(scene, key);
+}
+
class EventSpy : public QGraphicsWidget
{
Q_OBJECT
@@ -120,6 +171,39 @@ protected:
QEvent::Type spied;
};
+class EventSpy2 : public QGraphicsWidget
+{
+ Q_OBJECT
+public:
+ EventSpy2(QObject *watched)
+ {
+ watched->installEventFilter(this);
+ }
+
+ EventSpy2(QGraphicsScene *scene, QGraphicsItem *watched)
+ {
+ scene->addItem(this);
+ watched->installSceneEventFilter(this);
+ }
+
+ QMap<QEvent::Type, int> counts;
+
+protected:
+ bool eventFilter(QObject *watched, QEvent *event)
+ {
+ Q_UNUSED(watched);
+ ++counts[event->type()];
+ return false;
+ }
+
+ bool sceneEventFilter(QGraphicsItem *watched, QEvent *event)
+ {
+ Q_UNUSED(watched);
+ ++counts[event->type()];
+ return false;
+ }
+};
+
class EventTester : public QGraphicsItem
{
public:
@@ -296,6 +380,13 @@ private slots:
void ensureDirtySceneTransform();
void focusScope();
void stackBefore();
+ void sceneModality();
+ void panelModality();
+ void mixedModality();
+ void modality_hover();
+ void modality_mouseGrabber();
+ void modality_clickFocus();
+ void modality_keyEvents();
// task specific tests below me
void task141694_textItemEnsureVisible();
@@ -2925,10 +3016,8 @@ void tst_QGraphicsItem::hoverEventsGenerateRepaints()
QGraphicsScene scene;
QGraphicsView view(&scene);
view.show();
-#ifdef Q_WS_X11
- qt_x11_wait_for_window_manager(&view);
-#endif
- QTest::qWait(20);
+ QTest::qWaitForWindowShown(&view);
+ QTest::qWait(150);
EventTester *tester = new EventTester;
scene.addItem(tester);
@@ -4637,7 +4726,7 @@ void tst_QGraphicsItem::paint()
qApp->processEvents();
//First show one paint
- QVERIFY(tester2.painted == 1);
+ QTRY_COMPARE(tester2.painted, 1);
//nominal case, update call paint
tester2.update();
@@ -4670,11 +4759,11 @@ public:
{
QGraphicsRectItem::paint(painter, option, widget);
if (harakiri == 0) {
- // delete unsupported since 4.5
- /*
+ // delete unsupported since 4.5
+ /*
dead = 1;
- delete this;
- */
+ delete this;
+ */
}
}
@@ -6217,6 +6306,7 @@ void tst_QGraphicsItem::itemStacksBehindParent()
QGraphicsView view(&scene);
view.show();
QTest::qWaitForWindowShown(&view);
+ QTRY_VERIFY(!paintedItems.isEmpty());
QTest::qWait(100);
paintedItems.clear();
view.viewport()->update();
@@ -6226,7 +6316,7 @@ void tst_QGraphicsItem::itemStacksBehindParent()
<< grandChild121 << child12 << parent1
<< grandChild211 << child21
<< grandChild221 << child22 << parent2));
- QCOMPARE(paintedItems, QList<QGraphicsItem *>()
+ QTRY_COMPARE(paintedItems, QList<QGraphicsItem *>()
<< parent2 << child22 << grandChild221
<< child21 << grandChild211
<< parent1 << child12 << grandChild121
@@ -8485,5 +8575,923 @@ void tst_QGraphicsItem::QTBUG_4233_updateCachedWithSceneRect()
QCOMPARE(tester->repaints, 2);
}
+void tst_QGraphicsItem::sceneModality()
+{
+ // 1) Test mouse events (delivery/propagation/redirection)
+ // 2) Test hover events (incl. leave on block, enter on unblock)
+ // 3) Test cursor stuff (incl. unset on block, set on unblock)
+ // 4) Test clickfocus
+ // 5) Test grab/ungrab events (possibly ungrab on block, regrab on unblock)
+ // 6) ### modality for non-panels is unsupported for now
+ QGraphicsScene scene;
+
+ QGraphicsRectItem *bottomItem = scene.addRect(-150, -100, 300, 200);
+ bottomItem->setFlag(QGraphicsItem::ItemIsFocusable);
+ bottomItem->setBrush(Qt::yellow);
+
+ QGraphicsRectItem *leftParent = scene.addRect(-50, -50, 100, 100);
+ leftParent->setFlag(QGraphicsItem::ItemIsPanel);
+ leftParent->setBrush(Qt::blue);
+
+ QGraphicsRectItem *leftChild = scene.addRect(-25, -25, 50, 50);
+ leftChild->setFlag(QGraphicsItem::ItemIsPanel);
+ leftChild->setBrush(Qt::green);
+ leftChild->setParentItem(leftParent);
+
+ QGraphicsRectItem *rightParent = scene.addRect(-50, -50, 100, 100);
+ rightParent->setFlag(QGraphicsItem::ItemIsPanel);
+ rightParent->setBrush(Qt::red);
+ QGraphicsRectItem *rightChild = scene.addRect(-25, -25, 50, 50);
+ rightChild->setFlag(QGraphicsItem::ItemIsPanel);
+ rightChild->setBrush(Qt::gray);
+ rightChild->setParentItem(rightParent);
+
+ leftParent->setPos(-75, 0);
+ rightParent->setPos(75, 0);
+
+ bottomItem->setData(0, "bottomItem");
+ leftParent->setData(0, "leftParent");
+ leftChild->setData(0, "leftChild");
+ rightParent->setData(0, "rightParent");
+ rightChild->setData(0, "rightChild");
+
+ scene.setSceneRect(scene.itemsBoundingRect().adjusted(-50, -50, 50, 50));
+
+ EventSpy2 leftParentSpy(&scene, leftParent);
+ EventSpy2 leftChildSpy(&scene, leftChild);
+ EventSpy2 rightParentSpy(&scene, rightParent);
+ EventSpy2 rightChildSpy(&scene, rightChild);
+ EventSpy2 bottomItemSpy(&scene, bottomItem);
+
+ // Scene modality, also test multiple scene modal items
+ leftChild->setPanelModality(QGraphicsItem::SceneModal);
+ QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(bottomItemSpy.counts[QEvent::WindowBlocked], 0); // not a panel
+
+ // Click inside left child
+ sendMouseClick(&scene, leftChild->scenePos(), Qt::LeftButton);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 1);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMouseRelease], 0); // no grab
+ QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+ QCOMPARE(rightParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+ QCOMPARE(rightChildSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+ QCOMPARE(bottomItemSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+
+ // Click on left parent, event goes to modal child
+ sendMouseClick(&scene, leftParent->sceneBoundingRect().topLeft() + QPointF(5, 5), Qt::LeftButton);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 2);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMouseRelease], 0); // no grab
+ QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+ QCOMPARE(rightParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+ QCOMPARE(rightChildSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+ QCOMPARE(bottomItemSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+
+ // Click on all other items and outside the items
+ sendMouseClick(&scene, rightParent->sceneBoundingRect().topLeft() + QPointF(5, 5), Qt::LeftButton);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 3);
+ sendMouseClick(&scene, rightChild->scenePos(), Qt::LeftButton);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 4);
+ sendMouseClick(&scene, bottomItem->scenePos(), Qt::LeftButton);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 5);
+ sendMouseClick(&scene, QPointF(10000, 10000), Qt::LeftButton);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 6);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMouseRelease], 0); // no grab
+ QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+ QCOMPARE(rightParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+ QCOMPARE(rightChildSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+ QCOMPARE(bottomItemSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+
+ leftChildSpy.counts.clear();
+ rightChildSpy.counts.clear();
+ leftParentSpy.counts.clear();
+ rightParentSpy.counts.clear();
+ bottomItemSpy.counts.clear();
+
+ leftChild->setPanelModality(QGraphicsItem::NonModal);
+ QCOMPARE(leftChildSpy.counts[QEvent::WindowUnblocked], 0);
+ QCOMPARE(rightChildSpy.counts[QEvent::WindowUnblocked], 1);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowUnblocked], 1);
+ QCOMPARE(rightParentSpy.counts[QEvent::WindowUnblocked], 1);
+ QCOMPARE(bottomItemSpy.counts[QEvent::WindowUnblocked], 0);
+
+ // Left parent enters scene modality.
+ leftParent->setPanelModality(QGraphicsItem::SceneModal);
+ QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(bottomItemSpy.counts[QEvent::WindowBlocked], 0);
+
+ // Click inside left child.
+ sendMouseClick(&scene, leftChild->scenePos(), Qt::LeftButton);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 1);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMouseRelease], 0);
+ QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // panel stops propagation
+ QCOMPARE(rightParentSpy.counts[QEvent::GraphicsSceneMousePress], 0);
+ QCOMPARE(rightChildSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+ QCOMPARE(bottomItemSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+
+ // Click on left parent.
+ sendMouseClick(&scene, leftParent->sceneBoundingRect().topLeft() + QPointF(5, 5), Qt::LeftButton);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 1);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMouseRelease], 0);
+ QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 1);
+ QCOMPARE(rightParentSpy.counts[QEvent::GraphicsSceneMousePress], 0);
+ QCOMPARE(rightChildSpy.counts[QEvent::GraphicsSceneMousePress], 0);
+ QCOMPARE(bottomItemSpy.counts[QEvent::GraphicsSceneMousePress], 0);
+
+ // Click on all other items and outside the items
+ sendMouseClick(&scene, rightParent->sceneBoundingRect().topLeft() + QPointF(5, 5), Qt::LeftButton);
+ QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 2);
+ sendMouseClick(&scene, rightChild->scenePos(), Qt::LeftButton);
+ QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 3);
+ sendMouseClick(&scene, bottomItem->scenePos(), Qt::LeftButton);
+ QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 4);
+ sendMouseClick(&scene, QPointF(10000, 10000), Qt::LeftButton);
+ QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 5);
+ QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMouseRelease], 0);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 1);
+ QCOMPARE(rightParentSpy.counts[QEvent::GraphicsSceneMousePress], 0);
+ QCOMPARE(rightChildSpy.counts[QEvent::GraphicsSceneMousePress], 0);
+ QCOMPARE(bottomItemSpy.counts[QEvent::GraphicsSceneMousePress], 0);
+
+ leftChildSpy.counts.clear();
+ rightChildSpy.counts.clear();
+ leftParentSpy.counts.clear();
+ rightParentSpy.counts.clear();
+ bottomItemSpy.counts.clear();
+
+ // Now both left parent and child are scene modal. Left parent is blocked.
+ leftChild->setPanelModality(QGraphicsItem::SceneModal);
+ QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(bottomItemSpy.counts[QEvent::WindowBlocked], 0);
+
+ // Click inside left child
+ sendMouseClick(&scene, leftChild->scenePos(), Qt::LeftButton);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 1);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMouseRelease], 0); // no grab
+ QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+ QCOMPARE(rightParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+ QCOMPARE(rightChildSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+ QCOMPARE(bottomItemSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+
+ // Click on left parent, event goes to modal child
+ sendMouseClick(&scene, leftParent->sceneBoundingRect().topLeft() + QPointF(5, 5), Qt::LeftButton);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 2);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMouseRelease], 0); // no grab
+ QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+ QCOMPARE(rightParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+ QCOMPARE(rightChildSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+ QCOMPARE(bottomItemSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+
+ // Click on all other items and outside the items
+ sendMouseClick(&scene, rightParent->sceneBoundingRect().topLeft() + QPointF(5, 5), Qt::LeftButton);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 3);
+ sendMouseClick(&scene, rightChild->scenePos(), Qt::LeftButton);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 4);
+ sendMouseClick(&scene, bottomItem->scenePos(), Qt::LeftButton);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 5);
+ sendMouseClick(&scene, QPointF(10000, 10000), Qt::LeftButton);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMousePress], 6);
+ QCOMPARE(leftChildSpy.counts[QEvent::GraphicsSceneMouseRelease], 0); // no grab
+ QCOMPARE(leftParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+ QCOMPARE(rightParentSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+ QCOMPARE(rightChildSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+ QCOMPARE(bottomItemSpy.counts[QEvent::GraphicsSceneMousePress], 0); // blocked
+
+ leftChildSpy.counts.clear();
+ rightChildSpy.counts.clear();
+ leftParentSpy.counts.clear();
+ rightParentSpy.counts.clear();
+ bottomItemSpy.counts.clear();
+
+ // Right child enters scene modality, only left child is blocked.
+ rightChild->setPanelModality(QGraphicsItem::SceneModal);
+ QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(bottomItemSpy.counts[QEvent::WindowBlocked], 0);
+}
+
+void tst_QGraphicsItem::panelModality()
+{
+ // 1) Test mouse events (delivery/propagation/redirection)
+ // 2) Test hover events (incl. leave on block, enter on unblock)
+ // 3) Test cursor stuff (incl. unset on block, set on unblock)
+ // 4) Test clickfocus
+ // 5) Test grab/ungrab events (possibly ungrab on block, regrab on unblock)
+ // 6) ### modality for non-panels is unsupported for now
+ QGraphicsScene scene;
+
+ QGraphicsRectItem *bottomItem = scene.addRect(-150, -100, 300, 200);
+ bottomItem->setFlag(QGraphicsItem::ItemIsFocusable);
+ bottomItem->setBrush(Qt::yellow);
+
+ QGraphicsRectItem *leftParent = scene.addRect(-50, -50, 100, 100);
+ leftParent->setFlag(QGraphicsItem::ItemIsPanel);
+ leftParent->setBrush(Qt::blue);
+
+ QGraphicsRectItem *leftChild = scene.addRect(-25, -25, 50, 50);
+ leftChild->setFlag(QGraphicsItem::ItemIsPanel);
+ leftChild->setBrush(Qt::green);
+ leftChild->setParentItem(leftParent);
+
+ QGraphicsRectItem *rightParent = scene.addRect(-50, -50, 100, 100);
+ rightParent->setFlag(QGraphicsItem::ItemIsPanel);
+ rightParent->setBrush(Qt::red);
+ QGraphicsRectItem *rightChild = scene.addRect(-25, -25, 50, 50);
+ rightChild->setFlag(QGraphicsItem::ItemIsPanel);
+ rightChild->setBrush(Qt::gray);
+ rightChild->setParentItem(rightParent);
+
+ leftParent->setPos(-75, 0);
+ rightParent->setPos(75, 0);
+
+ bottomItem->setData(0, "bottomItem");
+ leftParent->setData(0, "leftParent");
+ leftChild->setData(0, "leftChild");
+ rightParent->setData(0, "rightParent");
+ rightChild->setData(0, "rightChild");
+
+ scene.setSceneRect(scene.itemsBoundingRect().adjusted(-50, -50, 50, 50));
+
+ EventSpy2 leftParentSpy(&scene, leftParent);
+ EventSpy2 leftChildSpy(&scene, leftChild);
+ EventSpy2 rightParentSpy(&scene, rightParent);
+ EventSpy2 rightChildSpy(&scene, rightChild);
+ EventSpy2 bottomItemSpy(&scene, bottomItem);
+
+ // Left Child enters panel modality, only left parent is blocked.
+ leftChild->setPanelModality(QGraphicsItem::PanelModal);
+ QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(bottomItemSpy.counts[QEvent::WindowBlocked], 0);
+
+ leftChild->setPanelModality(QGraphicsItem::NonModal);
+ leftChildSpy.counts.clear();
+ rightChildSpy.counts.clear();
+ leftParentSpy.counts.clear();
+ rightParentSpy.counts.clear();
+ bottomItemSpy.counts.clear();
+
+ // Left parent enter panel modality, nothing is blocked.
+ leftParent->setPanelModality(QGraphicsItem::PanelModal);
+ QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(bottomItemSpy.counts[QEvent::WindowBlocked], 0);
+
+ // Left child enters panel modality, left parent is blocked again.
+ leftChild->setPanelModality(QGraphicsItem::PanelModal);
+ QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(bottomItemSpy.counts[QEvent::WindowBlocked], 0);
+
+ leftChildSpy.counts.clear();
+ rightChildSpy.counts.clear();
+ leftParentSpy.counts.clear();
+ rightParentSpy.counts.clear();
+ bottomItemSpy.counts.clear();
+
+ leftChild->setPanelModality(QGraphicsItem::NonModal);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowUnblocked], 1);
+ leftParent->setPanelModality(QGraphicsItem::NonModal);
+ QCOMPARE(leftChildSpy.counts[QEvent::WindowUnblocked], 0);
+ QCOMPARE(rightChildSpy.counts[QEvent::WindowUnblocked], 0);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowUnblocked], 1);
+ QCOMPARE(rightParentSpy.counts[QEvent::WindowUnblocked], 0);
+ QCOMPARE(bottomItemSpy.counts[QEvent::WindowUnblocked], 0);
+
+ leftChildSpy.counts.clear();
+ rightChildSpy.counts.clear();
+ leftParentSpy.counts.clear();
+ rightParentSpy.counts.clear();
+ bottomItemSpy.counts.clear();
+
+ // Left and right child enter panel modality, both parents are blocked.
+ rightChild->setPanelModality(QGraphicsItem::PanelModal);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 1);
+ leftChild->setPanelModality(QGraphicsItem::PanelModal);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 1);
+}
+
+void tst_QGraphicsItem::mixedModality()
+{
+ // 1) Test mouse events (delivery/propagation/redirection)
+ // 2) Test hover events (incl. leave on block, enter on unblock)
+ // 3) Test cursor stuff (incl. unset on block, set on unblock)
+ // 4) Test clickfocus
+ // 5) Test grab/ungrab events (possibly ungrab on block, regrab on unblock)
+ // 6) ### modality for non-panels is unsupported for now
+ QGraphicsScene scene;
+
+ QGraphicsRectItem *bottomItem = scene.addRect(-150, -100, 300, 200);
+ bottomItem->setFlag(QGraphicsItem::ItemIsFocusable);
+ bottomItem->setBrush(Qt::yellow);
+
+ QGraphicsRectItem *leftParent = scene.addRect(-50, -50, 100, 100);
+ leftParent->setFlag(QGraphicsItem::ItemIsPanel);
+ leftParent->setBrush(Qt::blue);
+
+ QGraphicsRectItem *leftChild = scene.addRect(-25, -25, 50, 50);
+ leftChild->setFlag(QGraphicsItem::ItemIsPanel);
+ leftChild->setBrush(Qt::green);
+ leftChild->setParentItem(leftParent);
+
+ QGraphicsRectItem *rightParent = scene.addRect(-50, -50, 100, 100);
+ rightParent->setFlag(QGraphicsItem::ItemIsPanel);
+ rightParent->setBrush(Qt::red);
+ QGraphicsRectItem *rightChild = scene.addRect(-25, -25, 50, 50);
+ rightChild->setFlag(QGraphicsItem::ItemIsPanel);
+ rightChild->setBrush(Qt::gray);
+ rightChild->setParentItem(rightParent);
+
+ leftParent->setPos(-75, 0);
+ rightParent->setPos(75, 0);
+
+ bottomItem->setData(0, "bottomItem");
+ leftParent->setData(0, "leftParent");
+ leftChild->setData(0, "leftChild");
+ rightParent->setData(0, "rightParent");
+ rightChild->setData(0, "rightChild");
+
+ scene.setSceneRect(scene.itemsBoundingRect().adjusted(-50, -50, 50, 50));
+
+ EventSpy2 leftParentSpy(&scene, leftParent);
+ EventSpy2 leftChildSpy(&scene, leftChild);
+ EventSpy2 rightParentSpy(&scene, rightParent);
+ EventSpy2 rightChildSpy(&scene, rightChild);
+ EventSpy2 bottomItemSpy(&scene, bottomItem);
+
+ // Left Child enters panel modality, only left parent is blocked.
+ leftChild->setPanelModality(QGraphicsItem::PanelModal);
+ QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 0);
+
+ // Left parent enters scene modality, which blocks everything except the child.
+ leftParent->setPanelModality(QGraphicsItem::SceneModal);
+ QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(leftChildSpy.counts[QEvent::WindowUnblocked], 0);
+ QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(rightChildSpy.counts[QEvent::WindowUnblocked], 0);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowUnblocked], 0);
+ QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(rightParentSpy.counts[QEvent::WindowUnblocked], 0);
+
+ // Right child enters panel modality (changes nothing).
+ rightChild->setPanelModality(QGraphicsItem::PanelModal);
+ QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(leftChildSpy.counts[QEvent::WindowUnblocked], 0);
+ QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(rightChildSpy.counts[QEvent::WindowUnblocked], 0);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowUnblocked], 0);
+ QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(rightParentSpy.counts[QEvent::WindowUnblocked], 0);
+
+ // Left parent leaves modality. Right child is unblocked.
+ leftParent->setPanelModality(QGraphicsItem::NonModal);
+ QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 0);
+ QCOMPARE(leftChildSpy.counts[QEvent::WindowUnblocked], 0);
+ QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(rightChildSpy.counts[QEvent::WindowUnblocked], 1);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowUnblocked], 0);
+ QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(rightParentSpy.counts[QEvent::WindowUnblocked], 0);
+
+ // Right child "upgrades" its modality to scene modal. Left child is blocked.
+ // Right parent is unaffected.
+ rightChild->setPanelModality(QGraphicsItem::SceneModal);
+ QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(leftChildSpy.counts[QEvent::WindowUnblocked], 0);
+ QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(rightChildSpy.counts[QEvent::WindowUnblocked], 1);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowUnblocked], 0);
+ QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(rightParentSpy.counts[QEvent::WindowUnblocked], 0);
+
+ // "downgrade" right child back to panel modal, left child is unblocked
+ rightChild->setPanelModality(QGraphicsItem::PanelModal);
+ QCOMPARE(leftChildSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(leftChildSpy.counts[QEvent::WindowUnblocked], 1);
+ QCOMPARE(rightChildSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(rightChildSpy.counts[QEvent::WindowUnblocked], 1);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(leftParentSpy.counts[QEvent::WindowUnblocked], 0);
+ QCOMPARE(rightParentSpy.counts[QEvent::WindowBlocked], 1);
+ QCOMPARE(rightParentSpy.counts[QEvent::WindowUnblocked], 0);
+}
+
+void tst_QGraphicsItem::modality_hover()
+{
+ QGraphicsScene scene;
+ QGraphicsRectItem *rect1 = scene.addRect(-50, -50, 100, 100);
+ rect1->setFlag(QGraphicsItem::ItemIsPanel);
+ rect1->setAcceptHoverEvents(true);
+ rect1->setData(0, "rect1");
+
+ QGraphicsRectItem *rect2 = scene.addRect(-50, -50, 100, 100);
+ rect2->setParentItem(rect1);
+ rect2->setFlag(QGraphicsItem::ItemIsPanel);
+ rect2->setAcceptHoverEvents(true);
+ rect2->setPos(50, 50);
+ rect2->setPanelModality(QGraphicsItem::SceneModal);
+ rect2->setData(0, "rect2");
+
+ EventSpy2 rect1Spy(&scene, rect1);
+ EventSpy2 rect2Spy(&scene, rect2);
+
+ sendMouseMove(&scene, QPointF(-25, -25));
+
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverEnter], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverMove], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverLeave], 0);
+
+ sendMouseMove(&scene, QPointF(75, 75));
+
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverEnter], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverMove], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverLeave], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverEnter], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverMove], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverLeave], 0);
+
+ sendMouseMove(&scene, QPointF(-25, -25));
+
+ QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverLeave], 1);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverEnter], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverMove], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverLeave], 0);
+
+ rect2->setPanelModality(QGraphicsItem::NonModal);
+
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverEnter], 1);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverMove], 1);
+
+ sendMouseMove(&scene, QPointF(75, 75));
+
+ QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverEnter], 2);
+ QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverMove], 2);
+
+ rect2->setPanelModality(QGraphicsItem::SceneModal);
+
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverLeave], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverEnter], 2);
+ // changing modality causes a spurious GraphicsSceneHoveMove, even though the mouse didn't
+ // actually move
+ QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverMove], 3);
+
+ sendMouseMove(&scene, QPointF(-25, -25));
+
+ QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverLeave], 2);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverEnter], 1);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverMove], 1);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverLeave], 1);
+
+ rect2->setPanelModality(QGraphicsItem::PanelModal);
+
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverEnter], 1);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverMove], 1);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverLeave], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverEnter], 2);
+ QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverMove], 3);
+ QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverLeave], 2);
+
+ rect2->setPanelModality(QGraphicsItem::NonModal);
+
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverEnter], 2);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneHoverMove], 2);
+ QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverEnter], 2);
+ QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverMove], 3);
+ QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneHoverLeave], 2);
+}
+
+void tst_QGraphicsItem::modality_mouseGrabber()
+{
+ QGraphicsScene scene;
+ QGraphicsRectItem *rect1 = scene.addRect(-50, -50, 100, 100);
+ rect1->setFlag(QGraphicsItem::ItemIsPanel);
+ rect1->setFlag(QGraphicsItem::ItemIsMovable);
+ rect1->setData(0, "rect1");
+
+ QGraphicsRectItem *rect2 = scene.addRect(-50, -50, 100, 100);
+ rect2->setParentItem(rect1);
+ rect2->setFlag(QGraphicsItem::ItemIsPanel);
+ rect2->setFlag(QGraphicsItem::ItemIsMovable);
+ rect2->setPos(50, 50);
+ rect2->setData(0, "rect2");
+
+ EventSpy2 rect1Spy(&scene, rect1);
+ EventSpy2 rect2Spy(&scene, rect2);
+
+ {
+ // pressing mouse on rect1 starts implicit grab
+ sendMousePress(&scene, QPoint(-25, -25));
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 1);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMousePress], 1);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect1);
+
+ // grab lost when rect1 is modally shadowed
+ rect2->setPanelModality(QGraphicsItem::SceneModal);
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 1);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0);
+
+ // releasing goes nowhere
+ sendMouseRelease(&scene, QPoint(-25, -25));
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 1);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMouseRelease], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneMouseRelease], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0);
+
+ // pressing mouse on rect1 starts implicit grab on rect2 (since it is modal)
+ sendMouseClick(&scene, QPoint(-25, -25));
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 1);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMousePress], 1);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMouseRelease], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneMousePress], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneMouseRelease], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1);
+
+ rect2->setPanelModality(QGraphicsItem::NonModal);
+
+ // pressing mouse on rect1 starts implicit grab
+ sendMousePress(&scene, QPoint(-25, -25));
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 2);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMousePress], 2);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1);
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect1);
+
+ // grab lost to rect2 when rect1 is modally shadowed
+ rect2->setPanelModality(QGraphicsItem::SceneModal);
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 2);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 2);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1);
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0);
+
+ // rect1 does *not* re-grab when rect2 is no longer modal
+ rect2->setPanelModality(QGraphicsItem::NonModal);
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 2);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 2);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1);
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0);
+
+ // release goes nowhere
+ sendMouseRelease(&scene, QPoint(-25, -25));
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 2);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMouseRelease], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 2);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1);
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0);
+ }
+ {
+ // repeat the test using PanelModal
+ rect2->setPanelModality(QGraphicsItem::NonModal);
+ rect1Spy.counts.clear();
+ rect2Spy.counts.clear();
+
+ // pressing mouse on rect1 starts implicit grab
+ sendMousePress(&scene, QPoint(-25, -25));
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 1);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMousePress], 1);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect1);
+
+ // grab lost when rect1 is modally shadowed
+ rect2->setPanelModality(QGraphicsItem::PanelModal);
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 1);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0);
+
+ // releasing goes nowhere
+ sendMouseRelease(&scene, QPoint(-25, -25));
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 1);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMouseRelease], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneMouseRelease], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0);
+
+ // pressing mouse on rect1 starts implicit grab on rect2 (since it is modal)
+ sendMouseClick(&scene, QPoint(-25, -25));
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 1);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMousePress], 1);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMouseRelease], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneMousePress], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::GraphicsSceneMouseRelease], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1);
+
+ rect2->setPanelModality(QGraphicsItem::NonModal);
+
+ // pressing mouse on rect1 starts implicit grab
+ sendMousePress(&scene, QPoint(-25, -25));
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 2);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMousePress], 2);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1);
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect1);
+
+ // grab lost to rect2 when rect1 is modally shadowed
+ rect2->setPanelModality(QGraphicsItem::PanelModal);
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 2);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 2);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1);
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0);
+
+ // rect1 does *not* re-grab when rect2 is no longer modal
+ rect2->setPanelModality(QGraphicsItem::NonModal);
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 2);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 2);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1);
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0);
+
+ // release goes nowhere
+ sendMouseRelease(&scene, QPoint(-25, -25));
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 2);
+ QCOMPARE(rect1Spy.counts[QEvent::GraphicsSceneMouseRelease], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 2);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1);
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0);
+ }
+
+ {
+ // repeat the PanelModal tests, but this time the mouse events will be on a non-modal item,
+ // meaning normal grabbing should work
+ rect2->setPanelModality(QGraphicsItem::NonModal);
+ rect1Spy.counts.clear();
+ rect2Spy.counts.clear();
+
+ QGraphicsRectItem *rect3 = scene.addRect(-50, -50, 100, 100);
+ rect3->setFlag(QGraphicsItem::ItemIsPanel);
+ rect3->setFlag(QGraphicsItem::ItemIsMovable);
+ rect3->setPos(150, 50);
+ rect3->setData(0, "rect3");
+
+ EventSpy2 rect3Spy(&scene, rect3);
+
+ // pressing mouse on rect3 starts implicit grab
+ sendMousePress(&scene, QPoint(150, 50));
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 1);
+ QCOMPARE(rect3Spy.counts[QEvent::GraphicsSceneMousePress], 1);
+ QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3);
+
+ // grab is *not* lost when rect1 is modally shadowed by rect2
+ rect2->setPanelModality(QGraphicsItem::PanelModal);
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 1);
+ QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3);
+
+ // releasing goes to rect3
+ sendMouseRelease(&scene, QPoint(150, 50));
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 1);
+ QCOMPARE(rect3Spy.counts[QEvent::GraphicsSceneMouseRelease], 1);
+ QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 1);
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0);
+
+ rect2->setPanelModality(QGraphicsItem::NonModal);
+
+ // pressing mouse on rect3 starts implicit grab
+ sendMousePress(&scene, QPoint(150, 50));
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 2);
+ QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 1);
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3);
+
+ // grab is not lost
+ rect2->setPanelModality(QGraphicsItem::PanelModal);
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 2);
+ QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 1);
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3);
+
+ // grab stays on rect3
+ rect2->setPanelModality(QGraphicsItem::NonModal);
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 2);
+ QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 1);
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3);
+
+ // release goes to rect3
+ sendMouseRelease(&scene, QPoint(150, 50));
+ QCOMPARE(rect1Spy.counts[QEvent::GrabMouse], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
+ QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 2);
+ QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 2);
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) 0);
+ }
+}
+
+void tst_QGraphicsItem::modality_clickFocus()
+{
+ QGraphicsScene scene;
+ QGraphicsRectItem *rect1 = scene.addRect(-50, -50, 100, 100);
+ rect1->setFlag(QGraphicsItem::ItemIsPanel);
+ rect1->setFlag(QGraphicsItem::ItemIsFocusable);
+ rect1->setData(0, "rect1");
+
+ QGraphicsRectItem *rect2 = scene.addRect(-50, -50, 100, 100);
+ rect2->setParentItem(rect1);
+ rect2->setFlag(QGraphicsItem::ItemIsPanel);
+ rect2->setFlag(QGraphicsItem::ItemIsFocusable);
+ rect2->setPos(50, 50);
+ rect2->setData(0, "rect2");
+
+ QEvent windowActivateEvent(QEvent::WindowActivate);
+ QApplication::sendEvent(&scene, &windowActivateEvent);
+
+ EventSpy2 rect1Spy(&scene, rect1);
+ EventSpy2 rect2Spy(&scene, rect2);
+
+ // activate rect1, it should not get focus
+ rect1->setActive(true);
+ QCOMPARE(scene.focusItem(), (QGraphicsItem *) 0);
+
+ // focus stays unset when rect2 becomes modal
+ rect2->setPanelModality(QGraphicsItem::SceneModal);
+ QCOMPARE(scene.focusItem(), (QGraphicsItem *) 0);
+ QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 0);
+
+ // clicking on rect1 should not set it's focus item
+ sendMouseClick(&scene, QPointF(-25, -25));
+ QCOMPARE(rect1->focusItem(), (QGraphicsItem *) 0);
+ QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 0);
+
+ // clicking on rect2 gives it focus
+ rect2->setActive(true);
+ sendMouseClick(&scene, QPointF(75, 75));
+ QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect2);
+ QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 0);
+
+ // clicking on rect1 does *not* give it focus
+ rect1->setActive(true);
+ sendMouseClick(&scene, QPointF(-25, -25));
+ QCOMPARE(scene.focusItem(), (QGraphicsItem *) 0);
+ QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 1);
+
+ // focus doesn't change when leaving modality either
+ rect2->setPanelModality(QGraphicsItem::NonModal);
+ QCOMPARE(scene.focusItem(), (QGraphicsItem *) 0);
+ QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 1);
+
+ // click on rect1, it should get focus now
+ sendMouseClick(&scene, QPointF(-25, -25));
+ QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1);
+ QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 1);
+ QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0);
+ QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 1);
+ QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 1);
+}
+
+void tst_QGraphicsItem::modality_keyEvents()
+{
+ QGraphicsScene scene;
+ QGraphicsRectItem *rect1 = scene.addRect(-50, -50, 100, 100);
+ rect1->setFlag(QGraphicsItem::ItemIsPanel);
+ rect1->setFlag(QGraphicsItem::ItemIsFocusable);
+ rect1->setData(0, "rect1");
+
+ QGraphicsRectItem *rect1child = scene.addRect(-10, -10, 20, 20);
+ rect1child->setParentItem(rect1);
+ rect1child->setFlag(QGraphicsItem::ItemIsFocusable);
+ rect1child->setData(0, "rect1child1");
+
+ QGraphicsRectItem *rect2 = scene.addRect(-50, -50, 100, 100);
+ rect2->setParentItem(rect1);
+ rect2->setFlag(QGraphicsItem::ItemIsPanel);
+ rect2->setFlag(QGraphicsItem::ItemIsFocusable);
+ rect2->setPos(50, 50);
+ rect2->setData(0, "rect2");
+
+ QGraphicsRectItem *rect2child = scene.addRect(-10, -10, 20, 20);
+ rect2child->setParentItem(rect2);
+ rect2child->setFlag(QGraphicsItem::ItemIsFocusable);
+ rect2child->setData(0, "rect2child1");
+
+ QEvent windowActivateEvent(QEvent::WindowActivate);
+ QApplication::sendEvent(&scene, &windowActivateEvent);
+
+ EventSpy2 rect1Spy(&scene, rect1);
+ EventSpy2 rect1childSpy(&scene, rect1child);
+ EventSpy2 rect2Spy(&scene, rect2);
+ EventSpy2 rect2childSpy(&scene, rect2child);
+
+ // activate rect1 and give it rect1child focus
+ rect1->setActive(true);
+ rect1child->setFocus();
+ QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1child);
+
+ // focus stays on rect1child when rect2 becomes modal
+ rect2->setPanelModality(QGraphicsItem::SceneModal);
+ QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1child);
+
+ // but key events to rect1child should be neither delivered nor propagated
+ sendKeyClick(&scene, Qt::Key_A);
+ sendKeyClick(&scene, Qt::Key_S);
+ sendKeyClick(&scene, Qt::Key_D);
+ sendKeyClick(&scene, Qt::Key_F);
+ QCOMPARE(rect1childSpy.counts[QEvent::KeyPress], 0);
+ QCOMPARE(rect1childSpy.counts[QEvent::KeyRelease], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::KeyPress], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::KeyRelease], 0);
+
+ // change to panel modality, rect1child1 keeps focus
+ rect2->setPanelModality(QGraphicsItem::PanelModal);
+ QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1child);
+
+ // still no key events
+ sendKeyClick(&scene, Qt::Key_J);
+ sendKeyClick(&scene, Qt::Key_K);
+ sendKeyClick(&scene, Qt::Key_L);
+ sendKeyClick(&scene, Qt::Key_Semicolon);
+ QCOMPARE(rect1childSpy.counts[QEvent::KeyPress], 0);
+ QCOMPARE(rect1childSpy.counts[QEvent::KeyRelease], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::KeyPress], 0);
+ QCOMPARE(rect1Spy.counts[QEvent::KeyRelease], 0);
+}
+
QTEST_MAIN(tst_QGraphicsItem)
#include "tst_qgraphicsitem.moc"
diff --git a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
index 5c0073c..76e7202 100644
--- a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
+++ b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
@@ -1296,17 +1296,18 @@ void tst_QGraphicsProxyWidget::paintEvent()
w->show();
QTest::qWaitForWindowShown(w);
QApplication::processEvents();
-
+ QTest::qWait(50);
proxy.setWidget(w);
scene.addItem(&proxy);
//make sure we flush all the paint events
- QApplication::processEvents();
+ QTest::qWait(70);
QTRY_VERIFY(proxy.paintCount > 1);
+ QTest::qWait(70);
proxy.paintCount = 0;
w->update();
- QApplication::processEvents();
+ QTest::qWait(30);
QTRY_COMPARE(proxy.paintCount, 1); //the widget should have been painted now
}
@@ -1491,9 +1492,7 @@ void tst_QGraphicsProxyWidget::scrollUpdate()
View view(&scene);
view.show();
-#ifdef Q_WS_X11
- qt_x11_wait_for_window_manager(&view);
-#endif
+ QTest::qWaitForWindowShown(&view);
QTRY_VERIFY(view.npaints >= 1);
QTest::qWait(20);
widget->paintEventRegion = QRegion();
@@ -3061,6 +3060,8 @@ void tst_QGraphicsProxyWidget::deleteProxyForChildWidget()
proxy->setWidget(0);
//just don't crash
+ QApplication::processEvents();
+ delete combo;
}
void tst_QGraphicsProxyWidget::bypassGraphicsProxyWidget_data()
@@ -3092,11 +3093,17 @@ void tst_QGraphicsProxyWidget::bypassGraphicsProxyWidget()
if (bypass)
flags |= Qt::BypassGraphicsProxyWidget;
QFileDialog *dialog = new QFileDialog(widget, flags);
+ dialog->setOption(QFileDialog::DontUseNativeDialog, true);
dialog->show();
QCOMPARE(proxy->childItems().size(), bypass ? 0 : 1);
if (!bypass)
QCOMPARE(((QGraphicsProxyWidget *)proxy->childItems().first())->widget(), (QWidget *)dialog);
+
+ dialog->hide();
+ QApplication::processEvents();
+ delete dialog;
+ delete widget;
}
static void makeDndEvent(QGraphicsSceneDragDropEvent *event, QGraphicsView *view, const QPointF &pos)
diff --git a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp
index 07d7cce..e55dc9aa 100644
--- a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp
+++ b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp
@@ -1357,8 +1357,9 @@ void tst_QGraphicsScene::removeItem()
QVERIFY(!hoverItem->isHovered);
{
- QTest::mouseMove(view.viewport(), view.mapFromScene(hoverItem->scenePos()), Qt::NoButton);
QTest::qWait(250);
+ QTest::mouseMove(view.viewport(), view.mapFromScene(hoverItem->scenePos()), Qt::NoButton);
+ QTest::qWait(10);
QMouseEvent moveEvent(QEvent::MouseMove, view.mapFromScene(hoverItem->scenePos()), Qt::NoButton, 0, 0);
QApplication::sendEvent(view.viewport(), &moveEvent);
}
@@ -1632,6 +1633,7 @@ void tst_QGraphicsScene::hoverEvents_siblings()
#endif
qApp->setActiveWindow(&view);
view.activateWindow();
+ QTest::qWait(70);
QCursor::setPos(view.mapToGlobal(QPoint(-5, -5)));
@@ -1655,7 +1657,7 @@ void tst_QGraphicsScene::hoverEvents_siblings()
qApp->processEvents(); // this posts updates from the scene to the view
qApp->processEvents(); // which trigger a repaint here
- QVERIFY(items.at(i)->isHovered);
+ QTRY_VERIFY(items.at(i)->isHovered);
if (j && i > 0)
QVERIFY(!items.at(i - 1)->isHovered);
if (!j && i < 14)
@@ -1702,9 +1704,8 @@ void tst_QGraphicsScene::hoverEvents_parentChild()
view.rotate(10);
view.scale(1.7, 1.7);
view.show();
-#ifdef Q_WS_X11
- qt_x11_wait_for_window_manager(&view);
-#endif
+ QTest::qWaitForWindowShown(&view);
+ QTest::qWait(50);
QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove);
mouseEvent.setScenePos(QPointF(-1000, -1000));
@@ -3060,52 +3061,53 @@ void tst_QGraphicsScene::tabFocus_sceneWithFocusableItems()
widget.show();
qApp->setActiveWindow(&widget);
widget.activateWindow();
- QTest::qWait(125);
+ QTest::qWaitForWindowShown(&widget);
+ QApplication::processEvents();
dial1->setFocus();
- QVERIFY(dial1->hasFocus());
+ QTRY_VERIFY(dial1->hasFocus());
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
- QTest::qWait(125);
- QVERIFY(view->hasFocus());
+ QApplication::processEvents();
+ QTRY_VERIFY(view->hasFocus());
QVERIFY(view->viewport()->hasFocus());
QVERIFY(scene.hasFocus());
QVERIFY(item->hasFocus());
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
- QTest::qWait(125);
- QVERIFY(dial2->hasFocus());
+ QApplication::processEvents();
+ QTRY_VERIFY(dial2->hasFocus());
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
- QTest::qWait(125);
- QVERIFY(view->hasFocus());
- QVERIFY(view->viewport()->hasFocus());
- QVERIFY(scene.hasFocus());
- QVERIFY(item->hasFocus());
+ QApplication::processEvents();
+ QTRY_VERIFY(view->hasFocus());
+ QTRY_VERIFY(view->viewport()->hasFocus());
+ QTRY_VERIFY(scene.hasFocus());
+ QTRY_VERIFY(item->hasFocus());
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
- QTest::qWait(125);
- QVERIFY(dial1->hasFocus());
+ QApplication::processEvents();
+ QTRY_VERIFY(dial1->hasFocus());
// If the item requests input focus, it can only ensure that the scene
// sets focus on itself, but the scene cannot request focus from any view.
item->setFocus();
- QTest::qWait(125);
- QVERIFY(!view->hasFocus());
+ QApplication::processEvents();
+ QTRY_VERIFY(!view->hasFocus());
QVERIFY(!view->viewport()->hasFocus());
- QVERIFY(scene.hasFocus());
+ QTRY_VERIFY(scene.hasFocus());
QVERIFY(item->hasFocus());
view->setFocus();
- QTest::qWait(125);
- QVERIFY(view->hasFocus());
- QVERIFY(view->viewport()->hasFocus());
- QVERIFY(scene.hasFocus());
- QVERIFY(item->hasFocus());
+ QApplication::processEvents();
+ QTRY_VERIFY(view->hasFocus());
+ QTRY_VERIFY(view->viewport()->hasFocus());
+ QTRY_VERIFY(scene.hasFocus());
+ QTRY_VERIFY(item->hasFocus());
// Check that everyone loses focus when the widget is hidden.
widget.hide();
- QTest::qWait(125);
- QVERIFY(!view->hasFocus());
+ QTest::qWait(15);
+ QTRY_VERIFY(!view->hasFocus());
QVERIFY(!view->viewport()->hasFocus());
QVERIFY(!scene.hasFocus());
QVERIFY(!item->hasFocus());
@@ -3114,8 +3116,8 @@ void tst_QGraphicsScene::tabFocus_sceneWithFocusableItems()
widget.show();
qApp->setActiveWindow(&widget);
widget.activateWindow();
- QTest::qWait(125);
- QVERIFY(view->hasFocus());
+ QTest::qWaitForWindowShown(&widget);
+ QTRY_VERIFY(view->hasFocus());
QVERIFY(view->viewport()->hasFocus());
QVERIFY(scene.hasFocus());
QVERIFY(item->hasFocus());
@@ -3193,47 +3195,48 @@ void tst_QGraphicsScene::tabFocus_sceneWithFocusWidgets()
widget.show();
qApp->setActiveWindow(&widget);
widget.activateWindow();
- QTest::qWait(125);
+ QTest::qWaitForWindowShown(&widget);
+ QApplication::processEvents();
dial1->setFocus();
- QVERIFY(dial1->hasFocus());
+ QTRY_VERIFY(dial1->hasFocus());
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
- QTest::qWait(125);
- QVERIFY(view->hasFocus());
- QVERIFY(view->viewport()->hasFocus());
- QVERIFY(scene.hasFocus());
+ QApplication::processEvents();
+ QTRY_VERIFY(view->hasFocus());
+ QTRY_VERIFY(view->viewport()->hasFocus());
+ QTRY_VERIFY(scene.hasFocus());
QCOMPARE(widget1->tabs, 0);
QVERIFY(widget1->hasFocus());
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
- QTest::qWait(125);
- QCOMPARE(widget1->tabs, 1);
- QVERIFY(widget2->hasFocus());
+ QApplication::processEvents();
+ QTRY_COMPARE(widget1->tabs, 1);
+ QTRY_VERIFY(widget2->hasFocus());
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
- QTest::qWait(125);
- QCOMPARE(widget2->tabs, 1);
- QVERIFY(dial2->hasFocus());
+ QApplication::processEvents();
+ QTRY_COMPARE(widget2->tabs, 1);
+ QTRY_VERIFY(dial2->hasFocus());
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
- QTest::qWait(125);
- QVERIFY(widget2->hasFocus());
+ QApplication::processEvents();
+ QTRY_VERIFY(widget2->hasFocus());
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
- QTest::qWait(125);
- QCOMPARE(widget2->backTabs, 1);
- QVERIFY(widget1->hasFocus());
+ QApplication::processEvents();
+ QTRY_COMPARE(widget2->backTabs, 1);
+ QTRY_VERIFY(widget1->hasFocus());
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
- QTest::qWait(125);
- QCOMPARE(widget1->backTabs, 1);
- QVERIFY(dial1->hasFocus());
+ QApplication::processEvents();
+ QTRY_COMPARE(widget1->backTabs, 1);
+ QTRY_VERIFY(dial1->hasFocus());
widget1->setFocus();
view->viewport()->setFocus();
widget.hide();
- QTest::qWait(125);
+ QTest::qWait(15);
widget.show();
qApp->setActiveWindow(&widget);
widget.activateWindow();
- QTest::qWait(125);
- QVERIFY(widget1->hasFocus());
+ QTest::qWaitForWindowShown(&widget);
+ QTRY_VERIFY(widget1->hasFocus());
}
void tst_QGraphicsScene::tabFocus_sceneWithNestedFocusWidgets()
@@ -3276,10 +3279,10 @@ void tst_QGraphicsScene::tabFocus_sceneWithNestedFocusWidgets()
widget.show();
qApp->setActiveWindow(&widget);
widget.activateWindow();
- QTest::qWait(125);
+ QTest::qWaitForWindowShown(&widget);
dial1->setFocus();
- QVERIFY(dial1->hasFocus());
+ QTRY_VERIFY(dial1->hasFocus());
EventSpy focusInSpy_1(widget1, QEvent::FocusIn);
EventSpy focusOutSpy_1(widget1, QEvent::FocusOut);
@@ -3291,78 +3294,79 @@ void tst_QGraphicsScene::tabFocus_sceneWithNestedFocusWidgets()
EventSpy focusOutSpy_2(widget2, QEvent::FocusOut);
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
- QTest::qWait(125);
- QVERIFY(widget1->hasFocus());
+ QApplication::processEvents();
+ QTRY_VERIFY(widget1->hasFocus());
QCOMPARE(focusInSpy_1.count(), 1);
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
- QTest::qWait(125);
- QVERIFY(!widget1->hasFocus());
+ QApplication::processEvents();
+ QTRY_VERIFY(!widget1->hasFocus());
QVERIFY(widget1_1->hasFocus());
QCOMPARE(focusOutSpy_1.count(), 1);
QCOMPARE(focusInSpy_1_1.count(), 1);
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
- QTest::qWait(125);
- QVERIFY(!widget1_1->hasFocus());
+ QApplication::processEvents();
+ QTRY_VERIFY(!widget1_1->hasFocus());
QVERIFY(widget1_2->hasFocus());
QCOMPARE(focusOutSpy_1_1.count(), 1);
QCOMPARE(focusInSpy_1_2.count(), 1);
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
- QTest::qWait(125);
- QVERIFY(!widget1_2->hasFocus());
+ QApplication::processEvents();
+ QTRY_VERIFY(!widget1_2->hasFocus());
QVERIFY(widget2->hasFocus());
QCOMPARE(focusOutSpy_1_2.count(), 1);
QCOMPARE(focusInSpy_2.count(), 1);
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
- QTest::qWait(125);
- QVERIFY(!widget2->hasFocus());
+ QApplication::processEvents();
+ QTRY_VERIFY(!widget2->hasFocus());
QVERIFY(dial2->hasFocus());
QCOMPARE(focusOutSpy_2.count(), 1);
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
- QTest::qWait(125);
- QVERIFY(widget2->hasFocus());
+ QApplication::processEvents();
+ QTRY_VERIFY(widget2->hasFocus());
QCOMPARE(focusInSpy_2.count(), 2);
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
- QTest::qWait(125);
- QVERIFY(!widget2->hasFocus());
- QVERIFY(widget1_2->hasFocus());
+ QApplication::processEvents();
+ QTRY_VERIFY(!widget2->hasFocus());
+ QTRY_VERIFY(widget1_2->hasFocus());
QCOMPARE(focusOutSpy_2.count(), 2);
QCOMPARE(focusInSpy_1_2.count(), 2);
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
- QTest::qWait(125);
- QVERIFY(!widget1_2->hasFocus());
- QVERIFY(widget1_1->hasFocus());
+ QApplication::processEvents();
+ QTRY_VERIFY(!widget1_2->hasFocus());
+ QTRY_VERIFY(widget1_1->hasFocus());
QCOMPARE(focusOutSpy_1_2.count(), 2);
QCOMPARE(focusInSpy_1_1.count(), 2);
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
- QTest::qWait(125);
- QVERIFY(!widget1_1->hasFocus());
- QVERIFY(widget1->hasFocus());
+ QApplication::processEvents();
+ QTRY_VERIFY(!widget1_1->hasFocus());
+ QTRY_VERIFY(widget1->hasFocus());
QCOMPARE(focusOutSpy_1_1.count(), 2);
QCOMPARE(focusInSpy_1.count(), 2);
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
- QTest::qWait(125);
- QVERIFY(!widget1->hasFocus());
- QVERIFY(dial1->hasFocus());
+ QApplication::processEvents();
+ QTRY_VERIFY(!widget1->hasFocus());
+ QTRY_VERIFY(dial1->hasFocus());
QCOMPARE(focusOutSpy_1.count(), 2);
widget1->setFocus();
view->viewport()->setFocus();
widget.hide();
- QTest::qWait(125);
+ QTest::qWait(12);
widget.show();
qApp->setActiveWindow(&widget);
widget.activateWindow();
- QTest::qWait(125);
- QVERIFY(widget1->hasFocus());
+ QTest::qWaitForWindowShown(&widget);
+ QApplication::processEvents();
+ QTRY_VERIFY(widget1->hasFocus());
}
void tst_QGraphicsScene::style()
@@ -3454,10 +3458,10 @@ void tst_QGraphicsScene::task139782_containsItemBoundingRect()
void tst_QGraphicsScene::task176178_itemIndexMethodBreaksSceneRect()
{
- QGraphicsScene scene;
- scene.setItemIndexMethod(QGraphicsScene::NoIndex);
- QGraphicsRectItem *rect = new QGraphicsRectItem;
- rect->setRect(0,0,100,100);
+ QGraphicsScene scene;
+ scene.setItemIndexMethod(QGraphicsScene::NoIndex);
+ QGraphicsRectItem *rect = new QGraphicsRectItem;
+ rect->setRect(0,0,100,100);
scene.addItem(rect);
QCOMPARE(scene.sceneRect(), rect->rect());
}
@@ -3518,7 +3522,7 @@ void tst_QGraphicsScene::sorting_data()
void tst_QGraphicsScene::sorting()
{
QFETCH(bool, cache);
-
+
QGraphicsScene scene;
scene.setSortCacheEnabled(cache);
@@ -3552,15 +3556,15 @@ void tst_QGraphicsScene::sorting()
c_2_1_1->setPos(-16, 16);
c_2_2->setPos(-16, 28);
c_2_2->setZValue(1);
-
- c_1->setFlag(QGraphicsItem::ItemIsMovable);
- c_1_1->setFlag(QGraphicsItem::ItemIsMovable);
- c_1_1_1->setFlag(QGraphicsItem::ItemIsMovable);
- c_1_2->setFlag(QGraphicsItem::ItemIsMovable);
- c_2->setFlag(QGraphicsItem::ItemIsMovable);
- c_2_1->setFlag(QGraphicsItem::ItemIsMovable);
- c_2_1_1->setFlag(QGraphicsItem::ItemIsMovable);
- c_2_2->setFlag(QGraphicsItem::ItemIsMovable);
+
+ c_1->setFlag(QGraphicsItem::ItemIsMovable);
+ c_1_1->setFlag(QGraphicsItem::ItemIsMovable);
+ c_1_1_1->setFlag(QGraphicsItem::ItemIsMovable);
+ c_1_2->setFlag(QGraphicsItem::ItemIsMovable);
+ c_2->setFlag(QGraphicsItem::ItemIsMovable);
+ c_2_1->setFlag(QGraphicsItem::ItemIsMovable);
+ c_2_1_1->setFlag(QGraphicsItem::ItemIsMovable);
+ c_2_2->setFlag(QGraphicsItem::ItemIsMovable);
t_1->setData(0, "t_1");
c_1->setData(0, "c_1");
@@ -3585,7 +3589,7 @@ void tst_QGraphicsScene::sorting()
foreach (QGraphicsItem *item, scene.items(32, 31, 4, 55))
qDebug() << "\t" << item->data(0).toString();
qDebug() << "}";
-
+
QCOMPARE(scene.items(32, 31, 4, 55),
QList<QGraphicsItem *>()
<< c_1_2 << c_1_1_1 << c_1 << t_1);
diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
index 0c27079..78fb4f3 100644
--- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
+++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
@@ -3160,11 +3160,12 @@ void tst_QGraphicsView::moveItemWhileScrolling()
if (!adjustForAntialiasing)
view.setOptimizationFlag(QGraphicsView::DontAdjustForAntialiasing);
view.resize(200, 200);
+ view.painted = false;
view.show();
QTest::qWaitForWindowShown(&view);
+ QApplication::processEvents();
QTRY_VERIFY(view.painted);
view.painted = false;
-
view.lastPaintedRegion = QRegion();
view.horizontalScrollBar()->setValue(view.horizontalScrollBar()->value() + 10);
view.rect->moveBy(0, 10);
@@ -3366,6 +3367,7 @@ void tst_QGraphicsView::render()
view.painted = false;
view.show();
QTest::qWaitForWindowShown(&view);
+ QApplication::processEvents();
QTRY_VERIFY(view.painted > 0);
RenderTester *r1 = new RenderTester(QRectF(0, 0, 50, 50));
diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
index b6750ea..0b73733 100644
--- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
+++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
@@ -1456,7 +1456,7 @@ void tst_QGraphicsWidget::verifyFocusChain()
scene.addItem(w1_4);
QTRY_VERIFY(w1_3->hasFocus());
QTest::qWait(25);
- QVERIFY(compareFocusChain(view, QList<QGraphicsItem*>() << w1_3 << w1_4));
+ QTRY_VERIFY(compareFocusChain(view, QList<QGraphicsItem*>() << w1_3 << w1_4));
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
QTest::qWait(25);
QTRY_VERIFY(lineEdit->hasFocus());
diff --git a/tests/auto/qgridlayout/tst_qgridlayout.cpp b/tests/auto/qgridlayout/tst_qgridlayout.cpp
index 4a5a341..7c320be 100644
--- a/tests/auto/qgridlayout/tst_qgridlayout.cpp
+++ b/tests/auto/qgridlayout/tst_qgridlayout.cpp
@@ -884,6 +884,7 @@ void tst_QGridLayout::minMaxSize()
for (int pass = 0; pass < 2; ++pass) {
m_toplevel->hide();
QApplication::processEvents();
+ QTest::qWait(20);
// Test if removeItem uninitializes data properly
while (m_grid->count()) {
QLayoutItem *item = m_grid->itemAt(0);
@@ -921,7 +922,7 @@ void tst_QGridLayout::minMaxSize()
#endif
QTest::qWait(20);
m_toplevel->adjustSize();
- QTest::qWait(20); // wait for the implicit adjustSize
+ QTest::qWait(120); // wait for the implicit adjustSize
// If the following fails we might have to wait longer.
// If that does not help there is likely a problem with the implicit adjustSize in show()
if (!fixedSize.isValid()) {
diff --git a/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp b/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp
index 470e57f..6036a14 100644
--- a/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp
+++ b/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp
@@ -106,6 +106,7 @@ private Q_SLOTS:
void getMultiple_data();
void getMultiple();
void getMultipleWithPipeliningAndMultiplePriorities();
+ void getMultipleWithPriorities();
};
tst_QHttpNetworkConnection::tst_QHttpNetworkConnection()
@@ -908,5 +909,63 @@ void tst_QHttpNetworkConnection::getMultipleWithPipeliningAndMultiplePriorities(
qDeleteAll(replies);
}
+class GetMultipleWithPrioritiesReceiver : public QObject
+{
+ Q_OBJECT
+public:
+ int highPrioReceived;
+ int lowPrioReceived;
+ int requestCount;
+ GetMultipleWithPrioritiesReceiver(int rq) : highPrioReceived(0), lowPrioReceived(0), requestCount(rq) { }
+public Q_SLOTS:
+ void finishedSlot() {
+ QHttpNetworkReply *reply = (QHttpNetworkReply*) sender();
+ if (reply->request().priority() == QHttpNetworkRequest::HighPriority)
+ highPrioReceived++;
+ else if (reply->request().priority() == QHttpNetworkRequest::LowPriority)
+ lowPrioReceived++;
+ else
+ QFAIL("Wrong priority!?");
+
+ QVERIFY(highPrioReceived >= lowPrioReceived);
+
+ if (highPrioReceived + lowPrioReceived == requestCount)
+ QTestEventLoop::instance().exitLoop();
+ }
+};
+
+void tst_QHttpNetworkConnection::getMultipleWithPriorities()
+{
+ quint16 requestCount = 100;
+ // use 2 connections.
+ QHttpNetworkConnection connection(2, QtNetworkSettings::serverName());
+ GetMultipleWithPrioritiesReceiver receiver(requestCount);
+ QUrl url("http://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt");
+ QList<QHttpNetworkRequest*> requests;
+ QList<QHttpNetworkReply*> replies;
+
+ for (int i = 0; i < requestCount; i++) {
+ QHttpNetworkRequest *request = new QHttpNetworkRequest(url);;
+
+ if (i % 2)
+ request->setPriority(QHttpNetworkRequest::HighPriority);
+ else
+ request->setPriority(QHttpNetworkRequest::LowPriority);
+
+ requests.append(request);
+ QHttpNetworkReply *reply = connection.sendRequest(*request);
+ connect(reply, SIGNAL(finished()), &receiver, SLOT(finishedSlot()));
+ replies.append(reply);
+ }
+
+ QTestEventLoop::instance().enterLoop(40);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+
+ qDeleteAll(requests);
+ qDeleteAll(replies);
+}
+
+
+
QTEST_MAIN(tst_QHttpNetworkConnection)
#include "tst_qhttpnetworkconnection.moc"
diff --git a/tests/auto/qicon/image.tga b/tests/auto/qicon/image.tga
deleted file mode 100644
index 0cd507d..0000000
--- a/tests/auto/qicon/image.tga
+++ /dev/null
Binary files differ
diff --git a/tests/auto/qicon/qicon.pro b/tests/auto/qicon/qicon.pro
index 0c9c7e9..8ae252f 100644
--- a/tests/auto/qicon/qicon.pro
+++ b/tests/auto/qicon/qicon.pro
@@ -6,9 +6,9 @@ RESOURCES = tst_qicon.qrc
wince* {
QT += xml svg
addFiles.sources += $$_PRO_FILE_PWD_/*.png
- addFiles.sources += $$_PRO_FILE_PWD_/*.tga
addFiles.sources += $$_PRO_FILE_PWD_/*.svg
addFiles.sources += $$_PRO_FILE_PWD_/*.svgz
+ addFiles.sources += $$_PRO_FILE_PWD_/tst_qicon.cpp
addFiles.path = .
DEPLOYMENT += addFiles
@@ -16,7 +16,7 @@ wince* {
DEFINES += SRCDIR=\\\".\\\"
} else:symbian {
QT += xml svg
- addFiles.sources = *.png *.tga *.svg *.svgz
+ addFiles.sources = *.png tst_qicon.cpp *.svg *.svgz
addFiles.path = .
plugins.sources = qsvgicon.dll
plugins.path = iconengines
diff --git a/tests/auto/qicon/tst_qicon.cpp b/tests/auto/qicon/tst_qicon.cpp
index 96d1d6c..f5baeaa 100644
--- a/tests/auto/qicon/tst_qicon.cpp
+++ b/tests/auto/qicon/tst_qicon.cpp
@@ -242,7 +242,7 @@ void tst_QIcon::isNull() {
const QString prefix = QLatin1String(SRCDIR) + QLatin1String("/");
// test string constructor with existing file but unsupported format
- QIcon iconUnsupportedFormat = QIcon(prefix + "image.tga");
+ QIcon iconUnsupportedFormat = QIcon(prefix + "tst_qicon.cpp");
QVERIFY(!iconUnsupportedFormat.isNull());
QVERIFY(!iconUnsupportedFormat.actualSize(QSize(32, 32)).isValid());
diff --git a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp
index 5d1034a..426887d 100644
--- a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp
+++ b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp
@@ -865,7 +865,7 @@ void tst_QItemDelegate::decoration()
qt_x11_wait_for_window_manager(&table);
#endif
QApplication::setActiveWindow(&table);
- QTRY_COMPARE(QApplication::activeWindow(), &table);
+ QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget*>(&table));
QVariant value;
switch ((QVariant::Type)type) {
diff --git a/tests/auto/qmdiarea/tst_qmdiarea.cpp b/tests/auto/qmdiarea/tst_qmdiarea.cpp
index b110114..725c31e 100644
--- a/tests/auto/qmdiarea/tst_qmdiarea.cpp
+++ b/tests/auto/qmdiarea/tst_qmdiarea.cpp
@@ -468,6 +468,7 @@ void tst_QMdiArea::subWindowActivated2()
#ifdef Q_WS_X11
qt_x11_wait_for_window_manager(&mdiArea);
#endif
+ QTest::qWait(100);
QTRY_COMPARE(spy.count(), 5);
QCOMPARE(mdiArea.activeSubWindow(), mdiArea.subWindowList().back());
diff --git a/tests/auto/qmdisubwindow/tst_qmdisubwindow.cpp b/tests/auto/qmdisubwindow/tst_qmdisubwindow.cpp
index b897d8f..2d70bef 100644
--- a/tests/auto/qmdisubwindow/tst_qmdisubwindow.cpp
+++ b/tests/auto/qmdisubwindow/tst_qmdisubwindow.cpp
@@ -1065,6 +1065,7 @@ void tst_QMdiSubWindow::setSystemMenu()
qApp->setLayoutDirection(Qt::RightToLeft);
qApp->processEvents();
mainWindow.updateGeometry();
+ QTest::qWait(150);
subWindow->showSystemMenu();
QTest::qWait(250);
diff --git a/tests/auto/qmessagebox/tst_qmessagebox.cpp b/tests/auto/qmessagebox/tst_qmessagebox.cpp
index 5607fbd..1f8e925 100644
--- a/tests/auto/qmessagebox/tst_qmessagebox.cpp
+++ b/tests/auto/qmessagebox/tst_qmessagebox.cpp
@@ -714,7 +714,8 @@ void tst_QMessageBox::setInformativeText()
msgbox.setInformativeText(itext);
msgbox.show();
QCOMPARE(msgbox.informativeText(), itext);
- QVERIFY(msgbox.width() > 200); //verify it's big enough (task181688)
+ QVERIFY2(msgbox.width() > 190, //verify it's big enough (task181688)
+ qPrintable(QString("%1 > 190").arg(msgbox.width())));
}
void tst_QMessageBox::iconPixmap()
diff --git a/tests/auto/qpixmap/qpixmap.pro b/tests/auto/qpixmap/qpixmap.pro
index 31d6eaa..a3577bd 100644
--- a/tests/auto/qpixmap/qpixmap.pro
+++ b/tests/auto/qpixmap/qpixmap.pro
@@ -2,16 +2,23 @@ load(qttest_p4)
SOURCES += tst_qpixmap.cpp
contains(QT_CONFIG, qt3support): QT += qt3support
wince*|symbian*: {
- task31722_0.sources = convertFromImage/task31722_0/*
+
+ task31722_0.sources = convertFromImage/task31722_0/*.png
task31722_0.path = convertFromImage/task31722_0
- task31722_1.sources = convertFromImage/task31722_1/*
+
+ task31722_1.sources = convertFromImage/task31722_1/*.png
task31722_1.path = convertFromImage/task31722_1
- DEPLOYMENT += task31722_0 task31722_1
+
+ icons.sources = convertFromToHICON/*
+ icons.path = convertFromToHICON
+
+ DEPLOYMENT += task31722_0 task31722_1 icons
+ DEPLOYMENT_PLUGIN += qico
}
wince*: {
DEFINES += SRCDIR=\\\".\\\"
-} symbian*: {
+} else:symbian* {
DEPLOYMENT_PLUGIN += qmng
LIBS += -lfbscli.dll -lbitgdi.dll -lgdi.dll
contains(QT_CONFIG, openvg) {
diff --git a/tests/auto/qpixmap/tst_qpixmap.cpp b/tests/auto/qpixmap/tst_qpixmap.cpp
index 1bfddc1..2568b94 100644
--- a/tests/auto/qpixmap/tst_qpixmap.cpp
+++ b/tests/auto/qpixmap/tst_qpixmap.cpp
@@ -67,6 +67,9 @@
#include <bitdev.h>
#endif
+#ifdef Q_WS_X11
+#include <QX11Info>
+#endif
//TESTED_CLASS=
//TESTED_FILES=
@@ -175,6 +178,12 @@ static bool lenientCompare(const QPixmap &actual, const QPixmap &expected)
int size = actual.width() * actual.height();
+ int threshold = 2;
+#ifdef Q_WS_X11
+ if (QX11Info::appDepth() == 16)
+ threshold = 10;
+#endif
+
QRgb *a = (QRgb *)actualImage.bits();
QRgb *e = (QRgb *)expectedImage.bits();
for (int i = 0; i < size; ++i) {
@@ -183,11 +192,11 @@ static bool lenientCompare(const QPixmap &actual, const QPixmap &expected)
bool result = true;
- if (qAbs(ca.red() - ce.red()) > 2)
+ if (qAbs(ca.red() - ce.red()) > threshold)
result = false;
- if (qAbs(ca.green() - ce.green()) > 2)
+ if (qAbs(ca.green() - ce.green()) > threshold)
result = false;
- if (qAbs(ca.blue() - ce.blue()) > 2)
+ if (qAbs(ca.blue() - ce.blue()) > threshold)
result = false;
if (!result)
@@ -293,15 +302,23 @@ void tst_QPixmap::setAlphaChannel()
void tst_QPixmap::fromImage_data()
{
+ bool is16bit = false;
+#ifdef Q_WS_X11
+ if (QX11Info::appDepth() == 16)
+ is16bit = true;
+#endif
+
QTest::addColumn<QImage::Format>("format");
QTest::newRow("Format_Mono") << QImage::Format_Mono;
QTest::newRow("Format_MonoLSB") << QImage::Format_MonoLSB;
// QTest::newRow("Format_Indexed8") << QImage::Format_Indexed8;
- QTest::newRow("Format_RGB32") << QImage::Format_RGB32;
+ if (!is16bit)
+ QTest::newRow("Format_RGB32") << QImage::Format_RGB32;
QTest::newRow("Format_ARGB32") << QImage::Format_ARGB32;
QTest::newRow("Format_ARGB32_Premultiplied") << QImage::Format_ARGB32_Premultiplied;
- QTest::newRow("Format_RGB16") << QImage::Format_RGB16;
+ if (!is16bit)
+ QTest::newRow("Format_RGB16") << QImage::Format_RGB16;
}
void tst_QPixmap::fromImage()
@@ -986,7 +1003,7 @@ static void compareImages(const QImage &image1, const QImage &image2)
QRgb p1 = image1.pixel(x, y);
QRgb p2 = image2.pixel(x, y);
- bool pixelMatches =
+ bool pixelMatches =
qAbs(qRed(p1) - qRed(p2)) <= fuzz
&& qAbs(qGreen(p1) - qGreen(p2)) <= fuzz
&& qAbs(qBlue(p1) - qBlue(p2)) <= fuzz
@@ -1017,6 +1034,10 @@ void tst_QPixmap::toWinHICON_data()
void tst_QPixmap::toWinHICON()
{
+#ifdef Q_OS_WINCE
+ QSKIP("Test shall be enabled for Windows CE shortly.", SkipAll);
+#endif
+
QFETCH(int, width);
QFETCH(int, height);
QFETCH(QString, image);
@@ -1057,6 +1078,10 @@ void tst_QPixmap::fromWinHICON_data()
void tst_QPixmap::fromWinHICON()
{
+#ifdef Q_OS_WINCE
+ QSKIP("Test shall be enabled for Windows CE shortly.", SkipAll);
+
+#else
QFETCH(int, width);
QFETCH(int, height);
QFETCH(QString, image);
@@ -1073,6 +1098,7 @@ void tst_QPixmap::fromWinHICON()
// QVERIFY(imageFromHICON == imageFromFile);
compareImages(imageFromHICON, imageFromFile);
+#endif
}
#endif // Q_WS_WIN
diff --git a/tests/auto/qprinterinfo/tst_qprinterinfo.cpp b/tests/auto/qprinterinfo/tst_qprinterinfo.cpp
index e397b76..7352524 100644
--- a/tests/auto/qprinterinfo/tst_qprinterinfo.cpp
+++ b/tests/auto/qprinterinfo/tst_qprinterinfo.cpp
@@ -101,6 +101,8 @@ void tst_QPrinterInfo::macFixNameFormat(QString *printerName)
#ifdef Q_WS_MAC
printerName->replace(QLatin1String("___"), QLatin1String(" @ "));
printerName->replace(QLatin1String("_"), QLatin1String("."));
+#else
+ Q_UNUSED(printerName);
#endif
}
@@ -132,7 +134,7 @@ QStringList tst_QPrinterInfo::getPrintersFromSystem()
QString output = getOutputFromCommand(command);
QStringList list = output.split(QChar::fromLatin1('\n'));
- QRegExp reg("^[Pp]rinter ([a-zA-Z0-9_]+)");
+ QRegExp reg("^[Pp]rinter ([.a-zA-Z0-9_-]+)");
for (int c = 0; c < list.size(); ++c) {
if (reg.indexIn(list[c]) >= 0) {
QString printer = reg.cap(1);
@@ -282,16 +284,17 @@ void tst_QPrinterInfo::testForPrinters()
QCOMPARE(printers.size(), sysPrinters.size());
+ QHash<QString, bool> qtPrinters;
+
+ for (int j = 0; j < printers.size(); ++j) {
+ qtPrinters.insert(printers.at(j).printerName(), !printers.at(j).isNull());
+ }
+
for (int i = 0; i < sysPrinters.size(); ++i) {
- bool found = false;
- for (int j = 0; j < printers.size(); ++j) {
- if (sysPrinters.at(i) == printers.at(j).printerName()) {
- QVERIFY(!printers.at(j).isNull());
- found = true;
- break;
- }
+ if (!qtPrinters.value(sysPrinters.at(i))) {
+ qDebug() << "Avaliable printers: " << qtPrinters;
+ QFAIL(qPrintable(QString("Printer '%1' reported by system, but not reported by Qt").arg(sysPrinters.at(i))));
}
- if (!found) QFAIL("Printer reported by system, but not reported by Qt");
}
#else
QSKIP("Test doesn't work on non-Unix", SkipAll);
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp
index 183aa3f..25ee00f 100644
--- a/tests/auto/qscriptengine/tst_qscriptengine.cpp
+++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp
@@ -48,6 +48,7 @@
#include <qgraphicsitem.h>
#include <qstandarditemmodel.h>
#include <QtCore/qnumeric.h>
+#include <stdlib.h>
Q_DECLARE_METATYPE(QList<int>)
Q_DECLARE_METATYPE(QObjectList)
@@ -60,6 +61,22 @@ Q_DECLARE_METATYPE(QObjectList)
# define TOSTRING(x) STRINGIFY(x)
# define SRCDIR "C:/Private/" TOSTRING(SYMBIAN_SRCDIR_UID)
#endif
+
+// The JavaScriptCore GC marks the C stack. To try to ensure that there is
+// no JSObject* left in stack memory by the compiler, we call this function
+// to zap some bytes of memory before calling collectGarbage().
+static void zapSomeStack()
+{
+ char buf[4096];
+ memset(buf, 0, sizeof(buf));
+}
+
+static void collectGarbage_helper(QScriptEngine &eng)
+{
+ zapSomeStack();
+ eng.collectGarbage();
+}
+
class tst_QScriptEngine : public QObject
{
Q_OBJECT
@@ -825,7 +842,7 @@ void tst_QScriptEngine::newQMetaObject()
// verify that AutoOwnership is in effect
instance = QScriptValue();
- eng.collectGarbage();
+ collectGarbage_helper(eng);
QVERIFY(!qpointer1);
QVERIFY(qpointer2);
@@ -835,7 +852,7 @@ void tst_QScriptEngine::newQMetaObject()
QVERIFY(instance3.toQObject() == 0); // was child of instance
QVERIFY(instance2.toQObject() != 0);
instance2 = QScriptValue();
- eng.collectGarbage();
+ collectGarbage_helper(eng);
QVERIFY(instance2.toQObject() == 0);
// with custom constructor
@@ -922,14 +939,14 @@ void tst_QScriptEngine::getSetGlobalObject()
QCOMPARE(eng.globalObject().toString(), QString::fromLatin1("[object Object]"));
glob = QScriptValue(); // kill reference to old global object
- eng.collectGarbage();
+ collectGarbage_helper(eng);
obj = eng.newObject();
eng.setGlobalObject(obj);
QVERIFY(eng.globalObject().strictlyEquals(obj));
QVERIFY(eng.currentContext()->thisObject().strictlyEquals(obj));
QVERIFY(eng.currentContext()->activationObject().strictlyEquals(obj));
- eng.collectGarbage();
+ collectGarbage_helper(eng);
QVERIFY(eng.globalObject().strictlyEquals(obj));
QVERIFY(eng.currentContext()->thisObject().strictlyEquals(obj));
QVERIFY(eng.currentContext()->activationObject().strictlyEquals(obj));
@@ -1632,7 +1649,6 @@ void tst_QScriptEngine::errorMessage_QT679()
engine.globalObject().setProperty("foo", 15);
QScriptValue error = engine.evaluate("'hello world';\nfoo.bar.blah");
QVERIFY(error.isError());
- QEXPECT_FAIL("", "Task QT-679: the error message always contains the first line of the script, even if the error was on a different line", Continue);
QCOMPARE(error.toString(), QString::fromLatin1("TypeError: Result of expression 'foo.bar' [undefined] is not an object."));
}
@@ -2342,11 +2358,8 @@ void tst_QScriptEngine::collectGarbage()
a = eng.newObject();
QPointer<QObject> ptr = new QObject();
QVERIFY(ptr != 0);
- {
- QScriptValue v = eng.newQObject(ptr, QScriptEngine::ScriptOwnership);
- }
- eng.collectGarbage();
- QEXPECT_FAIL("","collectGarbage not working", Continue);
+ (void)eng.newQObject(ptr, QScriptEngine::ScriptOwnership);
+ collectGarbage_helper(eng);
QVERIFY(ptr == 0);
}
diff --git a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp
index 82bca8f..283e489 100644
--- a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp
+++ b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp
@@ -1193,10 +1193,15 @@ void tst_QScriptEngineAgent::positionChange_1()
QCOMPARE(spy->at(0).columnNumber, 1);
}
- {
+ QStringList lineTerminators;
+ lineTerminators << "\n" << "\r" << "\n\r" << "\r\n";
+ for (int i = 0; i < lineTerminators.size(); ++i) {
spy->clear();
int lineNumber = 456;
- eng.evaluate("1 + 2; 3 + 4;\n5 + 6", "foo.qs", lineNumber);
+ QString code = "1 + 2; 3 + 4;";
+ code.append(lineTerminators.at(i));
+ code.append("5 + 6");
+ eng.evaluate(code, "foo.qs", lineNumber);
QCOMPARE(spy->count(), 3);
// 1 + 2
diff --git a/tests/auto/qscriptjstestsuite/tst_qscriptjstestsuite.cpp b/tests/auto/qscriptjstestsuite/tst_qscriptjstestsuite.cpp
index 94f08d9..4f4c547 100644
--- a/tests/auto/qscriptjstestsuite/tst_qscriptjstestsuite.cpp
+++ b/tests/auto/qscriptjstestsuite/tst_qscriptjstestsuite.cpp
@@ -649,6 +649,8 @@ tst_Suite::tst_Suite()
addFileExclusion("regress-322135-04.js", "takes forever");
addFileExclusion("ecma_3/RegExp/regress-375715-04.js", "bug");
+ addFileExclusion("ecma_3/RegExp/regress-289669.js", "Can fail due to relying on wall-clock time");
+
// Failures due to switch to JSC as back-end
addExpectedFailure("ecma/Array/15.4.3.1-2.js", "var props = ''; for ( p in Array ) { props += p } props", willFixInNextReleaseMessage);
addExpectedFailure("ecma/Boolean/15.6.3.1-1.js", "var str='';for ( p in Boolean ) { str += p } str;", willFixInNextReleaseMessage);
diff --git a/tests/auto/qstatusbar/tst_qstatusbar.cpp b/tests/auto/qstatusbar/tst_qstatusbar.cpp
index 3727882..9774559 100644
--- a/tests/auto/qstatusbar/tst_qstatusbar.cpp
+++ b/tests/auto/qstatusbar/tst_qstatusbar.cpp
@@ -48,6 +48,8 @@
#include <QMainWindow>
#include <QSizeGrip>
+#include "../../shared/util.h"
+
//TESTED_CLASS=
//TESTED_FILES=
@@ -177,7 +179,7 @@ void tst_QStatusBar::setSizeGripEnabled()
qt_x11_wait_for_window_manager(&mainWindow);
#endif
- QVERIFY(statusBar->isVisible());
+ QTRY_VERIFY(statusBar->isVisible());
QPointer<QSizeGrip> sizeGrip = qFindChild<QSizeGrip *>(statusBar);
QVERIFY(sizeGrip);
QVERIFY(sizeGrip->isVisible());
@@ -223,11 +225,8 @@ void tst_QStatusBar::setSizeGripEnabled()
qApp->processEvents();
mainWindow.showNormal();
-#ifdef Q_WS_X11
- qt_x11_wait_for_window_manager(&mainWindow);
-#endif
qApp->processEvents();
- QVERIFY(sizeGrip->isVisible());
+ QTRY_VERIFY(sizeGrip->isVisible());
}
void tst_QStatusBar::task194017_hiddenWidget()
diff --git a/tests/auto/qtableview/tst_qtableview.cpp b/tests/auto/qtableview/tst_qtableview.cpp
index 71218a3..03f4966 100644
--- a/tests/auto/qtableview/tst_qtableview.cpp
+++ b/tests/auto/qtableview/tst_qtableview.cpp
@@ -378,7 +378,6 @@ public:
}
bool checkSignalOrder;
- using QTableView::wheelEvent;
public slots:
void currentChanged(QModelIndex , QModelIndex ) {
hasCurrentChanged++;
@@ -3222,6 +3221,7 @@ void tst_QTableView::mouseWheel()
for (int c = 0; c < 100; ++c)
view.setColumnWidth(c, 100);
view.show();
+ QTest::qWaitForWindowShown(&view);
view.setModel(&model);
@@ -3230,12 +3230,13 @@ void tst_QTableView::mouseWheel()
view.horizontalScrollBar()->setValue(10);
view.verticalScrollBar()->setValue(10);
- QPoint pos(100,100);
+ qDebug() << "delta" << delta << view.viewport()->geometry();
+ QPoint pos = view.viewport()->geometry().center();
QWheelEvent verticalEvent(pos, delta, 0, 0, Qt::Vertical);
QWheelEvent horizontalEvent(pos, delta, 0, 0, Qt::Horizontal);
- view.wheelEvent(&horizontalEvent);
+ QApplication::sendEvent(view.viewport(), &horizontalEvent);
QVERIFY(qAbs(view.horizontalScrollBar()->value() - horizontalPositon) < 10);
- view.wheelEvent(&verticalEvent);
+ QApplication::sendEvent(view.viewport(), &verticalEvent);
QVERIFY(qAbs(view.verticalScrollBar()->value() - verticalPosition) < 10);
}
diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp
index 112bcc8..91b2cc5 100644
--- a/tests/auto/qtreeview/tst_qtreeview.cpp
+++ b/tests/auto/qtreeview/tst_qtreeview.cpp
@@ -3113,7 +3113,7 @@ void tst_QTreeView::task224091_appendColumns()
treeView->show();
treeView->resize(50,50);
- QTest::qWait(50);
+ QTest::qWaitForWindowShown(treeView);
qApp->processEvents();
QList<QStandardItem *> projlist;
@@ -3125,7 +3125,7 @@ void tst_QTreeView::task224091_appendColumns()
QTest::qWait(50);
qApp->processEvents();
- QVERIFY(treeView->verticalScrollBar()->isVisible());
+ QTRY_VERIFY(treeView->verticalScrollBar()->isVisible());
delete treeView;
delete model;
diff --git a/tests/auto/qwidget/qwidget.pro b/tests/auto/qwidget/qwidget.pro
index def28f5..61db2ee 100644
--- a/tests/auto/qwidget/qwidget.pro
+++ b/tests/auto/qwidget/qwidget.pro
@@ -10,8 +10,8 @@ aix-g++*:QMAKE_CXXFLAGS+=-fpermissive
CONFIG += x11inc
mac {
-LIBS += -framework Security -framework AppKit
-OBJECTIVE_SOURCES += tst_qwidget_mac_helpers.mm
+ LIBS += -framework Security -framework AppKit -framework Carbon
+ OBJECTIVE_SOURCES += tst_qwidget_mac_helpers.mm
}
symbian {
diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp
index a94ce9f..a9033ba 100644
--- a/tests/auto/qwidget/tst_qwidget.cpp
+++ b/tests/auto/qwidget/tst_qwidget.cpp
@@ -355,6 +355,7 @@ private slots:
void maskedUpdate();
#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined(Q_WS_QWS)
void syntheticEnterLeave();
+ void taskQTBUG_4055_sendSyntheticEnterLeave();
#endif
void windowFlags();
void initialPosForDontShowOnScreenWidgets();
@@ -3117,7 +3118,7 @@ void tst_QWidget::saveRestoreGeometry()
widget.resize(size);
widget.show();
QTest::qWaitForWindowShown(&widget);
- QTest::qWait(200);
+ QTest::qWait(500);
QTRY_COMPARE(widget.geometry().size(), size);
QRect geom;
@@ -3127,7 +3128,7 @@ void tst_QWidget::saveRestoreGeometry()
geom = widget.geometry();
widget.setWindowState(widget.windowState() | Qt::WindowFullScreen);
QTRY_VERIFY((widget.windowState() & Qt::WindowFullScreen));
- QTest::qWait(200);
+ QTest::qWait(500);
QVERIFY(widget.restoreGeometry(savedGeometry));
QTest::qWait(120);
QTRY_VERIFY(!(widget.windowState() & Qt::WindowFullScreen));
@@ -3137,55 +3138,55 @@ void tst_QWidget::saveRestoreGeometry()
widget.setWindowState(widget.windowState() | Qt::WindowFullScreen);
QTest::qWait(120);
QTRY_VERIFY((widget.windowState() & Qt::WindowFullScreen));
- QTest::qWait(200);
+ QTest::qWait(500);
savedGeometry = widget.saveGeometry();
geom = widget.geometry();
widget.setWindowState(widget.windowState() ^ Qt::WindowFullScreen);
- QTest::qWait(20);
+ QTest::qWait(120);
QTRY_VERIFY(!(widget.windowState() & Qt::WindowFullScreen));
- QTest::qWait(200);
+ QTest::qWait(400);
QVERIFY(widget.restoreGeometry(savedGeometry));
- QTest::qWait(20);
+ QTest::qWait(120);
QTRY_VERIFY((widget.windowState() & Qt::WindowFullScreen));
QTRY_COMPARE(widget.geometry(), geom);
QVERIFY((widget.windowState() & Qt::WindowFullScreen));
widget.setWindowState(widget.windowState() ^ Qt::WindowFullScreen);
- QTest::qWait(20);
+ QTest::qWait(120);
QTRY_VERIFY(!(widget.windowState() & Qt::WindowFullScreen));
- QTest::qWait(20);
+ QTest::qWait(120);
//Restore from Maximised
widget.move(position);
widget.resize(size);
- QTest::qWait(20);
+ QTest::qWait(10);
QTRY_COMPARE(widget.size(), size);
- QTest::qWait(200);
+ QTest::qWait(500);
savedGeometry = widget.saveGeometry();
geom = widget.geometry();
widget.setWindowState(widget.windowState() | Qt::WindowMaximized);
- QTest::qWait(20);
+ QTest::qWait(120);
QTRY_VERIFY((widget.windowState() & Qt::WindowMaximized));
QTRY_VERIFY(widget.geometry() != geom);
- QTest::qWait(200);
+ QTest::qWait(500);
QVERIFY(widget.restoreGeometry(savedGeometry));
- QTest::qWait(20);
+ QTest::qWait(120);
QTRY_COMPARE(widget.geometry(), geom);
QVERIFY(!(widget.windowState() & Qt::WindowMaximized));
//Restore to maximised
widget.setWindowState(widget.windowState() | Qt::WindowMaximized);
- QTest::qWait(20);
+ QTest::qWait(120);
QTRY_VERIFY((widget.windowState() & Qt::WindowMaximized));
- QTest::qWait(200);
+ QTest::qWait(500);
geom = widget.geometry();
savedGeometry = widget.saveGeometry();
widget.setWindowState(widget.windowState() ^ Qt::WindowMaximized);
- QTest::qWait(20);
+ QTest::qWait(120);
QTRY_VERIFY(!(widget.windowState() & Qt::WindowMaximized));
- QTest::qWait(200);
+ QTest::qWait(500);
QVERIFY(widget.restoreGeometry(savedGeometry));
- QTest::qWait(20);
+ QTest::qWait(120);
QTRY_VERIFY((widget.windowState() & Qt::WindowMaximized));
QTRY_COMPARE(widget.geometry(), geom);
}
@@ -5500,14 +5501,14 @@ void tst_QWidget::multipleToplevelFocusCheck()
w1.activateWindow();
QApplication::setActiveWindow(&w1);
QApplication::processEvents();
- QTRY_COMPARE(QApplication::activeWindow(), &w1);
+ QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&w1));
QTest::mouseDClick(&w1, Qt::LeftButton);
QTRY_COMPARE(QApplication::focusWidget(), static_cast<QWidget *>(w1.edit));
w2.activateWindow();
QApplication::setActiveWindow(&w2);
QApplication::processEvents();
- QTRY_COMPARE(QApplication::activeWindow(), &w2);
+ QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&w2));
QTest::mouseClick(&w2, Qt::LeftButton);
#ifdef Q_WS_QWS
QEXPECT_FAIL("", "embedded toplevels take focus anyway", Continue);
@@ -5520,14 +5521,14 @@ void tst_QWidget::multipleToplevelFocusCheck()
w1.activateWindow();
QApplication::setActiveWindow(&w1);
QApplication::processEvents();
- QTRY_COMPARE(QApplication::activeWindow(), &w1);
+ QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&w1));
QTest::mouseDClick(&w1, Qt::LeftButton);
QTRY_COMPARE(QApplication::focusWidget(), static_cast<QWidget *>(w1.edit));
w2.activateWindow();
QApplication::setActiveWindow(&w2);
QApplication::processEvents();
- QTRY_COMPARE(QApplication::activeWindow(), &w2);
+ QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&w2));
QTest::mouseClick(&w2, Qt::LeftButton);
QTRY_COMPARE(QApplication::focusWidget(), (QWidget *)0);
}
@@ -6151,9 +6152,6 @@ void tst_QWidget::compatibilityChildInsertedEvents()
EventRecorder::EventList()
<< qMakePair(&widget, QEvent::PolishRequest)
<< qMakePair(&widget, QEvent::Type(QEvent::User + 1))
-#ifdef Q_OS_SYMBIAN
- << qMakePair(&widget, QEvent::SymbianDeferredFocusChanged)
-#endif
#if defined(Q_WS_X11) || defined(Q_WS_WIN) || defined(Q_WS_QWS) || defined(Q_WS_S60)
<< qMakePair(&widget, QEvent::UpdateRequest)
#endif
@@ -6249,9 +6247,6 @@ void tst_QWidget::compatibilityChildInsertedEvents()
<< qMakePair(&widget, QEvent::PolishRequest)
<< qMakePair(&widget, QEvent::Type(QEvent::User + 1))
<< qMakePair(&widget, QEvent::Type(QEvent::User + 2))
-#ifdef Q_OS_SYMBIAN
- << qMakePair(&widget, QEvent::SymbianDeferredFocusChanged)
-#endif
#if defined(Q_WS_X11) || defined(Q_WS_WIN) || defined(Q_WS_QWS) || defined(Q_WS_S60)
<< qMakePair(&widget, QEvent::UpdateRequest)
#endif
@@ -6347,9 +6342,6 @@ void tst_QWidget::compatibilityChildInsertedEvents()
<< qMakePair(&widget, QEvent::PolishRequest)
<< qMakePair(&widget, QEvent::Type(QEvent::User + 1))
<< qMakePair(&widget, QEvent::Type(QEvent::User + 2))
-#ifdef Q_OS_SYMBIAN
- << qMakePair(&widget, QEvent::SymbianDeferredFocusChanged)
-#endif
#if defined(Q_WS_X11) || defined(Q_WS_WIN) || defined(Q_WS_QWS) || defined(Q_WS_S60)
<< qMakePair(&widget, QEvent::UpdateRequest)
#endif
@@ -6515,7 +6507,7 @@ void tst_QWidget::renderInvisible()
dummyFocusWidget.show();
QTest::qWaitForWindowShown(&dummyFocusWidget);
qApp->processEvents();
- QTest::qWait(100);
+ QTest::qWait(120);
// Create normal reference image.
const QSize calendarSize = calendar->size();
@@ -6530,6 +6522,7 @@ void tst_QWidget::renderInvisible()
const QSize calendarSizeResized = calendar->size() + QSize(50, 50);
calendar->resize(calendarSizeResized);
qApp->processEvents();
+ QTest::qWait(30);
QImage referenceImageResized(calendarSizeResized, QImage::Format_ARGB32);
calendar->render(&referenceImageResized);
#ifdef RENDER_DEBUG
@@ -6540,6 +6533,7 @@ void tst_QWidget::renderInvisible()
// Explicitly hide the calendar.
calendar->hide();
qApp->processEvents();
+ QTest::qWait(30);
workaroundPaletteIssue(calendar);
{ // Make sure we get the same image when the calendar is explicitly hidden.
@@ -6570,6 +6564,7 @@ void tst_QWidget::renderInvisible()
calendar->hide();
qApp->processEvents();
+ QTest::qWait(30);
{ // Calendar explicitly hidden.
QImage testImage(calendarSize, QImage::Format_ARGB32);
@@ -6637,6 +6632,7 @@ void tst_QWidget::renderInvisible()
// Navigation bar isn't explicitly hidden anymore.
navigationBar->show();
qApp->processEvents();
+ QTest::qWait(30);
QVERIFY(!calendar->isVisible());
// Now, completely mess up the layout. This will trigger an update on the layout
@@ -8055,13 +8051,8 @@ void tst_QWidget::doubleRepaint()
QTRY_COMPARE(widget.numPaintEvents, expectedRepaints);
widget.numPaintEvents = 0;
-#ifndef Q_OS_WINCE //still no proper minimizing
// Minmize: Should not trigger a repaint.
widget.showMinimized();
-#else
- // Hide: Should not trigger a repaint.
- widget.hide();
-#endif
QTest::qWait(10);
QCOMPARE(widget.numPaintEvents, 0);
widget.numPaintEvents = 0;
@@ -8070,12 +8061,7 @@ void tst_QWidget::doubleRepaint()
widget.showNormal();
QTest::qWaitForWindowShown(&widget);
QTest::qWait(10);
-#ifndef Q_OS_WINCE
QCOMPARE(widget.numPaintEvents, 0);
-#else
- // We called hide(), and then it'll get repainted once it's shown again.
- QCOMPARE(widget.numPaintEvents, 1);
-#endif
}
#ifndef Q_WS_MAC
@@ -8205,7 +8191,7 @@ void tst_QWidget::moveInResizeEvent()
testWidget.setGeometry(50, 50, 200, 200);
testWidget.show();
QTest::qWaitForWindowShown(&testWidget);
- QTest::qWait(10);
+ QTest::qWait(120);
QRect expectedGeometry(100,100, 100, 100);
QTRY_COMPARE(testWidget.geometry(), expectedGeometry);
@@ -8692,7 +8678,7 @@ void tst_QWidget::setClearAndResizeMask()
QTRY_COMPARE(child.numPaintEvents, 1);
#else
// and ensure that we don't get any updates at all.
- QCOMPARE(child.numPaintEvents, 0);
+ QTRY_COMPARE(child.numPaintEvents, 0);
#endif
QCOMPARE(topLevel.numPaintEvents, 0);
@@ -8729,9 +8715,9 @@ void tst_QWidget::setClearAndResizeMask()
QTest::qWait(200);
#ifdef Q_WS_MAC
// Mac always issues a full update when calling setMask, and we cannot force it to not do so.
- QCOMPARE(resizeChild.paintedRegion, resizeChild.mask());
+ QTRY_COMPARE(resizeChild.paintedRegion, resizeChild.mask());
#else
- QCOMPARE(resizeChild.paintedRegion, QRegion());
+ QTRY_COMPARE(resizeChild.paintedRegion, QRegion());
#endif
resizeChild.paintedRegion = QRegion();
@@ -8740,9 +8726,9 @@ void tst_QWidget::setClearAndResizeMask()
QTest::qWait(100);
#ifdef Q_WS_MAC
// Mac always issues a full update when calling setMask, and we cannot force it to not do so.
- QCOMPARE(resizeChild.paintedRegion, resizeChild.mask());
+ QTRY_COMPARE(resizeChild.paintedRegion, resizeChild.mask());
#else
- QCOMPARE(resizeChild.paintedRegion, resizeChild.mask() - oldMask);
+ QTRY_COMPARE(resizeChild.paintedRegion, resizeChild.mask() - oldMask);
#endif
}
@@ -8996,6 +8982,87 @@ void tst_QWidget::syntheticEnterLeave()
QCOMPARE(window.numEnterEvents, 0);
QCOMPARE(child1->numEnterEvents, 1);
}
+
+void tst_QWidget::taskQTBUG_4055_sendSyntheticEnterLeave()
+{
+ class SELParent : public QWidget
+ {
+ public:
+ SELParent(QWidget *parent = 0): QWidget(parent) { }
+
+ void mousePressEvent(QMouseEvent *) { child->show(); }
+ QWidget *child;
+ };
+
+ class SELChild : public QWidget
+ {
+ public:
+ SELChild(QWidget *parent = 0) : QWidget(parent), numEnterEvents(0), numMouseMoveEvents(0) {}
+ void enterEvent(QEvent *) { ++numEnterEvents; }
+ void mouseMoveEvent(QMouseEvent *event)
+ {
+ QCOMPARE(event->button(), Qt::NoButton);
+ QCOMPARE(event->buttons(), Qt::MouseButtons(Qt::NoButton));
+ ++numMouseMoveEvents;
+ }
+ void reset() { numEnterEvents = numMouseMoveEvents = 0; }
+ int numEnterEvents, numMouseMoveEvents;
+ };
+
+ SELParent parent;
+ parent.resize(200, 200);
+ SELChild child(&parent);
+ child.resize(200, 200);
+ parent.show();
+ #ifdef Q_WS_X11
+ qt_x11_wait_for_window_manager(&parent);
+ #endif
+ QTest::qWait(100);
+
+ QCursor::setPos(child.mapToGlobal(QPoint(100, 100)));
+ QTest::qWait(100);
+ // Make sure the cursor has entered the child.
+ QVERIFY(child.numEnterEvents > 0);
+
+ child.hide();
+ child.reset();
+ child.show();
+
+ // Make sure the child gets enter event and no mouse move event.
+ QCOMPARE(child.numEnterEvents, 1);
+ QCOMPARE(child.numMouseMoveEvents, 0);
+
+ child.hide();
+ child.reset();
+ child.setMouseTracking(true);
+ child.show();
+
+ // Make sure the child gets enter event and mouse move event.
+ // Note that we verify event->button() and event->buttons()
+ // in SELChild::mouseMoveEvent().
+ QCOMPARE(child.numEnterEvents, 1);
+ QCOMPARE(child.numMouseMoveEvents, 1);
+
+ // Sending synthetic enter/leave trough the parent's mousePressEvent handler.
+ parent.child = &child;
+
+ child.hide();
+ child.reset();
+ QTest::mouseClick(&parent, Qt::LeftButton);
+
+ // Make sure the child gets enter event and one mouse move event.
+ QCOMPARE(child.numEnterEvents, 1);
+ QCOMPARE(child.numMouseMoveEvents, 1);
+
+ child.hide();
+ child.reset();
+ child.setMouseTracking(false);
+ QTest::mouseClick(&parent, Qt::LeftButton);
+
+ // Make sure the child gets enter event and no mouse move event.
+ QCOMPARE(child.numEnterEvents, 1);
+ QCOMPARE(child.numMouseMoveEvents, 0);
+ }
#endif
void tst_QWidget::windowFlags()
@@ -9155,6 +9222,9 @@ void tst_QWidget::destroyBackingStore()
void tst_QWidget::rectOutsideCoordinatesLimit_task144779()
{
+#ifdef Q_OS_WINCE_WM
+ QSKIP( "Tables of 5000 elements do not make sense on Windows Mobile.", SkipAll);
+#endif
QApplication::setOverrideCursor(Qt::BlankCursor); //keep the cursor out of screen grabs
QWidget main(0,Qt::FramelessWindowHint); //don't get confused by the size of the window frame
QPalette palette;
diff --git a/tests/auto/qwindowsurface/tst_qwindowsurface.cpp b/tests/auto/qwindowsurface/tst_qwindowsurface.cpp
index 0a6b7ad..2490a65 100644
--- a/tests/auto/qwindowsurface/tst_qwindowsurface.cpp
+++ b/tests/auto/qwindowsurface/tst_qwindowsurface.cpp
@@ -106,18 +106,26 @@ public:
QRegion r;
};
-#define VERIFY_COLOR(region, color) { \
- const QRegion r = QRegion(region); \
- for (int i = 0; i < r.rects().size(); ++i) { \
- const QRect rect = r.rects().at(i); \
- const QPixmap pixmap = QPixmap::grabWindow(QDesktopWidget().winId(), \
- rect.left(), rect.top(), \
- rect.width(), rect.height()); \
- QCOMPARE(pixmap.size(), rect.size()); \
- QPixmap expectedPixmap(pixmap); /* ensure equal formats */ \
- expectedPixmap.fill(color); \
- QCOMPARE(pixmap, expectedPixmap); \
- } \
+//from tst_qwidget.cpp
+static void VERIFY_COLOR(const QRegion &region, const QColor &color)
+{
+ const QRegion r = QRegion(region);
+ for (int i = 0; i < r.rects().size(); ++i) {
+ const QRect rect = r.rects().at(i);
+ for (int t = 0; t < 5; t++) {
+ const QPixmap pixmap = QPixmap::grabWindow(QDesktopWidget().winId(),
+ rect.left(), rect.top(),
+ rect.width(), rect.height());
+ QCOMPARE(pixmap.size(), rect.size());
+ QPixmap expectedPixmap(pixmap); /* ensure equal formats */
+ expectedPixmap.fill(color);
+ if (pixmap.toImage().pixel(0,0) != QColor(color).rgb() && t < 4 )
+ { QTest::qWait(200); continue; }
+ QCOMPARE(pixmap.toImage().pixel(0,0), QColor(color).rgb());
+ QCOMPARE(pixmap, expectedPixmap);
+ break;
+ }
+ }
}
void tst_QWindowSurface::getSetWindowSurface()
@@ -230,7 +238,7 @@ void tst_QWindowSurface::grabWidget()
parentWidget.show();
QTest::qWaitForWindowShown(&parentWidget);
- QTest::qWait(120);
+ QTest::qWait(220);
QPixmap parentPixmap = parentWidget.windowSurface()->grabWidget(&parentWidget);
QPixmap childPixmap = childWidget.windowSurface()->grabWidget(&childWidget);