mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
a71afd31ee
commit
d0edc29636
9 changed files with 62 additions and 59 deletions
|
@ -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();
|
||||
|
||||
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");
|
||||
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 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>();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue