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

Proposed by Zsombor Egri
Status: Rejected
Rejected by: Tim Peeters
Proposed branch: lp:~zsombi/ubuntu-ui-toolkit/crossFadeImage_SourceSize_fix
Merge into: lp:ubuntu-ui-toolkit
Diff against target: 120 lines (+55/-2)
4 files modified
CHANGES (+1/-0)
components.api (+1/-1)
modules/Ubuntu/Components/CrossFadeImage.qml (+41/-1)
tests/unit/tst_components/tst_CrossFadeImage.qml (+12/-0)
To merge this branch: bzr merge lp:~zsombi/ubuntu-ui-toolkit/crossFadeImage_SourceSize_fix
Reviewer Review Type Date Requested Status
Tim Peeters Disapprove
PS Jenkins bot continuous-integration Needs Fixing
Zoltan Balogh Approve
Review via email: mp+188778@code.launchpad.net

Commit message

Update CrossFadeImage API so that sourceSize can be set by the applications.

Description of the change

This MR was taken over from timp as his one fails on minor qdoc issues [1], and contains nothing more than the qdoc fix. The original MR was reviewed and top-approved, this failure sniffed in by mistake.

[1] https://code.launchpad.net/~tpeeters/ubuntu-ui-toolkit/crossFadeImage_SourceSize_fix/+merge/187454

To post a comment you must log in.
Revision history for this message
Michael Zanetti (mzanetti) wrote :

108 +
109 + function test_sourceSize() {
110 + loadImage("../../../examples/ubuntu-ui-toolkit-gallery/demo_image.jpg");
111 + compare(crossFadeImage.sourceSize.width, 640, "Source width incorrectly initialized.");
112 + compare(crossFadeImage.sourceSize.height, 427, "Source height incorrectly initialized.");
113 + crossFadeImage.sourceSize.width = 100;
114 + crossFadeImage.sourceSize.height = 101;
115 + compare(crossFadeImage.sourceSize.width, 100, "Source width incorrectly updated.");
116 + compare(crossFadeImage.sourceSize.height, 101, "Source height incorrectly updated.");
117 + waitForAnimation();
118 + cleanupTest();
119 + }

I've seen many of those tests in the SDK and I personally think this is quite useless. It only tests if the component actually compiles (ok, better than nothing) and if there actually is a property size sourceSize which is not readonly. That's it. But if the sourceSize is actually used by image? This is not tested. Here's an example how to check that:

// Put this into some helper.js, or TestCaseBase class to inherit from as you're gonna need this in every test as of now. In unity we have a UnityTestCase which inherits a TestCase and adds lots of useful helpers. Feel free to copy that too.

    // Find an object with the given name in the children tree of "obj"
    function findChild(obj,objectName) {
        var childs = new Array(0);
        childs.push(obj)
        while (childs.length > 0) {
            if (childs[0].objectName == objectName) {
                return childs[0]
            }
            for (var i in childs[0].children) {
                childs.push(childs[0].children[i])
            }
            childs.splice(0, 1);
        }
        return undefined;
    }

// Now we have a way to look inside the components. Let's do the test using this:

Edit CrossFadeImage.qml and add "objectName" properties to image1 and image2, like this:

Image {
    id: image1
    objectName: "image1"
    ...
}

And now the test

function test_sourceSize() {
  loadImage("../../../examples/ubuntu-ui-toolkit-gallery/demo_image.jpg");
  compare(crossFadeImage.sourceSize.width, 640, "Source width incorrectly initialized.");
  compare(crossFadeImage.sourceSize.height, 427, "Source height incorrectly initialized.");
  crossFadeImage.sourceSize.width = 100;
  crossFadeImage.sourceSize.height = 101;

  var image1 = findChild(crossFadeImage, "image1");
  var image2 = findChild(crossFadeImage, "image2");

  compare(image1.sourceSize.width, 100, "Source width incorrectly updated.");
  compare(image1.sourceSize.height, 101, "Source height incorrectly updated.");

  compare(image2.sourceSize.width, 100, "Source width incorrectly updated.");
  compare(image2.sourceSize.height, 101, "Source height incorrectly updated.");

  waitForAnimation();
  cleanupTest();
}

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Zsombor Egri (zsombi) wrote :

