diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-01-31 09:37:08 +0100 |
---|---|---|
committer | bstoeger <32835590+bstoeger@users.noreply.github.com> | 2020-01-31 21:28:45 +0100 |
commit | 188e513761fb07587b09f90c2d3f043da8870cc9 (patch) | |
tree | c159472ebfe90cff429efe1a80598b7ff52ea475 /mobile-widgets | |
parent | 9452a78b1d9f69121d81f345a5c3dbf2e100cf74 (diff) | |
download | subsurface-188e513761fb07587b09f90c2d3f043da8870cc9.tar.gz |
Cleanup: connect QMLInterface signals in constructor
It appears weird to connect the QMLInterface signal/slot combination
in a static helper function. This generates a bunch of lambdas that
call the instance() function.
Instead, simply do the connections in the constructor as we do it
in numerous other places.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'mobile-widgets')
-rw-r--r-- | mobile-widgets/qmlinterface.cpp | 99 | ||||
-rw-r--r-- | mobile-widgets/qmlinterface.h | 2 |
2 files changed, 52 insertions, 49 deletions
diff --git a/mobile-widgets/qmlinterface.cpp b/mobile-widgets/qmlinterface.cpp index f666d2dc0..67d4196a3 100644 --- a/mobile-widgets/qmlinterface.cpp +++ b/mobile-widgets/qmlinterface.cpp @@ -2,95 +2,98 @@ #include "qmlinterface.h" #include <QQmlEngine> -QMLInterface *QMLInterface::instance() -{ - static QMLInterface *self = new QMLInterface; - return self; -} - -void QMLInterface::setup(QQmlContext *ct) +QMLInterface::QMLInterface() { - // Register interface class - ct->setContextProperty("Backend", QMLInterface::instance()); - - // Make enums available as types - qmlRegisterUncreatableType<QMLInterface>("org.subsurfacedivelog.mobile",1,0,"Enums","Enum is not a type"); - // relink signals to QML connect(qPrefCloudStorage::instance(), &qPrefCloudStorage::cloud_verification_statusChanged, - [=] (int value) { emit instance()->cloud_verification_statusChanged(CLOUD_STATUS(value)); }); + [this] (int value) { emit cloud_verification_statusChanged(CLOUD_STATUS(value)); }); connect(qPrefUnits::instance(), &qPrefUnits::duration_unitsChanged, - [=] (int value) { emit instance()->duration_unitsChanged(DURATION(value)); }); + [this] (int value) { emit duration_unitsChanged(DURATION(value)); }); connect(qPrefUnits::instance(), &qPrefUnits::lengthChanged, - [=] (int value) { emit instance()->lengthChanged(LENGTH(value)); }); + [this] (int value) { emit lengthChanged(LENGTH(value)); }); connect(qPrefUnits::instance(), &qPrefUnits::pressureChanged, - [=] (int value) { emit instance()->pressureChanged(PRESSURE(value)); }); + [this] (int value) { emit pressureChanged(PRESSURE(value)); }); connect(qPrefUnits::instance(), &qPrefUnits::temperatureChanged, - [=] (int value) { emit instance()->temperatureChanged(TEMPERATURE(value)); }); + [this] (int value) { emit temperatureChanged(TEMPERATURE(value)); }); connect(qPrefUnits::instance(), &qPrefUnits::unit_systemChanged, - [=] (int value) { emit instance()->unit_systemChanged(UNIT_SYSTEM(value)); }); + [this] (int value) { emit unit_systemChanged(UNIT_SYSTEM(value)); }); connect(qPrefUnits::instance(), &qPrefUnits::vertical_speed_timeChanged, - [=] (int value) { emit instance()->vertical_speed_timeChanged(TIME(value)); }); + [this] (int value) { emit vertical_speed_timeChanged(TIME(value)); }); connect(qPrefUnits::instance(), &qPrefUnits::volumeChanged, - [=] (int value) { emit instance()->volumeChanged(VOLUME(value)); }); + [this] (int value) { emit volumeChanged(VOLUME(value)); }); connect(qPrefUnits::instance(), &qPrefUnits::weightChanged, - [=] (int value) { emit instance()->weightChanged(WEIGHT(value)); }); + [this] (int value) { emit weightChanged(WEIGHT(value)); }); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::ascratelast6mChanged, - instance(), &QMLInterface::ascratelast6mChanged); + this, &QMLInterface::ascratelast6mChanged); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::ascratestopsChanged, - instance(), &QMLInterface::ascratestopsChanged); + this, &QMLInterface::ascratestopsChanged); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::ascrate50Changed, - instance(), &QMLInterface::ascrate50Changed); + this, &QMLInterface::ascrate50Changed); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::ascrate75Changed, - instance(), &QMLInterface::ascrate75Changed); + this, &QMLInterface::ascrate75Changed); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::descrateChanged, - instance(), &QMLInterface::descrateChanged); + this, &QMLInterface::descrateChanged); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::safetystopChanged, - instance(), &QMLInterface::safetystopChanged); + this, &QMLInterface::safetystopChanged); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::gflowChanged, - instance(), &QMLInterface::gflowChanged); + this, &QMLInterface::gflowChanged); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::gfhighChanged, - instance(), &QMLInterface::gfhighChanged); + this, &QMLInterface::gfhighChanged); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::vpmb_conservatismChanged, - instance(), &QMLInterface::vpmb_conservatismChanged); + this, &QMLInterface::vpmb_conservatismChanged); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::drop_stone_modeChanged, - instance(), &QMLInterface::drop_stone_modeChanged); + this, &QMLInterface::drop_stone_modeChanged); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::last_stopChanged, - instance(), &QMLInterface::last_stop6mChanged); + this, &QMLInterface::last_stop6mChanged); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::switch_at_req_stopChanged, - instance(), &QMLInterface::switch_at_req_stopChanged); + this, &QMLInterface::switch_at_req_stopChanged); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::problemsolvingtimeChanged, - instance(), &QMLInterface::problemsolvingtimeChanged); + this, &QMLInterface::problemsolvingtimeChanged); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::bottomsacChanged, - instance(), &QMLInterface::bottomsacChanged); + this, &QMLInterface::bottomsacChanged); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::decosacChanged, - instance(), &QMLInterface::decosacChanged); + this, &QMLInterface::decosacChanged); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::sacfactorChanged, - instance(), &QMLInterface::sacfactorChanged); + this, &QMLInterface::sacfactorChanged); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::problemsolvingtimeChanged, - instance(), &QMLInterface::problemsolvingtimeChanged); + this, &QMLInterface::problemsolvingtimeChanged); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::o2narcoticChanged, - instance(), &QMLInterface::o2narcoticChanged); + this, &QMLInterface::o2narcoticChanged); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::bottompo2Changed, - instance(), &QMLInterface::bottompo2Changed); + this, &QMLInterface::bottompo2Changed); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::decopo2Changed, - instance(), &QMLInterface::decopo2Changed); + this, &QMLInterface::decopo2Changed); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::bestmixendChanged, - instance(), &QMLInterface::bestmixendChanged); + this, &QMLInterface::bestmixendChanged); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::display_runtimeChanged, - instance(), &QMLInterface::display_runtimeChanged); + this, &QMLInterface::display_runtimeChanged); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::display_durationChanged, - instance(), &QMLInterface::display_durationChanged); + this, &QMLInterface::display_durationChanged); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::display_transitionsChanged, - instance(), &QMLInterface::display_transitionsChanged); + this, &QMLInterface::display_transitionsChanged); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::verbatim_planChanged, - instance(), &QMLInterface::verbatim_planChanged); + this, &QMLInterface::verbatim_planChanged); connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::display_variationsChanged, - instance(), &QMLInterface::display_variationsChanged); + this, &QMLInterface::display_variationsChanged); +} + +QMLInterface *QMLInterface::instance() +{ + static QMLInterface *self = new QMLInterface; + return self; +} + +void QMLInterface::setup(QQmlContext *ct) +{ + // Register interface class + ct->setContextProperty("Backend", QMLInterface::instance()); + + // Make enums available as types + qmlRegisterUncreatableType<QMLInterface>("org.subsurfacedivelog.mobile",1,0,"Enums","Enum is not a type"); // calculate divesummary first time. // this is needed in order to load the divesummary page diff --git a/mobile-widgets/qmlinterface.h b/mobile-widgets/qmlinterface.h index 0669c402c..3c6022daa 100644 --- a/mobile-widgets/qmlinterface.h +++ b/mobile-widgets/qmlinterface.h @@ -317,6 +317,6 @@ signals: void diveSummaryTextChanged(QStringList); private: - QMLInterface() {} + QMLInterface(); }; #endif // QMLINTERFACE_H |