swift
informationmessage.cpp
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 
7 
8 SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc::aviation, CInformationMessage)
9 
10 namespace swift::misc::aviation
11 {
12  QString CInformationMessage::convertToQString(bool i18n) const
13  {
14  Q_UNUSED(i18n);
15  return m_message;
16  }
17 
19  {
21  qRegisterMetaType<CInformationMessage::InformationType>();
22  }
23 
25  {
26  static const CInformationMessage u(Unspecified);
27  return u;
28  }
29 
30  const QString &CInformationMessage::getTypeAsString() const
31  {
32  switch (m_type)
33  {
34  case ATIS:
35  {
36  static const QString atis("ATIS");
37  return atis;
38  }
39  case METAR:
40  {
41  static const QString metar("METAR");
42  return metar;
43  }
44  case TAF:
45  {
46  static const QString taf("TAF");
47  return taf;
48  }
49  default:
50  {
51  static const QString ds("unknown");
52  return ds;
53  }
54  }
55  }
56 
58  {
59  if (index.isMyself()) { return QVariant::fromValue(*this); }
61  const ColumnIndex i = index.frontCasted<ColumnIndex>();
62  switch (i)
63  {
64  case IndexType: return QVariant::fromValue(m_type);
65  case IndexMessage: return QVariant::fromValue(m_message);
66  default: break;
67  }
68  return CValueObject::propertyByIndex(index);
69  }
70 
71  void CInformationMessage::setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
72  {
73  if (index.isMyself())
74  {
75  (*this) = variant.value<CInformationMessage>();
76  return;
77  }
79  {
81  return;
82  }
83  const ColumnIndex i = index.frontCasted<ColumnIndex>();
84  switch (i)
85  {
86  case IndexType: m_type = static_cast<InformationType>(variant.toInt()); break;
87  case IndexMessage: m_message = variant.toString(); break;
88  default: break;
89  }
90  CValueObject::setPropertyByIndex(index, variant);
91  }
92 
94  const CInformationMessage &compareValue) const
95  {
96  if (index.isMyself())
97  {
98  const int c = Compare::compare(m_type, compareValue.m_type);
99  if (c != 0) return c;
100  return m_message.compare(compareValue.m_message, Qt::CaseInsensitive);
101  }
103  {
104  return ITimestampBased::comparePropertyByIndex(index, compareValue);
105  }
106  const ColumnIndex i = index.frontCasted<ColumnIndex>();
107  switch (i)
108  {
109  case IndexMessage: return m_message.compare(compareValue.m_message, Qt::CaseInsensitive);
110  case IndexType: return Compare::compare(this->getType(), compareValue.getType());
111  default: return CValueObject::comparePropertyByIndex(index, *this);
112  }
113  Q_ASSERT_X(false, Q_FUNC_INFO, "Compare failed");
114  return 0;
115  }
116 } // namespace swift::misc::aviation
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.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
int comparePropertyByIndex(CPropertyIndexRef index, const ITimestampBased &compareValue) const
Compare for index.
static bool canHandleIndex(CPropertyIndexRef index)
Can given index be handled.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Value object encapsulating information message (ATIS, METAR, TAF)
int comparePropertyByIndex(CPropertyIndexRef index, const CInformationMessage &compareValue) const
Compare for index.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
static const CInformationMessage & unspecified()
Unspecified object.
const QString & getTypeAsString() const
Type as string.
QString convertToQString(bool i18n=false) const
Cast as QString.
static void registerMetadata()
Register metadata.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
int comparePropertyByIndex(CPropertyIndexRef index, const Derived &compareValue) const
Compare for index.
Definition: mixinindex.h:187
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
static void registerMetadata()
Register metadata.
Definition: mixinmetatype.h:56
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition: valueobject.h:67