swift
aircraftcategory.h
Go to the documentation of this file.
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 #ifndef SWIFT_MISC_AVIATION_AIRCRAFTCATEGORY_H
7 #define SWIFT_MISC_AVIATION_AIRCRAFTCATEGORY_H
8 
9 #include <QJsonObject>
10 #include <QList>
11 #include <QMap>
12 #include <QMetaType>
13 #include <QString>
14 
15 #include "misc/db/datastore.h"
16 #include "misc/metaclass.h"
17 #include "misc/propertyindexref.h"
18 #include "misc/statusmessagelist.h"
19 #include "misc/swiftmiscexport.h"
20 #include "misc/valueobject.h"
21 
22 SWIFT_DECLARE_VALUEOBJECT_MIXINS(swift::misc::aviation, CAircraftCategory)
23 
24 namespace swift::misc::aviation
25 {
28  public CValueObject<CAircraftCategory>,
30  {
31  public:
34  {
35  IndexName = CPropertyIndexRef::GlobalIndexCAircraftCategory,
36  IndexDescription,
37  IndexLevelString,
38  IndexLevelStringAndName,
39  IndexLevelStringAndPath,
40  IndexPath,
41  IndexAssignable
42  };
43 
45  CAircraftCategory() = default;
46 
48  CAircraftCategory(const QString &name, const QString &description, const QString &path, bool assignable);
49 
51  const QString &getName() const { return m_name; }
52 
54  void setName(const QString &name) { m_name = name.trimmed(); }
55 
57  QString getNameDbKey() const;
58 
60  bool hasName() const;
61 
63  bool matchesName(const QString &name, Qt::CaseSensitivity cs) const;
64 
66  const QString &getDescription() const { return m_description; }
67 
69  void setDescription(const QString &description) { m_description = description.trimmed(); }
70 
72  const QString &getPath() const { return m_path; }
73 
75  void setLevel(int l1, int l2, int l3);
76 
78  bool isLevel(int l1, int l2, int l3) const;
79 
81  bool isLevel(const QList<int> &level) const;
82 
84  bool isLevel(const CAircraftCategory &category) const;
85 
87  QList<int> getLevel() const;
88 
90  int getFirstLevel() const { return m_l1; }
91 
93  int getSecondLevel() const { return m_l2; }
94 
96  bool isFirstLevel() const;
97 
99  int getDepth() const;
100 
102  QString getLevelString() const;
103 
105  QString getLevelAndName() const;
106 
108  QString getLevelAndPath() const;
109 
111  bool matchesPath(const QString &path, Qt::CaseSensitivity cs);
112 
114  bool matchesLevel(int l1, int l2 = 0, int l3 = 0) const;
115 
117  bool matchesLevel(const QList<int> &level) const;
118 
120  bool isAssignable() const { return m_assignable; }
121 
123  void setAssignable(bool assignable) { m_assignable = assignable; }
124 
126  QVariant propertyByIndex(CPropertyIndexRef index) const;
127 
129  void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant);
130 
132  int comparePropertyByIndex(CPropertyIndexRef index, const CAircraftCategory &compareValue) const;
133 
135  QString convertToQString(bool i18n = false) const;
136 
138  swift::misc::CStatusMessageList validate() const;
139 
141  bool isNull() const;
142 
144  int compareByLevel(const CAircraftCategory &other) const;
145 
147  bool isHigherLevel(const CAircraftCategory &other) const;
148 
150  static const CAircraftCategory &null();
151 
153  static CAircraftCategory fromDatabaseJson(const QJsonObject &json, const QString &prefix = QString());
154 
155  private:
156  QString m_name;
157  QString m_description;
158  QString m_path;
159  bool m_assignable = true;
160  int m_l1 = 0;
161  int m_l2 = 0;
162  int m_l3 = 0;
165  SWIFT_METAMEMBER(dbKey),
166  SWIFT_METAMEMBER(timestampMSecsSinceEpoch),
167  SWIFT_METAMEMBER(name),
168  SWIFT_METAMEMBER(l1),
169  SWIFT_METAMEMBER(l2),
170  SWIFT_METAMEMBER(l3),
171  SWIFT_METAMEMBER(description),
172  SWIFT_METAMEMBER(path),
173  SWIFT_METAMEMBER(assignable));
174  };
175 
178 
179 } // namespace swift::misc::aviation
180 
182 
183 #endif // SWIFT_MISC_AVIATION_AIRCRAFTCATEGORY_H
Non-owning reference to a CPropertyIndex with a subset of its features.
Status messages, e.g. from Core -> GUI.
Mix of the most commonly used mixin classes.
Definition: valueobject.h:114
Value object for aircraft categories.
void setAssignable(bool assignable)
Mark/set assignable.
void setDescription(const QString &description)
Set description.
const QString & getPath() const
Path.
const QString & getDescription() const
Description.
CAircraftCategory()=default
Default constructor.
const QString & getName() const
Get name.
void setName(const QString &name)
Set name.
Class from which a derived class can inherit datastore-related functions.
Definition: datastore.h:70
#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
#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