From 8839a0a001c7017a1acf1d7460c4c19893c74967 Mon Sep 17 00:00:00 2001 From: "Anselmo L. S. Melo" Date: Fri, 27 Jan 2012 07:49:34 -0300 Subject: Fix QGuiApplication::topLevelWindows(), introducing allWindows() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As discussed on the development mailing list, the window list returned by QGuiApplication::topLevellWindows() included all QWindows, even the non top-level ones. This commit introduces the new method allWindows(), which returns the list of all QWindows, fixes the list returned by topLevelWindows() and also introduces tests for both methods. Change-Id: I761f0fcdec79f83949012c628655ed12cd18572c Reviewed-by: Jonas Gastal Reviewed-by: Samuel Rødal --- src/gui/kernel/qguiapplication.cpp | 29 ++++++++++++++++++++++++++++- src/gui/kernel/qguiapplication.h | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index cc6ef36963..ea562c75b8 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -214,11 +214,38 @@ QObject *QGuiApplication::focusObject() return 0; } -QWindowList QGuiApplication::topLevelWindows() +/*! + \fn QGuiApplication::allWindows() + + Returns a list of all the windows in the application. + + The list is empty if there are no windows. + + \sa topLevelWindows() + */ +QWindowList QGuiApplication::allWindows() { return QGuiApplicationPrivate::window_list; } +/*! + \fn QGuiApplication::topLevelWindows() + + Returns a list of the top-level windows in the application. + + \sa allWindows() + */ +QWindowList QGuiApplication::topLevelWindows() +{ + const QWindowList &list = QGuiApplicationPrivate::window_list; + QWindowList topLevelWindows; + for (int i = 0; i < list.size(); i++) { + if (!list.at(i)->parent()) + topLevelWindows.prepend(list.at(i)); + } + return topLevelWindows; +} + QScreen *QGuiApplication::primaryScreen() { if (QGuiApplicationPrivate::screen_list.isEmpty()) diff --git a/src/gui/kernel/qguiapplication.h b/src/gui/kernel/qguiapplication.h index 90061ed338..9bf6a69c45 100644 --- a/src/gui/kernel/qguiapplication.h +++ b/src/gui/kernel/qguiapplication.h @@ -81,6 +81,7 @@ public: QGuiApplication(int &argc, char **argv, int = ApplicationFlags); virtual ~QGuiApplication(); + static QWindowList allWindows(); static QWindowList topLevelWindows(); static QWindow *topLevelAt(const QPoint &pos); -- cgit v1.2.3