Merge lp:~ubuntu-sdk-team/ubuntu-ui-toolkit/visualRoot into lp:ubuntu-ui-toolkit/staging

Proposed by Christian Dywan
Status: Merged
Approved by: Tim Peeters
Approved revision: 2070
Merged at revision: 2159
Proposed branch: lp:~ubuntu-sdk-team/ubuntu-ui-toolkit/visualRoot
Merge into: lp:ubuntu-ui-toolkit/staging
Prerequisite: lp:~ubuntu-sdk-team/ubuntu-ui-toolkit/outTheWindow
Diff against target: 218 lines (+99/-2)
7 files modified
src/UbuntuToolkit/quickutils.cpp (+9/-0)
src/UbuntuToolkit/ucmainwindow.cpp (+26/-0)
src/UbuntuToolkit/ucmainwindow_p.h (+7/-0)
src/UbuntuToolkit/ucmainwindow_p_p.h (+1/-0)
src/imports/Components/Popups/1.3/popupUtils.js (+6/-1)
tests/unit/mainwindow/VisualRoot.qml (+36/-0)
tests/unit/mainwindow/tst_mainwindow.cpp (+14/-1)
To merge this branch: bzr merge lp:~ubuntu-sdk-team/ubuntu-ui-toolkit/visualRoot
Reviewer Review Type Date Requested Status
ubuntu-sdk-build-bot continuous-integration Approve
Tim Peeters Approve
Zsombor Egri Needs Information
Review via email: mp+314684@code.launchpad.net

Commit message

Add visualRoot property to MainWindow

To post a comment you must log in.
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Tim Peeters (tpeeters) wrote :

Let's add documentation in PopupUtils and the popup components on how to change the root item. Also an example/use case would be useful.

2067. By Christian Dywan

Merge lp:ubuntu-ui-toolkit/staging

2068. By Christian Dywan

Document the role of visualRoot in QuickUtils and popupUtils

Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
2069. By Christian Dywan

Tweak quickutils header include in tst_mainwindow

Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Tim Peeters (tpeeters) wrote :

some small suggestions for the docs in the inline comments below.

2070. By Christian Dywan

Reword documentation of visualRoot for clarity

Revision history for this message
Christian Dywan (kalikiana) wrote :

> > The property holds the window's visual root,
> > as opposed to the root item.
> Should we prepend this sentence with 'If set,'?
> To make it clear that visualRoot is ignored
> when it is null? Or say 'set to null in order
> to use the root item....'.

I moved the If to the start of the sentence.

> > If set, popups (popovers, dialogs, menus) will
> > reparent to it when opened via
> They won't be reparented, they will be created
> as children of visualRoot (as you say in the
> docs of popupUtils).

Yes and no. popupUtils.open creates them initially with the parent. show() on the other hand does reparent after the fact if reparentToRootItem is true.

I made this more explicit now.

> > - QQuickItem *testItem(QQuickItem *that, const QString &identifier)
> > + QQuickItem *testItem(QObject *that, const QString &identifier)
> why does this have to be changed?

A QQuickWindow is not a QQuickItem. Properties and children are however implemented in QObject and aren't specific to items at all. So we can use them with a window just fine, so long as we don't try to cast it to something unrelated that it isn't.

Revision history for this message
Zsombor Egri (zsombi) wrote :

A small comment about the property, perhaps we would want to use the QQC2 ApplicationWindow's contentItem as property name?

http://doc.qt.io/qt-5/qml-qtquick-controls2-applicationwindow.html#contentItem-prop

review: Needs Information
Revision history for this message
Christian Dywan (kalikiana) wrote :

> A small comment about the property, perhaps we would want to use the QQC2
> ApplicationWindow's contentItem as property name?
>
> http://doc.qt.io/qt-5/qml-qtquick-controls2-applicationwindow.html
> #contentItem-prop

QQuickWindow already has a contentItem property and it's not the same as what we want for the visualItem to be.

Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Tim Peeters (tpeeters) wrote :

Looks good, thanks!

