swift
country.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2015 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_COUNTRY_H
7 #define SWIFT_MISC_COUNTRY_H
8 
9 #include <QJsonObject>
10 #include <QMetaType>
11 #include <QString>
12 
13 #include "misc/db/datastore.h"
14 #include "misc/metaclass.h"
15 #include "misc/propertyindexref.h"
16 #include "misc/swiftmiscexport.h"
17 #include "misc/valueobject.h"
18 
20 
21 namespace swift::misc
22 {
27  {
28  public:
31  {
32  IndexIsoCode = CPropertyIndexRef::GlobalIndexCCountry,
33  IndexIso3Code,
34  IndexName,
35  IndexAlias1,
36  IndexAlias2,
37  IndexNameIso,
38  IndexIsoName,
39  IndexHistoric
40  };
41 
43  CCountry() = default;
44 
46  CCountry(const QString &iso, const QString &name);
47 
49  bool isValid() const;
50 
52  CIcons::IconIndex toIcon() const;
53 
55  const QString &getIsoCode() const { return m_dbKey; }
56 
58  const QString &getIso3Code() const { return m_iso3; }
59 
61  void setIsoCode(const QString &iso);
62 
64  void setIso3Code(const QString &iso);
65 
67  bool hasIsoCode() const;
68 
70  bool hasIso3Code() const;
71 
73  const QString &getName() const { return m_name; }
74 
76  const QString &getSimplifiedName() const { return m_simplifiedName; }
77 
79  const QString &getAlias1() const { return m_alias1; }
80 
82  void setAlias1(const QString &alias);
83 
85  const QString &getAlias2() const { return m_alias2; }
86 
88  void setAlias2(const QString &alias);
89 
91  bool isHistoric() const { return m_historic; }
92 
94  void setHistoric(bool historic) { m_historic = historic; }
95 
97  QString getCombinedStringIsoName() const;
98 
100  QString getCombinedStringNameIso() const;
101 
103  void setName(const QString &countryName);
104 
106  bool matchesCountryName(const QString &name) const;
107 
109  bool matchesAlias(const QString &alias) const;
110 
112  QString convertToQString(bool i18n = false) const;
113 
115  QVariant propertyByIndex(CPropertyIndexRef index) const;
116 
118  void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant);
119 
121  int comparePropertyByIndex(CPropertyIndexRef index, const CCountry &compareValue) const;
122 
124  static CCountry fromDatabaseJson(const QJsonObject &json, const QString &prefix = QString());
125 
127  static bool isValidIsoCode(const QString &isoCode);
128 
129  private:
131  void setSimplifiedNameIfNotSame();
132 
133  QString m_iso3;
134  QString m_name;
135  QString m_simplifiedName;
136  QString m_alias1;
137  QString m_alias2;
138  bool m_historic = false;
139 
141  CCountry,
143  SWIFT_METAMEMBER(loadedFromDb),
144  SWIFT_METAMEMBER(timestampMSecsSinceEpoch),
145  SWIFT_METAMEMBER(iso3),
146  SWIFT_METAMEMBER(name),
147  SWIFT_METAMEMBER(simplifiedName),
148  SWIFT_METAMEMBER(alias1),
149  SWIFT_METAMEMBER(alias2),
150  SWIFT_METAMEMBER(historic));
151  };
152 } // namespace swift::misc
153 
154 Q_DECLARE_METATYPE(swift::misc::CCountry)
155 
156 #endif // SWIFT_MISC_COUNTRY_H
const QString & getName() const
Country name.
Definition: country.h:73
const QString & getIso3Code() const
Get 3 letter iso code.
Definition: country.h:58
CCountry()=default
Constructor.
const QString & getAlias1() const
Alias 1.
Definition: country.h:79
const QString & getIsoCode() const
DB ISO code.
Definition: country.h:55
ColumnIndex
Properties by index.
Definition: country.h:31
bool isHistoric() const
Historic / non-existing country (e.g. Soviet Union)
Definition: country.h:91
const QString & getAlias2() const
Alias 2.
Definition: country.h:85
const QString & getSimplifiedName() const
Country name (no accents ...)
Definition: country.h:76
void setHistoric(bool historic)
Historic country?
Definition: country.h:94
IconIndex
Index for each icon, allows to send them via DBus, efficiently store them, etc.
Definition: icons.h:32
Non-owning reference to a CPropertyIndex with a subset of its features.
Mix of the most commonly used mixin classes.
Definition: valueobject.h:114
Class from which a derived class can inherit datastore-related functions.
Definition: datastore.h:166
#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
@ CaseInsensitiveComparison
Element will be compared case insensitively (must be a QString)
Definition: metaclass.h:207
Free functions in swift::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