Merge lp:~zsombi/ubuntu-ui-toolkit/stateSaverWithRepeater into lp:ubuntu-ui-toolkit

Proposed by Zsombor Egri
Status: Merged
Approved by: Florian Boucault
Approved revision: 915
Merged at revision: 914
Proposed branch: lp:~zsombi/ubuntu-ui-toolkit/stateSaverWithRepeater
Merge into: lp:ubuntu-ui-toolkit
Diff against target: 320 lines (+254/-2)
6 files modified
modules/Ubuntu/Components/plugin/ucstatesaver.cpp (+31/-1)
tests/unit_x11/tst_statesaver/GridViewItems.qml (+38/-0)
tests/unit_x11/tst_statesaver/ListViewItems.qml (+38/-0)
tests/unit_x11/tst_statesaver/RepeaterStates.qml (+40/-0)
tests/unit_x11/tst_statesaver/tst_statesaver.cpp (+103/-0)
tests/unit_x11/tst_statesaver/tst_statesaver.pro (+4/-1)
To merge this branch: bzr merge lp:~zsombi/ubuntu-ui-toolkit/stateSaverWithRepeater
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Francis Ginther (community) Approve
Florian Boucault (community) Approve
Review via email: mp+201214@code.launchpad.net

Commit message

StateSaver failure with Repeater fixed. Indirectly fixes StateSaver with ListView and GridView.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Florian Boucault (fboucault) wrote :

Seems good to me.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Francis Ginther (fginther) wrote :

The autopilot-testrunner-otto-trusty job failed due to a transient problem with lxc.

Revision history for this message
Francis Ginther (fginther) wrote :

> The autopilot-testrunner-otto-trusty job failed due to a transient problem
> with lxc.

This MP should be re-approved to retry the build.

review: Approve
Revision history for this message
Francis Ginther (fginther) wrote :

> The autopilot-testrunner-otto-trusty job failed due to a transient problem
> with lxc.

