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
116
121 Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
122
125
128
131
138
145
147 Q_PROPERTY(bool nightMode READ nightMode WRITE setNightMode BINDABLE bindableNightMode NOTIFY nightModeChanged)
148
151
157 Q_PROPERTY(Units::ByteSize privacyHash READ privacyHash WRITE setPrivacyHash NOTIFY privacyHashChanged)
158
161
164
167
174
175
176 //
177 // Getter Methods
178 //
179
184 [[nodiscard]] auto acceptedTerms() const -> int { return m_settings.value(QStringLiteral("acceptedTerms"), 0).toInt(); }
185
190 [[nodiscard]] bool alwaysOpenExternalWebsites() const { return m_settings.value(QStringLiteral("alwaysOpenExternalWebsites"), false).toBool(); }
191
196 [[nodiscard]] auto airspaceAltitudeLimit() const -> Units::Distance;
197
202 [[nodiscard]] auto autoFlightDetection() const -> bool { return m_settings.value(QStringLiteral("FlightLog/autoFlightDetection"), false).toBool(); }
203
208 [[nodiscard]] bool expandNotamAbbreviations() const { return m_settings.value(QStringLiteral("expandNotamAbbreviations"), false).toBool(); }
209
214 [[nodiscard]] auto fontSize() const -> int;
215
220 [[nodiscard]] auto hideGlidingSectors() const -> bool { return m_settings.value(QStringLiteral("Map/hideGlidingSectors"), true).toBool(); }
221
226 [[nodiscard]] auto ignoreSSLProblems() const -> bool { return m_settings.value(QStringLiteral("ignoreSSLProblems"), false).toBool(); }
227
232 [[nodiscard]] auto lastValidAirspaceAltitudeLimit() const -> Units::Distance;
233
238 [[nodiscard]] auto lastWhatsNewHash() const -> Units::ByteSize
239 {
240 return m_settings.value(QStringLiteral("lastWhatsNewHash"), 0).value<size_t>();
241 }
242
247 [[nodiscard]] auto lastWhatsNewInMapsHash() const -> Units::ByteSize
248 {
249 return m_settings.value(QStringLiteral("lastWhatsNewInMapsHash"), 0).value<size_t>();
250 }
251
256 [[nodiscard]] auto nightMode() const -> bool { return m_nightMode.value(); }
257
262 [[nodiscard]] QBindable<bool> bindableNightMode() { return &m_nightMode; }
263
268 [[nodiscard]] bool positioningByTrafficDataReceiver() const { return m_positioningByTrafficDataReceiver.value(); }
269
274 [[nodiscard]] QBindable<bool> bindablePositioningByTrafficDataReceiver() const { return &m_positioningByTrafficDataReceiver; }
275
280 [[nodiscard]] auto privacyHash() const -> Units::ByteSize { return m_settings.value(QStringLiteral("privacyHash"), 0).value<size_t>(); }
281
286 [[nodiscard]] auto showAltitudeAGL() const -> bool { return m_settings.value(QStringLiteral("showAltitudeAGL"), false).toBool(); }
287
292 [[nodiscard]] auto showCurrentFlightTrace() const -> bool { return m_settings.value(QStringLiteral("FlightLog/showCurrentFlightTrace"), true).toBool(); }
293
298 [[nodiscard]] auto trackRecording() const -> bool { return m_settings.value(QStringLiteral("FlightLog/trackRecording"), true).toBool(); }
299
304 [[nodiscard]] auto voiceNotifications() const -> uint
305 {
306 return m_settings.value(QStringLiteral("voiceNotifications"),
311 }
312
313
314 //
315 // Setter Methods
316 //
317
322 void setAcceptedTerms(int terms);
323
328 void setAlwaysOpenExternalWebsites(bool alwaysOpen);
329
338 void setAirspaceAltitudeLimit(Units::Distance newAirspaceAltitudeLimit);
339
344 void setAutoFlightDetection(bool newAutoFlightDetection);
345
350 void setExpandNotamAbbreviations(bool newExpandNotamAbbreviations);
351
356 void setHideGlidingSectors(bool hide);
357
362 void setFontSize(int newFontSize);
363
368 void setIgnoreSSLProblems(bool ignore);
369
374 void setLargeFonts(bool newLargeFonts);
375
381
387
392 void setNightMode(bool newNightMode);
393
398 void setPositioningByTrafficDataReceiver(bool newPositioningByTrafficDataReceiver);
399
405
410 void setShowAltitudeAGL(bool newShowAltitudeAGL);
411
416 void setShowCurrentFlightTrace(bool newShowCurrentFlightTrace);
417
422 void setTrackRecording(bool newTrackRecording);
423
428 void setVoiceNotifications(uint newVoiceNotifications);
429
430
431 //
432 // Constants
433 //
434
437
438signals:
441
444
447
450
453
456
459
462
465
468
471
474
477
480
483
486
489
490private:
491 Q_DISABLE_COPY_MOVE(GlobalSettings)
492
493 QSettings m_settings;
494
495 // Property-backed night mode setting, so that C++ bindings can depend on
496 // it. Initialized from m_settings, which is declared above on purpose.
497 QProperty<bool> m_nightMode {m_settings.value(QStringLiteral("Map/nightMode"), false).toBool()};
498
499 QProperty<bool> m_positioningByTrafficDataReceiver;
500};
static Q_INVOKABLE GlobalSettings * globalSettings()
Pointer to appplication-wide static Settings instance.
QBindable< bool > bindableNightMode()
Getter function for property of the same name.
GlobalSettings(QObject *parent=nullptr)
Standard constructor.
void setShowAltitudeAGL(bool newShowAltitudeAGL)
Setter function for property of the same name.
auto trackRecording() const -> bool
Getter function for property of the same name.
void lastWhatsNewInMapsHashChanged()
Notifier signal.
void setShowCurrentFlightTrace(bool newShowCurrentFlightTrace)
Setter function for property of the same name.
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.
void trackRecordingChanged()
Notifier signal.
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 setAutoFlightDetection(bool newAutoFlightDetection)
Setter function for property of the same name.
void privacyHashChanged()
Notifier signal.
bool showCurrentFlightTrace
Show current flight trace on map.
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 setTrackRecording(bool newTrackRecording)
Setter function for property of the same name.
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.
bool expandNotamAbbreviations() const
Getter function for property of the same name.
void ignoreSSLProblemsChanged()
Notifier signal.
void showCurrentFlightTraceChanged()
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.
void autoFlightDetectionChanged()
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.
bool autoFlightDetection
Automatic flight detection enabled for FlightLog start and landing time.
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.
bool trackRecording
Flight track recording enabled.
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.
auto showCurrentFlightTrace() const -> bool
Getter function for property of the same name.
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