6 #include <QRegularExpression>
7 #include <QStringBuilder>
19 using namespace swift::misc::db;
23 namespace swift::misc::aviation
25 CAircraftCategory::CAircraftCategory(
const QString &name,
const QString &description,
const QString &path,
27 : m_name(name), m_description(description), m_path(path), m_assignable(assignable)
70 if (level.size() != 3) {
return false; }
71 return m_l1 == level[0] && m_l2 == level[1] && m_l3 == level[2];
76 if (category.
isNull()) {
return false; }
77 return category.m_l1 == m_l1 && category.m_l2 == m_l2 && category.m_l3 == m_l3;
83 if (m_l1 > 0) l << m_l1;
84 if (m_l2 > 0) l << m_l2;
85 if (m_l3 > 0) l << m_l3;
94 if (m_l3 == 0 && m_l2 > 0 && m_l1 > 0) {
return 2; }
100 if (this->
isNull()) {
return {}; }
101 return QStringLiteral(
"%1.%2.%3").arg(m_l1).arg(m_l2).arg(m_l3);
106 if (this->
isNull()) {
return {}; }
112 if (this->
isNull()) {
return {}; }
123 if (l1 != m_l1) {
return false; }
124 if (l2 > 0 && l2 != m_l2) {
return false; }
125 if (l3 > 0 && l3 != m_l3) {
return false; }
131 if (level.isEmpty()) {
return false; }
132 const int l1 = level.first();
133 const int l2 = level.size() > 1 ? level.at(1) : 0;
134 const int l3 = level.size() > 2 ? level.at(2) : 0;
140 if (index.
isMyself()) {
return QVariant::fromValue(*
this); }
141 if (IDatastoreObjectWithIntegerKey::canHandleIndex(index))
143 return IDatastoreObjectWithIntegerKey::propertyByIndex(index);
148 case IndexName:
return QVariant::fromValue(m_name);
149 case IndexDescription:
return QVariant::fromValue(m_description);
150 case IndexAssignable:
return QVariant::fromValue(m_assignable);
151 case IndexPath:
return QVariant::fromValue(m_path);
152 case IndexLevelString:
return QVariant::fromValue(this->
getLevelString());
153 case IndexLevelStringAndName:
return QVariant::fromValue(this->
getLevelAndName());
154 case IndexLevelStringAndPath:
return QVariant::fromValue(this->
getLevelAndPath());
166 if (IDatastoreObjectWithIntegerKey::canHandleIndex(index))
168 IDatastoreObjectWithIntegerKey::setPropertyByIndex(index, variant);
174 case IndexName: this->
setName(variant.value<QString>());
break;
175 case IndexDescription: this->
setDescription(variant.value<QString>());
break;
176 case IndexAssignable: this->
setAssignable(variant.value<
bool>());
break;
183 if (index.
isMyself()) {
return m_path.compare(compareValue.
getPath(), Qt::CaseInsensitive); }
184 if (IDatastoreObjectWithIntegerKey::canHandleIndex(index))
186 return IDatastoreObjectWithIntegerKey::comparePropertyByIndex(index, compareValue);
191 case IndexName:
return m_name.compare(compareValue.
getName(), Qt::CaseInsensitive);
192 case IndexPath:
return m_path.compare(compareValue.
getPath(), Qt::CaseInsensitive);
193 case IndexDescription:
return m_description.compare(compareValue.
getDescription(), Qt::CaseInsensitive);
195 case IndexLevelStringAndName:
196 case IndexLevelStringAndPath:
200 Q_ASSERT_X(
false, Q_FUNC_INFO,
"No comparison");
206 const QString name(json.value(prefix % u
"name").toString());
207 const QString description(json.value(prefix % u
"description").toString());
208 const QString path(json.value(prefix % u
"path").toString());
209 const bool assignable = CDatastoreUtility::dbBoolStringToBool(json.value(prefix % u
"assignable").toString());
210 const int l1 = json.value(prefix % u
"l1").toInt();
211 const int l2 = json.value(prefix % u
"l2").toInt();
212 const int l3 = json.value(prefix % u
"l3").toInt();
223 int c = Compare::compare(m_l1, other.m_l1);
224 if (c != 0) {
return c; }
225 c = Compare::compare(m_l2, other.m_l2);
226 if (c != 0) {
return c; }
227 c = Compare::compare(m_l3, other.m_l3);
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.
Status messages, e.g. from Core -> GUI.
Value object for aircraft categories.
bool isFirstLevel() const
First level.
int getDepth() const
Depth 1, 2, 3.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
void setAssignable(bool assignable)
Mark/set assignable.
bool isHigherLevel(const CAircraftCategory &other) const
Higher level?
int comparePropertyByIndex(CPropertyIndexRef index, const CAircraftCategory &compareValue) const
Compare for index.
void setDescription(const QString &description)
Set description.
bool isAssignable() const
Assignable?
const QString & getPath() const
Path.
const QString & getDescription() const
Description.
ColumnIndex
Properties by index.
bool isNull() const
Null category?
int compareByLevel(const CAircraftCategory &other) const
Level compare.
QString getLevelAndName() const
Level and name.
swift::misc::CStatusMessageList validate() const
Validate data.
bool isLevel(int l1, int l2, int l3) const
Is that given level?
QString getLevelString() const
Level string.
bool matchesName(const QString &name, Qt::CaseSensitivity cs) const
Matching name?
QString getNameDbKey() const
Designator and DB key.
QList< int > getLevel() const
Levels depending on depth, 3.2 -> 3,2 / 1.0 -> 1 / 4.3.1 -> 4,3,1.
QString convertToQString(bool i18n=false) const
Cast as QString.
static CAircraftCategory fromDatabaseJson(const QJsonObject &json, const QString &prefix=QString())
From our database JSON format.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
QString getLevelAndPath() const
Level and path.
bool matchesPath(const QString &path, Qt::CaseSensitivity cs)
Matching path?
void setLevel(int l1, int l2, int l3)
Level.
static const CAircraftCategory & null()
NULL object.
bool hasName() const
Aircraft designator?
const QString & getName() const
Get name.
bool matchesLevel(int l1, int l2=0, int l3=0) const
Is matching the level, 0 ignored.
void setName(const QString &name)
Set name.
bool isLoadedFromDb() const
Loaded from DB.
QString getDbKeyAsStringInParentheses(const QString &prefix={}) const
Db key in parentheses, e.g. "(3)".
void setKeyVersionTimestampFromDatabaseJson(const QJsonObject &json, const QString &prefix=QString())
Set key and timestamp values.
int comparePropertyByIndex(CPropertyIndexRef index, const Derived &compareValue) const
Compare for index.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Free functions in swift::misc.
SWIFT_MISC_EXPORT bool stringCompare(const QString &c1, const QString &c2, Qt::CaseSensitivity cs)
String compare.
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.