Enroute Flight Navigation
A navigation app for VFR pilots
GlobalSettings.h
1/***************************************************************************
2 * Copyright (C) 2019-2024 by Stefan Kebekus *
3 * stefan.kebekus@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#pragma once
22
23#include <QProperty>
24#include <QQmlEngine>
25#include <QSettings>
26
27#include "GlobalObject.h"
28#include "notification/Notification.h"
29#include "units/ByteSize.h"
30#include "units/Distance.h"
31
32
44
45class GlobalSettings : public QObject
46{
47 Q_OBJECT
48 QML_ELEMENT
49 QML_SINGLETON
50
51public:
52 //
53 // Constructor and destructor
54 //
55
60 explicit GlobalSettings(QObject *parent = nullptr);
61
62 // No default constructor, important for QML singleton
63 explicit GlobalSettings() = delete;
64
65 // Standard Destructor
66 ~GlobalSettings() override = default;
67
68 // factory function for QML singleton
69 static GlobalSettings* create(QQmlEngine * /*unused*/, QJSEngine * /*unused*/)
70 {
72 }
73
74
75 //
76 // Properties
77 //
78
81
82
90
98
103 Q_PROPERTY(Units::Distance airspaceAltitudeLimit_min MEMBER airspaceAltitudeLimit_min CONSTANT)
104
109 Q_PROPERTY(Units::Distance airspaceAltitudeLimit_max MEMBER airspaceAltitudeLimit_max CONSTANT)
110
113
118 Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
119
122
125
128
135
142
144 Q_PROPERTY(bool nightMode READ nightMode WRITE setNightMode NOTIFY nightModeChanged)
145
148
154 Q_PROPERTY(Units::ByteSize privacyHash READ privacyHash WRITE setPrivacyHash NOTIFY privacyHashChanged)
155
158
165
166
167 //
168 // Getter Methods
169 //
170
175 [[nodiscard]] auto acceptedTerms() const -> int { return m_settings.value(QStringLiteral("acceptedTerms"), 0).toInt(); }
176
181 [[nodiscard]] bool alwaysOpenExternalWebsites() const { return m_settings.value(QStringLiteral("alwaysOpenExternalWebsites"), false).toBool(); }
182
187 [[nodiscard]] auto airspaceAltitudeLimit() const -> Units::Distance;
188
193 [[nodiscard]] bool expandNotamAbbreviations() const { return m_settings.value(QStringLiteral("expandNotamAbbreviations"), false).toBool(); }
194
199 [[nodiscard]] auto fontSize() const -> int;
200
205 [[nodiscard]] auto hideGlidingSectors() const -> bool { return m_settings.value(QStringLiteral("Map/hideGlidingSectors"), true).toBool(); }
206
211 [[nodiscard]] auto ignoreSSLProblems() const -> bool { return m_settings.value(QStringLiteral("ignoreSSLProblems"), false).toBool(); }
212
217 [[nodiscard]] auto lastValidAirspaceAltitudeLimit() const -> Units::Distance;
218
223 [[nodiscard]] auto lastWhatsNewHash() const -> Units::ByteSize
224 {
225 return m_settings.value(QStringLiteral("lastWhatsNewHash"), 0).value<size_t>();
226 }
227
232 [[nodiscard]] auto lastWhatsNewInMapsHash() const -> Units::ByteSize
233 {
234 return m_settings.value(QStringLiteral("lastWhatsNewInMapsHash"), 0).value<size_t>();
235 }
236
241 [[nodiscard]] auto nightMode() const -> bool { return m_settings.value(QStringLiteral("Map/nightMode"), false).toBool(); }
242
247 [[nodiscard]] bool positioningByTrafficDataReceiver() const { return m_positioningByTrafficDataReceiver.value(); }
248
253 [[nodiscard]] QBindable<bool> bindablePositioningByTrafficDataReceiver() const { return &m_positioningByTrafficDataReceiver; }
254
259 [[nodiscard]] auto privacyHash() const -> Units::ByteSize { return m_settings.value(QStringLiteral("privacyHash"), 0).value<size_t>(); }
260
265 [[nodiscard]] auto showAltitudeAGL() const -> bool { return m_settings.value(QStringLiteral("showAltitudeAGL"), false).toBool(); }
266
271 [[nodiscard]] auto voiceNotifications() const -> uint
272 {
273 return m_settings.value(QStringLiteral("voiceNotifications"),
278 }
279
280
281 //
282 // Setter Methods
283 //
284
289 void setAcceptedTerms(int terms);
290
295 void setAlwaysOpenExternalWebsites(bool alwaysOpen);
296
305 void setAirspaceAltitudeLimit(Units::Distance newAirspaceAltitudeLimit);
306
311 void setExpandNotamAbbreviations(bool newExpandNotamAbbreviations);
312
317 void setHideGlidingSectors(bool hide);
318
323 void setFontSize(int newFontSize);
324
329 void setIgnoreSSLProblems(bool ignore);
330
335 void setLargeFonts(bool newLargeFonts);
336
342
348
353 void setNightMode(bool newNightMode);
354
359 void setPositioningByTrafficDataReceiver(bool newPositioningByTrafficDataReceiver);
360
366
371 void setShowAltitudeAGL(bool newShowAltitudeAGL);
372
377 void setVoiceNotifications(uint newVoiceNotifications);
378
379
380 //
381 // Constants
382 //
383
386
387signals:
390
393
396
399
402
405
408
411
414
417
420
423
426
429
430private:
431 Q_DISABLE_COPY_MOVE(GlobalSettings)
432
433 QSettings m_settings;
434
435 QProperty<bool> m_positioningByTrafficDataReceiver;
436};
static Q_INVOKABLE GlobalSettings * globalSettings()
Pointer to appplication-wide static Settings instance.
GlobalSettings(QObject *parent=nullptr)
Standard constructor.
void setShowAltitudeAGL(bool newShowAltitudeAGL)
Setter function for property of the same name.
void lastWhatsNewInMapsHashChanged()
Notifier signal.
void setLastWhatsNewHash(Units::ByteSize lwnh)
Getter function for property of the same name.
bool expandNotamAbbreviations
Should we expand notam abbreviations.
void setFontSize(int newFontSize)
Setter function for property of the same name.
uint voiceNotifications
Voice notifications that should be played.
bool ignoreSSLProblems
Ignore SSL security problems.
bool nightMode
Night mode.
bool alwaysOpenExternalWebsites
Privacy setting: always open external web sites.
bool positioningByTrafficDataReceiver
Use traffic data receiver for positioning.
bool positioningByTrafficDataReceiver() const
Getter function for property of the same name.
void setLargeFonts(bool newLargeFonts)
Getter function for property of the same name.
Units::Distance airspaceAltitudeLimit
Airspace altitude limit for map display.
QBindable< bool > bindablePositioningByTrafficDataReceiver() const
Getter function for property of the same name.
Units::Distance airspaceAltitudeLimit_max
Maximum acceptable value for property airspaceAltitudeLimit.
Units::ByteSize lastWhatsNewHash
Hash of the last "what's new" message that was shown to the user.
void setPositioningByTrafficDataReceiver(bool newPositioningByTrafficDataReceiver)
Setter function for property of the same name.
auto voiceNotifications() const -> uint
Getter function for property of the same name.
void airspaceAltitudeLimitChanged()
Notifier signal.
void privacyHashChanged()
Notifier signal.
void fontSizeChanged()
Notifier signal.
auto airspaceAltitudeLimit() const -> Units::Distance
Getter function for property of the same name.
auto lastWhatsNewInMapsHash() const -> Units::ByteSize
Getter function for property of the same name.
void alwaysOpenExternalWebsitesChanged()
Notifier signal.
void setNightMode(bool newNightMode)
Setter function for property of the same name.
void showAltitudeAGLChanged()
Notifier signal.
void setLastWhatsNewInMapsHash(Units::ByteSize lwnh)
Getter function for property of the same name.
void ignoreSSLProblemsChanged()
Notifier signal.
void setExpandNotamAbbreviations(bool newExpandNotamAbbreviations)
Setter function for property of the same name.
Units::ByteSize privacyHash
Hash of the last "privacy" message that was accepted by the user.
void lastWhatsNewHashChanged()
Notifier signal.
auto privacyHash() const -> Units::ByteSize
Getter function for property of the same name.
auto lastValidAirspaceAltitudeLimit() const -> Units::Distance
Getter function for property with the same name.
bool alwaysOpenExternalWebsites() const
Getter function for property of the same name.
void setVoiceNotifications(uint newVoiceNotifications)
Setter function for property of the same name.
void setAirspaceAltitudeLimit(Units::Distance newAirspaceAltitudeLimit)
Setter function for property of the same name.
void voiceNotificationsChanged()
Notifier signal.
void setPrivacyHash(Units::ByteSize newHash)
Getter function for property of the same name.
bool hideGlidingSectors
Hide gliding sectors.
auto nightMode() const -> bool
Getter function for property of the same name.
void expandNotamAbbreviationsChanged()
Notifier signal.
void setIgnoreSSLProblems(bool ignore)
Setter function for property of the same name.
void acceptedTermsChanged()
Notifier signal.
void setHideGlidingSectors(bool hide)
Setter function for property of the same name.
int fontSize
Font size.
void hideGlidingSectorsChanged()
Notifier signal.
void setAcceptedTerms(int terms)
Setter function for property of the same name.
void setAlwaysOpenExternalWebsites(bool alwaysOpen)
Setter function for property of the same name.
auto showAltitudeAGL() const -> bool
Getter function for property of the same name.
auto ignoreSSLProblems() const -> bool
Getter function for property of the same name.
void nightModeChanged()
Notifier signal.
int acceptedTerms
Find out if Terms & Conditions have been accepted.
Units::ByteSize lastWhatsNewInMapsHash
Hash of the last "what's new in maps" message that was shown to the user.
Units::Distance airspaceAltitudeLimit_min
Minimum acceptable value for property airspaceAltitudeLimit.
bool showAltitudeAGL
Show Altitude AGL.
void lastValidAirspaceAltitudeLimitChanged()
Notifier signal.
Units::Distance lastValidAirspaceAltitudeLimit
Last finite value of airspaceAltitudeLimit.
auto fontSize() const -> int
Getter function for property with the same name.
@ Warning_Navigation
Serious warning, "Prohibited Airspace 1 minutes ahead".
@ Info_Navigation
Information pertaining to navigation, "Top of descent reached".
@ Alert
Alert. Immediate action is required to avoid accident or serious rule infringion.
@ Warning
Generic warning, "Traffic data receiver inop".
Convenience class for size_t.
Definition ByteSize.h:37
Convenience class for distance computations.
Definition Distance.h:35
static Q_INVOKABLE constexpr Units::Distance fromFT(double distanceInFT)
Constructs a distance.
Definition Distance.h:108
Conversion between units used in aviation.
Definition Angle.h:34