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

Proposed by Cris 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 Cris Dywan

Merge lp:ubuntu-ui-toolkit/staging

2068. By Cris 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 Cris 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 Cris Dywan

Reword documentation of visualRoot for clarity

Revision history for this message
Cris 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
Cris 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
=== modified file 'src/UbuntuToolkit/quickutils.cpp'
--- src/UbuntuToolkit/quickutils.cpp 2016-11-11 06:57:56 +0000
+++ src/UbuntuToolkit/quickutils.cpp 2017-01-18 15:22:13 +0000
@@ -29,6 +29,8 @@
29#include <QtQuick/private/qquicktextedit_p.h>29#include <QtQuick/private/qquicktextedit_p.h>
30#include <QtSystemInfo/QInputInfoManager>30#include <QtSystemInfo/QInputInfoManager>
3131
32#include <UbuntuToolkit/private/ucmainwindow_p.h>
33
32UT_NAMESPACE_BEGIN34UT_NAMESPACE_BEGIN
3335
34QuickUtils *QuickUtils::m_instance = nullptr;36QuickUtils *QuickUtils::m_instance = nullptr;
@@ -170,11 +172,18 @@
170 * \internal172 * \internal
171 * Returns the root item of a given item. In case there is a QQuickWindow (Window)173 * Returns the root item of a given item. In case there is a QQuickWindow (Window)
172 * found in the hierarchy, the function will return the contentItem of the window.174 * found in the hierarchy, the function will return the contentItem of the window.
175 * If the root item is a \b MainWindow, the visualRoot property will be respected.
173 */176 */
174QQuickItem *QuickUtils::rootItem(QObject *object)177QQuickItem *QuickUtils::rootItem(QObject *object)
175{178{
176 // make sure we have the m_rootView updated179 // make sure we have the m_rootView updated
177 lookupQuickView();180 lookupQuickView();
181
182 UCMainWindow *mainWindow(qobject_cast<UCMainWindow*>(m_rootWindow));
183 if (mainWindow && mainWindow->visualRoot()) {
184 return mainWindow->visualRoot();
185 }
186
178 if (!object) {187 if (!object) {
179 return m_rootView ? m_rootView->rootObject() : (m_rootWindow ? m_rootWindow->contentItem() : 0);188 return m_rootView ? m_rootView->rootObject() : (m_rootWindow ? m_rootWindow->contentItem() : 0);
180 }189 }
181190
=== modified file 'src/UbuntuToolkit/ucmainwindow.cpp'
--- src/UbuntuToolkit/ucmainwindow.cpp 2017-01-17 08:50:14 +0000
+++ src/UbuntuToolkit/ucmainwindow.cpp 2017-01-18 15:22:13 +0000
@@ -238,6 +238,32 @@
238 return d_func()->m_actionContext;238 return d_func()->m_actionContext;
239}239}
240240
241/*!
242 \qmlproperty Item MainWindow::visualRoot
243
244 If set, the property holds the window's visual root, as opposed to root item
245 of the scene.
246 Popups (popovers, dialogs, menus) opened with popupUtils.open() will be
247 children of the visual root, or the root item otherwise.
248 Popups shown via show() may respectively reparent to the visual root, if it
249 is set, or the root item otherwise, if reparentToRootItem is set.
250*/
251QQuickItem *UCMainWindow::visualRoot() const
252{
253 return d_func()->m_visualRoot;
254}
255
256void UCMainWindow::setVisualRoot(QQuickItem *visualRoot)
257{
258 Q_D(UCMainWindow);
259
260 if (d->m_visualRoot == visualRoot)
261 return;
262
263 d->m_visualRoot = visualRoot;
264 Q_EMIT visualRootChanged(visualRoot);
265}
266
241UT_NAMESPACE_END267UT_NAMESPACE_END
242268
243#include "moc_ucmainwindow_p.cpp"269#include "moc_ucmainwindow_p.cpp"
244270
=== modified file 'src/UbuntuToolkit/ucmainwindow_p.h'
--- src/UbuntuToolkit/ucmainwindow_p.h 2017-01-12 15:20:31 +0000
+++ src/UbuntuToolkit/ucmainwindow_p.h 2017-01-18 15:22:13 +0000
@@ -37,10 +37,12 @@
37 Q_PROPERTY(UT_PREPEND_NAMESPACE(UCUnits)* units READ units NOTIFY unitsChanged)37 Q_PROPERTY(UT_PREPEND_NAMESPACE(UCUnits)* units READ units NOTIFY unitsChanged)
38 Q_PROPERTY(UT_PREPEND_NAMESPACE(UbuntuI18n)* i18n READ i18n NOTIFY i18nChanged)38 Q_PROPERTY(UT_PREPEND_NAMESPACE(UbuntuI18n)* i18n READ i18n NOTIFY i18nChanged)
39 Q_PROPERTY(UT_PREPEND_NAMESPACE(UCPopupContext)* actionContext READ actionContext NOTIFY actionContextChanged)39 Q_PROPERTY(UT_PREPEND_NAMESPACE(UCPopupContext)* actionContext READ actionContext NOTIFY actionContextChanged)
40 Q_PROPERTY(UT_PREPEND_NAMESPACE(QQuickItem)* visualRoot READ visualRoot WRITE setVisualRoot NOTIFY visualRootChanged)
40#else41#else
41 Q_PROPERTY(UCUnits* units READ units NOTIFY unitsChanged)42 Q_PROPERTY(UCUnits* units READ units NOTIFY unitsChanged)
42 Q_PROPERTY(UbuntuI18n* i18n READ i18n NOTIFY i18nChanged)43 Q_PROPERTY(UbuntuI18n* i18n READ i18n NOTIFY i18nChanged)
43 Q_PROPERTY(UCPopupContext* actionContext READ actionContext NOTIFY actionContextChanged)44 Q_PROPERTY(UCPopupContext* actionContext READ actionContext NOTIFY actionContextChanged)
45 Q_PROPERTY(QQuickItem* visualRoot READ visualRoot WRITE setVisualRoot NOTIFY visualRootChanged)
44#endif46#endif
4547
46public:48public:
@@ -57,6 +59,9 @@
5759
58 UCPopupContext* actionContext() const;60 UCPopupContext* actionContext() const;
5961
62 QQuickItem* visualRoot() const;
63 void setVisualRoot(QQuickItem*);
64
60Q_SIGNALS:65Q_SIGNALS:
61 void applicationNameChanged(QString applicationName);66 void applicationNameChanged(QString applicationName);
62 void organizationNameChanged(QString applicationName);67 void organizationNameChanged(QString applicationName);
@@ -64,8 +69,10 @@
64 void unitsChanged();69 void unitsChanged();
65#ifndef Q_QDOC70#ifndef Q_QDOC
66 void actionContextChanged(UT_PREPEND_NAMESPACE(UCPopupContext)* actionContext);71 void actionContextChanged(UT_PREPEND_NAMESPACE(UCPopupContext)* actionContext);
72 void visualRootChanged(UT_PREPEND_NAMESPACE(QQuickItem)* visualRoot);
67#else73#else
68 void actionContextChanged(UCPopupContext* actionContext);74 void actionContextChanged(UCPopupContext* actionContext);
75 void visualRootChanged(QQuickItem* visualRoot);
69#endif76#endif
7077
71private:78private:
7279
=== modified file 'src/UbuntuToolkit/ucmainwindow_p_p.h'
--- src/UbuntuToolkit/ucmainwindow_p_p.h 2017-01-12 15:20:31 +0000
+++ src/UbuntuToolkit/ucmainwindow_p_p.h 2017-01-18 15:22:13 +0000
@@ -40,6 +40,7 @@
40 QString m_organizationName;40 QString m_organizationName;
41 UCPopupContext* m_actionContext = nullptr;41 UCPopupContext* m_actionContext = nullptr;
42 UCUnits* m_units = nullptr;42 UCUnits* m_units = nullptr;
43 QQuickItem* m_visualRoot = nullptr;
4344
44};45};
4546
4647
=== modified file 'src/imports/Components/Popups/1.3/popupUtils.js'
--- src/imports/Components/Popups/1.3/popupUtils.js 2017-01-05 14:11:37 +0000
+++ src/imports/Components/Popups/1.3/popupUtils.js 2017-01-18 15:22:13 +0000
@@ -32,7 +32,12 @@
32 \a caller should be given when a \l ComposerSheet or \l Dialog is specified using a URL32 \a caller should be given when a \l ComposerSheet or \l Dialog is specified using a URL
33 and opened inside a \b Window. If not, the application's root item will be the dismiss area.33 and opened inside a \b Window. If not, the application's root item will be the dismiss area.
3434
35 Returns a popop object, which can be closed using \l close.35 Returns a popup object, which can be closed using \l close.
36
37 Note that popups created from a file or component will be created as children
38 of the root item. If that's not a good choice, a \b MainWindow used as the
39 root item can set the \b visualRoot property an arbitrary \b Item that acts
40 as the parent of all popups.
3641
37 \qml42 \qml
38 import Ubuntu.Components 1.343 import Ubuntu.Components 1.3
3944
=== added file 'tests/unit/mainwindow/VisualRoot.qml'
--- tests/unit/mainwindow/VisualRoot.qml 1970-01-01 00:00:00 +0000
+++ tests/unit/mainwindow/VisualRoot.qml 2017-01-18 15:22:13 +0000
@@ -0,0 +1,36 @@
1/*
2 * Copyright 2013-2017 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17import QtQuick 2.4
18import Ubuntu.Components 1.3
19import Ubuntu.Components.Labs 1.0
20
21MainWindow {
22 objectName: "visualRoot"
23 applicationName: "org.gnu.wildebeest"
24 visualRoot: myRoot
25
26 Rectangle {
27 id: myRoot
28 objectName: "myRoot"
29 anchors.fill: parent
30
31 Label {
32 objectName: "myLabel"
33 text: "Lorem ipsum dolor sit amet"
34 }
35 }
36}
037
=== modified file 'tests/unit/mainwindow/tst_mainwindow.cpp'
--- tests/unit/mainwindow/tst_mainwindow.cpp 2017-01-12 15:20:31 +0000
+++ tests/unit/mainwindow/tst_mainwindow.cpp 2017-01-18 15:22:13 +0000
@@ -41,7 +41,9 @@
41#include <QtQml/QQmlComponent>41#include <QtQml/QQmlComponent>
4242
43#include <UbuntuToolkit/ubuntutoolkitmodule.h>43#include <UbuntuToolkit/ubuntutoolkitmodule.h>
44#include <UbuntuToolkit/private/quickutils_p.h>
44#include <UbuntuToolkit/private/ucapplication_p.h>45#include <UbuntuToolkit/private/ucapplication_p.h>
46#include <UbuntuToolkit/private/ucmainwindow_p.h>
45#include <UbuntuToolkit/private/ucunits_p.h>47#include <UbuntuToolkit/private/ucunits_p.h>
4648
47UT_USE_NAMESPACE49UT_USE_NAMESPACE
@@ -90,7 +92,7 @@
90 return window;92 return window;
91 }93 }
9294
93 QQuickItem *testItem(QQuickItem *that, const QString &identifier)95 QQuickItem *testItem(QObject *that, const QString &identifier)
94 {96 {
95 if (that->property(identifier.toLocal8Bit()).isValid())97 if (that->property(identifier.toLocal8Bit()).isValid())
96 return that->property(identifier.toLocal8Bit()).value<QQuickItem*>();98 return that->property(identifier.toLocal8Bit()).value<QQuickItem*>();
@@ -132,6 +134,17 @@
132 QCOMPARE(organizationName, mainWindow->property("organizationName").toString());134 QCOMPARE(organizationName, mainWindow->property("organizationName").toString());
133 QCOMPARE(organizationName, QCoreApplication::organizationName());135 QCOMPARE(organizationName, QCoreApplication::organizationName());
134 }136 }
137
138 void testCase_VisualRoot()
139 {
140 QString applicationName("tv.island.pacific");
141 QQuickWindow *mainWindow(loadTest("VisualRoot.qml"));
142 QVERIFY(mainWindow);
143 QQuickItem* myLabel(testItem(mainWindow, "myLabel"));
144 QQuickItem* visualRoot(QuickUtils::instance()->rootItem(myLabel));
145 QQuickItem* myRoot(testItem(mainWindow, "myRoot"));
146 QCOMPARE(visualRoot, myRoot);
147 }
135};148};
136149
137QTEST_MAIN(tst_MainWindow)150QTEST_MAIN(tst_MainWindow)

Subscribers

People subscribed via source and target branches