Merge lp:~zsombi/ubuntu-ui-toolkit/layouts-visibility into lp:ubuntu-ui-toolkit/staging

Proposed by Zsombor Egri
Status: Merged
Approved by: Cris Dywan
Approved revision: 1055
Merged at revision: 1065
Proposed branch: lp:~zsombi/ubuntu-ui-toolkit/layouts-visibility
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 1516 lines (+595/-227)
12 files modified
components.api (+2/-0)
modules/Ubuntu/Layouts/plugin/plugin.pro (+1/-1)
modules/Ubuntu/Layouts/plugin/propertychanges.cpp (+18/-33)
modules/Ubuntu/Layouts/plugin/propertychanges_p.h (+3/-16)
modules/Ubuntu/Layouts/plugin/ulitemlayout.h (+4/-1)
modules/Ubuntu/Layouts/plugin/ullayouts.cpp (+92/-81)
modules/Ubuntu/Layouts/plugin/ullayouts.h (+8/-3)
modules/Ubuntu/Layouts/plugin/ullayouts_p.h (+3/-5)
tests/unit_x11/tst_layouts/NestedVisibility.qml (+163/-0)
tests/unit_x11/tst_layouts/Visibility.qml (+84/-0)
tests/unit_x11/tst_layouts/tst_layouts.cpp (+214/-86)
tests/unit_x11/tst_layouts/tst_layouts.pro (+3/-1)
To merge this branch: bzr merge lp:~zsombi/ubuntu-ui-toolkit/layouts-visibility
Reviewer Review Type Date Requested Status
Cris Dywan Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+218916@code.launchpad.net

Commit message

Ubuntu Layouts reparents those default layout components which are not subject of layout instead of altering their visible and enabled properties.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:1041
http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/192/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/106
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/94
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-amd64-ci/24
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/24
        deb: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/24/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-i386-ci/24
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/618
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/264
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/264/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/6988
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/87
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/137
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/137/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/192/rebuild

review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Cris Dywan (kalikiana) wrote :

The test case should
 - check that visible is not changed, ie. bug 1300668
 - verify ordering of the components

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:1043
http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/219/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/175
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/165
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-amd64-ci/51
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/51
        deb: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/51/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-i386-ci/51
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/675
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/389
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/389/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/7103
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/150
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/211
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/211/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/219/rebuild

review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:1052
http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/239/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/273
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/248
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-amd64-ci/71
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/71
        deb: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/71/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-i386-ci/71
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/760
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/554
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/554/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/7257
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/224
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/312
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/312/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/239/rebuild

review: Approve (continuous-integration)
1053. By Zsombor Egri

test cases merged

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:1053
http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/241/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/278
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/252
    FAILURE: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-amd64-ci/73/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/73
        deb: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/73/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-i386-ci/73
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/764
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/563
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/563/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/7265
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/228
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/316
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/316/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/241/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Cris Dywan (kalikiana) wrote :

Thanks for the change to data!

992 QTest::newRow("portrait") << "tabletLandscapeLayout" << "tabletLandscape";

This should probably be "landscape"

Aside from that it's looking good.

review: Needs Fixing
1054. By Zsombor Egri

test tag fixed

1055. By Zsombor Egri

staging merge

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:1055
http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/260/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/360
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/313
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-amd64-ci/92
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/92
        deb: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/92/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-i386-ci/92
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/832
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/707
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/707/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/7416
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/278
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/401
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/401/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/260/rebuild

