diff options
author | 2018-09-04 11:18:43 +0200 | |
---|---|---|
committer | 2018-09-11 17:22:58 -0700 | |
commit | d0edc296360e7653a4c8b672cfb136581c4a10f0 (patch) | |
tree | 6d42fcee2174770cd1e0c8edd892540553ee40b6 /core | |
parent | a71afd31ee66edf45c8970dcbd6514d7c4b5e9f0 (diff) | |
download | subsurface-d0edc296360e7653a4c8b672cfb136581c4a10f0.tar.gz |
core,tests: change qml register function
In order to address the C++ object directy in qml, a different
registration is needed.
qmlRegisterType, registers the C++ class, allowing qml code to inherit
from it and make qml objects. This is needed for graphical elemnets
like profile and map
setContentProperty, registers the C++ object, thus allowing signals to be
catched.
Signed-off-by: Jan Iversen <jani@apache.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/qt-gui.h | 1 | ||||
-rw-r--r-- | core/settings/qPref.cpp | 53 | ||||
-rw-r--r-- | core/settings/qPref.h | 5 |
3 files changed, 32 insertions, 27 deletions
diff --git a/core/qt-gui.h b/core/qt-gui.h index a1e608122..9bfe0e001 100644 --- a/core/qt-gui.h +++ b/core/qt-gui.h @@ -6,7 +6,6 @@ void init_qt_late(); void init_ui(); void run_ui(); -void register_qml_types(); void exit_ui(); void set_non_bt_addresses(); diff --git a/core/settings/qPref.cpp b/core/settings/qPref.cpp index b37024f32..61561a188 100644 --- a/core/settings/qPref.cpp +++ b/core/settings/qPref.cpp @@ -2,8 +2,7 @@ #include "qPref.h" #include "qPrefPrivate.h" -#include <QQuickItem> -#include <QQmlEngine> +#include <QtQml> #include <QQmlContext> qPref::qPref(QObject *parent) : QObject(parent) @@ -39,28 +38,34 @@ void qPref::loadSync(bool doSync) qPrefUpdateManager::loadSync(doSync); } -#define REGISTER_QPREF(useClass, useQML) \ - rc = qmlRegisterType<useClass>("org.subsurfacedivelog.mobile", 1, 0, useQML); \ - if (rc < 0) \ - qWarning() << "ERROR: Cannot register " << useQML << ", QML will not work!!"; - -void qPref::registerQML() +Q_DECLARE_METATYPE(deco_mode); +Q_DECLARE_METATYPE(def_file_behavior); +Q_DECLARE_METATYPE(taxonomy_category); +void qPref::registerQML(QQmlEngine *engine) { - int rc; + if (engine) { + QQmlContext *ct = engine->rootContext(); + + ct->setContextProperty("Pref", qPref::instance()); + ct->setContextProperty("PrefCloudStorage", qPrefCloudStorage::instance()); + ct->setContextProperty("PrefDisplay", qPrefDisplay::instance()); + ct->setContextProperty("PrefDiveComputer", qPrefDiveComputer::instance()); + ct->setContextProperty("PrefDivePlanner", qPrefDivePlanner::instance()); + ct->setContextProperty("PrefFacebook", qPrefFacebook::instance()); + ct->setContextProperty("PrefGeneral", qPrefGeneral::instance()); + ct->setContextProperty("PrefGeocoding", qPrefGeocoding::instance()); + ct->setContextProperty("PrefLanguage", qPrefLanguage::instance()); + ct->setContextProperty("PrefLocationService", qPrefLocationService::instance()); + ct->setContextProperty("PrefPartialPressureGas", qPrefPartialPressureGas::instance()); + ct->setContextProperty("PrefProxy", qPrefProxy::instance()); + ct->setContextProperty("PrefTechnicalDetails", qPrefTechnicalDetails::instance()); + ct->setContextProperty("PrefUnits", qPrefUnits::instance()); + ct->setContextProperty("PrefUpdateManager", qPrefUpdateManager::instance()); + } - REGISTER_QPREF(qPref, "SsrfPrefs"); - REGISTER_QPREF(qPrefCloudStorage, "SsrfCloudStoragePrefs"); - REGISTER_QPREF(qPrefDisplay, "SsrfDisplayPrefs"); - REGISTER_QPREF(qPrefDiveComputer, "SsrfDiveComputerPrefs"); - REGISTER_QPREF(qPrefDivePlanner, "SsrfDivePlannerPrefs"); - REGISTER_QPREF(qPrefFacebook, "SsrfFacebookPrefs"); - REGISTER_QPREF(qPrefGeneral, "SsrfGeneralPrefs"); - REGISTER_QPREF(qPrefGeocoding, "SsrfGeocodingPrefs"); - REGISTER_QPREF(qPrefLanguage, "SsrfLanguagePrefs"); - REGISTER_QPREF(qPrefLocationService, "SsrfLocationServicePrefs"); - REGISTER_QPREF(qPrefPartialPressureGas, "SsrfPartialPressureGasPrefs"); - REGISTER_QPREF(qPrefProxy, "SsrfProxyPrefs"); - REGISTER_QPREF(qPrefTechnicalDetails, "SsrfTechnicalDetailsPrefs"); - REGISTER_QPREF(qPrefUnits, "SsrfUnitPrefs"); - REGISTER_QPREF(qPrefUpdateManager, "SsrfUpdateManagerPrefs"); + // Register special types + qmlRegisterUncreatableType<qPref>("org.subsurfacedivelog.mobile",1,0,"CloudStatus","Enum is not a type"); + qRegisterMetaType<deco_mode>(); + qRegisterMetaType<def_file_behavior>(); + qRegisterMetaType<taxonomy_category>(); } diff --git a/core/settings/qPref.h b/core/settings/qPref.h index f62a5eec4..e42e2b96b 100644 --- a/core/settings/qPref.h +++ b/core/settings/qPref.h @@ -5,6 +5,7 @@ #include "ssrf-version.h" #include <QObject> +#include <QQmlEngine> #include "qPrefCloudStorage.h" #include "qPrefDisplay.h" @@ -23,7 +24,6 @@ class qPref : public QObject { Q_OBJECT - Q_ENUMS(cloud_status); Q_PROPERTY(QString canonical_version READ canonical_version); Q_PROPERTY(QString mobile_version READ mobile_version); @@ -36,7 +36,7 @@ public: static void sync() { loadSync(true); } // Register QML - void registerQML(); + void registerQML(QQmlEngine *engine); public: enum cloud_status { @@ -46,6 +46,7 @@ public: CS_VERIFIED, CS_NOCLOUD }; + Q_ENUM(cloud_status); static const QString canonical_version() { return QString(CANONICAL_VERSION_STRING); } static const QString mobile_version() { return QString(MOBILE_VERSION_STRING); } |