diff options
author | jan Iversen <jani@apache.org> | 2018-09-04 11:18:43 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-09-11 17:22:58 -0700 |
commit | d0edc296360e7653a4c8b672cfb136581c4a10f0 (patch) | |
tree | 6d42fcee2174770cd1e0c8edd892540553ee40b6 /core/settings/qPref.cpp | |
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/settings/qPref.cpp')
-rw-r--r-- | core/settings/qPref.cpp | 53 |
1 files changed, 29 insertions, 24 deletions
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>(); } |