swift
xswiftbussettings.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include "misc/simulation/settings/xswiftbussettingsqtfree.inc"
7 
8 SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc::simulation::settings, CXSwiftBusSettings)
9 
10 namespace swift::misc::simulation::settings
11 {
13 
14  CXSwiftBusSettings::CXSwiftBusSettings(const QString &json) { this->parseXSwiftBusStringQt(json); }
15 
17  {
18  if (index.isMyself()) { return QVariant::fromValue(*this); }
20  const ColumnIndex i = index.frontCasted<ColumnIndex>();
21  switch (i)
22  {
23  case IndexMaxPlanes: return QVariant::fromValue(m_maxPlanes);
24  case IndexDBusServerAddress: return QVariant::fromValue(QString::fromStdString(m_dBusServerAddress));
25  case IndexNightTextureMode: return QVariant::fromValue(QString::fromStdString(m_nightTextureMode));
26  case IndexMessageBoxMargins: return QVariant::fromValue(QString::fromStdString(m_msgBox));
27  case IndexDrawingLabels: return QVariant::fromValue(m_drawingLabels);
28  case IndexBundleTaxiLandingLights: return QVariant::fromValue(m_bundleTaxiLandingLights);
29  case IndexMaxDrawingDistance: return QVariant::fromValue(m_maxDrawDistanceNM);
30  case IndexFollowAircraftDistance: return QVariant::fromValue(m_followAircraftDistanceM);
31  default: break;
32  }
33  return CValueObject::propertyByIndex(index);
34  }
35 
36  void CXSwiftBusSettings::setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
37  {
38  if (index.isMyself())
39  {
40  (*this) = variant.value<CXSwiftBusSettings>();
41  return;
42  }
44 
45  const ColumnIndex i = index.frontCasted<ColumnIndex>();
46  switch (i)
47  {
48  case IndexMaxPlanes: m_maxPlanes = variant.toInt(); break;
49  case IndexDBusServerAddress: m_dBusServerAddress = variant.toString().toStdString(); break;
50  case IndexMessageBoxMargins: m_msgBox = variant.toString().toStdString(); break;
51  case IndexNightTextureMode: m_nightTextureMode = variant.toString().toStdString(); break;
52  case IndexDrawingLabels: m_drawingLabels = variant.toBool(); break;
53  case IndexBundleTaxiLandingLights: m_bundleTaxiLandingLights = variant.toBool(); break;
54  case IndexMaxDrawingDistance: m_maxDrawDistanceNM = variant.toDouble(); break;
55  case IndexFollowAircraftDistance: m_followAircraftDistanceM = variant.toInt(); break;
56  default: CValueObject::setPropertyByIndex(index, variant); break;
57  }
58  }
59 
60  QString CXSwiftBusSettings::convertToQString(bool i18n) const
61  {
62  Q_UNUSED(i18n);
63  return QString::fromStdString(CXSwiftBusSettingsQtFree::convertToString());
64  }
65 
67  {
70  }
71 
73  {
74  CStatusMessageList msgs;
75  const QString dbus = QString::fromStdString(m_dBusServerAddress);
77  {
78  msgs.addValidationMessage(QStringLiteral("Invalid DBus address '%1'").arg(dbus),
80  }
81  return msgs;
82  }
83 
85  {
86  static const CXSwiftBusSettings s;
87  return s;
88  }
89 
91 } // namespace swift::misc::simulation::settings
static bool isSessionOrSystemAddress(const QString &address)
True if address is session or system bus address.
Definition: dbusserver.cpp:178
static bool isQtDBusAddress(const QString &address)
True if a valid Qt DBus address, e.g. "unix:tmpdir=/tmp", "tcp:host=127.0.0.1,port=45000".
Definition: dbusserver.cpp:173
Non-owning reference to a CPropertyIndex with a subset of its features.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
constexpr static auto SeverityError
Status severities.
Status messages, e.g. from Core -> GUI.
void addValidationMessage(const QString &validationText, CStatusMessage::StatusSeverity severity)
Convenience function to push back a validation message.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
static bool canHandleIndex(CPropertyIndexRef index)
Can given index be handled.
qint64 m_timestampMSecsSinceEpoch
timestamp value
void setCurrentUtcTime()
Set the current time as timestamp.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
ColumnIndex
Base class enums.
Definition: mixinindex.h:44
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
Definition: mixinindex.h:160
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Definition: mixinindex.h:167
QString convertToQString(bool i18n=false) const
Cast as QString.
void parseXSwiftBusStringQt(const QString &json)
Load and parse config file.
static const CXSwiftBusSettings & defaultValue()
Default value for settings.
virtual void objectUpdated() final
Object has been updated.
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
virtual void setCurrentUtcTime()
Sets both timestamps.
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
CStatusMessageList validate() const
Valid settings?
std::string m_dBusServerAddress
DBus server (also in class CXSwiftBusConfigWriter)
std::string m_msgBox
left, top, right, bottom, lines, duration, colors
std::string convertToString() const
Convert to string.
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition: valueobject.h:67