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

Proposed by Cris Dywan
Status: Merged
Approved by: Tim Peeters
Approved revision: 1796
Merged at revision: 1793
Proposed branch: lp:~ubuntu-sdk-team/ubuntu-ui-toolkit/scaleMeBabyOneMoreTime
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 221 lines (+132/-12)
5 files modified
src/Ubuntu/Components/plugin/ucqquickimageextension.cpp (+11/-6)
src/Ubuntu/Components/plugin/ucscalingimageprovider.cpp (+3/-1)
tests/unit_x11/tst_components/battery-100-charging.svg (+25/-0)
tests/unit_x11/tst_components/shape.svg (+77/-0)
tests/unit_x11/tst_components/tst_imageprovider.qml (+16/-5)
To merge this branch: bzr merge lp:~ubuntu-sdk-team/ubuntu-ui-toolkit/scaleMeBabyOneMoreTime
Reviewer Review Type Date Requested Status
Tim Peeters Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+281275@code.launchpad.net

Commit message

Use resolved filename but add fragment

Description of the change

Use resolved filename but add fragment

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
1794. By Cris Dywan

Better test cases for scaling image provider

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

Make scaling provider aware of fragments

Revision history for this message
Tim Peeters (tpeeters) wrote :

Looks good.

The only addition I like to suggest is to test explicitly the code branches for scaleFactor==1 and scaleFactor!=1.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
1796. By Cris Dywan

Fragment also needs to be kept in SciFi

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

