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
116
119
127 Q_PROPERTY(bool flightLogEnabled READ flightLogEnabled CONSTANT)
128
133 Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
134
137
140
143
150
157
159 Q_PROPERTY(bool nightMode READ nightMode WRITE setNightMode BINDABLE bindableNightMode NOTIFY nightModeChanged)
160
163
169 Q_PROPERTY(Units::ByteSize privacyHash READ privacyHash WRITE setPrivacyHash NOTIFY privacyHashChanged)
170
173
176
179
186
187
188 //
189 // Getter Methods
190 //
191
196 [[nodiscard]] auto acceptedTerms() const -> int { return m_settings.value(QStringLiteral("acceptedTerms"), 0).toInt(); }
197
202 [[nodiscard]] bool alwaysOpenExternalWebsites() const { return m_settings.value(QStringLiteral("alwaysOpenExternalWebsites"), false).toBool(); }
203
208 [[nodiscard]] auto airspaceAltitudeLimit() const -> Units::Distance;
209
214 [[nodiscard]] auto autoFlightDetection() const -> bool;
215
220 [[nodiscard]] bool expandNotamAbbreviations() const { return m_settings.value(QStringLiteral("expandNotamAbbreviations"), false).toBool(); }
221
226 [[nodiscard]] auto flightLogEnabled() const -> bool;
227
232 [[nodiscard]] auto fontSize() const -> int;
233
238 [[nodiscard]] auto hideGlidingSectors() const -> bool { return m_settings.value(QStringLiteral("Map/hideGlidingSectors"), true).toBool(); }
239
244 [[nodiscard]] auto ignoreSSLProblems() const -> bool { return m_settings.value(QStringLiteral("ignoreSSLProblems"), false).toBool(); }
245
250 [[nodiscard]] auto lastValidAirspaceAltitudeLimit() const -> Units::Distance;
251
256 [[nodiscard]] auto lastWhatsNewHash() const -> Units::ByteSize
257 {
258 return m_settings.value(QStringLiteral("lastWhatsNewHash"), 0).value<size_t>();
259 }
260
265 [[nodiscard]] auto lastWhatsNewInMapsHash() const -> Units::ByteSize
266 {
267 return m_settings.value(QStringLiteral("lastWhatsNewInMapsHash"), 0).value<size_t>();
268 }
269
274 [[nodiscard]] auto nightMode() const -> bool { return m_nightMode.value(); }
275
280 [[nodiscard]] QBindable<bool> bindableNightMode() { return &m_nightMode; }
281
286 [[nodiscard]] bool positioningByTrafficDataReceiver() const { return m_positioningByTrafficDataReceiver.value(); }
287
292 [[nodiscard]] QBindable<bool> bindablePositioningByTrafficDataReceiver() const { return &m_positioningByTrafficDataReceiver; }
293
298 [[nodiscard]] auto privacyHash() const -> Units::ByteSize { return m_settings.value(QStringLiteral("privacyHash"), 0).value<size_t>(); }
299
304 [[nodiscard]] auto showAltitudeAGL() const -> bool { return m_settings.value(QStringLiteral("showAltitudeAGL"), false).toBool(); }
305
310 [[nodiscard]] auto showCurrentFlightTrace() const -> bool { return m_settings.value(QStringLiteral("FlightLog/showCurrentFlightTrace"), true).toBool(); }
311
316 [[nodiscard]] auto trackRecording() const -> bool { return m_settings.value(QStringLiteral("FlightLog/trackRecording"), true).toBool(); }
317
322 [[nodiscard]] auto voiceNotifications() const -> uint
323 {
324 return m_settings.value(QStringLiteral("voiceNotifications"),
329 }
330
331
332 //
333 // Setter Methods
334 //
335
340 void setAcceptedTerms(int terms);
341
346 void setAlwaysOpenExternalWebsites(bool alwaysOpen);
347
356 void setAirspaceAltitudeLimit(Units::Distance newAirspaceAltitudeLimit);
357
362 void setAutoFlightDetection(bool newAutoFlightDetection);
363
368 void setExpandNotamAbbreviations(bool newExpandNotamAbbreviations);
369
374 void setHideGlidingSectors(bool hide);
375
380 void setFontSize(int newFontSize);
381
386 void setIgnoreSSLProblems(bool ignore);
387
392 void setLargeFonts(bool newLargeFonts);
393
399
405
410 void setNightMode(bool newNightMode);
411
416 void setPositioningByTrafficDataReceiver(bool newPositioningByTrafficDataReceiver);
417
423
428 void setShowAltitudeAGL(bool newShowAltitudeAGL);
429
434 void setShowCurrentFlightTrace(bool newShowCurrentFlightTrace);
435
440 void setTrackRecording(bool newTrackRecording);
441
446 void setVoiceNotifications(uint newVoiceNotifications);
447
448
449 //
450 // Constants
451 //
452
455
456signals:
459
462
465
468
471
474
477
480
483
486
489
492
495
498
501
504
507
508private:
509 Q_DISABLE_COPY_MOVE(GlobalSettings)
510
511 QSettings m_settings;
512
513 // Property-backed night mode setting, so that C++ bindings can depend on
514 // it. Initialized from m_settings, which is declared above on purpose.
515 QProperty<bool> m_nightMode {m_settings.value(QStringLiteral("Map/nightMode"), false).toBool()};
516
517 QProperty<bool> m_positioningByTrafficDataReceiver;
518};
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.
bool flightLogEnabled
True if this build includes the flight log.
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.
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.
auto flightLogEnabled() const -> bool
Getter 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.
@ 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