review: Approve (continuous-integration)
Revision history for this message
Cris Dywan (kalikiana) wrote :

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'components.api'
--- components.api 2014-05-15 09:41:46 +0000
+++ components.api 2014-05-20 19:37:09 +0000
@@ -868,6 +868,8 @@
868 exports: ["Layouts 0.1", "Layouts 1.0"]868 exports: ["Layouts 0.1", "Layouts 1.0"]
869 Property { name: "currentLayout"; type: "string"; isReadonly: true }869 Property { name: "currentLayout"; type: "string"; isReadonly: true }
870 Property { name: "layouts"; type: "ULConditionalLayout"; isList: true; isReadonly: true }870 Property { name: "layouts"; type: "ULConditionalLayout"; isList: true; isReadonly: true }
871 Property { name: "data"; type: "QObject"; isList: true; isReadonly: true }
872 Property { name: "children"; type: "QQuickItem"; isList: true; isReadonly: true }
871 name: "ULLayoutsAttached"873 name: "ULLayoutsAttached"
872 prototype: "QObject"874 prototype: "QObject"
873 Property { name: "item"; type: "string" }875 Property { name: "item"; type: "string" }
874876
=== modified file 'modules/Ubuntu/Layouts/plugin/plugin.pro'
--- modules/Ubuntu/Layouts/plugin/plugin.pro 2013-11-22 11:15:48 +0000
+++ modules/Ubuntu/Layouts/plugin/plugin.pro 2014-05-20 19:37:09 +0000
@@ -5,7 +5,7 @@
55
6QMAKE_CXXFLAGS += -Werror6QMAKE_CXXFLAGS += -Werror
77
8QT += quick-private8QT += quick-private gui-private
9QT += qml-private core-private9QT += qml-private core-private
1010
11equals(QT_MAJOR_VERSION, 5):lessThan(QT_MINOR_VERSION, 2) {11equals(QT_MAJOR_VERSION, 5):lessThan(QT_MINOR_VERSION, 2) {
1212
=== modified file 'modules/Ubuntu/Layouts/plugin/propertychanges.cpp'
--- modules/Ubuntu/Layouts/plugin/propertychanges.cpp 2013-06-26 09:58:41 +0000
+++ modules/Ubuntu/Layouts/plugin/propertychanges.cpp 2014-05-20 19:37:09 +0000
@@ -145,7 +145,7 @@
145 }145 }
146 if (fromBinding) {146 if (fromBinding) {
147 QQmlAbstractBinding *revertedBinding = QQmlPropertyPrivate::setBinding(property, fromBinding);147 QQmlAbstractBinding *revertedBinding = QQmlPropertyPrivate::setBinding(property, fromBinding);
148 if (revertedBinding && ((revertedBinding != toBinding.data()) || (revertedBinding == toBinding.data() && deleteToBinding))) {148 if (revertedBinding && (revertedBinding != fromBinding) && ((revertedBinding != toBinding.data()) || (revertedBinding == toBinding.data() && deleteToBinding))) {
149 revertedBinding->destroy();149 revertedBinding->destroy();
150 }150 }
151 } else if (!toBinding.isNull() && QQmlPropertyPrivate::binding(property) == toBinding.data()) {151 } else if (!toBinding.isNull() && QQmlPropertyPrivate::binding(property) == toBinding.data()) {
@@ -222,24 +222,6 @@
222{222{
223}223}
224224
225/******************************************************************************
226 * ReparentChange
227 */
228ReparentChange::ReparentChange(QQuickItem *target, const QString &property, QQuickItem *source)
229 : PropertyChange(target, property, QVariant(), Normal)
230 , sourceProperty(source, property, qmlContext(source))
231{
232 action.type = PropertyAction::Binding;
233}
234
235void ReparentChange::saveState()
236{
237 action.toValue = sourceProperty.read();
238 PropertyChange::saveState();
239 if (sourceProperty.isValid()) {
240 action.setTargetBinding(QQmlPropertyPrivate::binding(sourceProperty), false);
241 }
242}
243225
244/******************************************************************************226/******************************************************************************
245 * ParentChange227 * ParentChange
@@ -304,35 +286,31 @@
304 * ItemStackBackup286 * ItemStackBackup
305 * High priority change backing up the item's stack position.287 * High priority change backing up the item's stack position.
306 */288 */
307ItemStackBackup::ItemStackBackup(QQuickItem *item, QQuickItem *currentLayoutItem, QQuickItem *previousLayoutItem)289ItemStackBackup::ItemStackBackup(QQuickItem *item)
308 : PropertyChange(High)290 : PropertyChange(High)
309 , target(item)291 , target(item)
310 , currentLayout(currentLayoutItem)292 , prevItem(0)
311 , previousLayout(previousLayoutItem)
312 , originalStackBefore(0)
313{293{
314}294}
315295
316void ItemStackBackup::saveState()296void ItemStackBackup::saveState()
317{297{
318 QQuickItem *rewindParent = target->parentItem();298 QQuickItem *rewindParent = target->parentItem();
299 if (!rewindParent) {
300 return;
301 }
319 // save original stack position, but detect layout objects!302 // save original stack position, but detect layout objects!
320 QList<QQuickItem*> children = rewindParent->childItems();303 QList<QQuickItem*> children = rewindParent->childItems();
321 for (int ii = 0; ii < children.count() - 1; ++ii) {304 int index = children.indexOf(target);
322 if (children.at(ii) == target) {305 if (index > 0) {
323 originalStackBefore = children.at(ii + 1);306 prevItem = children.at(index - 1);
324 if (originalStackBefore == currentLayout || originalStackBefore == previousLayout) {
325 originalStackBefore = 0;
326 }
327 break;
328 }
329 }307 }
330}308}
331309
332void ItemStackBackup::revert()310void ItemStackBackup::revert()
333{311{
334 if (originalStackBefore) {312 if (prevItem) {
335 target->stackBefore(originalStackBefore);313 target->stackAfter(prevItem);
336 }314 }
337}315}
338316
@@ -459,6 +437,13 @@
459 return *this;437 return *this;
460}438}
461439
440// creates two changes, one for reparenting and one for itemstack backup
441ChangeList &ChangeList::addParentChange(QQuickItem *item, QQuickItem *newParent, bool topmostItem)
442{
443 return addChange(new ParentChange(item, newParent, topmostItem))
444 .addChange(new ItemStackBackup(item));
445}
446
462QList<PropertyChange*> ChangeList::unifiedChanges()447QList<PropertyChange*> ChangeList::unifiedChanges()
463{448{
464 QList<PropertyChange*> list;449 QList<PropertyChange*> list;
465450
=== modified file 'modules/Ubuntu/Layouts/plugin/propertychanges_p.h'
--- modules/Ubuntu/Layouts/plugin/propertychanges_p.h 2013-06-26 09:58:41 +0000
+++ modules/Ubuntu/Layouts/plugin/propertychanges_p.h 2014-05-20 19:37:09 +0000
@@ -104,18 +104,6 @@
104};104};
105105
106106
107class ReparentChange : public PropertyChange
108{
109public:
110 ReparentChange(QQuickItem *item, const QString &property, QQuickItem *source);
111
112protected:
113 virtual void saveState();
114
115 QQmlProperty sourceProperty;
116};
117
118
119class ParentChange : public PropertyChange107class ParentChange : public PropertyChange
120{108{
121public:109public:
@@ -143,16 +131,14 @@
143class ItemStackBackup : public PropertyChange131class ItemStackBackup : public PropertyChange
144{132{
145public:133public:
146 ItemStackBackup(QQuickItem *item, QQuickItem *currentLayoutItem, QQuickItem *previousLayoutItem);134 ItemStackBackup(QQuickItem *item);
147 void apply() {}135 void apply() {}
148 void revert();136 void revert();
149137
150protected:138protected:
151 virtual void saveState();139 virtual void saveState();
152 QQuickItem *target;140 QQuickItem *target;
153 QQuickItem *currentLayout;141 QQuickItem *prevItem;
154 QQuickItem *previousLayout;
155 QQuickItem *originalStackBefore;
156private:142private:
157 friend class ULLayouts;143 friend class ULLayouts;
158};144};
@@ -214,6 +200,7 @@
214 void clear();200 void clear();
215201
216 ChangeList &addChange(PropertyChange *change);202 ChangeList &addChange(PropertyChange *change);
203 ChangeList &addParentChange(QQuickItem *item, QQuickItem *newParent, bool topmostItem);
217204
218private:205private:
219 QList<PropertyChange*> changes[PropertyChange::MaxPriority];206 QList<PropertyChange*> changes[PropertyChange::MaxPriority];
220207
=== modified file 'modules/Ubuntu/Layouts/plugin/ulitemlayout.h'
--- modules/Ubuntu/Layouts/plugin/ulitemlayout.h 2013-06-06 16:00:10 +0000
+++ modules/Ubuntu/Layouts/plugin/ulitemlayout.h 2014-05-20 19:37:09 +0000
@@ -26,7 +26,7 @@
26 Q_OBJECT26 Q_OBJECT
27 Q_DISABLE_COPY(ULItemLayout)27 Q_DISABLE_COPY(ULItemLayout)
2828
29 Q_PROPERTY(QString item READ item WRITE setItem)29 Q_PROPERTY(QString item READ item WRITE setItem NOTIFY itemChanged)
3030
31public:31public:
32 explicit ULItemLayout(QQuickItem *parent = 0);32 explicit ULItemLayout(QQuickItem *parent = 0);
@@ -35,6 +35,9 @@
35 QString item() const;35 QString item() const;
36 void setItem(const QString &value);36 void setItem(const QString &value);
3737
38Q_SIGNALS:
39 void itemChanged();
40
38private:41private:
39 QString m_itemName;42 QString m_itemName;
40};43};
4144
=== modified file 'modules/Ubuntu/Layouts/plugin/ullayouts.cpp'
--- modules/Ubuntu/Layouts/plugin/ullayouts.cpp 2014-04-20 19:25:12 +0000
+++ modules/Ubuntu/Layouts/plugin/ullayouts.cpp 2014-05-20 19:37:09 +0000
@@ -22,15 +22,21 @@
22#include "ulconditionallayout.h"22#include "ulconditionallayout.h"
23#include "propertychanges_p.h"23#include "propertychanges_p.h"
24#include <QtQml/QQmlInfo>24#include <QtQml/QQmlInfo>
25#include <QtQuick/private/qquickitem_p.h>
2526
26ULLayoutsPrivate::ULLayoutsPrivate(ULLayouts *qq)27ULLayoutsPrivate::ULLayoutsPrivate(ULLayouts *qq)
27 : QQmlIncubator(Asynchronous)28 : QQmlIncubator(Asynchronous)
28 , q_ptr(qq)29 , q_ptr(qq)
29 , currentLayoutItem(0)30 , currentLayoutItem(0)
30 , previousLayoutItem(0)31 , previousLayoutItem(0)
32 , contentItem(new QQuickItem)
31 , currentLayoutIndex(-1)33 , currentLayoutIndex(-1)
32 , ready(false)34 , ready(false)
33{35{
36 // hidden container for the components that are not laid out
37 // any component not subject of layout is reparented into this component
38 contentItem->setParent(qq);
39 contentItem->setParentItem(qq);
34}40}
3541
3642
@@ -80,7 +86,6 @@
80 QQuickItem *item = static_cast<QQuickItem*>(object);86 QQuickItem *item = static_cast<QQuickItem*>(object);
81 // set disabled and invisible, and set its parent as last action87 // set disabled and invisible, and set its parent as last action
82 item->setVisible(false);88 item->setVisible(false);
83 item->setEnabled(false);
84}89}
8590
86/*91/*
@@ -98,14 +103,16 @@
98 currentLayoutItem = qobject_cast<QQuickItem*>(object());103 currentLayoutItem = qobject_cast<QQuickItem*>(object());
99 Q_ASSERT(currentLayoutItem);104 Q_ASSERT(currentLayoutItem);
100105
101 // hide all non-laid out items first
102 hideExcludedItems();
103
104 //reparent components to be laid out106 //reparent components to be laid out
105 reparentItems();107 reparentItems();
106 // set parent item, then enable and show layout108 // set parent item, then enable and show layout
107 changes.addChange(new ParentChange(currentLayoutItem, q, false));109 changes.addChange(new ParentChange(currentLayoutItem, q, false));
108 itemActivate(currentLayoutItem, true);110
111 // hide default layout, then show the new one
112 // there's no need to queue these property changes as we do not need
113 // to back up their previosus states
114 contentItem->setVisible(false);
115 currentLayoutItem->setVisible(true);
109 // apply changes116 // apply changes
110 changes.apply();117 changes.apply();
111 // clear previous layout118 // clear previous layout
@@ -114,18 +121,10 @@
114121
115 Q_EMIT q->currentLayoutChanged();122 Q_EMIT q->currentLayoutChanged();
116 } else if (status == Error) {123 } else if (status == Error) {
117 Q_Q(ULLayouts);
118 error(q, errors());124 error(q, errors());
119 }125 }
120}126}
121127
122void ULLayoutsPrivate::hideExcludedItems()
123{
124 for (int i = 0; i < excludedFromLayout.count(); i++) {
125 itemActivate(excludedFromLayout[i], false);
126 }
127}
128
129/*128/*
130 * Re-parent items to the new layout.129 * Re-parent items to the new layout.
131 */130 */
@@ -134,26 +133,32 @@
134 // create copy of items list, to keep track of which ones we change133 // create copy of items list, to keep track of which ones we change
135 LaidOutItemsMap unusedItems = itemsToLayout;134 LaidOutItemsMap unusedItems = itemsToLayout;
136135
137 // iterate through the Layout definition to find containers - those Items with136 // iterate through the Layout definition to find containers - ItemLayout items
138 // ConditionalLayout.items set137 QList<ULItemLayout*> containers = collectContainers(currentLayoutItem);
139 QList<QQuickItem*> items = currentLayoutItem->findChildren<QQuickItem*>();138
140 // add the root item as that also can be the container139 Q_FOREACH(ULItemLayout *container, containers) {
141 items.prepend(currentLayoutItem);140 reparentToItemLayout(unusedItems, container);
142141 }
143 Q_FOREACH(QQuickItem *container, items) {142}
144 // check whether we have ItemLayout declared143
145 ULItemLayout *itemLayout = qobject_cast<ULItemLayout*>(container);144QList<ULItemLayout*> ULLayoutsPrivate::collectContainers(QQuickItem *fromItem)
146 if (itemLayout) {145{
147 reparentToItemLayout(unusedItems, itemLayout);146 QList<ULItemLayout*> result;
147 // check first if the fromItem is also a container
148 ULItemLayout *container = qobject_cast<ULItemLayout*>(fromItem);
149 if (container) {
150 result.append(container);
151 }
152
153 // loop through children but exclude nested Layouts
154 QList<QQuickItem*> children = fromItem->childItems();
155 Q_FOREACH(QQuickItem *child, children) {
156 if (qobject_cast<ULLayouts*>(child)) {
157 continue;
148 }158 }
149 }159 result.append(collectContainers(child));
150160 }
151 // hide the rest of the unused ones161 return result;
152 LaidOutItemsMapIterator i(unusedItems);
153 while (i.hasNext()) {
154 i.next();
155 itemActivate(i.value(), false);
156 }
157}162}
158163
159/*164/*
@@ -176,8 +181,7 @@
176 }181 }
177182
178 // the component fills the parent183 // the component fills the parent
179 changes.addChange(new ParentChange(item, fragment, true));184 changes.addParentChange(item, fragment, true);
180 changes.addChange(new ItemStackBackup(item, currentLayoutItem, previousLayoutItem));
181 changes.addChange(new AnchorChange(item, "fill", fragment));185 changes.addChange(new AnchorChange(item, "fill", fragment));
182 changes.addChange(new PropertyChange(item, "anchors.margins", 0));186 changes.addChange(new PropertyChange(item, "anchors.margins", 0));
183 changes.addChange(new PropertyChange(item, "anchors.leftMargin", 0));187 changes.addChange(new PropertyChange(item, "anchors.leftMargin", 0));
@@ -194,18 +198,6 @@
194 map.remove(itemName);198 map.remove(itemName);
195}199}
196200
197void ULLayoutsPrivate::itemActivate(QQuickItem *item, bool activate)
198{
199 changes.addChange(new PropertyChange(item, "visible", activate))
200 .addChange(new PropertyChange(item, "enabled", activate));
201}
202
203// remove the deleted item from the excluded ones
204void ULLayoutsPrivate::_q_removeExcludedItem(QObject *excludedItem)
205{
206 excludedFromLayout.removeAll(static_cast<QQuickItem*>(excludedItem));
207}
208
209/*201/*
210 * Validates the declared conditional layouts by checking whether they have name202 * Validates the declared conditional layouts by checking whether they have name
211 * property set and whether the value set is unique, and whether the conditional203 * property set and whether the value set is unique, and whether the conditional
@@ -244,44 +236,20 @@
244/*236/*
245 * Collect items to be laid out.237 * Collect items to be laid out.
246 */238 */
247void ULLayoutsPrivate::getLaidOutItems()239void ULLayoutsPrivate::getLaidOutItems(QQuickItem *container)
248{240{
249 Q_Q(ULLayouts);241 Q_FOREACH(QQuickItem *child, container->childItems()) {
250242 // skip nested layouts
251 QList<QQuickItem*> items = q->findChildren<QQuickItem*>();243 if (qobject_cast<ULLayouts*>(child)) {
252 for (int i = 0; i < items.count(); i++) {244 continue;
253 QQuickItem *item = items[i];245 }
254 ULLayoutsAttached *marker = qobject_cast<ULLayoutsAttached*>(246 ULLayoutsAttached *marker = qobject_cast<ULLayoutsAttached*>(
255 qmlAttachedPropertiesObject<ULLayouts>(item, false));247 qmlAttachedPropertiesObject<ULLayouts>(child, false));
256 if (marker && !marker->item().isEmpty()) {248 if (marker && !marker->item().isEmpty()) {
257 itemsToLayout.insert(marker->item(), item);249 itemsToLayout.insert(marker->item(), child);
258 } else {250 } else {
259 // the item is not marked to be laid out but one of its parents251 // continue to search in between the child's children
260 // can be, therefore check252 getLaidOutItems(child);
261 // check if the item's parent is included in the layout
262 QQuickItem *pl = item->parentItem();
263 marker = 0;
264 if (!pl && item->parent()) {
265 // this may be an item instance assigned to a property
266 // like "property var anItem: Item {}"
267 // in which case we must get the parent object of it, not the parent item
268 pl = qobject_cast<QQuickItem*>(item->parent());
269 }
270 while (pl) {
271 marker = qobject_cast<ULLayoutsAttached*>(
272 qmlAttachedPropertiesObject<ULLayouts>(pl, false));
273 if (marker && !marker->item().isEmpty()) {
274 break;
275 }
276 pl = pl->parentItem();
277 }
278 if (!marker || (marker && marker->item().isEmpty())) {
279 // remember theese so we hide them once we switch away from default layout
280 excludedFromLayout << item;
281 // and make sure we remove the item from excluded ones in case the item is destroyed
282 QObject::connect(item, SIGNAL(destroyed(QObject*)),
283 q, SLOT(_q_removeExcludedItem(QObject*)));
284 }
285 }253 }
286 }254 }
287}255}
@@ -344,6 +312,9 @@
344 // revert and clear changes312 // revert and clear changes
345 changes.revert();313 changes.revert();
346 changes.clear();314 changes.clear();
315 // make contentItem visible
316
317 contentItem->setVisible(true);
347 delete currentLayoutItem;318 delete currentLayoutItem;
348 currentLayoutItem = 0;319 currentLayoutItem = 0;
349 currentLayoutIndex = -1;320 currentLayoutIndex = -1;
@@ -606,10 +577,18 @@
606 Q_D(ULLayouts);577 Q_D(ULLayouts);
607 d->ready = true;578 d->ready = true;
608 d->validateConditionalLayouts();579 d->validateConditionalLayouts();
609 d->getLaidOutItems();580 d->getLaidOutItems(d->contentItem);
610 d->updateLayout();581 d->updateLayout();
611}582}
612583
584void ULLayouts::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
585{
586 Q_D(ULLayouts);
587 QQuickItem::geometryChanged(newGeometry, oldGeometry);
588 // simply update the container's width/height to the new width/height
589 d->contentItem->setSize(newGeometry.size());
590}
591
613/*!592/*!
614 * \qmlproperty string Layouts::currentLayout593 * \qmlproperty string Layouts::currentLayout
615 * The property holds the active layout name. The default layout is identified594 * The property holds the active layout name. The default layout is identified
@@ -634,6 +613,17 @@
634}613}
635614
636/*!615/*!
616 * \internal
617 * Returns the contentItem for internal use.
618 */
619QQuickItem *ULLayouts::contentItem() const
620{
621 Q_D(const ULLayouts);
622 return d->contentItem;
623}
624
625
626/*!
637 * \qmlproperty list<ConditionalLayout> Layouts::layouts627 * \qmlproperty list<ConditionalLayout> Layouts::layouts
638 * The property holds the list of different ConditionalLayout elements.628 * The property holds the list of different ConditionalLayout elements.
639 */629 */
@@ -647,4 +637,25 @@
647 &ULLayoutsPrivate::clear_layouts);637 &ULLayoutsPrivate::clear_layouts);
648}638}
649639
640/*!
641 * \internal
642 * Overrides the default data property.
643 */
644QQmlListProperty<QObject> ULLayouts::data()
645{
646 Q_D(ULLayouts);
647 return QQuickItemPrivate::get(d->contentItem)->data();
648}
649
650/*!
651 * \internal
652 * Overrides the default children property.
653 */
654QQmlListProperty<QQuickItem> ULLayouts::children()
655{
656 Q_D(ULLayouts);
657 return QQuickItemPrivate::get(d->contentItem)->children();
658}
659
660
650#include "moc_ullayouts.cpp"661#include "moc_ullayouts.cpp"
651662
=== modified file 'modules/Ubuntu/Layouts/plugin/ullayouts.h'
--- modules/Ubuntu/Layouts/plugin/ullayouts.h 2014-02-18 13:27:23 +0000
+++ modules/Ubuntu/Layouts/plugin/ullayouts.h 2014-05-20 19:37:09 +0000
@@ -55,7 +55,10 @@
5555
56 Q_PROPERTY(QString currentLayout READ currentLayout NOTIFY currentLayoutChanged DESIGNABLE false)56 Q_PROPERTY(QString currentLayout READ currentLayout NOTIFY currentLayoutChanged DESIGNABLE false)
57 Q_PROPERTY(QQmlListProperty<ULConditionalLayout> layouts READ layouts DESIGNABLE false)57 Q_PROPERTY(QQmlListProperty<ULConditionalLayout> layouts READ layouts DESIGNABLE false)
58 58
59 Q_PROPERTY(QQmlListProperty<QObject> data READ data DESIGNABLE false)
60 Q_PROPERTY(QQmlListProperty<QQuickItem> children READ children DESIGNABLE false)
61 Q_CLASSINFO("DefaultProperty", "data")
59public:62public:
60 explicit ULLayouts(QQuickItem *parent = 0);63 explicit ULLayouts(QQuickItem *parent = 0);
61 ~ULLayouts();64 ~ULLayouts();
@@ -64,21 +67,23 @@
6467
65 QString currentLayout() const;68 QString currentLayout() const;
66 QList<ULConditionalLayout*> layoutList();69 QList<ULConditionalLayout*> layoutList();
70 QQuickItem *contentItem() const;
6771
68Q_SIGNALS:72Q_SIGNALS:
69 void currentLayoutChanged();73 void currentLayoutChanged();
7074
71protected:75protected:
72 void componentComplete();76 void componentComplete();
77 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
7378
74private:79private:
75 QQmlListProperty<ULConditionalLayout> layouts();80 QQmlListProperty<ULConditionalLayout> layouts();
81 QQmlListProperty<QObject> data();
82 QQmlListProperty<QQuickItem> children();
7683
77 friend class ULConditionalLayout;84 friend class ULConditionalLayout;
78 Q_DECLARE_PRIVATE(ULLayouts)85 Q_DECLARE_PRIVATE(ULLayouts)
79 QScopedPointer<ULLayoutsPrivate> d_ptr;86 QScopedPointer<ULLayoutsPrivate> d_ptr;
80
81 Q_PRIVATE_SLOT(d_func(), void _q_removeExcludedItem(QObject*))
82};87};
8388
84QML_DECLARE_TYPE(ULLayouts)89QML_DECLARE_TYPE(ULLayouts)
8590
=== modified file 'modules/Ubuntu/Layouts/plugin/ullayouts_p.h'
--- modules/Ubuntu/Layouts/plugin/ullayouts_p.h 2014-02-18 13:27:23 +0000
+++ modules/Ubuntu/Layouts/plugin/ullayouts_p.h 2014-05-20 19:37:09 +0000
@@ -33,9 +33,8 @@
3333
34 ULLayoutsPrivate(ULLayouts *qq);34 ULLayoutsPrivate(ULLayouts *qq);
3535
36 void _q_removeExcludedItem(QObject *excludedItem);
37 void validateConditionalLayouts();36 void validateConditionalLayouts();
38 void getLaidOutItems();37 void getLaidOutItems(QQuickItem *item);
39 void updateLayout();38 void updateLayout();
4039
41 static void error(QObject *item, const QString &message);40 static void error(QObject *item, const QString &message);
@@ -51,9 +50,9 @@
51 QList<ULConditionalLayout*> layouts;50 QList<ULConditionalLayout*> layouts;
52 ChangeList changes;51 ChangeList changes;
53 LaidOutItemsMap itemsToLayout;52 LaidOutItemsMap itemsToLayout;
54 QList<QQuickItem*> excludedFromLayout;
55 QQuickItem* currentLayoutItem;53 QQuickItem* currentLayoutItem;
56 QQuickItem* previousLayoutItem;54 QQuickItem* previousLayoutItem;
55 QQuickItem* contentItem;
57 int currentLayoutIndex;56 int currentLayoutIndex;
58 bool ready:1;57 bool ready:1;
5958
@@ -64,10 +63,9 @@
64 static void clear_layouts(QQmlListProperty<ULConditionalLayout>*);63 static void clear_layouts(QQmlListProperty<ULConditionalLayout>*);
6564
66 void reLayout();65 void reLayout();
67 void hideExcludedItems();
68 void reparentItems();66 void reparentItems();
67 QList<ULItemLayout*> collectContainers(QQuickItem *fromItem);
69 void reparentToItemLayout(LaidOutItemsMap &map, ULItemLayout *fragment);68 void reparentToItemLayout(LaidOutItemsMap &map, ULItemLayout *fragment);
70 void itemActivate(QQuickItem *item, bool activate);
71};69};
7270
73#endif // ULLAYOUTS_P_H71#endif // ULLAYOUTS_P_H
7472
=== added file 'tests/unit_x11/tst_layouts/NestedVisibility.qml'
--- tests/unit_x11/tst_layouts/NestedVisibility.qml 1970-01-01 00:00:00 +0000
+++ tests/unit_x11/tst_layouts/NestedVisibility.qml 2014-05-20 19:37:09 +0000
@@ -0,0 +1,163 @@
1/*
2 * Copyright 2014 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.0
18import Ubuntu.Components 1.1
19import Ubuntu.Layouts 1.0
20
21MainView {
22 id: main
23 objectName: "mainView"
24 applicationName: "test-app"
25
26 /*
27 This property enables the application to change orientation
28 when the device is rotated. The default is false.
29 */
30 automaticOrientation: true // TODO: support wide aspect ratios, esp. on prepareGamePage
31
32 width: units.gu(40)
33 height: units.gu(75)
34
35 function phoneLayout() {
36 width = units.gu(50);
37 }
38 function tabletPortraitLayout() {
39 width = units.gu(70);
40 }
41 function tabletLandscapeLayout() {
42 width = units.gu(100);
43 }
44
45 PageStack {
46 Component.onCompleted: push(testPage)
47
48 Page {
49 title: i18n.tr("Conditional Layouts with PageStack")
50 id: testPage
51 visible: false
52
53 Layouts {
54 id: layouts
55 objectName: "mainLayout"
56 width: parent.width
57 height: parent.height
58 layouts: [
59 ConditionalLayout {
60 name: "tabletPortrait"
61 when: main.width > units.gu(50)
62 Layouts {
63 anchors.fill: parent
64 objectName: "nestedLayout"
65 layouts: [
66 ConditionalLayout {
67 name: "tabletLandscape"
68 when: main.width > units.gu(70)
69 Row {
70 objectName: "tabletLandscape"
71 anchors.fill: parent
72 Rectangle {
73 height: parent.height
74 color: "white"
75 width: parent.width / 5
76 }
77 Flow {
78 spacing: units.gu(2)
79 ItemLayout {
80 objectName: "nestedMagentaContainer"
81 item: "mainMagenta"
82 width: units.gu(20)
83 height: width
84 }
85 ItemLayout {
86 objectName: "nestedGreenContainer"
87 item: "mainGreen"
88 width: units.gu(60)
89 height: width
90 }
91 }
92 }
93 }
94 ]
95 // Default layout, but can have ItemLayouts
96 // as those will belong to the previous Layouts
97 // and attaching Layouts.item we can layout it further
98 Flow {
99 objectName: "tabletPortrait"
100 anchors.fill: parent
101 ItemLayout {
102 objectName: "greenContainer"
103 item: "mainGreen"
104 width: units.gu(40)
105 height: width
106 Layouts.item: item
107 }
108 ItemLayout {
109 objectName: "magentaContainer"
110 item: "mainMagenta"
111 width: units.gu(60)
112 height: width
113 Layouts.item: item
114 }
115 }
116 }
117 }
118 ]
119
120 // default layout for mainLayout
121 Flow {
122 objectName: "mainDefaultLayout"
123 anchors.fill: parent
124 Rectangle {
125 objectName: "mainRed"
126 width: units.gu(15)
127 height: width
128 color: "red"
129 Layouts.item: "mainRed"
130 }
131 Rectangle {
132 objectName: "mainGreen"
133 width: units.gu(15)
134 height: width
135 color: "green"
136 Layouts.item: "mainGreen"
137 }
138 Rectangle {
139 objectName: "mainBlue"
140 width: units.gu(15)
141 height: width
142 color: "blue"
143 Layouts.item: "mainBlue"
144 }
145 Rectangle {
146 objectName: "mainMagenta"
147 width: units.gu(15)
148 height: width
149 color: "magenta"
150 Layouts.item: "mainMagenta"
151 }
152 Rectangle {
153 objectName: "mainHidden"
154 width: units.gu(15)
155 height: width
156 color: "yellow"
157 visible: false
158 }
159 }
160 }
161 }
162 }
163}
0164
=== added file 'tests/unit_x11/tst_layouts/Visibility.qml'
--- tests/unit_x11/tst_layouts/Visibility.qml 1970-01-01 00:00:00 +0000
+++ tests/unit_x11/tst_layouts/Visibility.qml 2014-05-20 19:37:09 +0000
@@ -0,0 +1,84 @@
1/*
2 * Copyright 2014 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.0
18import Ubuntu.Components 1.1
19import Ubuntu.Layouts 1.0
20
21MainView {
22 id: main
23 objectName: "mainView"
24 applicationName: "test-app"
25
26 /*
27 This property enables the application to change orientation
28 when the device is rotated. The default is false.
29 */
30 automaticOrientation: true // TODO: support wide aspect ratios, esp. on prepareGamePage
31
32 property bool boundValue: true
33
34 width: units.gu(100)
35 height: units.gu(75)
36
37 function portraitLayout() {
38 width = units.gu(50);
39 }
40 function landscapeLayout() {
41 width = units.gu(100);
42 }
43
44 PageStack {
45 Component.onCompleted: push(testPage)
46
47 Page {
48 title: i18n.tr("Conditional Layouts with PageStack")
49 id: testPage
50 visible: false
51
52 Layouts {
53 id: layouts
54 objectName: "layoutManager"
55 width: parent.width
56 height: parent.height
57 layouts: [
58 ConditionalLayout {
59 name: "wide"
60 when: layouts.width < units.gu(60)
61 UbuntuShape {
62 width: units.gu(20)
63 height: units.gu(20)
64 color: "red"
65 Label { text: "wide" }
66 }
67 }
68 ]
69
70 // This is a default layout.
71 // When using a PageStack and layouts is not empty, it won't display or switch to the default layout.
72 // However it only works when putting it into the layouts list with an inversed condition.
73 UbuntuShape {
74 objectName: "DefaultLayout"
75 width: units.gu(20)
76 height: units.gu(20)
77 color: "green"
78 visible: main.boundValue
79 Label { text: "default" }
80 }
81 }
82 }
83 }
84}
085
=== modified file 'tests/unit_x11/tst_layouts/tst_layouts.cpp'
--- tests/unit_x11/tst_layouts/tst_layouts.cpp 2014-03-19 12:48:33 +0000
+++ tests/unit_x11/tst_layouts/tst_layouts.cpp 2014-05-20 19:37:09 +0000
@@ -72,6 +72,25 @@
72 return (children.count() > 0) ? children[0] : 0;72 return (children.count() > 0) ? children[0] : 0;
73 }73 }
7474
75 bool hasChildItem(QQuickItem *child, QQuickItem *parent)
76 {
77 QQuickItem *pl = child->parentItem();
78 while (pl) {
79 if (pl == parent) {
80 return true;
81 }
82 pl = pl->parentItem();
83 }
84 return false;
85 }
86
87 QQuickItem *prevSibling(QQuickItem *item)
88 {
89 QList<QQuickItem*> children = item->parentItem()->childItems();
90 int index = children.indexOf(item);
91 return (index > 0) ? children.at(index - 1) : 0;
92 }
93
7594
76private Q_SLOTS:95private Q_SLOTS:
77 void initTestCase()96 void initTestCase()
@@ -419,16 +438,16 @@
419438
420 void testCase_AnchorFilledReparenting()439 void testCase_AnchorFilledReparenting()
421 {440 {
422 QScopedPointer<QQuickView> view(loadTest("AnchorFilledReparenting.qml"));441 QScopedPointer<UbuntuTestCase> view(new UbuntuTestCase("AnchorFilledReparenting.qml"));
423 QVERIFY(view);442 QVERIFY(view);
424 QQuickItem *root = view->rootObject();443 QQuickItem *root = view->rootObject();
425 QVERIFY(root);444 QVERIFY(root);
426445
427 QQuickItem *layout = testItem(root, "layoutManager");446 ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager");
428 QVERIFY(layout);447 QVERIFY(layout);
429 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));448 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));
430449
431 QQuickItem *item = testItem(root, "testItem");450 QQuickItem *item = view->findItem<QQuickItem*>("testItem");
432 QVERIFY(item);451 QVERIFY(item);
433452
434 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();453 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();
@@ -436,27 +455,27 @@
436455
437 root->setWidth(root->width() + 100);456 root->setWidth(root->width() + 100);
438 layoutChangeSpy.wait(100);457 layoutChangeSpy.wait(100);
439 QQuickItem *testLayout = testItem(root, "testLayout");458 QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout");
440 QVERIFY(testLayout);459 QVERIFY(testLayout);
441 QCOMPARE(anchors->fill(), testLayout);460 QCOMPARE(anchors->fill(), testLayout);
442461
443 root->setWidth(root->width() - 100);462 root->setWidth(root->width() - 100);
444 layoutChangeSpy.wait(100);463 layoutChangeSpy.wait(100);
445 QCOMPARE(anchors->fill(), layout);464 QCOMPARE(anchors->fill(), layout->contentItem());
446 }465 }
447466
448 void testCase_AnchorFilledMargins()467 void testCase_AnchorFilledMargins()
449 {468 {
450 QScopedPointer<QQuickView> view(loadTest("AnchorFilledMargins.qml"));469 QScopedPointer<UbuntuTestCase> view(new UbuntuTestCase("AnchorFilledMargins.qml"));
451 QVERIFY(view);470 QVERIFY(view);
452 QQuickItem *root = view->rootObject();471 QQuickItem *root = view->rootObject();
453 QVERIFY(root);472 QVERIFY(root);
454473
455 QQuickItem *layout = testItem(root, "layoutManager");474 ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager");
456 QVERIFY(layout);475 QVERIFY(layout);
457 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));476 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));
458477
459 QQuickItem *item = testItem(root, "testItem");478 QQuickItem *item = view->findItem<QQuickItem*>("testItem");
460 QVERIFY(item);479 QVERIFY(item);
461480
462 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();481 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();
@@ -465,29 +484,29 @@
465 root->setWidth(root->width() + 100);484 root->setWidth(root->width() + 100);
466 layoutChangeSpy.wait(100);485 layoutChangeSpy.wait(100);
467486
468 QQuickItem *testLayout = testItem(root, "testLayout");487 QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout");
469 QVERIFY(testLayout);488 QVERIFY(testLayout);
470 QCOMPARE(anchors->fill(), testLayout);489 QCOMPARE(anchors->fill(), testLayout);
471 QCOMPARE(anchors->margins(), 0.0);490 QCOMPARE(anchors->margins(), 0.0);
472491
473 root->setWidth(root->width() - 100);492 root->setWidth(root->width() - 100);
474 layoutChangeSpy.wait(100);493 layoutChangeSpy.wait(100);
475 QCOMPARE(anchors->fill(), layout);494 QCOMPARE(anchors->fill(), layout->contentItem());
476 QCOMPARE(anchors->margins(), 10.0);495 QCOMPARE(anchors->margins(), 10.0);
477 }496 }
478497
479 void testCase_AnchorFilledSeparateMargins()498 void testCase_AnchorFilledSeparateMargins()
480 {499 {
481 QScopedPointer<QQuickView> view(loadTest("AnchorFilledSeparateMargins.qml"));500 QScopedPointer<UbuntuTestCase> view(new UbuntuTestCase("AnchorFilledSeparateMargins.qml"));
482 QVERIFY(view);501 QVERIFY(view);
483 QQuickItem *root = view->rootObject();502 QQuickItem *root = view->rootObject();
484 QVERIFY(root);503 QVERIFY(root);
485504
486 QQuickItem *layout = testItem(root, "layoutManager");505 ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager");
487 QVERIFY(layout);506 QVERIFY(layout);
488 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));507 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));
489508
490 QQuickItem *item = testItem(root, "testItem");509 QQuickItem *item = view->findItem<QQuickItem*>("testItem");
491 QVERIFY(item);510 QVERIFY(item);
492511
493 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();512 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();
@@ -496,7 +515,7 @@
496 root->setWidth(root->width() + 100);515 root->setWidth(root->width() + 100);
497 layoutChangeSpy.wait(100);516 layoutChangeSpy.wait(100);
498517
499 QQuickItem *testLayout = testItem(root, "testLayout");518 QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout");
500 QVERIFY(testLayout);519 QVERIFY(testLayout);
501 QCOMPARE(anchors->fill(), testLayout);520 QCOMPARE(anchors->fill(), testLayout);
502 QCOMPARE(anchors->margins(), 0.0);521 QCOMPARE(anchors->margins(), 0.0);
@@ -507,7 +526,7 @@
507526
508 root->setWidth(root->width() - 100);527 root->setWidth(root->width() - 100);
509 layoutChangeSpy.wait(100);528 layoutChangeSpy.wait(100);
510 QCOMPARE(anchors->fill(), layout);529 QCOMPARE(anchors->fill(), layout->contentItem());
511 QCOMPARE(anchors->leftMargin(), 10.0);530 QCOMPARE(anchors->leftMargin(), 10.0);
512 QCOMPARE(anchors->topMargin(), 20.0);531 QCOMPARE(anchors->topMargin(), 20.0);
513 QCOMPARE(anchors->rightMargin(), 30.0);532 QCOMPARE(anchors->rightMargin(), 30.0);
@@ -516,16 +535,16 @@
516535
517 void testCase_AnchorCenteredInDefault()536 void testCase_AnchorCenteredInDefault()
518 {537 {
519 QScopedPointer<QQuickView> view(loadTest("AnchorCenteredInDefault.qml"));538 QScopedPointer<UbuntuTestCase> view(new UbuntuTestCase("AnchorCenteredInDefault.qml"));
520 QVERIFY(view);539 QVERIFY(view);
521 QQuickItem *root = view->rootObject();540 QQuickItem *root = view->rootObject();
522 QVERIFY(root);541 QVERIFY(root);
523542
524 QQuickItem *layout = testItem(root, "layoutManager");543 ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager");
525 QVERIFY(layout);544 QVERIFY(layout);
526 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));545 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));
527546
528 QQuickItem *item = testItem(root, "testItem");547 QQuickItem *item = view->findItem<QQuickItem*>("testItem");
529 QVERIFY(item);548 QVERIFY(item);
530549
531 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();550 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();
@@ -533,335 +552,335 @@
533552
534 root->setWidth(root->width() + 100);553 root->setWidth(root->width() + 100);
535 layoutChangeSpy.wait(100);554 layoutChangeSpy.wait(100);
536 QQuickItem *testLayout = testItem(root, "testLayout");555 QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout");
537 QVERIFY(testLayout);556 QVERIFY(testLayout);
538 QCOMPARE(anchors->fill(), testLayout);557 QCOMPARE(anchors->fill(), testLayout);
539558
540 root->setWidth(root->width() - 100);559 root->setWidth(root->width() - 100);
541 layoutChangeSpy.wait(100);560 layoutChangeSpy.wait(100);
542 QCOMPARE(anchors->centerIn(), layout);561 QCOMPARE(anchors->centerIn(), layout->contentItem());
543 }562 }
544563
545 void testCase_AnchorVerticalCenter()564 void testCase_AnchorVerticalCenter()
546 {565 {
547 QScopedPointer<QQuickView> view(loadTest("AnchorVerticalCenter.qml"));566 QScopedPointer<UbuntuTestCase> view(new UbuntuTestCase("AnchorVerticalCenter.qml"));
548 QVERIFY(view);567 QVERIFY(view);
549 QQuickItem *root = view->rootObject();568 QQuickItem *root = view->rootObject();
550 QVERIFY(root);569 QVERIFY(root);
551570
552 QQuickItem *layout = testItem(root, "layoutManager");571 ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager");
553 QVERIFY(layout);572 QVERIFY(layout);
554 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));573 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));
555574
556 QQuickItem *item = testItem(root, "testItem");575 QQuickItem *item = view->findItem<QQuickItem*>("testItem");
557 QVERIFY(item);576 QVERIFY(item);
558577
559 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();578 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();
560 QVERIFY(anchors);579 QVERIFY(anchors);
561580
562 QCOMPARE(anchors->verticalCenter().item, layout);581 QCOMPARE(anchors->verticalCenter().item, layout->contentItem());
563582
564 root->setWidth(root->width() + 100);583 root->setWidth(root->width() + 100);
565 layoutChangeSpy.wait(100);584 layoutChangeSpy.wait(100);
566 QQuickItem *testLayout = testItem(root, "testLayout");585 QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout");
567 QVERIFY(testLayout);586 QVERIFY(testLayout);
568 QCOMPARE(anchors->fill(), testLayout);587 QCOMPARE(anchors->fill(), testLayout);
569588
570 root->setWidth(root->width() - 100);589 root->setWidth(root->width() - 100);
571 layoutChangeSpy.wait(100);590 layoutChangeSpy.wait(100);
572 QCOMPARE(anchors->verticalCenter().item, layout);591 QCOMPARE(anchors->verticalCenter().item, layout->contentItem());
573 }592 }
574593
575 void testCase_AnchorVerticalCenterOffset()594 void testCase_AnchorVerticalCenterOffset()
576 {595 {
577 QScopedPointer<QQuickView> view(loadTest("AnchorVerticalCenterOffset.qml"));596 QScopedPointer<UbuntuTestCase> view(new UbuntuTestCase("AnchorVerticalCenterOffset.qml"));
578 QVERIFY(view);597 QVERIFY(view);
579 QQuickItem *root = view->rootObject();598 QQuickItem *root = view->rootObject();
580 QVERIFY(root);599 QVERIFY(root);
581600
582 QQuickItem *layout = testItem(root, "layoutManager");601 ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager");
583 QVERIFY(layout);602 QVERIFY(layout);
584 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));603 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));
585604
586 QQuickItem *item = testItem(root, "testItem");605 QQuickItem *item = view->findItem<QQuickItem*>("testItem");
587 QVERIFY(item);606 QVERIFY(item);
588607
589 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();608 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();
590 QVERIFY(anchors);609 QVERIFY(anchors);
591610
592 QCOMPARE(anchors->verticalCenter().item, layout);611 QCOMPARE(anchors->verticalCenter().item, layout->contentItem());
593 QCOMPARE(anchors->verticalCenterOffset(), 50.0);612 QCOMPARE(anchors->verticalCenterOffset(), 50.0);
594613
595 root->setWidth(root->width() + 100);614 root->setWidth(root->width() + 100);
596 layoutChangeSpy.wait(100);615 layoutChangeSpy.wait(100);
597 QQuickItem *testLayout = qobject_cast<QQuickItem*>(testItem(root, "testLayout"));616 QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout");
598 QVERIFY(testLayout);617 QVERIFY(testLayout);
599 QCOMPARE(anchors->fill(), testLayout);618 QCOMPARE(anchors->fill(), testLayout);
600 // no need to check offset as it does not affect the fill619 // no need to check offset as it does not affect the fill
601620
602 root->setWidth(root->width() - 100);621 root->setWidth(root->width() - 100);
603 layoutChangeSpy.wait(100);622 layoutChangeSpy.wait(100);
604 QCOMPARE(anchors->verticalCenter().item, layout);623 QCOMPARE(anchors->verticalCenter().item, layout->contentItem());
605 QCOMPARE(anchors->verticalCenterOffset(), 50.0);624 QCOMPARE(anchors->verticalCenterOffset(), 50.0);
606 }625 }
607626
608 void testCase_AnchorHorizontalCenter()627 void testCase_AnchorHorizontalCenter()
609 {628 {
610 QScopedPointer<QQuickView> view(loadTest("AnchorHorizontalCenter.qml"));629 QScopedPointer<UbuntuTestCase> view(new UbuntuTestCase("AnchorHorizontalCenter.qml"));
611 QVERIFY(view);630 QVERIFY(view);
612 QQuickItem *root = view->rootObject();631 QQuickItem *root = view->rootObject();
613 QVERIFY(root);632 QVERIFY(root);
614633
615 QQuickItem *layout = testItem(root, "layoutManager");634 ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager");
616 QVERIFY(layout);635 QVERIFY(layout);
617 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));636 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));
618637
619 QQuickItem *item = testItem(root, "testItem");638 QQuickItem *item = view->findItem<QQuickItem*>("testItem");
620 QVERIFY(item);639 QVERIFY(item);
621640
622 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();641 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();
623 QVERIFY(anchors);642 QVERIFY(anchors);
624643
625 QCOMPARE(anchors->horizontalCenter().item, layout);644 QCOMPARE(anchors->horizontalCenter().item, layout->contentItem());
626645
627 root->setWidth(root->width() + 100);646 root->setWidth(root->width() + 100);
628 layoutChangeSpy.wait(100);647 layoutChangeSpy.wait(100);
629 QQuickItem *testLayout = testItem(root, "testLayout");648 QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout");
630 QVERIFY(testLayout);649 QVERIFY(testLayout);
631 QCOMPARE(anchors->fill(), testLayout);650 QCOMPARE(anchors->fill(), testLayout);
632651
633 root->setWidth(root->width() - 100);652 root->setWidth(root->width() - 100);
634 layoutChangeSpy.wait(100);653 layoutChangeSpy.wait(100);
635 QCOMPARE(anchors->horizontalCenter().item, layout);654 QCOMPARE(anchors->horizontalCenter().item, layout->contentItem());
636 }655 }
637656
638 void testCase_AnchorHorizontalCenterOffset()657 void testCase_AnchorHorizontalCenterOffset()
639 {658 {
640 QScopedPointer<QQuickView> view(loadTest("AnchorHorizontalCenterOffset.qml"));659 QScopedPointer<UbuntuTestCase> view(new UbuntuTestCase("AnchorHorizontalCenterOffset.qml"));
641 QVERIFY(view);660 QVERIFY(view);
642 QQuickItem *root = view->rootObject();661 QQuickItem *root = view->rootObject();
643 QVERIFY(root);662 QVERIFY(root);
644663
645 QQuickItem *layout = testItem(root, "layoutManager");664 ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager");
646 QVERIFY(layout);665 QVERIFY(layout);
647 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));666 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));
648667
649 QQuickItem *item = testItem(root, "testItem");668 QQuickItem *item = view->findItem<QQuickItem*>("testItem");
650 QVERIFY(item);669 QVERIFY(item);
651670
652 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();671 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();
653 QVERIFY(anchors);672 QVERIFY(anchors);
654673
655 QCOMPARE(anchors->horizontalCenter().item, layout);674 QCOMPARE(anchors->horizontalCenter().item, layout->contentItem());
656 QCOMPARE(anchors->horizontalCenterOffset(), 50.0);675 QCOMPARE(anchors->horizontalCenterOffset(), 50.0);
657676
658 root->setWidth(root->width() + 100);677 root->setWidth(root->width() + 100);
659 layoutChangeSpy.wait(100);678 layoutChangeSpy.wait(100);
660 QQuickItem *testLayout = testItem(root, "testLayout");679 QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout");
661 QVERIFY(testLayout);680 QVERIFY(testLayout);
662 QCOMPARE(anchors->fill(), testLayout);681 QCOMPARE(anchors->fill(), testLayout);
663 // no need to check offset as it does not affect the fill682 // no need to check offset as it does not affect the fill
664683
665 root->setWidth(root->width() - 100);684 root->setWidth(root->width() - 100);
666 layoutChangeSpy.wait(100);685 layoutChangeSpy.wait(100);
667 QCOMPARE(anchors->horizontalCenter().item, layout);686 QCOMPARE(anchors->horizontalCenter().item, layout->contentItem());
668 QCOMPARE(anchors->horizontalCenterOffset(), 50.0);687 QCOMPARE(anchors->horizontalCenterOffset(), 50.0);
669 }688 }
670689
671 void testCase_AnchorCenterWithOffset()690 void testCase_AnchorCenterWithOffset()
672 {691 {
673 QScopedPointer<QQuickView> view(loadTest("AnchorCenterWithOffset.qml"));692 QScopedPointer<UbuntuTestCase> view(new UbuntuTestCase("AnchorCenterWithOffset.qml"));
674 QVERIFY(view);693 QVERIFY(view);
675 QQuickItem *root = view->rootObject();694 QQuickItem *root = view->rootObject();
676 QVERIFY(root);695 QVERIFY(root);
677696
678 QQuickItem *layout = testItem(root, "layoutManager");697 ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager");
679 QVERIFY(layout);698 QVERIFY(layout);
680 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));699 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));
681700
682 QQuickItem *item = testItem(root, "testItem");701 QQuickItem *item = view->findItem<QQuickItem*>("testItem");
683 QVERIFY(item);702 QVERIFY(item);
684703
685 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();704 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();
686 QVERIFY(anchors);705 QVERIFY(anchors);
687706
688 QCOMPARE(anchors->centerIn(), layout);707 QCOMPARE(anchors->centerIn(), layout->contentItem());
689 QCOMPARE(anchors->verticalCenterOffset(), 50.0);708 QCOMPARE(anchors->verticalCenterOffset(), 50.0);
690 QCOMPARE(anchors->horizontalCenterOffset(), 40.0);709 QCOMPARE(anchors->horizontalCenterOffset(), 40.0);
691710
692 root->setWidth(root->width() + 100);711 root->setWidth(root->width() + 100);
693 layoutChangeSpy.wait(100);712 layoutChangeSpy.wait(100);
694 QQuickItem *testLayout = testItem(root, "testLayout");713 QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout");
695 QVERIFY(testLayout);714 QVERIFY(testLayout);
696 QCOMPARE(anchors->fill(), testLayout);715 QCOMPARE(anchors->fill(), testLayout);
697 // no need to check offsets as it does not affect the fill716 // no need to check offsets as it does not affect the fill
698717
699 root->setWidth(root->width() - 100);718 root->setWidth(root->width() - 100);
700 layoutChangeSpy.wait(100);719 layoutChangeSpy.wait(100);
701 QCOMPARE(anchors->centerIn(), layout);720 QCOMPARE(anchors->centerIn(), layout->contentItem());
702 QCOMPARE(anchors->verticalCenterOffset(), 50.0);721 QCOMPARE(anchors->verticalCenterOffset(), 50.0);
703 QCOMPARE(anchors->horizontalCenterOffset(), 40.0);722 QCOMPARE(anchors->horizontalCenterOffset(), 40.0);
704 }723 }
705724
706 void testCase_AnchorLeft()725 void testCase_AnchorLeft()
707 {726 {
708 QScopedPointer<QQuickView> view(loadTest("AnchorLeft.qml"));727 QScopedPointer<UbuntuTestCase> view(new UbuntuTestCase("AnchorLeft.qml"));
709 QVERIFY(view);728 QVERIFY(view);
710 QQuickItem *root = view->rootObject();729 QQuickItem *root = view->rootObject();
711 QVERIFY(root);730 QVERIFY(root);
712731
713 QQuickItem *layout = testItem(root, "layoutManager");732 ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager");
714 QVERIFY(layout);733 QVERIFY(layout);
715 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));734 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));
716735
717 QQuickItem *item = testItem(root, "testItem");736 QQuickItem *item = view->findItem<QQuickItem*>("testItem");
718 QVERIFY(item);737 QVERIFY(item);
719738
720 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();739 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();
721 QVERIFY(anchors);740 QVERIFY(anchors);
722741
723 QCOMPARE(anchors->left().item, layout);742 QCOMPARE(anchors->left().item, layout->contentItem());
724 QCOMPARE(anchors->leftMargin(), 10.0);743 QCOMPARE(anchors->leftMargin(), 10.0);
725744
726 root->setWidth(root->width() + 100);745 root->setWidth(root->width() + 100);
727 layoutChangeSpy.wait(100);746 layoutChangeSpy.wait(100);
728 QQuickItem *testLayout = testItem(root, "testLayout");747 QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout");
729 QVERIFY(testLayout);748 QVERIFY(testLayout);
730 QCOMPARE(anchors->fill(), testLayout);749 QCOMPARE(anchors->fill(), testLayout);
731 QCOMPARE(anchors->leftMargin(), 0.0);750 QCOMPARE(anchors->leftMargin(), 0.0);
732751
733 root->setWidth(root->width() - 100);752 root->setWidth(root->width() - 100);
734 layoutChangeSpy.wait(100);753 layoutChangeSpy.wait(100);
735 QCOMPARE(anchors->left().item, layout);754 QCOMPARE(anchors->left().item, layout->contentItem());
736 QCOMPARE(anchors->leftMargin(), 10.0);755 QCOMPARE(anchors->leftMargin(), 10.0);
737 }756 }
738757
739 void testCase_AnchorTop()758 void testCase_AnchorTop()
740 {759 {
741 QScopedPointer<QQuickView> view(loadTest("AnchorTop.qml"));760 QScopedPointer<UbuntuTestCase> view(new UbuntuTestCase("AnchorTop.qml"));
742 QVERIFY(view);761 QVERIFY(view);
743 QQuickItem *root = view->rootObject();762 QQuickItem *root = view->rootObject();
744 QVERIFY(root);763 QVERIFY(root);
745764
746 QQuickItem *layout = testItem(root, "layoutManager");765 ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager");
747 QVERIFY(layout);766 QVERIFY(layout);
748 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));767 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));
749768
750 QQuickItem *item = testItem(root, "testItem");769 QQuickItem *item = view->findItem<QQuickItem*>("testItem");
751 QVERIFY(item);770 QVERIFY(item);
752771
753 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();772 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();
754 QVERIFY(anchors);773 QVERIFY(anchors);
755774
756 QCOMPARE(anchors->top().item, layout);775 QCOMPARE(anchors->top().item, layout->contentItem());
757 QCOMPARE(anchors->topMargin(), 10.0);776 QCOMPARE(anchors->topMargin(), 10.0);
758777
759 root->setWidth(root->width() + 100);778 root->setWidth(root->width() + 100);
760 layoutChangeSpy.wait(100);779 layoutChangeSpy.wait(100);
761 QQuickItem *testLayout = testItem(root, "testLayout");780 QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout");
762 QVERIFY(testLayout);781 QVERIFY(testLayout);
763 QCOMPARE(anchors->fill(), testLayout);782 QCOMPARE(anchors->fill(), testLayout);
764 QCOMPARE(anchors->topMargin(), 0.0);783 QCOMPARE(anchors->topMargin(), 0.0);
765784
766 root->setWidth(root->width() - 100);785 root->setWidth(root->width() - 100);
767 layoutChangeSpy.wait(100);786 layoutChangeSpy.wait(100);
768 QCOMPARE(anchors->top().item, layout);787 QCOMPARE(anchors->top().item, layout->contentItem());
769 QCOMPARE(anchors->topMargin(), 10.0);788 QCOMPARE(anchors->topMargin(), 10.0);
770 }789 }
771790
772 void testCase_AnchorRight()791 void testCase_AnchorRight()
773 {792 {
774 QScopedPointer<QQuickView> view(loadTest("AnchorRight.qml"));793 QScopedPointer<UbuntuTestCase> view(new UbuntuTestCase("AnchorRight.qml"));
775 QVERIFY(view);794 QVERIFY(view);
776 QQuickItem *root = view->rootObject();795 QQuickItem *root = view->rootObject();
777 QVERIFY(root);796 QVERIFY(root);
778797
779 QQuickItem *layout = testItem(root, "layoutManager");798 ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager");
780 QVERIFY(layout);799 QVERIFY(layout);
781 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));800 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));
782801
783 QQuickItem *item = testItem(root, "testItem");802 QQuickItem *item = view->findItem<QQuickItem*>("testItem");
784 QVERIFY(item);803 QVERIFY(item);
785804
786 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();805 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();
787 QVERIFY(anchors);806 QVERIFY(anchors);
788807
789 QCOMPARE(anchors->right().item, layout);808 QCOMPARE(anchors->right().item, layout->contentItem());
790 QCOMPARE(anchors->rightMargin(), 10.0);809 QCOMPARE(anchors->rightMargin(), 10.0);
791810
792 root->setWidth(root->width() + 100);811 root->setWidth(root->width() + 100);
793 layoutChangeSpy.wait(100);812 layoutChangeSpy.wait(100);
794 QQuickItem *testLayout = testItem(root, "testLayout");813 QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout");
795 QVERIFY(testLayout);814 QVERIFY(testLayout);
796 QCOMPARE(anchors->fill(), testLayout);815 QCOMPARE(anchors->fill(), testLayout);
797 QCOMPARE(anchors->rightMargin(), 0.0);816 QCOMPARE(anchors->rightMargin(), 0.0);
798817
799 root->setWidth(root->width() - 100);818 root->setWidth(root->width() - 100);
800 layoutChangeSpy.wait(100);819 layoutChangeSpy.wait(100);
801 QCOMPARE(anchors->right().item, layout);820 QCOMPARE(anchors->right().item, layout->contentItem());
802 QCOMPARE(anchors->rightMargin(), 10.0);821 QCOMPARE(anchors->rightMargin(), 10.0);
803 }822 }
804823
805 void testCase_AnchorBottom()824 void testCase_AnchorBottom()
806 {825 {
807 QScopedPointer<QQuickView> view(loadTest("AnchorBottom.qml"));826 QScopedPointer<UbuntuTestCase> view(new UbuntuTestCase("AnchorBottom.qml"));
808 QVERIFY(view);827 QVERIFY(view);
809 QQuickItem *root = view->rootObject();828 QQuickItem *root = view->rootObject();
810 QVERIFY(root);829 QVERIFY(root);
811830
812 QQuickItem *layout = testItem(root, "layoutManager");831 ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager");
813 QVERIFY(layout);832 QVERIFY(layout);
814 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));833 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));
815834
816 QQuickItem *item = testItem(root, "testItem");835 QQuickItem *item = view->findItem<QQuickItem*>("testItem");
817 QVERIFY(item);836 QVERIFY(item);
818837
819 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();838 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();
820 QVERIFY(anchors);839 QVERIFY(anchors);
821840
822 QCOMPARE(anchors->bottom().item, layout);841 QCOMPARE(anchors->bottom().item, layout->contentItem());
823 QCOMPARE(anchors->bottomMargin(), 10.0);842 QCOMPARE(anchors->bottomMargin(), 10.0);
824843
825 root->setWidth(root->width() + 100);844 root->setWidth(root->width() + 100);
826 layoutChangeSpy.wait(100);845 layoutChangeSpy.wait(100);
827 QQuickItem *testLayout = testItem(root, "testLayout");846 QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout");
828 QVERIFY(testLayout);847 QVERIFY(testLayout);
829 QCOMPARE(anchors->fill(), testLayout);848 QCOMPARE(anchors->fill(), testLayout);
830 QCOMPARE(anchors->bottomMargin(), 0.0);849 QCOMPARE(anchors->bottomMargin(), 0.0);
831850
832 root->setWidth(root->width() - 100);851 root->setWidth(root->width() - 100);
833 layoutChangeSpy.wait(100);852 layoutChangeSpy.wait(100);
834 QCOMPARE(anchors->bottom().item, layout);853 QCOMPARE(anchors->bottom().item, layout->contentItem());
835 QCOMPARE(anchors->bottomMargin(), 10.0);854 QCOMPARE(anchors->bottomMargin(), 10.0);
836 }855 }
837856
838 void testCase_AnchorAll()857 void testCase_AnchorAll()
839 {858 {
840 QScopedPointer<QQuickView> view(loadTest("AnchorAll.qml"));859 QScopedPointer<UbuntuTestCase> view(new UbuntuTestCase("AnchorAll.qml"));
841 QVERIFY(view);860 QVERIFY(view);
842 QQuickItem *root = view->rootObject();861 QQuickItem *root = view->rootObject();
843 QVERIFY(root);862 QVERIFY(root);
844863
845 QQuickItem *layout = testItem(root, "layoutManager");864 ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager");
846 QVERIFY(layout);865 QVERIFY(layout);
847 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));866 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));
848867
849 QQuickItem *item = testItem(root, "testItem");868 QQuickItem *item = view->findItem<QQuickItem*>("testItem");
850 QVERIFY(item);869 QVERIFY(item);
851870
852 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();871 QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>();
853 QVERIFY(anchors);872 QVERIFY(anchors);
854873
855 QCOMPARE(anchors->left().item, layout);874 QCOMPARE(anchors->left().item, layout->contentItem());
856 QCOMPARE(anchors->top().item, layout);875 QCOMPARE(anchors->top().item, layout->contentItem());
857 QCOMPARE(anchors->right().item, layout);876 QCOMPARE(anchors->right().item, layout->contentItem());
858 QCOMPARE(anchors->bottom().item, layout);877 QCOMPARE(anchors->bottom().item, layout->contentItem());
859 QVERIFY(!anchors->fill());878 QVERIFY(!anchors->fill());
860 QCOMPARE(anchors->margins(), 20.0);879 QCOMPARE(anchors->margins(), 20.0);
861880
862 root->setWidth(root->width() + 100);881 root->setWidth(root->width() + 100);
863 layoutChangeSpy.wait(100);882 layoutChangeSpy.wait(100);
864 QQuickItem *testLayout = testItem(root, "testLayout");883 QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout");
865 QVERIFY(testLayout);884 QVERIFY(testLayout);
866 QCOMPARE(anchors->fill(), testLayout);885 QCOMPARE(anchors->fill(), testLayout);
867 QVERIFY(!anchors->left().item);886 QVERIFY(!anchors->left().item);
@@ -872,10 +891,10 @@
872891
873 root->setWidth(root->width() - 100);892 root->setWidth(root->width() - 100);
874 layoutChangeSpy.wait(100);893 layoutChangeSpy.wait(100);
875 QCOMPARE(anchors->left().item, layout);894 QCOMPARE(anchors->left().item, layout->contentItem());
876 QCOMPARE(anchors->top().item, layout);895 QCOMPARE(anchors->top().item, layout->contentItem());
877 QCOMPARE(anchors->right().item, layout);896 QCOMPARE(anchors->right().item, layout->contentItem());
878 QCOMPARE(anchors->bottom().item, layout);897 QCOMPARE(anchors->bottom().item, layout->contentItem());
879 QVERIFY(!anchors->fill());898 QVERIFY(!anchors->fill());
880 QCOMPARE(anchors->margins(), 20.0);899 QCOMPARE(anchors->margins(), 20.0);
881 }900 }
@@ -932,6 +951,115 @@
932 QCOMPARE(layoutChangeSpy.count(), 1);951 QCOMPARE(layoutChangeSpy.count(), 1);
933 }952 }
934953
954 // guard bug #1204834 and #1300668
955 void testCase_Visibility()
956 {
957 QScopedPointer<UbuntuTestCase> view(new UbuntuTestCase("Visibility.qml"));
958 QVERIFY(view);
959 QQuickItem *root = view->rootObject();
960 QVERIFY(root);
961
962 ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager");
963 QVERIFY(layout);
964 QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged()));
965
966 QQuickItem *defaultLayout = testItem(root, "DefaultLayout");
967 QVERIFY(defaultLayout);
968
969 // invoke layout change
970 view->rootObject()->metaObject()->invokeMethod(view->rootObject(), "portraitLayout");
971 layoutChangeSpy.wait(1000);
972 QCOMPARE(defaultLayout->parentItem(), layout->contentItem());
973 // despite of visible property binding, the visibility of the component is false
974 // while its parent is set to invisible
975 QCOMPARE(defaultLayout->isVisible(), false);
976 QCOMPARE(layout->contentItem()->isVisible(), false);
977
978 // change layout back
979 layoutChangeSpy.clear();
980 view->rootObject()->metaObject()->invokeMethod(view->rootObject(), "landscapeLayout");
981 layoutChangeSpy.wait(1000);
982 QCOMPARE(defaultLayout->parentItem(), layout->contentItem());
983 QCOMPARE(defaultLayout->isVisible(), true);
984 QCOMPARE(layout->contentItem()->isVisible(), true);
985 }
986
987 void testCase_NestedVisibility_data() {
988 QTest::addColumn<QString>("layoutFunction");
989 QTest::addColumn<QString>("layoutName");
990
991 QTest::newRow("portrait") << "tabletPortraitLayout" << "tabletPortrait";
992 QTest::newRow("landscape") << "tabletLandscapeLayout" << "tabletLandscape";
993 }
994
995 void testCase_NestedVisibility()
996 {
997 QFETCH(QString, layoutFunction);
998 QFETCH(QString, layoutName);
999
1000 QScopedPointer<UbuntuTestCase> view(new UbuntuTestCase("NestedVisibility.qml"));
1001 QVERIFY(view);
1002 QQuickItem *root = view->rootObject();
1003 QVERIFY(root);
1004
1005 ULLayouts *mainLayout = view->findItem<ULLayouts*>("mainLayout");
1006 QVERIFY(mainLayout);
1007 QQuickItem *red = testItem(mainLayout, "mainRed");
1008 QVERIFY(red);
1009 QQuickItem *green = testItem(mainLayout, "mainGreen");
1010 QVERIFY(green);
1011 QQuickItem *blue = testItem(mainLayout, "mainBlue");
1012 QVERIFY(blue);
1013 QQuickItem *magenta = testItem(mainLayout, "mainMagenta");
1014 QVERIFY(magenta);
1015 QQuickItem *hidden = testItem(mainLayout, "mainHidden");
1016 QVERIFY(hidden);
1017 QCOMPARE(hidden->isVisible(), false);
1018 // default is phone layout, get layd out items' neighbors
1019 QQuickItem *greenPrev = prevSibling(green);
1020 QQuickItem *magentaPrev = prevSibling(magenta);
1021 QSizeF greenSize(green->width(), green->height());
1022 QSizeF magentaSize(magenta->width(), magenta->height());
1023
1024 // invoke tablet layout change
1025 QSignalSpy mainLayoutChangeSpy(mainLayout, SIGNAL(currentLayoutChanged()));
1026 view->rootObject()->metaObject()->invokeMethod(view->rootObject(), layoutFunction.toLocal8Bit().data());
1027 mainLayoutChangeSpy.wait(1000);
1028 // get the nested layout
1029 ULLayouts *nestedLayout = qobject_cast<ULLayouts*>(testItem(mainLayout, "nestedLayout"));
1030 QVERIFY(nestedLayout);
1031 QQuickItem *nestedActiveLayout = testItem(nestedLayout, layoutName);
1032 QVERIFY(nestedActiveLayout);
1033 QCOMPARE(red->isVisible(), false);
1034 QCOMPARE(green->isVisible(), true);
1035 QCOMPARE(blue->isVisible(), false);
1036 QCOMPARE(magenta->isVisible(), true);
1037 QCOMPARE(hidden->isVisible(), false);
1038 // we cannot use findChild() to locate green and magenta boxes, as reparenting only
1039 // changes the parentItem, not the parent object itself; therefore we only check if
1040 // their container is in the layout
1041 QVERIFY(hasChildItem(green, nestedActiveLayout));
1042 QVERIFY(hasChildItem(magenta, nestedActiveLayout));
1043
1044 // go back to default layout of main
1045 mainLayoutChangeSpy.clear();
1046 view->rootObject()->metaObject()->invokeMethod(view->rootObject(), "phoneLayout");
1047 mainLayoutChangeSpy.wait(1000);
1048 QCOMPARE(red->isVisible(), true);
1049 QCOMPARE(green->isVisible(), true);
1050 QCOMPARE(blue->isVisible(), true);
1051 QCOMPARE(magenta->isVisible(), true);
1052 QCOMPARE(hidden->isVisible(), false);
1053 QCOMPARE(prevSibling(green), greenPrev);
1054 QCOMPARE(prevSibling(magenta), magentaPrev);
1055 QCOMPARE(green->width(), greenSize.width());
1056 QCOMPARE(green->height(), greenSize.height());
1057 QCOMPARE(magenta->width(), magentaSize.width());
1058 QCOMPARE(magenta->height(), magentaSize.height());
1059 QVERIFY(hasChildItem(green, mainLayout->contentItem()));
1060 QVERIFY(hasChildItem(magenta, mainLayout->contentItem()));
1061 }
1062
935};1063};
9361064
937QTEST_MAIN(tst_Layouts)1065QTEST_MAIN(tst_Layouts)
9381066
=== modified file 'tests/unit_x11/tst_layouts/tst_layouts.pro'
--- tests/unit_x11/tst_layouts/tst_layouts.pro 2014-02-18 13:27:23 +0000
+++ tests/unit_x11/tst_layouts/tst_layouts.pro 2014-05-20 19:37:09 +0000
@@ -37,4 +37,6 @@
37 AnchorAll.qml \37 AnchorAll.qml \
38 ItemInstanceAsProperty.qml \38 ItemInstanceAsProperty.qml \
39 DialerCrash.qml \39 DialerCrash.qml \
40 ExcludedItemDeleted.qml40 ExcludedItemDeleted.qml \
41 Visibility.qml \
42 NestedVisibility.qml

Subscribers

People subscribed via source and target branches