> 108 +
> 109 + function test_sourceSize() {
> 110 + loadImage("../../../examples/ubuntu-ui-toolkit-
> gallery/demo_image.jpg");
> 111 + compare(crossFadeImage.sourceSize.width, 640, "Source width
> incorrectly initialized.");
> 112 + compare(crossFadeImage.sourceSize.height, 427, "Source height
> incorrectly initialized.");
> 113 + crossFadeImage.sourceSize.width = 100;
> 114 + crossFadeImage.sourceSize.height = 101;
> 115 + compare(crossFadeImage.sourceSize.width, 100, "Source width
> incorrectly updated.");
> 116 + compare(crossFadeImage.sourceSize.height, 101, "Source height
> incorrectly updated.");
> 117 + waitForAnimation();
> 118 + cleanupTest();
> 119 + }
>
> I've seen many of those tests in the SDK and I personally think this is quite
> useless. It only tests if the component actually compiles (ok, better than
> nothing) and if there actually is a property size sourceSize which is not
> readonly. That's it. But if the sourceSize is actually used by image? This is
> not tested. Here's an example how to check that:
>
> // Put this into some helper.js, or TestCaseBase class to inherit from as
> you're gonna need this in every test as of now. In unity we have a
> UnityTestCase which inherits a TestCase and adds lots of useful helpers. Feel
> free to copy that too.
>
> // Find an object with the given name in the children tree of "obj"
> function findChild(obj,objectName) {
> var childs = new Array(0);
> childs.push(obj)
> while (childs.length > 0) {
> if (childs[0].objectName == objectName) {
> return childs[0]
> }
> for (var i in childs[0].children) {
> childs.push(childs[0].children[i])
> }
> childs.splice(0, 1);
> }
> return undefined;
> }
>
>
> // Now we have a way to look inside the components. Let's do the test using
> this:
>
> Edit CrossFadeImage.qml and add "objectName" properties to image1 and image2,
> like this:
>
> Image {
> id: image1
> objectName: "image1"
> ...
> }
>
> And now the test
>
> function test_sourceSize() {
> loadImage("../../../examples/ubuntu-ui-toolkit-gallery/demo_image.jpg");
> compare(crossFadeImage.sourceSize.width, 640, "Source width incorrectly
> initialized.");
> compare(crossFadeImage.sourceSize.height, 427, "Source height incorrectly
> initialized.");
> crossFadeImage.sourceSize.width = 100;
> crossFadeImage.sourceSize.height = 101;
>
> var image1 = findChild(crossFadeImage, "image1");
> var image2 = findChild(crossFadeImage, "image2");
>
> compare(image1.sourceSize.width, 100, "Source width incorrectly updated.");
> compare(image1.sourceSize.height, 101, "Source height incorrectly
> updated.");
>
> compare(image2.sourceSize.width, 100, "Source width incorrectly updated.");
> compare(image2.sourceSize.height, 101, "Source height incorrectly
> updated.");
>
> waitForAnimation();
> cleanupTest();
> }

Nice. But let's do this in a separate MR as we also need to agree on how to use the objectName in our components.

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

is this MR still valid?

Looks the same as this one: https://code.launchpad.net/~tpeeters/ubuntu-ui-toolkit/crossFadeImage_SourceSize_fix/+merge/187454 but that one has additional changes.

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

original MR fixed the qdoc issue, so let's go back to that one.

review: Disapprove

Unmerged revisions

776. By Zsombor Egri

qdoc failure fixed

775. By Zsombor Egri

bug attached

774. By Zsombor Egri

timp's MR merged - lp:~tpeeters/ubuntu-ui-toolkit/crossFadeImage_SourceSize_fix

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CHANGES'
2--- CHANGES 2013-09-24 19:47:54 +0000
3+++ CHANGES 2013-10-02 08:07:31 +0000
4@@ -54,6 +54,7 @@
5 * ADDED IN Panel: function open()
6 * ADDED IN Panel: function close()
7 * DEPRECATED IN Panel: writable property opened. Will be made read-only.
8+* CHANGED in CrossFadeImage: readonly property size sourceSize TO property size sourceSize
9
10 Compatibility Breaks
11 ********************
12
13=== modified file 'components.api'
14--- components.api 2013-09-30 12:00:41 +0000
15+++ components.api 2013-10-02 08:07:31 +0000
16@@ -42,7 +42,7 @@
17 property int fillMode
18 property int fadeDuration
19 readonly property bool running
20- readonly property size sourceSize
21+ property size sourceSize
22 readonly property int status
23 modules/Ubuntu/Components/DraggingArea.qml
24 MouseArea
25
26=== modified file 'modules/Ubuntu/Components/CrossFadeImage.qml'
27--- modules/Ubuntu/Components/CrossFadeImage.qml 2013-08-28 12:56:17 +0000
28+++ modules/Ubuntu/Components/CrossFadeImage.qml 2013-10-02 08:07:31 +0000
29@@ -81,8 +81,31 @@
30
31 /*!
32 The actual width and height of the loaded image
33+ This property holds the actual width and height of the loaded image.
34+
35+ Unlike the width and height properties, which scale the painting of the image,
36+ this property sets the actual number of pixels stored for the loaded image so that large
37+ images do not use more memory than necessary.
38+
39+ Note: Changing this property dynamically causes the image source to be reloaded, potentially
40+ even from the network, if it is not in the disk cache.
41 */
42- readonly property size sourceSize: Qt.size(internals.loadingImage.sourceSize.width, internals.loadingImage.sourceSize.height)
43+ // FIXME: Support resetting sourceSize
44+ property size sourceSize: internals.loadingImage ? Qt.size(internals.loadingImage.sourceSize.width, internals.loadingImage.sourceSize.height) : Qt.size(0, 0)
45+
46+ Binding {
47+ target: crossFadeImage
48+ property: "sourceSize"
49+ value: internals.loadingImage ? Qt.size(internals.loadingImage.sourceSize.width, internals.loadingImage.sourceSize.height) : Qt.size(0, 0)
50+ when: internals.forcedSourceSize === undefined
51+ }
52+
53+ /*! \internal */
54+ onSourceSizeChanged: {
55+ if (internals.loadingImage && (sourceSize != Qt.size(internals.loadingImage.sourceSize.width, internals.loadingImage.sourceSize.height))) {
56+ internals.forcedSourceSize = sourceSize;
57+ }
58+ }
59
60 /*!
61 \qmlproperty enumeration status
62@@ -102,6 +125,11 @@
63 id: internals
64
65 /*! \internal
66+ Source size specified by the setting crossFadeImage.sourceSize.
67+ */
68+ property size forcedSourceSize
69+
70+ /*! \internal
71 Defines the image currently being shown
72 */
73 property Image currentImage: image1
74@@ -130,6 +158,12 @@
75 asynchronous: true
76 fillMode: parent.fillMode
77 z: 1
78+ Binding {
79+ target: image1
80+ property: "sourceSize"
81+ value: internals.forcedSourceSize
82+ when: internals.forcedSourceSize !== undefined
83+ }
84 }
85
86 Image {
87@@ -139,6 +173,12 @@
88 asynchronous: true
89 fillMode: parent.fillMode
90 z: 0
91+ Binding {
92+ target: image2
93+ property: "sourceSize"
94+ value: internals.forcedSourceSize
95+ when: internals.forcedSourceSize !== undefined
96+ }
97 }
98
99 /*!
100
101=== modified file 'tests/unit/tst_components/tst_CrossFadeImage.qml'
102--- tests/unit/tst_components/tst_CrossFadeImage.qml 2013-07-08 13:44:33 +0000
103+++ tests/unit/tst_components/tst_CrossFadeImage.qml 2013-10-02 08:07:31 +0000
104@@ -93,4 +93,16 @@
105 waitForAnimation();
106 cleanupTest();
107 }
108+
109+ function test_sourceSize() {
110+ loadImage("../../../examples/ubuntu-ui-toolkit-gallery/demo_image.jpg");
111+ compare(crossFadeImage.sourceSize.width, 640, "Source width incorrectly initialized.");
112+ compare(crossFadeImage.sourceSize.height, 427, "Source height incorrectly initialized.");
113+ crossFadeImage.sourceSize.width = 100;
114+ crossFadeImage.sourceSize.height = 101;
115+ compare(crossFadeImage.sourceSize.width, 100, "Source width incorrectly updated.");
116+ compare(crossFadeImage.sourceSize.height, 101, "Source height incorrectly updated.");
117+ waitForAnimation();
118+ cleanupTest();
119+ }
120 }

Subscribers

People subscribed via source and target branches

to status/vote changes: