aboutsummaryrefslogtreecommitdiff
path: root/qml/pages/MassModel.qml
blob: cadcdf0749785557e960bb96d7839fd39ca397ec (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
import QtQuick 2.0

ListModel {
    function from(title, value) {
        var functions = {
            "kilogram": function () { return value; },
            "gram": function () { return value/1000.0; },
            "tonne": function () { return value*1000.0; },
            "pound": function () { return value*0.45359237; },
            "ounce": function () { return value*0.028349523125; }
        };
        return functions[title]();
    }

    function to(title, value) {
        var functions = {
            "kilogram": function () { return value; },
            "gram": function () { return value*1000.0; },
            "tonne": function () { return value/1000.0; },
            "pound": function () { return value/0.45359237; },
            "ounce": function () { return value/0.028349523125; }
        };
        return functions[title]();
    }

    ListElement {
        title: "kilogram"
        abbr: "kg"
    }

    ListElement {
        title: "gram"
        abbr: "g"
    }

    ListElement {
        title: "tonne"
        abbr: "t"
    }

    ListElement {
        title: "pound"
        abbr: "lb"
    }

    ListElement {
        title: "ounce"
        abbr: "oz"
    }
}