aboutsummaryrefslogtreecommitdiffstats
path: root/mobile-widgets/qmlinterface.cpp
diff options
context:
space:
mode:
authorGravatar jan Iversen <jan@casacondor.com>2020-01-04 09:26:09 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-01-18 17:31:58 -0800
commitfdc2fd35bf3a24f64b3f86a1caa4d69257c9dfab (patch)
tree5adcb0083bc506cfcba4f92de39a26abaffd5ae9 /mobile-widgets/qmlinterface.cpp
parentfe8b7e3b726dbb8a5dca80dbe5ad52b59ab5244f (diff)
downloadsubsurface-fdc2fd35bf3a24f64b3f86a1caa4d69257c9dfab.tar.gz
mobile-widgets: add pure interface for passing values to QML
Add a header file that contains a duplicate of the enums, that are needed in QML in one class. the unit enums are added imidiatly, since they are needed or will be neede shortly in Settings and DivePlannerSettings This class will also contain Q_PROPERTY and signal/slot for variables used in QML. This is done to allow e.g. deco_mode qPrefUnits::planner_deco_mode() void qPrefUnits::set_planner_deco_mode(deco_mode) as strongly typed in C++ and DECO_MODE planner_deco_mode() void set_planner_deco_mode(DECO_MODE) as strongly typed in QML Remark: wrong assignments gives errors in QML The advantage over using strings or the value directly is that QML detects typos and flags them as errors/warnings. It is important to note that the class may only contain a) a function call to the implementation b) a reference to a global variable e.g. prefs. Added note to the original definitions of the enums that they have been duplicated. Signed-off-by: jan Iversen <jan@casacondor.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'mobile-widgets/qmlinterface.cpp')
-rw-r--r--mobile-widgets/qmlinterface.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/mobile-widgets/qmlinterface.cpp b/mobile-widgets/qmlinterface.cpp
new file mode 100644
index 000000000..78aba6a5c
--- /dev/null
+++ b/mobile-widgets/qmlinterface.cpp
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "qmlinterface.h"
+
+#include <QQmlEngine>
+
+QMLInterface *QMLInterface::instance()
+{
+ static QMLInterface *self = new QMLInterface;
+ return self;
+}
+
+void QMLInterface::setup(QQmlContext *ct)
+{
+ // Register interface class
+ ct->setContextProperty("Backend", QMLInterface::instance());
+
+ // Make enums available as types
+ qmlRegisterUncreatableType<QMLInterface>("org.subsurfacedivelog.mobile",1,0,"Enums","Enum is not a type");
+
+ // relink signals to QML
+}