From e841cc37bf7fde58e7b0ffc024d31f6a46a83745 Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Wed, 29 Jul 2009 03:21:09 +0200 Subject: Fix remaining autotest failures in tst_QGraphicsWidget Change f68fed3 introduced a few regressions in the QGraphicsWidget autotests. It turned out those autotests relied on behavior that this fix "fixed". The exact bugs were 1) that setting focus on a window or a child of a window that isn't active will automatically give that item focus, despite that its window is inactive (in contrast it should just set up subfocus and give the item focus when the window is activated), and 2) that adding a window to a scene that is active did not immediately activate that window. So one fix in the test and one in QGraphicsScene. The autotests were modified so that the respective tests operate on an active scene (by assigning the scene to an active view). The change in QGraphicsScene ensures that the first window that gets added to an active scene that does not have any active windows already, automatically gets activated. Reviewed-by: Michael Brasser --- src/gui/graphicsview/qgraphicsscene.cpp | 4 ++++ tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index f223cbe..e54efe0 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -2356,6 +2356,10 @@ void QGraphicsScene::addItem(QGraphicsItem *item) // Deliver post-change notification item->itemChange(QGraphicsItem::ItemSceneHasChanged, newSceneVariant); + // Auto-activate the first inactive window if the scene is active. + if (d->activationRefCount > 0 && !d->activeWindow && item->isWindow()) + setActiveWindow(static_cast(item)); + // Ensure that newly added items that have subfocus set, gain // focus automatically if there isn't a focus item already. if (!d->focusItem && item->focusItem()) diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp index 78d13d3..2cfedb1 100644 --- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp @@ -1315,6 +1315,12 @@ void tst_QGraphicsWidget::focusNextPrevChild() void tst_QGraphicsWidget::verifyFocusChain() { QGraphicsScene scene; + QGraphicsView view(&scene); + view.show(); +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(&view); +#endif + QTest::qWait(250); { // parent/child focus SubQGraphicsWidget *w = new SubQGraphicsWidget(0, Qt::Window); @@ -1448,6 +1454,11 @@ void tst_QGraphicsWidget::updateFocusChainWhenChildDie() QGraphicsScene scene; QGraphicsView view(&scene); view.show(); +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(&view); +#endif + QTest::qWait(250); + // delete item in focus chain with no focus and verify chain SubQGraphicsWidget *parent = new SubQGraphicsWidget(0, Qt::Window); SubQGraphicsWidget *w = new SubQGraphicsWidget(0, Qt::Window); -- cgit v0.12