aboutsummaryrefslogtreecommitdiff
path: root/src/qml/pages/MassModel.qml
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/pages/MassModel.qml')
-rw-r--r--src/qml/pages/MassModel.qml50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/qml/pages/MassModel.qml b/src/qml/pages/MassModel.qml
new file mode 100644
index 0000000..cadcdf0
--- /dev/null
+++ b/src/qml/pages/MassModel.qml
@@ -0,0 +1,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"
+ }
+}