review: Approve
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/UbuntuToolkit/quickutils.cpp'
2--- src/UbuntuToolkit/quickutils.cpp 2016-11-11 06:57:56 +0000
3+++ src/UbuntuToolkit/quickutils.cpp 2017-01-18 15:22:13 +0000
4@@ -29,6 +29,8 @@
5 #include <QtQuick/private/qquicktextedit_p.h>
6 #include <QtSystemInfo/QInputInfoManager>
7
8+#include <UbuntuToolkit/private/ucmainwindow_p.h>
9+
10 UT_NAMESPACE_BEGIN
11
12 QuickUtils *QuickUtils::m_instance = nullptr;
13@@ -170,11 +172,18 @@
14 * \internal
15 * Returns the root item of a given item. In case there is a QQuickWindow (Window)
16 * found in the hierarchy, the function will return the contentItem of the window.
17+ * If the root item is a \b MainWindow, the visualRoot property will be respected.
18 */
19 QQuickItem *QuickUtils::rootItem(QObject *object)
20 {
21 // make sure we have the m_rootView updated
22 lookupQuickView();
23+
24+ UCMainWindow *mainWindow(qobject_cast<UCMainWindow*>(m_rootWindow));
25+ if (mainWindow && mainWindow->visualRoot()) {
26+ return mainWindow->visualRoot();
27+ }
28+
29 if (!object) {
30 return m_rootView ? m_rootView->rootObject() : (m_rootWindow ? m_rootWindow->contentItem() : 0);
31 }
32
33=== modified file 'src/UbuntuToolkit/ucmainwindow.cpp'
34--- src/UbuntuToolkit/ucmainwindow.cpp 2017-01-17 08:50:14 +0000
35+++ src/UbuntuToolkit/ucmainwindow.cpp 2017-01-18 15:22:13 +0000
36@@ -238,6 +238,32 @@
37 return d_func()->m_actionContext;
38 }
39
40+/*!
41+ \qmlproperty Item MainWindow::visualRoot
42+
43+ If set, the property holds the window's visual root, as opposed to root item
44+ of the scene.
45+ Popups (popovers, dialogs, menus) opened with popupUtils.open() will be
46+ children of the visual root, or the root item otherwise.
47+ Popups shown via show() may respectively reparent to the visual root, if it
48+ is set, or the root item otherwise, if reparentToRootItem is set.
49+*/
50+QQuickItem *UCMainWindow::visualRoot() const
51+{
52+ return d_func()->m_visualRoot;
53+}
54+
55+void UCMainWindow::setVisualRoot(QQuickItem *visualRoot)
56+{
57+ Q_D(UCMainWindow);
58+
59+ if (d->m_visualRoot == visualRoot)
60+ return;
61+
62+ d->m_visualRoot = visualRoot;
63+ Q_EMIT visualRootChanged(visualRoot);
64+}
65+
66 UT_NAMESPACE_END
67
68 #include "moc_ucmainwindow_p.cpp"
69
70=== modified file 'src/UbuntuToolkit/ucmainwindow_p.h'
71--- src/UbuntuToolkit/ucmainwindow_p.h 2017-01-12 15:20:31 +0000
72+++ src/UbuntuToolkit/ucmainwindow_p.h 2017-01-18 15:22:13 +0000
73@@ -37,10 +37,12 @@
74 Q_PROPERTY(UT_PREPEND_NAMESPACE(UCUnits)* units READ units NOTIFY unitsChanged)
75 Q_PROPERTY(UT_PREPEND_NAMESPACE(UbuntuI18n)* i18n READ i18n NOTIFY i18nChanged)
76 Q_PROPERTY(UT_PREPEND_NAMESPACE(UCPopupContext)* actionContext READ actionContext NOTIFY actionContextChanged)
77+ Q_PROPERTY(UT_PREPEND_NAMESPACE(QQuickItem)* visualRoot READ visualRoot WRITE setVisualRoot NOTIFY visualRootChanged)
78 #else
79 Q_PROPERTY(UCUnits* units READ units NOTIFY unitsChanged)
80 Q_PROPERTY(UbuntuI18n* i18n READ i18n NOTIFY i18nChanged)
81 Q_PROPERTY(UCPopupContext* actionContext READ actionContext NOTIFY actionContextChanged)
82+ Q_PROPERTY(QQuickItem* visualRoot READ visualRoot WRITE setVisualRoot NOTIFY visualRootChanged)
83 #endif
84
85 public:
86@@ -57,6 +59,9 @@
87
88 UCPopupContext* actionContext() const;
89
90+ QQuickItem* visualRoot() const;
91+ void setVisualRoot(QQuickItem*);
92+
93 Q_SIGNALS:
94 void applicationNameChanged(QString applicationName);
95 void organizationNameChanged(QString applicationName);
96@@ -64,8 +69,10 @@
97 void unitsChanged();
98 #ifndef Q_QDOC
99 void actionContextChanged(UT_PREPEND_NAMESPACE(UCPopupContext)* actionContext);
100+ void visualRootChanged(UT_PREPEND_NAMESPACE(QQuickItem)* visualRoot);
101 #else
102 void actionContextChanged(UCPopupContext* actionContext);
103+ void visualRootChanged(QQuickItem* visualRoot);
104 #endif
105
106 private:
107
108=== modified file 'src/UbuntuToolkit/ucmainwindow_p_p.h'
109--- src/UbuntuToolkit/ucmainwindow_p_p.h 2017-01-12 15:20:31 +0000
110+++ src/UbuntuToolkit/ucmainwindow_p_p.h 2017-01-18 15:22:13 +0000
111@@ -40,6 +40,7 @@
112 QString m_organizationName;
113 UCPopupContext* m_actionContext = nullptr;
114 UCUnits* m_units = nullptr;
115+ QQuickItem* m_visualRoot = nullptr;
116
117 };
118
119
120=== modified file 'src/imports/Components/Popups/1.3/popupUtils.js'
121--- src/imports/Components/Popups/1.3/popupUtils.js 2017-01-05 14:11:37 +0000
122+++ src/imports/Components/Popups/1.3/popupUtils.js 2017-01-18 15:22:13 +0000
123@@ -32,7 +32,12 @@
124 \a caller should be given when a \l ComposerSheet or \l Dialog is specified using a URL
125 and opened inside a \b Window. If not, the application's root item will be the dismiss area.
126
127- Returns a popop object, which can be closed using \l close.
128+ Returns a popup object, which can be closed using \l close.
129+
130+ Note that popups created from a file or component will be created as children
131+ of the root item. If that's not a good choice, a \b MainWindow used as the
132+ root item can set the \b visualRoot property an arbitrary \b Item that acts
133+ as the parent of all popups.
134
135 \qml
136 import Ubuntu.Components 1.3
137
138=== added file 'tests/unit/mainwindow/VisualRoot.qml'
139--- tests/unit/mainwindow/VisualRoot.qml 1970-01-01 00:00:00 +0000
140+++ tests/unit/mainwindow/VisualRoot.qml 2017-01-18 15:22:13 +0000
141@@ -0,0 +1,36 @@
142+/*
143+ * Copyright 2013-2017 Canonical Ltd.
144+ *
145+ * This program is free software; you can redistribute it and/or modify
146+ * it under the terms of the GNU Lesser General Public License as published by
147+ * the Free Software Foundation; version 3.
148+ *
149+ * This program is distributed in the hope that it will be useful,
150+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
151+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
152+ * GNU Lesser General Public License for more details.
153+ *
154+ * You should have received a copy of the GNU Lesser General Public License
155+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
156+ */
157+
158+import QtQuick 2.4
159+import Ubuntu.Components 1.3
160+import Ubuntu.Components.Labs 1.0
161+
162+MainWindow {
163+ objectName: "visualRoot"
164+ applicationName: "org.gnu.wildebeest"
165+ visualRoot: myRoot
166+
167+ Rectangle {
168+ id: myRoot
169+ objectName: "myRoot"
170+ anchors.fill: parent
171+
172+ Label {
173+ objectName: "myLabel"
174+ text: "Lorem ipsum dolor sit amet"
175+ }
176+ }
177+}
178
179=== modified file 'tests/unit/mainwindow/tst_mainwindow.cpp'
180--- tests/unit/mainwindow/tst_mainwindow.cpp 2017-01-12 15:20:31 +0000
181+++ tests/unit/mainwindow/tst_mainwindow.cpp 2017-01-18 15:22:13 +0000
182@@ -41,7 +41,9 @@
183 #include <QtQml/QQmlComponent>
184
185 #include <UbuntuToolkit/ubuntutoolkitmodule.h>
186+#include <UbuntuToolkit/private/quickutils_p.h>
187 #include <UbuntuToolkit/private/ucapplication_p.h>
188+#include <UbuntuToolkit/private/ucmainwindow_p.h>
189 #include <UbuntuToolkit/private/ucunits_p.h>
190
191 UT_USE_NAMESPACE
192@@ -90,7 +92,7 @@
193 return window;
194 }
195
196- QQuickItem *testItem(QQuickItem *that, const QString &identifier)
197+ QQuickItem *testItem(QObject *that, const QString &identifier)
198 {
199 if (that->property(identifier.toLocal8Bit()).isValid())
200 return that->property(identifier.toLocal8Bit()).value<QQuickItem*>();
201@@ -132,6 +134,17 @@
202 QCOMPARE(organizationName, mainWindow->property("organizationName").toString());
203 QCOMPARE(organizationName, QCoreApplication::organizationName());
204 }
205+
206+ void testCase_VisualRoot()
207+ {
208+ QString applicationName("tv.island.pacific");
209+ QQuickWindow *mainWindow(loadTest("VisualRoot.qml"));
210+ QVERIFY(mainWindow);
211+ QQuickItem* myLabel(testItem(mainWindow, "myLabel"));
212+ QQuickItem* visualRoot(QuickUtils::instance()->rootItem(myLabel));
213+ QQuickItem* myRoot(testItem(mainWindow, "myRoot"));
214+ QCOMPARE(visualRoot, myRoot);
215+ }
216 };
217
218 QTEST_MAIN(tst_MainWindow)

Subscribers

People subscribed via source and target branches