File: conversions.qml

package info (click to toggle)
qt6-declarative 6.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 308,920 kB
  • sloc: cpp: 775,911; javascript: 514,247; xml: 10,855; python: 2,806; ansic: 2,253; java: 810; sh: 262; makefile: 41; php: 27
file content (130 lines) | stat: -rw-r--r-- 3,578 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import QML

QtObject {
    id: self
    property var aNull:   null
    property var anInt:   5
    property var aZero:   0
    property var anArray: []
    property var anObject: ({a: 12, b: 14, c: "somestring"})

    property int cmpEqInt: {
        if ({} == 12)
            return 8;
        if ([] == 12)
            return 2;
        if (null == 12)
            return 3;
        if (undefined == 12)
            return 4;
        if (12 == 12)
            return 17;
        return 5;
    }

    property bool nullIsNull:   aNull    == null
    property bool intIsNull:    anInt    == null
    property bool zeroIsNull:   aZero    == null
    property bool arrayIsNull:  anArray  == null
    property bool objectIsNull: anObject == null

    property bool nullIsNotNull:   aNull    != null
    property bool intIsNotNull:    anInt    != null
    property bool zeroIsNotNull:   aZero    != null
    property bool arrayIsNotNull:  anArray  != null
    property bool objectIsNotNull: anObject != null

    property bool boolEqualsBool: nullIsNull == zeroIsNull
    property bool boolNotEqualsBool: nullIsNull != zeroIsNull

    property var aInObject: "a" in anObject
    property var lengthInArray: "length" in anArray
    property var fooInNumber: "foo" in 12
    property var numberInObject: 12 in anObject
    property var numberInArray: 2 in [1, 12, 3]

    property real varPlusVar: aInObject + lengthInArray
    property real varMinusVar: lengthInArray - fooInNumber
    property real varTimesVar: fooInNumber * numberInObject
    property real varDivVar: numberInObject / numberInArray

    property var stringPlusString: "12" + "20"
    property var stringMinusString: "12" - "20"
    property var stringTimesString: "12" * "20"
    property var stringDivString: "12" / "20"

    property string uglyString: "with\nnewline" + 'with"quot' + "with\\slashes";

    property QtObject nullObject1: aInObject ? null : self
    property QtObject nullObject2: {
        if (lengthInArray)
            return self
        if (aInObject)
            return null;
        return undefined;
    }

    property var doneStuff
    function doStuff(stuff) {
        var a = {g: 0, h: 5};
        var b = {i: 6, j: 7};
        var c = {k: 9, l: 9};

        a.g = 4;

        doneStuff = a.g + b.i + c.l
        return stuff[3] ? stuff[3] : stuff.z
    }

    property var passObjectLiteral: doStuff({"x": 13, "y": 17, "z": 11})
    property var passArrayLiteral: doStuff([1, 2, 3, 4])

    property bool neNull: {
        var a = anArray[12]
        if (a)
            return true;
        else
            return false;
    }

    property bool eqNull: {
        var a = anArray[12]
        if (!a)
            return true;
        else
            return false;
    }

    property string undefinedType: typeof undefined
    property string booleanType: typeof true
    property string numberType: typeof 12
    property string stringType: typeof "bah"
    property string objectType: typeof null
    property string symbolType: typeof Symbol("baz") 

    property var modulos: [
        -20 % -1,
        0 % 1,
        20 % 4.4,
        -4.4 % true,
        false % "11",
        undefined % null,
        {} % []
    ]

    property var unaryOps: {
        var a = stringPlusString;
        var b = stringPlusString;
        var c = +stringPlusString;
        var d = -stringPlusString;
        var e = a++;
        var f = b--;
        return [ a, b, c, d, e, f ];
    }

    function retUndefined() {
        var a = 5 + 12;
        if (false)
            return a;
    }
}