From c696c7941df1b083e41fbf72376a0f8f82b9652b Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Sat, 28 Jul 2018 19:24:55 +0200 Subject: [PATCH] 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 --- subsurface-helper.cpp | 61 ++++++++++++++----------------------------- 1 file 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("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("org.subsurfacedivelog.mobile", 1, 0, "SsrfPrefs"); - if (rc < 0) - qDebug() << "ERROR: Cannot register SsrfPrefs (class qPref), QML will not work!!"; - rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "SsrfAnimationsPrefs"); - if (rc < 0) - qDebug() << "ERROR: Cannot register SsrfAnimationsPrefs (class qPrefAnimations), QML will not work!!"; - rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "SsrfCloudStoragePrefs"); - if (rc < 0) - qDebug() << "ERROR: Cannot register SsrfCloudStoragePrefs (class qPrefCloudStorage), QML will not work!!"; - rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "SsrfDisplayPrefs"); - if (rc < 0) - qDebug() << "ERROR: Cannot register DisplayPrefs (class qPrefDisplay), QML will not work!!"; - rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "SsrfDiveComputerPrefs"); - if (rc < 0) - qDebug() << "ERROR: Cannot register DiveComputerPrefs (class qPrefDiveComputer), QML will not work!!"; - rc = qmlRegisterType("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("org.subsurfacedivelog.mobile", 1, 0, "QMLManager"); - if (rc < 0) - qDebug() << "ERROR: Cannot register QMLManager, QML will not work!!"; - rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "QMLPrefs"); - if (rc < 0) - qDebug() << "ERROR: Cannot register QMLPrefs, QML will not work!!"; - rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile"); - if (rc < 0) - qDebug() << "ERROR: Cannot register QMLProfile, QML will not work!!"; - rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "DCDownloadThread"); - if (rc < 0) - qDebug() << "ERROR: Cannot register DCDownloadThread, QML will not work!!"; - rc = qmlRegisterType("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("org.subsurfacedivelog.mobile", 1, 0, "MapWidgetHelper"); - if (rc < 0) - qDebug() << "ERROR: Cannot register MapWidgetHelper, QML will not work!!"; - rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "MapLocationModel"); - if (rc < 0) - qDebug() << "ERROR: Cannot register MapLocationModel, QML will not work!!"; - rc = qmlRegisterType("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 }