This MP should be re-approved to retry the build.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'modules/Ubuntu/Components/plugin/ucstatesaver.cpp'
2--- modules/Ubuntu/Components/plugin/ucstatesaver.cpp 2013-11-19 17:26:04 +0000
3+++ modules/Ubuntu/Components/plugin/ucstatesaver.cpp 2014-01-10 16:16:30 +0000
4@@ -86,13 +86,20 @@
5
6 QString UCStateSaverAttachedPrivate::absoluteId(const QString &id)
7 {
8- QQmlContextData *cdata = QQmlContextData::get(qmlContext(m_attachee));
9+ QQmlContext *attacheeContext = qmlContext(m_attachee);
10+ QQmlContextData *cdata = QQmlContextData::get(attacheeContext);
11 QQmlData *ddata = QQmlData::get(m_attachee);
12 QString path = cdata->url.path().replace('/', '_') + ':'
13 + QString::number(ddata->lineNumber) + ':'
14 + QString::number(ddata->columnNumber) + ':' + id;
15 QObject *parent = m_attachee->parent();
16
17+ // check whether we have an "index" context property defined
18+ QVariant indexValue = attacheeContext->contextProperty("index");
19+ if (indexValue.isValid() && (indexValue.type() == QVariant::Int)) {
20+ path += indexValue.toString();
21+ }
22+
23 while (parent) {
24 QString parentId = qmlContext(parent)->nameForObject(parent);
25 QString className = QuickUtils::instance().className(parent);
26@@ -233,6 +240,29 @@
27 * }
28 * \endqml
29 *
30+ * When used with Repeater, each created item from the Repeater's delegate will
31+ * be saved separately. Note that due to the way Repeater works, Repeaters do not
32+ * need to have id specified.
33+ *
34+ * \qml
35+ * Item {
36+ * id: root
37+ * // [...]
38+ * Repeater {
39+ * model: 10
40+ * Rectangle {
41+ * id: rect
42+ * width: 50; height: 50
43+ * StateSaver.properties: "width, height"
44+ * }
45+ * }
46+ * // [...]
47+ * }
48+ * \endqml
49+ *
50+ * It can be used in the same way in ListView or GridView, except that both ListView
51+ * and GridView must have an id set.
52+ *
53 * The StateSaver can save all \l{http://qt-project.org/doc/qt-5.0/qtqml/qtqml-typesystem-basictypes.html}{QML base types},
54 * Objects, list of objects or variants containing any of these cannot be saved.
55 */
56
57=== added file 'tests/unit_x11/tst_statesaver/GridViewItems.qml'
58--- tests/unit_x11/tst_statesaver/GridViewItems.qml 1970-01-01 00:00:00 +0000
59+++ tests/unit_x11/tst_statesaver/GridViewItems.qml 2014-01-10 16:16:30 +0000
60@@ -0,0 +1,38 @@
61+/*
62+ * Copyright 2014 Canonical Ltd.
63+ *
64+ * This program is free software; you can redistribute it and/or modify
65+ * it under the terms of the GNU Lesser General Public License as published by
66+ * the Free Software Foundation; version 3.
67+ *
68+ * This program is distributed in the hope that it will be useful,
69+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
70+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
71+ * GNU Lesser General Public License for more details.
72+ *
73+ * You should have received a copy of the GNU Lesser General Public License
74+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
75+ */
76+
77+import QtQuick 2.0
78+import Ubuntu.Components 0.1
79+
80+Item {
81+ id: root
82+ width: 100
83+ height: 100
84+
85+ GridView {
86+ id: listView
87+ objectName: "grid"
88+ anchors.fill: parent
89+ model: 2
90+ delegate: Rectangle {
91+ id: listItem
92+ objectName: "testItem"
93+ width: 20
94+ height: 20
95+ StateSaver.properties: "height"
96+ }
97+ }
98+}
99
100=== added file 'tests/unit_x11/tst_statesaver/ListViewItems.qml'
101--- tests/unit_x11/tst_statesaver/ListViewItems.qml 1970-01-01 00:00:00 +0000
102+++ tests/unit_x11/tst_statesaver/ListViewItems.qml 2014-01-10 16:16:30 +0000
103@@ -0,0 +1,38 @@
104+/*
105+ * Copyright 2014 Canonical Ltd.
106+ *
107+ * This program is free software; you can redistribute it and/or modify
108+ * it under the terms of the GNU Lesser General Public License as published by
109+ * the Free Software Foundation; version 3.
110+ *
111+ * This program is distributed in the hope that it will be useful,
112+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
113+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
114+ * GNU Lesser General Public License for more details.
115+ *
116+ * You should have received a copy of the GNU Lesser General Public License
117+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
118+ */
119+
120+import QtQuick 2.0
121+import Ubuntu.Components 0.1
122+
123+Item {
124+ id: root
125+ width: 100
126+ height: 100
127+
128+ ListView {
129+ id: listView
130+ objectName: "list"
131+ anchors.fill: parent
132+ model: 2
133+ delegate: Rectangle {
134+ id: listItem
135+ objectName: "testItem"
136+ width: parent.width
137+ height: 20
138+ StateSaver.properties: "height"
139+ }
140+ }
141+}
142
143=== added file 'tests/unit_x11/tst_statesaver/RepeaterStates.qml'
144--- tests/unit_x11/tst_statesaver/RepeaterStates.qml 1970-01-01 00:00:00 +0000
145+++ tests/unit_x11/tst_statesaver/RepeaterStates.qml 2014-01-10 16:16:30 +0000
146@@ -0,0 +1,40 @@
147+/*
148+ * Copyright 2014 Canonical Ltd.
149+ *
150+ * This program is free software; you can redistribute it and/or modify
151+ * it under the terms of the GNU Lesser General Public License as published by
152+ * the Free Software Foundation; version 3.
153+ *
154+ * This program is distributed in the hope that it will be useful,
155+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
156+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
157+ * GNU Lesser General Public License for more details.
158+ *
159+ * You should have received a copy of the GNU Lesser General Public License
160+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
161+ */
162+
163+import QtQuick 2.0
164+import Ubuntu.Components 0.1
165+
166+Item {
167+ id: root
168+ width: 100
169+ height: 100
170+
171+ Column {
172+ id: column
173+ objectName: "column"
174+ Repeater {
175+ id: repeater
176+ model: 4
177+ Rectangle {
178+ id: rect
179+ width: root.width
180+ height: 20
181+ objectName: "testItem"
182+ StateSaver.properties: "height"
183+ }
184+ }
185+ }
186+}
187
188=== modified file 'tests/unit_x11/tst_statesaver/tst_statesaver.cpp'
189--- tests/unit_x11/tst_statesaver/tst_statesaver.cpp 2014-01-08 12:15:32 +0000
190+++ tests/unit_x11/tst_statesaver/tst_statesaver.cpp 2014-01-10 16:16:30 +0000
191@@ -28,6 +28,7 @@
192 #include <QMatrix4x4>
193 #include <QtQuick/QQuickItem>
194 #include <QtQml/QQmlProperty>
195+#include "quickutils.h"
196
197 #define protected public
198 #include "ucstatesaver.h"
199@@ -435,6 +436,108 @@
200 QVERIFY(testItem);
201 delete view;
202 }
203+
204+ void test_repeaterStates()
205+ {
206+ QScopedPointer<QQuickView> view(createView("RepeaterStates.qml"));
207+ QVERIFY(view);
208+ QQuickItem *column = view->rootObject()->findChild<QQuickItem*>("column");
209+ QVERIFY(column);
210+
211+ QList<QQuickItem*> items = column->childItems();
212+ QCOMPARE(items.count(), 5); // 4 Rectangles + 1 Repeater
213+
214+ Q_FOREACH(QQuickItem *item, items) {
215+ if (QuickUtils::instance().className(item) == "QQuickRectangle") {
216+ item->setHeight(25);
217+ }
218+ }
219+ view.reset();
220+
221+ view.reset(createView("RepeaterStates.qml"));
222+ QVERIFY(view);
223+ column = view->rootObject()->findChild<QQuickItem*>("column");
224+ QVERIFY(column);
225+
226+ items = column->childItems();
227+ QCOMPARE(items.count(), 5); // 4 Rectangles + 1 Repeater
228+
229+ Q_FOREACH(QQuickItem *item, items) {
230+ if (QuickUtils::instance().className(item) == "QQuickRectangle") {
231+ QCOMPARE(item->height(), 25.0);
232+ }
233+ }
234+ }
235+
236+ void test_ListViewItemStates()
237+ {
238+ QScopedPointer<QQuickView> view(createView("ListViewItems.qml"));
239+ QVERIFY(view);
240+ QQuickItem *list = view->rootObject()->findChild<QQuickItem*>("list");
241+ QVERIFY(list);
242+ QQuickItem *contentItem = list->property("contentItem").value<QQuickItem*>();
243+ QVERIFY(contentItem);
244+ QList<QQuickItem*> items = contentItem->childItems();
245+
246+ int testItemCount = 0;
247+ Q_FOREACH(QQuickItem *item, items) {
248+ if (item->objectName() == "testItem") {
249+ item->setHeight(25);
250+ testItemCount++;
251+ }
252+ }
253+ QCOMPARE(testItemCount, 2);
254+ view.reset();
255+
256+ view.reset(createView("ListViewItems.qml"));
257+ QVERIFY(view);
258+ list = view->rootObject()->findChild<QQuickItem*>("list");
259+ QVERIFY(list);
260+ contentItem = list->property("contentItem").value<QQuickItem*>();
261+ QVERIFY(contentItem);
262+ items = contentItem->childItems();
263+
264+ Q_FOREACH(QQuickItem *item, items) {
265+ if (item->objectName() == "testItem") {
266+ QCOMPARE(item->height(), 25.0);
267+ }
268+ }
269+ }
270+
271+ void test_GridViewItemStates()
272+ {
273+ QScopedPointer<QQuickView> view(createView("GridViewItems.qml"));
274+ QVERIFY(view);
275+ QQuickItem *list = view->rootObject()->findChild<QQuickItem*>("grid");
276+ QVERIFY(list);
277+ QQuickItem *contentItem = list->property("contentItem").value<QQuickItem*>();
278+ QVERIFY(contentItem);
279+ QList<QQuickItem*> items = contentItem->childItems();
280+
281+ int testItemCount = 0;
282+ Q_FOREACH(QQuickItem *item, items) {
283+ if (item->objectName() == "testItem") {
284+ item->setHeight(25);
285+ testItemCount++;
286+ }
287+ }
288+ QCOMPARE(testItemCount, 2);
289+ view.reset();
290+
291+ view.reset(createView("GridViewItems.qml"));
292+ QVERIFY(view);
293+ list = view->rootObject()->findChild<QQuickItem*>("grid");
294+ QVERIFY(list);
295+ contentItem = list->property("contentItem").value<QQuickItem*>();
296+ QVERIFY(contentItem);
297+ items = contentItem->childItems();
298+
299+ Q_FOREACH(QQuickItem *item, items) {
300+ if (item->objectName() == "testItem") {
301+ QCOMPARE(item->height(), 25.0);
302+ }
303+ }
304+ }
305 };
306
307 QTEST_MAIN(tst_StateSaverTest)
308
309=== modified file 'tests/unit_x11/tst_statesaver/tst_statesaver.pro'
310--- tests/unit_x11/tst_statesaver/tst_statesaver.pro 2014-01-08 10:22:46 +0000
311+++ tests/unit_x11/tst_statesaver/tst_statesaver.pro 2014-01-10 16:16:30 +0000
312@@ -22,4 +22,7 @@
313 ComponentsWithStateSavers.qml \
314 CustomControl.qml \
315 ComponentsWithStateSaversNoId.qml \
316- NestedDynamics.qml
317+ NestedDynamics.qml \
318+ RepeaterStates.qml \
319+ ListViewItems.qml \
320+ GridViewItems.qml

Subscribers

People subscribed via source and target branches

to status/vote changes: