summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qwindow.cpp
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2016-11-24 16:09:39 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2016-12-08 15:57:18 +0000
commit7a93d98f29fca9f1610f3b61b055535916903500 (patch)
tree9dd8bee59e0a1a308228edc01b6d642186936cc5 /src/gui/kernel/qwindow.cpp
parent6604d79a21fcdd23f7f58055299aa1ab914eb734 (diff)
Add QWindow::AncestorMode overload of QWindow::parent()
Simplifies code that traverses the parent hierarchy, including transient parents. For Qt6 we should merge the two parent() functions, adding a default value for the mode, probably ExcludeTransients. Change-Id: Ic9cdae3e31a3a8e140a5b175160f3b934d2b6e00 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/gui/kernel/qwindow.cpp')
-rw-r--r--src/gui/kernel/qwindow.cpp34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index ba7fc8533f..93edfe6331 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -629,6 +629,22 @@ WId QWindow::winId() const
return d->platformWindow->winId();
}
+ /*!
+ Returns the parent window, if any.
+
+ If \a mode is IncludeTransients, then the transient parent is returned
+ if there is no parent.
+
+ A window without a parent is known as a top level window.
+
+ \since 5.9
+*/
+QWindow *QWindow::parent(AncestorMode mode) const
+{
+ Q_D(const QWindow);
+ return d->parentWindow ? d->parentWindow : (mode == IncludeTransients ? transientParent() : nullptr);
+}
+
/*!
Returns the parent window, if any.
@@ -1117,11 +1133,10 @@ bool QWindow::isActive() const
if (focus == this)
return true;
- if (!parent() && !transientParent()) {
+ if (QWindow *p = parent(IncludeTransients))
+ return p->isActive();
+ else
return isAncestorOf(focus);
- } else {
- return (parent() && parent()->isActive()) || (transientParent() && transientParent()->isActive());
- }
}
/*!
@@ -1285,8 +1300,10 @@ bool QWindow::isAncestorOf(const QWindow *child, AncestorMode mode) const
if (child->parent() == this || (mode == IncludeTransients && child->transientParent() == this))
return true;
- return (child->parent() && isAncestorOf(child->parent(), mode))
- || (mode == IncludeTransients && child->transientParent() && isAncestorOf(child->transientParent(), mode));
+ if (child->parent(mode) && isAncestorOf(child->parent(mode), mode))
+ return true;
+
+ return false;
}
/*!
@@ -2497,10 +2514,7 @@ QWindow *QWindowPrivate::topLevelWindow() const
QWindow *window = const_cast<QWindow *>(q);
while (window) {
- QWindow *parent = window->parent();
- if (!parent)
- parent = window->transientParent();
-
+ QWindow *parent = window->parent(QWindow::IncludeTransients);
if (!parent)
break;