Initial import from the monolithic Qt.
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / qdeclarativeecmascript / data / functionAssignment.2.qml
1 import Qt.test 1.0
2 import QtQuick 1.0
3
4 import "functionAssignment.js" as Script
5
6 MyQmlObject {
7     property variant a
8     property int aNumber: 10
9
10     property bool assignToProperty: false
11     property bool assignToPropertyFromJsFile: false
12
13     property bool assignWithThis: false
14     property bool assignWithThisFromJsFile: false
15
16     property bool assignToValueType: false
17
18     property bool assignFuncWithoutReturn: false
19     property bool assignWrongType: false
20     property bool assignWrongTypeToValueType: false
21
22
23     onAssignToPropertyChanged: {
24         function myFunction() {
25             return aNumber * 10;
26         }
27         a = myFunction;
28     }
29
30     property QtObject obj: QtObject {
31         property int aNumber: 4212
32         function myFunction() {
33             return this.aNumber * 10;   // should use the aNumber from root, not this object
34         }
35     }
36     onAssignWithThisChanged: {
37         a = obj.myFunction;
38     }
39
40     onAssignToPropertyFromJsFileChanged: {
41         Script.bindPropertyWithThis()
42     }
43
44     onAssignWithThisFromJsFileChanged: {
45         Script.bindProperty()
46     }
47
48     property Text text: Text { }
49     onAssignToValueTypeChanged: {
50         text.font.pixelSize = (function() { return aNumber * 10; })
51         a = (function() { return text.font.pixelSize; })
52     }
53
54
55     // detecting errors:
56
57     onAssignFuncWithoutReturnChanged: {
58         function myFunction() {
59         }
60         a = myFunction;
61     }
62
63     onAssignWrongTypeChanged: {
64         function myFunction() {
65             return 'a string';
66         }
67         aNumber = myFunction;
68     }
69
70     onAssignWrongTypeToValueTypeChanged: {
71         text.font.pixelSize = (function() { return 'a string'; })
72     }
73 }