summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qwindow.cpp
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>2015-10-16 16:41:34 +0200
committerTor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>2015-10-26 17:10:02 +0000
commit73c86fcb400cb91868b56ac05a3b82a3f7ba1a1b (patch)
tree03a2eaf34b0b7866291931742bf42a166dcdee17 /src/gui/kernel/qwindow.cpp
parentac27f9a83e916431fc378d99959187d339af4639 (diff)
Defer QPlatformWindow creation on setVisible(true) if parent hasn't been created
When a child QWindow is shown by calling setVisible(true), we don't need to create the platform window immediately if the parent window hasn't been created yet. We defer creation until the parent is created, or we're re-parented into a created parent or made top level. This optimization is more important now that we create the full parent hierarchy once we decide that we need to create a child QWindow. Change-Id: Ia4f0430f0d3709a12f41f6473c1cea6b0ef3c9cd Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src/gui/kernel/qwindow.cpp')
-rw-r--r--src/gui/kernel/qwindow.cpp50
1 files changed, 37 insertions, 13 deletions
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index f55e7f0803..3f971d700e 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -406,13 +406,21 @@ void QWindowPrivate::create(bool recursive)
QObjectList childObjects = q->children();
for (int i = 0; i < childObjects.size(); i ++) {
QObject *object = childObjects.at(i);
- if (object->isWindowType()) {
- QWindow *window = static_cast<QWindow *>(object);
- if (recursive)
- window->d_func()->create(true);
- if (window->d_func()->platformWindow)
- window->d_func()->platformWindow->setParent(platformWindow);
- }
+ if (!object->isWindowType())
+ continue;
+
+ QWindow *childWindow = static_cast<QWindow *>(object);
+ if (recursive)
+ childWindow->d_func()->create(recursive);
+
+ // The child may have had deferred creation due to this window not being created
+ // at the time setVisible was called, so we re-apply the visible state, which
+ // may result in creating the child, and emitting the appropriate signals.
+ if (childWindow->isVisible())
+ childWindow->setVisible(true);
+
+ if (QPlatformWindow *childPlatformWindow = childWindow->d_func()->platformWindow)
+ childPlatformWindow->setParent(this->platformWindow);
}
QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceCreated);
@@ -477,14 +485,23 @@ void QWindow::setVisible(bool visible)
{
Q_D(QWindow);
- if (d->visible == visible)
+ if (d->visible != visible) {
+ d->visible = visible;
+ emit visibleChanged(visible);
+ d->updateVisibility();
+ } else if (d->platformWindow) {
+ // Visibility hasn't changed, and the platform window is in sync
return;
- d->visible = visible;
- emit visibleChanged(visible);
- d->updateVisibility();
+ }
- if (!d->platformWindow)
- create();
+ if (!d->platformWindow) {
+ // If we have a parent window, but the parent hasn't been created yet, we
+ // can defer creation until the parent is created or we're re-parented.
+ if (parent() && !parent()->handle())
+ return;
+ else
+ create();
+ }
if (visible) {
// remove posted quit events when showing a new window
@@ -523,6 +540,7 @@ void QWindow::setVisible(bool visible)
if (visible && (d->hasCursor || QGuiApplication::overrideCursor()))
d->applyCursor();
#endif
+
d->platformWindow->setVisible(visible);
if (!visible) {
@@ -619,6 +637,12 @@ void QWindow::setParent(QWindow *parent)
else
d->connectToScreen(newScreen);
+ // If we were set visible, but not created because we were a child, and we're now
+ // re-parented into a created parent, or to being a top level, we need re-apply the
+ // visibility state, which will also create.
+ if (isVisible() && (!parent || parent->handle()))
+ setVisible(true);
+
if (d->platformWindow) {
if (parent)
parent->create();