aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2017-12-15 13:26:28 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2018-02-02 07:14:53 +0000
commit4b014effe1f27407f5073ba738498ce87b918b9d (patch)
tree79d85bbd05fc4122b4bfc2ef407342edacebc77f /src
parent7bd5d93899ca6c2175d6937f2011428c654bff02 (diff)
If Loader loads Window, set its transient parent to the Loader's window
This makes the Item { Loader { sourceComponent: Window { } } } case consistent with the Item { Window { } } case: the inner Window is transient for the outer Window. It works even if the Loader's Window has a visible: true declaration: in that case, until now, the Loader's Window would become visible at component creation time, before the outer Item became visible. So the test to check whether it had a transient parent did not work. We now change the delayed-visibility mechanism in QQuickWindowQmlImpl to wait for the parent Item to acquire a window of its own rather than waiting for the transient-parent-if-any to become visible. It should still take care of all the old cases too, e.g. in the Window { Window { } } case, the inner Window's QObject parent is actually the QQuickRootItem. (Amends 701255c76f671f100338a799f0194bf10e26c9d1) [ChangeLog][QtQuick][QQuickWindow] When a Window is declared inside another Item or Window, the window will not be created until the parent window is created. This allows it to have the correct transientParent and be managed as a transient window. Task-number: QTBUG-52944 Change-Id: Iaf4aafbd696f6e8dd0eec1d02db8bd181483bd07 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/quick/items/qquickloader.cpp19
-rw-r--r--src/quick/items/qquickloader_p.h1
-rw-r--r--src/quick/items/qquickwindowmodule.cpp15
3 files changed, 31 insertions, 4 deletions
diff --git a/src/quick/items/qquickloader.cpp b/src/quick/items/qquickloader.cpp
index 414103c63e..a3e8379368 100644
--- a/src/quick/items/qquickloader.cpp
+++ b/src/quick/items/qquickloader.cpp
@@ -674,6 +674,13 @@ void QQuickLoaderPrivate::incubatorStateChanged(QQmlIncubator::Status status)
if (status == QQmlIncubator::Ready) {
object = incubator->object();
item = qmlobject_cast<QQuickItem*>(object);
+ if (!item) {
+ QQuickWindow *window = qmlobject_cast<QQuickWindow*>(object);
+ if (window) {
+ qCDebug(lcTransient) << window << "is transient for" << q->window();
+ window->setTransientParent(q->window());
+ }
+ }
emit q->itemChanged();
initResize();
incubator->clear();
@@ -818,6 +825,18 @@ void QQuickLoader::componentComplete()
}
}
+void QQuickLoader::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value)
+{
+ if (change == ItemSceneChange) {
+ QQuickWindow *loadedWindow = qmlobject_cast<QQuickWindow *>(item());
+ if (loadedWindow) {
+ qCDebug(lcTransient) << loadedWindow << "is transient for" << value.window;
+ loadedWindow->setTransientParent(value.window);
+ }
+ }
+ QQuickItem::itemChange(change, value);
+}
+
/*!
\qmlsignal QtQuick::Loader::loaded()
diff --git a/src/quick/items/qquickloader_p.h b/src/quick/items/qquickloader_p.h
index db171dcd1e..8f0a9980b9 100644
--- a/src/quick/items/qquickloader_p.h
+++ b/src/quick/items/qquickloader_p.h
@@ -107,6 +107,7 @@ Q_SIGNALS:
protected:
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE;
void componentComplete() Q_DECL_OVERRIDE;
+ void itemChange(ItemChange change, const ItemChangeData &value) override;
private:
void setSource(const QUrl &sourceUrl, bool needsClear);
diff --git a/src/quick/items/qquickwindowmodule.cpp b/src/quick/items/qquickwindowmodule.cpp
index 1981ed2f70..e702cc5a3e 100644
--- a/src/quick/items/qquickwindowmodule.cpp
+++ b/src/quick/items/qquickwindowmodule.cpp
@@ -123,7 +123,13 @@ void QQuickWindowQmlImpl::componentComplete()
{
Q_D(QQuickWindowQmlImpl);
d->complete = true;
- if (transientParent() && !transientParent()->isVisible()) {
+ QQuickItem *itemParent = qmlobject_cast<QQuickItem *>(QObject::parent());
+ if (itemParent && !itemParent->window()) {
+ qCDebug(lcTransient) << "window" << title() << "has invisible Item parent" << itemParent << "transientParent"
+ << transientParent() << "declared visibility" << d->visibility << "; delaying show";
+ connect(itemParent, &QQuickItem::windowChanged, this,
+ &QQuickWindowQmlImpl::setWindowVisibility, Qt::QueuedConnection);
+ } else if (transientParent() && !transientParent()->isVisible()) {
connect(transientParent(), &QQuickWindow::visibleChanged, this,
&QQuickWindowQmlImpl::setWindowVisibility, Qt::QueuedConnection);
} else {
@@ -137,9 +143,10 @@ void QQuickWindowQmlImpl::setWindowVisibility()
if (transientParent() && !transientParent()->isVisible())
return;
- if (sender()) {
- disconnect(transientParent(), &QWindow::visibleChanged, this,
- &QQuickWindowQmlImpl::setWindowVisibility);
+ if (QQuickItem *senderItem = qmlobject_cast<QQuickItem *>(sender())) {
+ disconnect(senderItem, &QQuickItem::windowChanged, this, &QQuickWindowQmlImpl::setWindowVisibility);
+ } else if (sender()) {
+ disconnect(transientParent(), &QWindow::visibleChanged, this, &QQuickWindowQmlImpl::setWindowVisibility);
}
// We have deferred window creation until we have the full picture of what