summaryrefslogtreecommitdiff
path: root/tests/auto/qml/qmlcppcodegen/data/javaScriptArgument.qml
blob: 058a2ad574cf92a86bedc06855f0d32500f638bc (plain)
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
pragma Strict
import QtQml

QtObject {
    function absMinusOne(amount: real) : real {
        // Access it before the condition below, to make sure we still get the original
        var minusOne = amount !== 0 ? -1 : 0;

        // The condition causes the original arguemnt to be overwritten rather than a new
        // register to be allocated
        if (amount < 0)
            amount = -amount;

        return amount + minusOne;
    }

    property real a: absMinusOne(-5)
    property real b: absMinusOne(10)

    function stringMinusOne(amount: real) : string {
        // Access it before the condition below, to make sure we still get the original
        var minusOne = amount !== 0 ? -1 : 0;

        // The condition causes the original arguemnt to be overwritten rather than a new
        // register to be allocated
        if (amount < 0)
            amount = -amount + "t";

        return amount + minusOne;
    }

    property string c: stringMinusOne(-5)
    property string d: stringMinusOne(10)

    function printAmount(amount: real) : string {
        var sign;
        if (amount < 0) {
            sign = "-";
            amount = -amount;
        } else {
            sign = "";
        }
        return sign + amount;
    }

    property string e: printAmount(10);
    property string f: printAmount(-10);

    readonly property string units: " kMGT"

    function roundTo3Digits(number: real) : real  {
        var factor;

        if (number < 10)
            factor = 100;
        else if (number < 100)
            factor = 10;
        else
            factor = 1;

        return Math.round(number * factor) / factor;
    }

    function prettyPrintScale(amount: real) : string {
        var sign;
        if (amount < 0) {
            sign = "-";
            amount = -amount;
        } else {
            sign = "";
        }
        var unitOffset = 0;
        var unitAmount = 1;
        for (unitOffset = 0; amount > unitAmount * 1024; ++unitOffset, unitAmount *= 1024) {}
        var result = amount / unitAmount;
        return sign + roundTo3Digits(result) + units[unitOffset];
    }

    property list<string> scales: [
        prettyPrintScale(0),

        prettyPrintScale(1),
        prettyPrintScale(10),
        prettyPrintScale(100),
        prettyPrintScale(1000),
        prettyPrintScale(10000),
        prettyPrintScale(100000),
        prettyPrintScale(1000000),
        prettyPrintScale(10000000),
        prettyPrintScale(100000000),
        prettyPrintScale(1000000000),
        prettyPrintScale(10000000000),
        prettyPrintScale(100000000000),
        prettyPrintScale(1000000000000),
        prettyPrintScale(10000000000000),

        prettyPrintScale(-1),
        prettyPrintScale(-10),
        prettyPrintScale(-100),
        prettyPrintScale(-1000),
        prettyPrintScale(-10000),
        prettyPrintScale(-100000),
        prettyPrintScale(-1000000),
        prettyPrintScale(-10000000),
        prettyPrintScale(-100000000),
        prettyPrintScale(-1000000000),
        prettyPrintScale(-10000000000),
        prettyPrintScale(-100000000000),
        prettyPrintScale(-1000000000000),
        prettyPrintScale(-10000000000000),
    ]

    function forwardArg(a: real) : string {
        return prettyPrintScale(a);
    }
}