diff options
author | Sune Vuorela <sune@vuorela.dk> | 2013-09-16 23:54:21 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-20 11:54:13 +0200 |
commit | e24f75af4db89ebdfd3d48e9d007238a1b990cd2 (patch) | |
tree | a2cd5345e259fdd2ab8156ddfa02e7b929f3dbc7 /tests/auto | |
parent | 938c838c1019a21f22c8f238852084969a3d0682 (diff) |
Implement QMainWindow::takeCentralWidget()
This allows the application developer to restructure the application,
including moving the central widget some place else.
Change-Id: Idca2f74c190500db24404e020b0eb400e41aad10
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp b/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp index b42bfcac81..e5a9b570bb 100644 --- a/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp +++ b/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp @@ -118,6 +118,7 @@ private slots: void toolButtonStyle(); void menuBar(); void centralWidget(); + void takeCentralWidget(); void corner(); void addToolBarBreak(); void insertToolBarBreak(); @@ -189,6 +190,14 @@ void tst_QMainWindow::getSetCheck() obj1.setCentralWidget((QWidget *)0); QCOMPARE((QWidget *)0, obj1.centralWidget()); // delete var3; // No delete, since QMainWindow takes ownership + + QWidget *var4 = new QWidget; + QPointer<QWidget> oldcentralwidget(var4); + obj1.setCentralWidget(var4); + obj1.setCentralWidget(new QWidget); + QCoreApplication::sendPostedEvents(var4, QEvent::DeferredDelete); + QVERIFY(oldcentralwidget.isNull()); + QVERIFY(obj1.centralWidget()->parent()); } tst_QMainWindow::tst_QMainWindow() @@ -806,6 +815,52 @@ void tst_QMainWindow::centralWidget() QVERIFY(w1 == 0); QVERIFY(w2 == 0); } + +} + +void tst_QMainWindow::takeCentralWidget() { + // test if takeCentralWidget works + QMainWindow mw; + + QPointer<QWidget> w1 = new QWidget; + + QVERIFY(mw.centralWidget() == 0); + + mw.setCentralWidget(w1); + + QWidget *oldCentralWidget = mw.takeCentralWidget(); + QVERIFY(oldCentralWidget == w1.data()); + + // ensure that takeCentralWidget doesn't end up calling deleteLater + // on the central widget + QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); + QVERIFY(mw.centralWidget() == 0); + QVERIFY(!w1.isNull()); + QVERIFY(w1->parent() == 0); + + mw.setCentralWidget(w1); + // ensure that the deleteLater called by setCentralWidget + // gets executed + QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); + QVERIFY(mw.centralWidget() == w1.data()); + + QPointer<QWidget> w2 = new QWidget; + + mw.setCentralWidget(w2); + // ensure w2 gets deleted + QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); + QVERIFY(w1.isNull()); + + QVERIFY(mw.centralWidget() == w2.data()); + + QWidget *hopefullyW2 = mw.takeCentralWidget(); + QVERIFY(mw.centralWidget() == 0); + // ensure that takeCentralWidget doesn't end up calling deleteLater + // on the central widget + QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); + + QVERIFY(!w2.isNull()); + QCOMPARE(w2.data(), hopefullyW2); } void tst_QMainWindow::corner() |