Refactor QGuiApplication::topLevelWindows()

Unifies the three conditions where we do not treat a window as a
top level window.

Uses QWindow::isTopLevel() instead of manually checking parent.

Updated the comment about embedded windows, which applies to all
embedded windows, not just QAxServers windows.

Change-Id: I7f9dbdf50044bf375ca21818ac29fbd3fe502166
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Tor Arne Vestbø 2016-11-21 12:51:02 +01:00
parent 69d0eafa08
commit a1c84af6f5

View File

@ -937,15 +937,25 @@ QWindowList QGuiApplication::topLevelWindows()
{
const QWindowList &list = QGuiApplicationPrivate::window_list;
QWindowList topLevelWindows;
for (int i = 0; i < list.size(); i++) {
if (!list.at(i)->parent() && list.at(i)->type() != Qt::Desktop) {
// Top windows of embedded QAxServers do not have QWindow parents,
// but they are not true top level windows, so do not include them.
const bool embedded = list.at(i)->handle() && list.at(i)->handle()->isEmbedded();
if (!embedded)
topLevelWindows.prepend(list.at(i));
}
for (int i = 0; i < list.size(); ++i) {
QWindow *window = list.at(i);
if (!window->isTopLevel())
continue;
// Desktop windows are special, as each individual desktop window
// will report that it's a top level window, but we don't want to
// include them in the application wide list of top level windows.
if (window->type() == Qt::Desktop)
continue;
// Windows embedded in native windows do not have QWindow parents,
// but they are not true top level windows, so do not include them.
if (window->handle() && window->handle()->isEmbedded())
continue;
topLevelWindows.prepend(window);
}
return topLevelWindows;
}