mobile-widgets: allow qPrefUnit strongly typed in QML

Add qPrefUnit Q_PROPERTY but using QMLInterface enums, that way
all variables become strongly typed in QML.

Signed-off-by: jan Iversen <jan@casacondor.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
jan Iversen 2020-01-18 23:12:32 +01:00 committed by Dirk Hohndel
parent 52b390d32a
commit 25a5be0fe9
2 changed files with 49 additions and 0 deletions

View file

@ -20,4 +20,20 @@ void QMLInterface::setup(QQmlContext *ct)
// relink signals to QML // relink signals to QML
connect(qPrefCloudStorage::instance(), &qPrefCloudStorage::cloud_verification_statusChanged, connect(qPrefCloudStorage::instance(), &qPrefCloudStorage::cloud_verification_statusChanged,
[=] (int value) { emit instance()->cloud_verification_statusChanged(CLOUD_STATUS(value)); }); [=] (int value) { emit instance()->cloud_verification_statusChanged(CLOUD_STATUS(value)); });
connect(qPrefUnits::instance(), &qPrefUnits::duration_unitsChanged,
[=] (int value) { emit instance()->duration_unitsChanged(DURATION(value)); });
connect(qPrefUnits::instance(), &qPrefUnits::lengthChanged,
[=] (int value) { emit instance()->lengthChanged(LENGTH(value)); });
connect(qPrefUnits::instance(), &qPrefUnits::pressureChanged,
[=] (int value) { emit instance()->pressureChanged(PRESSURE(value)); });
connect(qPrefUnits::instance(), &qPrefUnits::temperatureChanged,
[=] (int value) { emit instance()->temperatureChanged(TEMPERATURE(value)); });
connect(qPrefUnits::instance(), &qPrefUnits::unit_systemChanged,
[=] (int value) { emit instance()->unit_systemChanged(UNIT_SYSTEM(value)); });
connect(qPrefUnits::instance(), &qPrefUnits::vertical_speed_timeChanged,
[=] (int value) { emit instance()->vertical_speed_timeChanged(TIME(value)); });
connect(qPrefUnits::instance(), &qPrefUnits::volumeChanged,
[=] (int value) { emit instance()->volumeChanged(VOLUME(value)); });
connect(qPrefUnits::instance(), &qPrefUnits::weightChanged,
[=] (int value) { emit instance()->weightChanged(WEIGHT(value)); });
} }

View file

@ -2,6 +2,7 @@
#ifndef QMLINTERFACE_H #ifndef QMLINTERFACE_H
#define QMLINTERFACE_H #define QMLINTERFACE_H
#include "core/settings/qPrefCloudStorage.h" #include "core/settings/qPrefCloudStorage.h"
#include "core/settings/qPrefUnit.h"
#include <QObject> #include <QObject>
#include <QQmlContext> #include <QQmlContext>
@ -25,6 +26,14 @@ class QMLInterface : public QObject {
// Q_PROPERTY used in QML // Q_PROPERTY used in QML
Q_PROPERTY(CLOUD_STATUS cloud_verification_status READ cloud_verification_status WRITE set_cloud_verification_status NOTIFY cloud_verification_statusChanged) Q_PROPERTY(CLOUD_STATUS cloud_verification_status READ cloud_verification_status WRITE set_cloud_verification_status NOTIFY cloud_verification_statusChanged)
Q_PROPERTY(DURATION duration_units READ duration_units WRITE set_duration_units NOTIFY duration_unitsChanged)
Q_PROPERTY(LENGTH length READ length WRITE set_length NOTIFY lengthChanged)
Q_PROPERTY(PRESSURE pressure READ pressure WRITE set_pressure NOTIFY pressureChanged)
Q_PROPERTY(TEMPERATURE temperature READ temperature WRITE set_temperature NOTIFY temperatureChanged)
Q_PROPERTY(UNIT_SYSTEM unit_system READ unit_system WRITE set_unit_system NOTIFY unit_systemChanged)
Q_PROPERTY(TIME vertical_speed_time READ vertical_speed_time WRITE set_vertical_speed_time NOTIFY vertical_speed_timeChanged)
Q_PROPERTY(VOLUME volume READ volume WRITE set_volume NOTIFY volumeChanged)
Q_PROPERTY(WEIGHT weight READ weight WRITE set_weight NOTIFY weightChanged)
public: public:
static QMLInterface *instance(); static QMLInterface *instance();
@ -102,12 +111,36 @@ public:
public: public:
CLOUD_STATUS cloud_verification_status() { return (CLOUD_STATUS)prefs.cloud_verification_status; } CLOUD_STATUS cloud_verification_status() { return (CLOUD_STATUS)prefs.cloud_verification_status; }
DURATION duration_units() { return (DURATION)prefs.units.duration_units; }
LENGTH length() { return (LENGTH)prefs.units.length; }
PRESSURE pressure() { return (PRESSURE)prefs.units.pressure; }
TEMPERATURE temperature() { return (TEMPERATURE)prefs.units.temperature; }
UNIT_SYSTEM unit_system() { return (UNIT_SYSTEM)prefs.unit_system; }
TIME vertical_speed_time() { return (TIME)prefs.units.vertical_speed_time; }
VOLUME volume() { return (VOLUME)prefs.units.volume; }
WEIGHT weight() { return (WEIGHT)prefs.units.weight; }
public slots: public slots:
void set_cloud_verification_status(CLOUD_STATUS value) { qPrefCloudStorage::set_cloud_verification_status(value); } void set_cloud_verification_status(CLOUD_STATUS value) { qPrefCloudStorage::set_cloud_verification_status(value); }
void set_duration_units(DURATION value) { qPrefUnits::set_duration_units((units::DURATION)value); }
void set_length(LENGTH value) { qPrefUnits::set_length((units::LENGTH)value); }
void set_pressure(PRESSURE value) { qPrefUnits::set_pressure((units::PRESSURE)value); }
void set_temperature(TEMPERATURE value) { qPrefUnits::set_temperature((units::TEMPERATURE)value); }
void set_unit_system(UNIT_SYSTEM value) { qPrefUnits::set_unit_system((unit_system_values)value); }
void set_vertical_speed_time(TIME value) { qPrefUnits::set_vertical_speed_time((units::TIME)value); }
void set_volume(VOLUME value) { qPrefUnits::set_volume((units::VOLUME)value); }
void set_weight(WEIGHT value) { qPrefUnits::set_weight((units::WEIGHT)value); }
signals: signals:
void cloud_verification_statusChanged(CLOUD_STATUS); void cloud_verification_statusChanged(CLOUD_STATUS);
void duration_unitsChanged(DURATION);
void lengthChanged(LENGTH);
void pressureChanged(PRESSURE);
void temperatureChanged(TEMPERATURE);
void unit_systemChanged(UNIT_SYSTEM);
void vertical_speed_timeChanged(TIME);
void volumeChanged(VOLUME);
void weightChanged(WEIGHT);
private: private:
QMLInterface() {} QMLInterface() {}