Fix Infinite loop in QGraphicsScene::focusNextPrevChild

Task-number: QTBUG-42915
Change-Id: Ie380e0d77453bcdb68e92dcffe8278f169da27bc
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
bb10
João de Deus Morgado 2015-06-11 07:40:31 +01:00 committed by Alex Blasche
parent 87c426d5f4
commit 1f8a2ff41d
2 changed files with 28 additions and 1 deletions

View File

@ -5430,12 +5430,14 @@ bool QGraphicsScene::focusNextPrevChild(bool next)
return true;
}
if (d->activePanel->isWidget()) {
QGraphicsWidget *fw = static_cast<QGraphicsWidget *>(d->activePanel)->d_func()->focusNext;
QGraphicsWidget *test = static_cast<QGraphicsWidget *>(d->activePanel);
QGraphicsWidget *fw = next ? test->d_func()->focusNext : test->d_func()->focusPrev;
do {
if (fw->focusPolicy() & Qt::TabFocus) {
setFocusItem(fw, next ? Qt::TabFocusReason : Qt::BacktabFocusReason);
return true;
}
fw = next ? fw->d_func()->focusNext : fw->d_func()->focusPrev;
} while (fw != d->activePanel);
}
}

View File

@ -267,6 +267,7 @@ private slots:
void taskQT_3674_doNotCrash();
void taskQTBUG_15977_renderWithDeviceCoordinateCache();
void taskQTBUG_16401_focusItem();
void taskQTBUG_42915_focusNextPrevChild();
};
void tst_QGraphicsScene::cleanup()
@ -4815,5 +4816,29 @@ void tst_QGraphicsScene::taskQTBUG_16401_focusItem()
QVERIFY(!scene.focusItem());
}
void tst_QGraphicsScene::taskQTBUG_42915_focusNextPrevChild()
{
QGraphicsScene scene;
QGraphicsView view(&scene);
scene.setSceneRect(1, 1, 198, 198);
view.setFocus();
QGraphicsWidget *widget1 = new QGraphicsWidget();
QGraphicsRectItem *rect1 = new QGraphicsRectItem(-50, -50, 100, 100, widget1);
rect1->setBrush(Qt::blue);
scene.addItem(widget1);
widget1->setPos(100, 100);
widget1->setFlags(QGraphicsItem::ItemIsPanel);
QGraphicsWidget *widget2 = new QGraphicsWidget(widget1);
widget2->setFocusPolicy(Qt::NoFocus);
view.show();
QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowActive(&view));
QTest::keyEvent(QTest::Click, &view, Qt::Key_Tab);
}
QTEST_MAIN(tst_QGraphicsScene)
#include "tst_qgraphicsscene.moc"