From 76a5ce8acb4580a63cbeb3852e6d842a8aa2903d Mon Sep 17 00:00:00 2001 From: "Anselmo L. S. Melo" Date: Fri, 20 Jan 2012 09:08:42 -0300 Subject: Implement QWindow::close() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement the public slot QWindow::close() and add the correspondent test. Change-Id: If3f07cce3b26640f06fc52d0e4dca875d9894b3d Reviewed-by: Samuel Rødal --- src/gui/kernel/qwindow.cpp | 24 ++++++++++++++++++++++-- tests/auto/gui/kernel/qwindow/tst_qwindow.cpp | 16 ++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 5bab203abc..daee1cdd3b 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -845,8 +845,28 @@ void QWindow::showNormal() bool QWindow::close() { - //should we have close? - qDebug() << "unimplemented:" << __FILE__ << __LINE__; + Q_D(QWindow); + + // Do not close non top level windows + if (parent()) + return false; + + if (QGuiApplicationPrivate::focus_window == this) + QGuiApplicationPrivate::focus_window = 0; + + QObjectList childrenWindows = children(); + for (int i = 0; i < childrenWindows.size(); i++) { + QObject *object = childrenWindows.at(i); + if (object->isWindowType()) { + QWindow *w = static_cast(object); + QGuiApplicationPrivate::window_list.removeAll(w); + w->destroy(); + } + } + + QGuiApplicationPrivate::window_list.removeAll(this); + destroy(); + d->maybeQuitOnLastWindowClosed(); return true; } diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index 91f9e4ef49..a19af79caa 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -58,6 +58,7 @@ private slots: void mouseToTouchTranslation(); void mouseToTouchLoop(); void orientation(); + void close(); void initTestCase() { touchDevice = new QTouchDevice; @@ -503,5 +504,20 @@ void tst_QWindow::orientation() QCOMPARE(spy.count(), 1); } +void tst_QWindow::close() +{ + QWindow a; + QWindow b; + QWindow c(&a); + + a.show(); + b.show(); + + // we can not close a non top level window + QVERIFY(!c.close()); + QVERIFY(a.close()); + QVERIFY(b.close()); +} + #include QTEST_MAIN(tst_QWindow); -- cgit v1.2.3