summaryrefslogtreecommitdiffstats
path: root/mobile-widgets/qmlinterface.h
blob: fca87260e1687423f22549e97bcae069ef3114e9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// SPDX-License-Identifier: GPL-2.0
#ifndef QMLINTERFACE_H
#define QMLINTERFACE_H
#include "core/settings/qPrefCloudStorage.h"
#include "core/settings/qPrefUnit.h"

#include <QObject>
#include <QQmlContext>
// This class is a pure interface class and may not contain any implementation code
// Allowed are:
//     header
//        Q_PROPERTY
//        signal/slot for Q_PROPERTY functions
//        the functions may contain either
//             a) a function call to the implementation
//             b) a reference to a global variable like e.g. prefs.
//        Q_INVOCABLE functions
//        the functions may contain
//             a) a function call to the implementation
//    source
//        connect signal/signal to pass signals from implementation


class QMLInterface : public QObject {
	Q_OBJECT

	// 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(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:
	static QMLInterface *instance();

	// function to do the needed setup and do connect of signal/signal
	static void setup(QQmlContext *ct);

	// Duplicated enums, these enums are properly defined in the C/C++ structure
	// but duplicated here to make them available to QML.

	// Duplicating the enums poses a slight risk for forgetting to update
	// them if the proper enum is changed (e.g. assigning a new start value).

	// remark please do not use these enums outside the C++/QML interface.
	enum UNIT_SYSTEM {
		METRIC,
		IMPERIAL,
		PERSONALIZE
	};
	Q_ENUM(UNIT_SYSTEM);

	enum LENGTH {
		METERS,
		FEET
	};
	Q_ENUM(LENGTH);

	enum VOLUME {
		LITER,
		CUFT
	};
	Q_ENUM(VOLUME);

	enum PRESSURE {
		BAR,
		PSI,
		PASCALS
	};
	Q_ENUM(PRESSURE);

	enum TEMPERATURE {
		CELSIUS,
		FAHRENHEIT,
		KELVIN
	};
	Q_ENUM(TEMPERATURE);

	enum WEIGHT {
		KG,
		LBS
	};
	Q_ENUM(WEIGHT);

	enum TIME {
		SECONDS,
		MINUTES
	};
	Q_ENUM(TIME);

	enum DURATION {
		MIXED,
		MINUTES_ONLY,
		ALWAYS_HOURS
	};
	Q_ENUM(DURATION);

	enum CLOUD_STATUS {
			CS_UNKNOWN,
			CS_INCORRECT_USER_PASSWD,
			CS_NEED_TO_VERIFY,
			CS_VERIFIED,
			CS_NOCLOUD
	};
	Q_ENUM(CLOUD_STATUS);

public:
	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:
	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:
	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:
	QMLInterface() {}
};
#endif // QMLINTERFACE_H