aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2016-01-31 09:39:34 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2016-02-12 15:33:53 +0000
commit04d4dca69d526611b60ec32e873d5de51d10be4d (patch)
tree936ec7b3d0ded1b73e538d75de79edc0fe902a00
parent20a51e87fd15b8a6c1503b905399f7befe31114b (diff)
Add Window.window attached property
The Window attached property exposes all kinds of window attributes, but not the window itself. Being able to access the window is often useful for various purposes. For example, in QML TestCase, to be able to access the window of the TestCase so that one can call various slots such as requestActivate(). Change-Id: Id03c9f277bb17810b41a60957011ccf07399e149 Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
-rw-r--r--src/quick/items/qquickwindow.cpp8
-rw-r--r--src/quick/items/qquickwindowattached.cpp13
-rw-r--r--src/quick/items/qquickwindowattached_p.h5
-rw-r--r--tests/auto/quick/qquickwindow/data/windowattached.qml2
-rw-r--r--tests/auto/quick/qquickwindow/tst_qquickwindow.cpp3
5 files changed, 27 insertions, 4 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp
index 635f1da77e..10f4fb20fc 100644
--- a/src/quick/items/qquickwindow.cpp
+++ b/src/quick/items/qquickwindow.cpp
@@ -3872,6 +3872,14 @@ void QQuickWindow::resetOpenGLState()
*/
/*!
+ \qmlattachedproperty Window Window::window
+ \since 5.7
+
+ This attached property holds the item's window.
+ The Window attached property can be attached to any Item.
+*/
+
+/*!
\qmlattachedproperty int Window::width
\qmlattachedproperty int Window::height
\since 5.5
diff --git a/src/quick/items/qquickwindowattached.cpp b/src/quick/items/qquickwindowattached.cpp
index 992bbae382..c6380e2b9a 100644
--- a/src/quick/items/qquickwindowattached.cpp
+++ b/src/quick/items/qquickwindowattached.cpp
@@ -51,9 +51,9 @@ QQuickWindowAttached::QQuickWindowAttached(QObject* attachee)
{
m_attachee = qobject_cast<QQuickItem*>(attachee);
if (m_attachee && m_attachee->window()) // It might not be in a window yet
- windowChanged(m_attachee->window());
+ windowChange(m_attachee->window());
if (m_attachee)
- connect(m_attachee, &QQuickItem::windowChanged, this, &QQuickWindowAttached::windowChanged);
+ connect(m_attachee, &QQuickItem::windowChanged, this, &QQuickWindowAttached::windowChange);
}
QWindow::Visibility QQuickWindowAttached::visibility() const
@@ -86,7 +86,12 @@ int QQuickWindowAttached::height() const
return (m_window ? m_window->height() : 0);
}
-void QQuickWindowAttached::windowChanged(QQuickWindow *window)
+QQuickWindow *QQuickWindowAttached::window() const
+{
+ return m_window;
+}
+
+void QQuickWindowAttached::windowChange(QQuickWindow *window)
{
if (window != m_window) {
QQuickWindow* oldWindow = m_window;
@@ -95,6 +100,8 @@ void QQuickWindowAttached::windowChanged(QQuickWindow *window)
if (oldWindow)
oldWindow->disconnect(this);
+ emit windowChanged();
+
if (!oldWindow || !window || window->visibility() != oldWindow->visibility())
emit visibilityChanged();
if (!oldWindow || !window || window->isActive() != oldWindow->isActive())
diff --git a/src/quick/items/qquickwindowattached_p.h b/src/quick/items/qquickwindowattached_p.h
index 5e4b2c1721..3212508fd8 100644
--- a/src/quick/items/qquickwindowattached_p.h
+++ b/src/quick/items/qquickwindowattached_p.h
@@ -69,6 +69,7 @@ class Q_AUTOTEST_EXPORT QQuickWindowAttached : public QObject
Q_PROPERTY(QQuickItem* contentItem READ contentItem NOTIFY contentItemChanged)
Q_PROPERTY(int width READ width NOTIFY widthChanged)
Q_PROPERTY(int height READ height NOTIFY heightChanged)
+ Q_PROPERTY(QQuickWindow *window READ window NOTIFY windowChanged)
public:
QQuickWindowAttached(QObject* attachee);
@@ -79,6 +80,7 @@ public:
QQuickItem* contentItem() const;
int width() const;
int height() const;
+ QQuickWindow *window() const;
Q_SIGNALS:
@@ -88,9 +90,10 @@ Q_SIGNALS:
void contentItemChanged();
void widthChanged();
void heightChanged();
+ void windowChanged();
protected Q_SLOTS:
- void windowChanged(QQuickWindow*);
+ void windowChange(QQuickWindow*);
private:
QQuickWindow* m_window;
diff --git a/tests/auto/quick/qquickwindow/data/windowattached.qml b/tests/auto/quick/qquickwindow/data/windowattached.qml
index a9f052d55e..9d61a02452 100644
--- a/tests/auto/quick/qquickwindow/data/windowattached.qml
+++ b/tests/auto/quick/qquickwindow/data/windowattached.qml
@@ -9,6 +9,7 @@ Rectangle {
property Item contentItem: root.Window.contentItem
property int windowWidth: root.Window.width
property int windowHeight: root.Window.height
+ property var window: root.Window.window
Text {
objectName: "rectangleWindowText"
anchors.centerIn: parent
@@ -26,6 +27,7 @@ Rectangle {
property Item contentItem: Window.contentItem
property int windowWidth: Window.width
property int windowHeight: Window.height
+ property var window: Window.window
}
}
}
diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
index 8aeb449a85..ff8c80e3ae 100644
--- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
+++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
@@ -2033,6 +2033,7 @@ void tst_qquickwindow::attachedProperty()
QCOMPARE(view.rootObject()->property("contentItem").value<QQuickItem*>(), view.contentItem());
QCOMPARE(view.rootObject()->property("windowWidth").toInt(), view.width());
QCOMPARE(view.rootObject()->property("windowHeight").toInt(), view.height());
+ QCOMPARE(view.rootObject()->property("window").value<QQuickView*>(), &view);
QQuickWindow *innerWindow = view.rootObject()->findChild<QQuickWindow*>("extraWindow");
QVERIFY(innerWindow);
@@ -2045,11 +2046,13 @@ void tst_qquickwindow::attachedProperty()
QCOMPARE(text->property("contentItem").value<QQuickItem*>(), innerWindow->contentItem());
QCOMPARE(text->property("windowWidth").toInt(), innerWindow->width());
QCOMPARE(text->property("windowHeight").toInt(), innerWindow->height());
+ QCOMPARE(text->property("window").value<QQuickWindow*>(), innerWindow);
text->setParentItem(0);
QVERIFY(!text->property("contentItem").value<QQuickItem*>());
QCOMPARE(text->property("windowWidth").toInt(), 0);
QCOMPARE(text->property("windowHeight").toInt(), 0);
+ QVERIFY(!text->property("window").value<QQuickWindow*>());
}
class RenderJob : public QRunnable