diff options
author | jan Iversen <jani@apache.org> | 2018-07-28 19:24:55 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-07-30 07:43:22 -0700 |
commit | c696c7941df1b083e41fbf72376a0f8f82b9652b (patch) | |
tree | 7d93088a3f78f774b5d4cbe95ec1392bab34b0cb | |
parent | 600da8b9ff4946d6500e2327dc8f7e361a3616cc (diff) | |
download | subsurface-c696c7941df1b083e41fbf72376a0f8f82b9652b.tar.gz |
ssrf: simplify Register/check calls in subsurface-helper
Add REGISTER_TYPE macro, that expands to register_type and the "if"
There are no functional changes, but the code is a lot easier to read.
Signed-off-by: Jan Iversen <jani@apache.org>
-rw-r--r-- | subsurface-helper.cpp | 61 |
1 files changed, 19 insertions, 42 deletions
diff --git a/subsurface-helper.cpp b/subsurface-helper.cpp index b8ccf5a92..ea4aaa8b1 100644 --- a/subsurface-helper.cpp +++ b/subsurface-helper.cpp @@ -147,55 +147,32 @@ static void register_meta_types() } #endif // not SUBSURFACE_TEST_DATA +#define REGISTER_TYPE(useClass, useQML) \ + rc = qmlRegisterType<useClass>("org.subsurfacedivelog.mobile", 1, 0, useQML); \ + if (rc < 0) \ + qWarning() << "ERROR: Cannot register " << useQML << ", QML will not work!!"; + void register_qml_types() { int rc; - rc = qmlRegisterType<qPref>("org.subsurfacedivelog.mobile", 1, 0, "SsrfPrefs"); - if (rc < 0) - qDebug() << "ERROR: Cannot register SsrfPrefs (class qPref), QML will not work!!"; - rc = qmlRegisterType<qPrefAnimations>("org.subsurfacedivelog.mobile", 1, 0, "SsrfAnimationsPrefs"); - if (rc < 0) - qDebug() << "ERROR: Cannot register SsrfAnimationsPrefs (class qPrefAnimations), QML will not work!!"; - rc = qmlRegisterType<qPrefCloudStorage>("org.subsurfacedivelog.mobile", 1, 0, "SsrfCloudStoragePrefs"); - if (rc < 0) - qDebug() << "ERROR: Cannot register SsrfCloudStoragePrefs (class qPrefCloudStorage), QML will not work!!"; - rc = qmlRegisterType<qPrefDisplay>("org.subsurfacedivelog.mobile", 1, 0, "SsrfDisplayPrefs"); - if (rc < 0) - qDebug() << "ERROR: Cannot register DisplayPrefs (class qPrefDisplay), QML will not work!!"; - rc = qmlRegisterType<qPrefDiveComputer>("org.subsurfacedivelog.mobile", 1, 0, "SsrfDiveComputerPrefs"); - if (rc < 0) - qDebug() << "ERROR: Cannot register DiveComputerPrefs (class qPrefDiveComputer), QML will not work!!"; - rc = qmlRegisterType<qPrefFacebook>("org.subsurfacedivelog.mobile", 1, 0, "SsrfFacebookPrefs"); - if (rc < 0) - qDebug() << "ERROR: Cannot register FacebookPrefs (class qPrefFacebook), QML will not work!!"; + REGISTER_TYPE(qPref, "SsrfPrefs"); + REGISTER_TYPE(qPrefAnimations, "SsrfAnimationsPrefs"); + REGISTER_TYPE(qPrefCloudStorage, "SsrfCloudStoragePrefs"); + REGISTER_TYPE(qPrefDisplay, "SsrfDisplayPrefs"); + REGISTER_TYPE(qPrefDiveComputer, "SsrfDiveComputerPrefs"); + REGISTER_TYPE(qPrefFacebook, "SsrfFacebookPrefs"); #ifndef SUBSURFACE_TEST_DATA #ifdef SUBSURFACE_MOBILE - rc = qmlRegisterType<QMLManager>("org.subsurfacedivelog.mobile", 1, 0, "QMLManager"); - if (rc < 0) - qDebug() << "ERROR: Cannot register QMLManager, QML will not work!!"; - rc = qmlRegisterType<QMLPrefs>("org.subsurfacedivelog.mobile", 1, 0, "QMLPrefs"); - if (rc < 0) - qDebug() << "ERROR: Cannot register QMLPrefs, QML will not work!!"; - rc = qmlRegisterType<QMLProfile>("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile"); - if (rc < 0) - qDebug() << "ERROR: Cannot register QMLProfile, QML will not work!!"; - rc = qmlRegisterType<DownloadThread>("org.subsurfacedivelog.mobile", 1, 0, "DCDownloadThread"); - if (rc < 0) - qDebug() << "ERROR: Cannot register DCDownloadThread, QML will not work!!"; - rc = qmlRegisterType<DiveImportedModel>("org.subsurfacedivelog.mobile", 1, 0, "DCImportModel"); - if (rc < 0) - qDebug() << "ERROR: Cannot register DCImportModel, QML will not work!!"; + REGISTER_TYPE(QMLManager, "QMLManager"); + REGISTER_TYPE(QMLPrefs, "QMLPrefs"); + REGISTER_TYPE(QMLProfile, "QMLProfile"); + REGISTER_TYPE(DownloadThread, "DCDownloadThread"); + REGISTER_TYPE(DiveImportedModel, "DCImportModel"); #endif // not SUBSURFACE_MOBILE - rc = qmlRegisterType<MapWidgetHelper>("org.subsurfacedivelog.mobile", 1, 0, "MapWidgetHelper"); - if (rc < 0) - qDebug() << "ERROR: Cannot register MapWidgetHelper, QML will not work!!"; - rc = qmlRegisterType<MapLocationModel>("org.subsurfacedivelog.mobile", 1, 0, "MapLocationModel"); - if (rc < 0) - qDebug() << "ERROR: Cannot register MapLocationModel, QML will not work!!"; - rc = qmlRegisterType<MapLocation>("org.subsurfacedivelog.mobile", 1, 0, "MapLocation"); - if (rc < 0) - qDebug() << "ERROR: Cannot register MapLocation, QML will not work!!"; + REGISTER_TYPE(MapWidgetHelper, "MapWidgetHelper"); + REGISTER_TYPE(MapLocationModel, "MapLocationModel"); + REGISTER_TYPE(MapLocation, "MapLocation"); #endif // not SUBSURFACE_TEST_DATA } |