From 0c019d7bd2fff4eba39afc3a4db63d71d13988da Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Fri, 29 Jan 2016 22:29:58 +0100 Subject: QDockWidget: Restore using setGeometry since the geometry is used for the state This solves an instance where restoreState() was used when the dockwidget was already floating and the saved state was also for a floating dockwidget. Change-Id: I1fe764ae2a6b0351ae26e33ffec682ad37c944d7 Reviewed-by: Friedemann Kleint Reviewed-by: Olivier Goffart (Woboq GmbH) --- .../widgets/qdockwidget/tst_qdockwidget.cpp | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp b/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp index 713dc6b9b8..61a9461a62 100644 --- a/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp +++ b/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp @@ -75,6 +75,7 @@ private slots: void titleBarDoubleClick(); void restoreStateOfFloating(); void restoreDockWidget(); + void restoreStateWhileStillFloating(); // task specific tests: void task165177_deleteFocusWidget(); void task169808_setFloating(); @@ -757,6 +758,31 @@ void tst_QDockWidget::restoreStateOfFloating() QVERIFY(!dock->isFloating()); } +void tst_QDockWidget::restoreStateWhileStillFloating() +{ + // When the dock widget is already floating then it takes a different code path + // so this test covers the case where the restoreState() is effectively just + // moving it back and resizing it + const QRect availGeom = QApplication::desktop()->availableGeometry(); + const QPoint startingDockPos = availGeom.center(); + QMainWindow mw; + QDockWidget *dock = createTestDock(mw); + mw.addDockWidget(Qt::TopDockWidgetArea, dock); + dock->setFloating(true); + dock->move(startingDockPos); + mw.show(); + QVERIFY(QTest::qWaitForWindowExposed(&mw)); + QVERIFY(dock->isFloating()); + QByteArray ba = mw.saveState(); + const QPoint dockPos = dock->pos(); + dock->move(availGeom.topLeft() + QPoint(10, 10)); + dock->resize(dock->size() + QSize(10, 10)); + QVERIFY(mw.restoreState(ba)); + QVERIFY(dock->isFloating()); + if (!QGuiApplication::platformName().compare("xcb", Qt::CaseInsensitive)) + QTRY_COMPARE(dock->pos(), dockPos); +} + void tst_QDockWidget::restoreDockWidget() { QByteArray geometry; -- cgit v1.2.3