swift
Loading...
Searching...
No Matches
vatsimsettings.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#ifndef SWIFT_CORE_VATSIM_SETTINGS_H
7#define SWIFT_CORE_VATSIM_SETTINGS_H
8
10#include "misc/directoryutils.h"
12#include "misc/pq/time.h"
13#include "misc/settingscache.h"
15#include "misc/valueobject.h"
16
17SWIFT_DECLARE_VALUEOBJECT_MIXINS(swift::core::vatsim, CReaderSettings)
18SWIFT_DECLARE_VALUEOBJECT_MIXINS(swift::core::vatsim, CRawFsdMessageSettings)
19
20namespace swift::core::vatsim
21{
25 class SWIFT_CORE_EXPORT CReaderSettings : public swift::misc::CValueObject<swift::core::vatsim::CReaderSettings>
26 {
27 public:
30 {
31 IndexInitialTime = swift::misc::CPropertyIndexRef::GlobalIndexCSettingsReaders,
32 IndexPeriodicTime,
33 IndexNeverUpdate
34 };
35
37 CReaderSettings() = default;
38
41 const swift::misc::physical_quantities::CTime &periodicTime, bool neverUpdate = false);
42
44 const swift::misc::physical_quantities::CTime &getInitialTime() const { return m_initialTime; }
45
47 void setInitialTime(const swift::misc::physical_quantities::CTime &time) { m_initialTime = time; }
48
50 const swift::misc::physical_quantities::CTime &getPeriodicTime() const { return m_periodicTime; }
51
53 void setPeriodicTime(const swift::misc::physical_quantities::CTime &time) { m_periodicTime = time; }
54
56 bool isNeverUpdate() const { return m_neverUpdate; }
57
59 QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const;
60
62 void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant);
63
65 QString convertToQString(bool i18n = false) const;
66
68 static const CReaderSettings &neverUpdateSettings();
69
70 private:
71 swift::misc::physical_quantities::CTime m_initialTime { 30.0,
73 swift::misc::physical_quantities::CTime m_periodicTime { 30.0,
75 bool m_neverUpdate = false;
76
78 CReaderSettings,
79 SWIFT_METAMEMBER(initialTime),
80 SWIFT_METAMEMBER(periodicTime),
81 SWIFT_METAMEMBER(neverUpdate));
82 };
83
85 struct TVatsimDataFile : public swift::misc::TSettingTrait<CReaderSettings>
86 {
88 static const char *key() { return "vatsimreaders/datafile"; }
89
91 static const QString &humanReadable()
92 {
93 static const QString name("VATSIM data file");
94 return name;
95 }
96
106 };
107
109 struct TVatsimMetars : public swift::misc::TSettingTrait<CReaderSettings>
110 {
112 static const char *key() { return "vatsimreaders/metars"; }
113
115 static const QString &humanReadable()
116 {
117 static const QString name("VATSIM METARs");
118 return name;
119 }
120
123 {
124 static const swift::core::vatsim::CReaderSettings reader {
127 };
128 return reader;
129 }
130 };
131
134 public swift::misc::CValueObject<swift::core::vatsim::CRawFsdMessageSettings>
135 {
136 public:
139 {
140 None,
141 Truncate,
142 Append,
143 Timestamped
144 };
145
148 {
149 IndexRawFsdMessagesEnabled = swift::misc::CPropertyIndexRef::GlobalIndexRawFsdMessageSettings,
150 IndexFileDir,
151 IndexFileWriteMode
152 };
153
156
158 CRawFsdMessageSettings(bool enabled, const QString &fileDir);
159
161 bool areRawFsdMessagesEnabled() const { return m_rawFsdMessagesEnabled; }
162
164 QString getFileDir() const { return m_FileDir; }
165
167 FileWriteMode getFileWriteMode() const { return m_fileWriteMode; }
168
170 QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const;
171
173 void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant);
174
176 QString convertToQString(bool i18n = false) const;
177
178 private:
179 bool m_rawFsdMessagesEnabled = false;
180 QString m_FileDir;
181 FileWriteMode m_fileWriteMode = None;
182
185 SWIFT_METAMEMBER(rawFsdMessagesEnabled),
186 SWIFT_METAMEMBER(FileDir),
187 SWIFT_METAMEMBER(fileWriteMode));
188 };
189
191 struct TRawFsdMessageSetting : public swift::misc::TSettingTrait<CRawFsdMessageSettings>
192 {
194 static const char *key() { return "network/rawfsdmessagelog"; }
195
197 static const QString &humanReadable()
198 {
199 static const QString name("FSD message Logging");
200 return name;
201 }
202
203 /* //! \copydoc swift::misc::TSettingTrait::isValid
204 static bool isValid(const CRawFsdMessageSettings &setting, QString &)
205 {
206 if (setting.areRawFsdMessagesEnabled()) { return !setting.getFileDir().isEmpty(); }
207 return true;
208 }*/
209
212 {
214 return setting;
215 }
216 };
217} // namespace swift::core::vatsim
218
219Q_DECLARE_METATYPE(swift::core::vatsim::CReaderSettings)
223
224#endif // SWIFT_CORE_VATSIM_SETTINGS_H
CRawFsdMessageSettings()=default
Default constructor.
QString getFileDir() const
Get file directory.
FileWriteMode getFileWriteMode() const
Get file write mode.
bool areRawFsdMessagesEnabled() const
Are raw FSD messages enabled?
Settings used with readers.
const swift::misc::physical_quantities::CTime & getPeriodicTime() const
Get time.
CReaderSettings()=default
Default constructor.
const swift::misc::physical_quantities::CTime & getInitialTime() const
Get time.
void setPeriodicTime(const swift::misc::physical_quantities::CTime &time)
Set time.
bool isNeverUpdate() const
Never ever update?
void setInitialTime(const swift::misc::physical_quantities::CTime &time)
Set time.
Generic ordered container with value semantics.
Definition collection.h:113
Non-owning reference to a CPropertyIndex with a subset of its features.
static const QString & logDirectory()
Directory for log files.
Mix of the most commonly used mixin classes.
static CTimeUnit s()
Second s.
Definition units.h:938
#define SWIFT_METAMEMBER(MEMBER,...)
Macro to define an element within a metaclass.
Definition metaclass.h:72
#define SWIFT_METACLASS(CLASS,...)
Macro to define a nested metaclass that describes the attributes of its enclosing class.
Definition metaclass.h:52
static const QString & humanReadable()
Optional human readable name.
static const CRawFsdMessageSettings & defaultValue()
Return the value to use in case the supplied value does not satisfy the validator....
static const char * key()
Key string of the value. Reimplemented in derived class.
static const swift::core::vatsim::CReaderSettings & defaultValue()
Return the value to use in case the supplied value does not satisfy the validator....
static const QString & humanReadable()
Optional human readable name.
static const char * key()
Key string of the value. Reimplemented in derived class.
static const swift::core::vatsim::CReaderSettings & defaultValue()
Return the value to use in case the supplied value does not satisfy the validator....
static const char * key()
Key string of the value. Reimplemented in derived class.
static const QString & humanReadable()
Optional human readable name.
Base class for traits to be used as template argument to swift::misc::CSetting.
#define SWIFT_CORE_EXPORT
Export a class or function from the library.
#define SWIFT_DECLARE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template declaration of mixins for a CValueObject subclass to be placed near the top of the ...
Definition valueobject.h:65