swift
informationmessage.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_MISC_AVIATION_INFORMATIONMESSAGE_H
7 #define SWIFT_MISC_AVIATION_INFORMATIONMESSAGE_H
8 
9 #include <QDateTime>
10 #include <QMetaType>
11 #include <QString>
12 #include <QtGlobal>
13 
14 #include "misc/dbus.h"
15 #include "misc/metaclass.h"
16 #include "misc/swiftmiscexport.h"
17 #include "misc/timestampbased.h"
18 #include "misc/valueobject.h"
19 
20 SWIFT_DECLARE_VALUEOBJECT_MIXINS(swift::misc::aviation, CInformationMessage)
21 
22 namespace swift::misc::aviation
23 {
25  class SWIFT_MISC_EXPORT CInformationMessage : public CValueObject<CInformationMessage>, public ITimestampBased
26  {
27  public:
30  {
31  Unspecified,
32  ATIS,
33  METAR,
34  TAF
35  };
36 
39  {
40  IndexType = CPropertyIndexRef::GlobalIndexCInformationMessage,
41  IndexMessage,
42  };
43 
45  CInformationMessage() : m_type(CInformationMessage::Unspecified) {}
46 
48  explicit CInformationMessage(InformationType type) : m_type(type) {}
49 
51  CInformationMessage(InformationType type, const QString &message) : m_type(type), m_message(message) {}
52 
54  const QString &getMessage() const { return m_message; }
55 
57  bool hasMessage() const { return !m_message.isEmpty(); }
58 
60  void setMessage(const QString &message)
61  {
62  this->setCurrentUtcTime();
63  m_message = message;
64  }
65 
67  void appendMessage(const QString &messagePart)
68  {
69  this->setCurrentUtcTime();
70  m_message.append(messagePart);
71  }
72 
74  const QString &getTypeAsString() const;
75 
77  InformationType getType() const { return m_type; }
78 
80  void setType(InformationType type) { m_type = type; }
81 
83  qint64 timeDiffReceivedMs() const { return this->getTimeDifferenceToNowMs(); }
84 
86  bool isEmpty() const { return m_message.isEmpty(); }
87 
89  QVariant propertyByIndex(CPropertyIndexRef index) const;
90 
92  void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant);
93 
95  int comparePropertyByIndex(CPropertyIndexRef index, const CInformationMessage &compareValue) const;
96 
98  QString convertToQString(bool i18n = false) const;
99 
101  static void registerMetadata();
102 
104  static const CInformationMessage &unspecified();
105 
106  private:
107  InformationType m_type;
108  QString m_message;
109 
112  SWIFT_METAMEMBER(type),
113  SWIFT_METAMEMBER(message),
114  SWIFT_METAMEMBER(timestampMSecsSinceEpoch));
115  };
116 } // namespace swift::misc::aviation
117 
120 
121 #endif // SWIFT_MISC_AVIATION_INFORMATIONMESSAGE_H
Non-owning reference to a CPropertyIndex with a subset of its features.
Mix of the most commonly used mixin classes.
Definition: valueobject.h:114
Entity with timestamp.
Value object encapsulating information message (ATIS, METAR, TAF)
void appendMessage(const QString &messagePart)
Append message part.
const QString & getMessage() const
Get message.
bool hasMessage() const
Is a message available.
void setType(InformationType type)
Set type.
void setMessage(const QString &message)
Set message.
qint64 timeDiffReceivedMs() const
Received before n ms.
CInformationMessage(InformationType type)
Information message of type.
CInformationMessage(InformationType type, const QString &message)
Information message of type.
#define SWIFT_METAMEMBER(MEMBER,...)
Macro to define an element within a metaclass.
Definition: metaclass.h:73
#define SWIFT_METACLASS(CLASS,...)
Macro to define a nested metaclass that describes the attributes of its enclosing class.
Definition: metaclass.h:53
void registerMetadata()
Register all relevant metadata in Misc.
#define SWIFT_MISC_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