Thanks for adding the additional tests.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Ubuntu/Components/plugin/ucqquickimageextension.cpp'
2--- src/Ubuntu/Components/plugin/ucqquickimageextension.cpp 2015-12-18 12:33:35 +0000
3+++ src/Ubuntu/Components/plugin/ucqquickimageextension.cpp 2015-12-23 16:05:41 +0000
4@@ -77,17 +77,19 @@
5 int separatorPosition = resolved.indexOf("/");
6 QString scaleFactor = resolved.left(separatorPosition);
7 QString selectedFilePath = resolved.mid(separatorPosition+1);
8+ QString fragment(m_source.hasFragment() ? "#" + m_source.fragment() : QString(""));
9
10 if (scaleFactor == "1") {
11 if (qFuzzyCompare(qGuiApp->devicePixelRatio(), (qreal)1.0)
12 || selectedFilePath.endsWith(".svg") || selectedFilePath.endsWith(".svgz")) {
13- // No scaling necessary. Just pass the original file as is
14- // to keep the full url structure
15- m_image->setSource(m_source);
16+ // Take care to pass the original fragment
17+ QUrl selectedFileUrl(QUrl::fromLocalFile(selectedFilePath));
18+ selectedFileUrl.setFragment(fragment);
19+ m_image->setSource(selectedFileUrl);
20 } else {
21 // Need to scale the pixel-based image to suit the devicePixelRatio setting ourselves.
22 // If we let Qt do it, Qt will not choose the UITK-supported "@gu" scaled images.
23- m_image->setSource(QUrl("image://scaling/1/" + selectedFilePath));
24+ m_image->setSource(QUrl("image://scaling/1/" + selectedFilePath + fragment));
25 // explicitly set the source size in the QQuickImageBase, this persuades it that the
26 // supplied image is suitable for the current devicePixelRatio.
27 m_image->setSourceSize(m_image->sourceSize());
28@@ -96,7 +98,7 @@
29 // Prepend "image://scaling" for the image to be loaded by UCScalingImageProvider.
30 if (!m_source.path().endsWith(".sci")) {
31 // Regular image file
32- m_image->setSource(QUrl("image://scaling/" + resolved));
33+ m_image->setSource(QUrl("image://scaling/" + resolved + fragment));
34 } else {
35 // .sci image file. Rewrite the .sci file into a temporary file.
36 bool rewritten = true;
37@@ -125,7 +127,10 @@
38 }
39
40 if (rewritten) {
41- m_image->setSource(QUrl::fromLocalFile(rewrittenSciFile->fileName()));
42+ // Take care to pass the original fragment
43+ QUrl rewrittenSciFileUrl(QUrl::fromLocalFile(rewrittenSciFile->fileName()));
44+ rewrittenSciFileUrl.setFragment(fragment);
45+ m_image->setSource(rewrittenSciFileUrl);
46 } else {
47 m_image->setSource(m_source);
48 }
49
50=== modified file 'src/Ubuntu/Components/plugin/ucscalingimageprovider.cpp'
51--- src/Ubuntu/Components/plugin/ucscalingimageprovider.cpp 2014-09-30 12:10:46 +0000
52+++ src/Ubuntu/Components/plugin/ucscalingimageprovider.cpp 2015-12-23 16:05:41 +0000
53@@ -40,7 +40,9 @@
54 {
55 int separatorPosition = id.indexOf("/");
56 float scaleFactor = id.left(separatorPosition).toFloat();
57- QString path = id.mid(separatorPosition+1);
58+ int fragmentPosition = id.lastIndexOf("#");
59+ int pathLength = fragmentPosition > -1 ? fragmentPosition - separatorPosition - 1 : -1;
60+ QString path = id.mid(separatorPosition + 1, pathLength);
61 QFile file(path);
62
63 if (file.open(QIODevice::ReadOnly)) {
64
65=== added file 'tests/unit_x11/tst_components/PageHeaderBaseDividerBottom@18.png'
66Binary files tests/unit_x11/tst_components/PageHeaderBaseDividerBottom@18.png 1970-01-01 00:00:00 +0000 and tests/unit_x11/tst_components/PageHeaderBaseDividerBottom@18.png 2015-12-23 16:05:41 +0000 differ
67=== added file 'tests/unit_x11/tst_components/battery-100-charging.svg'
68--- tests/unit_x11/tst_components/battery-100-charging.svg 1970-01-01 00:00:00 +0000
69+++ tests/unit_x11/tst_components/battery-100-charging.svg 2015-12-23 16:05:41 +0000
70@@ -0,0 +1,25 @@
71+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
72+<!-- Created with Inkscape (http://www.inkscape.org/) -->
73+<svg id="svg4966" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="90" viewBox="0 0 139.00489 90.000001" width="139" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
74+ <metadata id="metadata4971">
75+ <rdf:RDF>
76+ <cc:Work rdf:about="">
77+ <dc:format>image/svg+xml</dc:format>
78+ <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
79+ <dc:title/>
80+ </cc:Work>
81+ </rdf:RDF>
82+ </metadata>
83+ <g id="layer1" transform="translate(-149.78 -484.51)">
84+ <g id="g5120" transform="translate(-433.79 125.71)">
85+ <g id="g5124" transform="translate(409.57 223.43)">
86+ <g id="g5126" style="fill:none" transform="matrix(2.1875 0 0 1.875 -456 -1657.8)">
87+ <rect id="rect5128" style="opacity:.21171;fill:none" transform="translate(0 804.36)" height="48" width="48" y="152" x="288"/>
88+ </g>
89+ <path id="path5130" style="fill:#808080" transform="translate(174 135.36)" d="m86 15-75.156 0.012c-7.844-0.012-10.844 1.988-10.844 11.988v18 18c0 10 3 12 10.844 11.988l75.156 0.012c7.8438 0.01172 11-2.3633 11-12v-4.0117h8v-13.988-13.988h-8v-4.012c0-9.637-3.156-12.012-11-12zm-75 6c21.619 0.0096 48.956 0.0081 75 0 4 0 5 1 5 6v18 18c0 5-1 6-5 6-26.044-0.008-53.381-0.01-75 0-4 0-5-1-5-6v-18-18c0-5 1-6 5-6z"/>
90+ <path id="path5132" style="fill:#38b44a" d="m1051 697c-3 0-4 0-4 5v26c0 5 1 5 4 5h65c3 0 4 0 4-5v-26c0-5-1-5-4-5z" transform="translate(-861 -534.64)"/>
91+ <path id="path3847-0" style="fill:#808080" d="m299 150.36-13.996 35h14v25l14.005-35h-14z"/>
92+ </g>
93+ </g>
94+ </g>
95+</svg>
96
97=== added file 'tests/unit_x11/tst_components/shape.svg'
98--- tests/unit_x11/tst_components/shape.svg 1970-01-01 00:00:00 +0000
99+++ tests/unit_x11/tst_components/shape.svg 2015-12-23 16:05:41 +0000
100@@ -0,0 +1,77 @@
101+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
102+<!-- Created with Inkscape (http://www.inkscape.org/) -->
103+
104+<svg
105+ xmlns:dc="http://purl.org/dc/elements/1.1/"
106+ xmlns:cc="http://creativecommons.org/ns#"
107+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
108+ xmlns:svg="http://www.w3.org/2000/svg"
109+ xmlns="http://www.w3.org/2000/svg"
110+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
111+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
112+ width="64"
113+ height="64"
114+ id="svg3336"
115+ version="1.1"
116+ inkscape:version="0.48.5 r10040"
117+ sodipodi:docname="ushape.svg">
118+ <defs
119+ id="defs3338" />
120+ <sodipodi:namedview
121+ id="base"
122+ pagecolor="#ffffff"
123+ bordercolor="#666666"
124+ borderopacity="1.0"
125+ inkscape:pageopacity="0.0"
126+ inkscape:pageshadow="2"
127+ inkscape:zoom="4"
128+ inkscape:cx="113.3337"
129+ inkscape:cy="-31.239507"
130+ inkscape:document-units="px"
131+ inkscape:current-layer="layer1"
132+ showgrid="false"
133+ inkscape:window-width="1871"
134+ inkscape:window-height="1056"
135+ inkscape:window-x="49"
136+ inkscape:window-y="24"
137+ inkscape:window-maximized="1"
138+ inkscape:showpageshadow="false"
139+ borderlayer="false"
140+ showborder="true" />
141+ <metadata
142+ id="metadata3341">
143+ <rdf:RDF>
144+ <cc:Work
145+ rdf:about="">
146+ <dc:format>image/svg+xml</dc:format>
147+ <dc:type
148+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
149+ <dc:title />
150+ </cc:Work>
151+ </rdf:RDF>
152+ </metadata>
153+ <g
154+ inkscape:label="Layer 1"
155+ inkscape:groupmode="layer"
156+ id="layer1"
157+ transform="translate(0,-988.36218)">
158+ <g
159+ transform="matrix(0.92774742,0,0,0.92677598,0,190.60819)"
160+ id="layer1-3"
161+ inkscape:label="Layer 1"
162+ style="fill:#000000;display:inline">
163+ <g
164+ style="fill:#000000"
165+ inkscape:label="Layer 1"
166+ id="layer1-2"
167+ transform="translate(0,9.99998)">
168+ <path
169+ sodipodi:nodetypes="sssssssss"
170+ inkscape:connector-curvature="0"
171+ id="path3774"
172+ d="m 66.770269,850.78408 72.334451,0 c 58.42399,0 66.77028,8.34623 66.77028,66.77022 l 0,58.03793 c 0,58.42377 -8.34629,66.76997 -66.77028,66.76997 l -72.334451,0 C 8.3462835,1042.3622 0,1034.016 0,975.59223 L 0,917.5543 c 0,-58.42399 8.3462835,-66.77022 66.770269,-66.77022 z"
173+ style="fill:#000000;fill-opacity:1;stroke:none;display:inline" />
174+ </g>
175+ </g>
176+ </g>
177+</svg>
178
179=== modified file 'tests/unit_x11/tst_components/tst_imageprovider.qml'
180--- tests/unit_x11/tst_components/tst_imageprovider.qml 2015-12-18 12:33:35 +0000
181+++ tests/unit_x11/tst_components/tst_imageprovider.qml 2015-12-23 16:05:41 +0000
182@@ -60,23 +60,34 @@
183
184 // tests adjusted to reproduce bug #1401920
185 function test_sourceChanged_bug1401920_data() {
186- var file = "file:///usr/share/icons/ubuntu-mobile/actions/scalable/delete.svg";
187 return [
188- {rag: "Existing file", file: file},
189- {rag: "Url with fragment", file: file + "#" + Date.now()},
190+ {tag: "Bitmap file", file: 'tst_icon-select.png'},
191+ {tag: "Bitmap file(18gu)", gu: 18, file: 'tst_icon-select.png'},
192+ {tag: "Bitmap with fragment", file: 'tst_icon-select.png#' + Date.now()},
193+ {tag: "Bitmap with fragment(18gu)", gu: 18, file: 'PageHeaderBaseDividerBottom@18.png#' + Date.now()},
194+ {tag: "Bitmap file with gu", file: 'tst_icon-select@18.png'},
195+ {tag: "Bitmap file with gu(18gu)", gu: 18, file: 'PageHeaderBaseDividerBottom@18.png'},
196+ {tag: "Bitmap with gu/ fragment", file: 'tst_icon-select@18.png#' + Date.now()},
197+ {tag: "Bitmap with gu/ fragment(18gu)", gu: 18, file: 'PageHeaderBaseDividerBottom@18.png#' + Date.now()},
198+ {tag: "Scalable file", file: 'battery-100-charging.svg'},
199+ {tag: "Scalable file(18gu)", gu: 18, file: 'shape.svg'},
200+ {tag: "Scalable with fragment", file: 'shape.svg#' + Date.now()},
201+ {tag: "Scalable with fragment(18gu)", gu: 18, file: 'battery-100-charging.svg#' + Date.now()},
202 ];
203 }
204
205 function test_sourceChanged_bug1401920(data) {
206+ units.gridUnit = data.gu ? data.gu : 8;
207 sourceChangeSpy.target = test;
208- test.source = data.file;
209+ test.source = Qt.resolvedUrl(data.file);
210 sourceChangeSpy.wait(400);
211+ compare(test.source, Qt.resolvedUrl(data.file));
212 }
213
214 function test_sourceNOTIFYable() {
215 /* Test source through visible to cover NOTIFYable errors */
216 visibleChangedSpy.target = bindingTest;
217- bindingTest.source = "/usr/share/icons/ubuntu-mobile/actions/scalable/help.svg";
218+ bindingTest.source = Qt.resolvedUrl('battery-100-charging.svg');
219 visibleChangedSpy.wait();
220 }
221 }

Subscribers

People subscribed via source and target branches