swift
Loading...
Searching...
No Matches
aircraftmodel.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
6#include <algorithm>
7
8#include <QFileInfo>
9#include <QJsonDocument>
10#include <QJsonObject>
11#include <QJsonValue>
12#include <QList>
13#include <QString>
14#include <QStringBuilder>
15#include <QtGlobal>
16
17#include "config/buildconfig.h"
20#include "misc/fileutils.h"
21#include "misc/logcategories.h"
24#include "misc/statusmessage.h"
25#include "misc/stringutils.h"
26#include "misc/verify.h"
27
28using namespace swift::config;
29using namespace swift::misc::aviation;
30using namespace swift::misc::physical_quantities;
31using namespace swift::misc::db;
32
33SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc::simulation, CAircraftModel)
34
35namespace swift::misc::simulation
36{
38 {
40 qRegisterMetaType<ModelType>();
41 }
42
44 : m_modelString(model.trimmed().toUpper()), m_modelType(type)
45 {}
46
48 const CLivery &livery)
49 : m_aircraftIcao(icao), m_livery(livery), m_modelString(model.trimmed().toUpper()), m_modelType(type)
50 {}
51
53 const CAircraftIcaoCode &icao, const aviation::CLivery &livery)
54 : m_aircraftIcao(icao), m_livery(livery), m_modelString(model.trimmed().toUpper()),
55 m_description(description.trimmed()), m_modelType(type)
56 {}
57
59 const CSimulatorInfo &simulator, const QString &name, const QString &description)
60 : m_simulator(simulator), m_modelString(model.trimmed().toUpper()), m_name(name.trimmed()),
61 m_description(description.trimmed()), m_modelType(type)
62 {}
63
65 const CSimulatorInfo &simulator, const QString &name, const QString &description,
66 const CAircraftIcaoCode &icao, const CLivery &livery)
67 : m_aircraftIcao(icao), m_livery(livery), m_simulator(simulator), m_modelString(model.trimmed().toUpper()),
68 m_name(name.trimmed()), m_description(description.trimmed()), m_modelType(type)
69 {}
70
72 {
73 const QString s = (this->hasAnyModelString() ?
74 inApostrophes(this->getAllModelStringsAliasesAndDbKey(), true) % QStringLiteral(" ") :
75 QString()) %
76 u" type: '" % this->getModelTypeAsString() % u"' ICAO: {" %
77 this->getAircraftIcaoCode().toQString(i18n) % u"} CG: " %
78 this->getCG().valueRoundedWithUnit(1) % u"' livery: {" % m_livery.toQString(i18n) %
79 u"} file: '" % m_fileName % u'\'';
80 return s;
81 }
82
84 {
85 QJsonObject obj;
86
87 // filename not in DB
88 obj.insert("id", this->getDbKeyAsJsonValue());
89 obj.insert("name", this->getName());
90 obj.insert("modelstring", QJsonValue(m_modelString));
91 obj.insert("description", QJsonValue(m_description));
92 obj.insert("parts", QJsonValue(m_supportedParts));
93 obj.insert("version", CBuildConfig::getVersionString());
94 obj.insert("mode", QJsonValue(getModelModeAsString().left(1).toUpper())); // clazy:exclude=qstring-left
95 if (m_cg.isNull())
96 {
97 obj.insert("cgft", QJsonValue()); // null value
98 }
99 else
100 {
101 obj.insert("cgft", QJsonValue(m_cg.value(CLengthUnit::ft())));
102 }
103
104 // sims
105 const CSimulatorInfo sim(getSimulator());
106 QString flag = "N";
107 obj.insert("simfsx", QJsonValue(flag));
109 obj.insert("simp3d", QJsonValue(flag));
110 flag = "N";
111 obj.insert("simfs9", QJsonValue(flag));
113 obj.insert("simmsfs", QJsonValue(flag));
115 obj.insert("simmsfs2024", QJsonValue(flag));
117 obj.insert("simxplane", QJsonValue(flag));
119 obj.insert("simfg", QJsonValue(flag));
120
121 // foreign keys
122 obj.insert("iddistributor", this->getDistributor().getDbKeyAsJsonValue());
123 obj.insert("idaircrafticao", this->getAircraftIcaoCode().getDbKeyAsJsonValue());
124 obj.insert("idlivery", this->getLivery().getDbKeyAsJsonValue());
125 obj.insert(
126 "idairlineicao",
127 this->getLivery().getAirlineIcaoCode().getDbKeyAsJsonValue()); // not really needed if livery is complete
128
129 return obj;
130 }
131
136
137 QJsonObject CAircraftModel::toMemoizedJson(MemoHelper::CMemoizer &helper) const
138 {
139 QJsonObject json;
140 // NOLINTBEGIN(readability-static-accessed-through-instance)
141 introspect<CAircraftModel>().forEachMember([&, this](auto member) {
142 if constexpr (!decltype(member)::has(MetaFlags<DisabledForJson>()))
143 {
144 auto &&maybeMemo = helper.maybeMemoize(member.in(*this));
145 json << std::make_pair(CExplicitLatin1String(member.latin1Name()), std::cref(maybeMemo));
146 }
147 });
148 // NOLINTEND(readability-static-accessed-through-instance)
149 return json;
150 }
151
152 void CAircraftModel::convertFromMemoizedJson(const QJsonObject &json, const MemoHelper::CUnmemoizer &helper)
153 {
154 // NOLINTBEGIN(readability-static-accessed-through-instance)
155 introspect<CAircraftModel>().forEachMember([&, this](auto member) {
156 if constexpr (!decltype(member)::has(MetaFlags<DisabledForJson>()))
157 {
158 auto it = json.find(CExplicitLatin1String(member.latin1Name()));
159 if (it != json.end())
160 {
161 it.value() >> helper.maybeUnmemoize(member.in(*this)).get();
162 }
163 }
164 });
165 // NOLINTEND(readability-static-accessed-through-instance)
166 }
167
169 {
170 return QStringLiteral(
171 "Model: %1 changed: %2%3Simulator: %4 Mode: %5 Distributor: %6%7Aircraft ICAO: %8%9Livery: %10")
172 .arg(this->getModelStringAndDbKey(), this->getFormattedUtcTimestampYmdhms(), separator,
173 this->getSimulator().toQString(true), this->getModelModeAsString(),
174 this->getDistributor().getIdAndDescription(), separator, this->getAircraftIcaoCode().asHtmlSummary(),
175 separator)
176 .arg(this->getLivery().asHtmlSummary("&nbsp;"))
177 .replace(" ", "&nbsp;");
178 }
179
180 bool CAircraftModel::matchesFileName(const QString &fileName) const
181 {
182 return stringCompare(fileName, m_fileName, CFileUtils::osFileNameCaseSensitivity());
183 }
184
186 {
188 const ModelType t = this->getModelType();
191 {
192 if (!this->hasExistingCorrespondingFile())
193 {
194 const CStatusMessage m = CStatusMessage(this).validationWarning(u"File '%1' not readable")
195 << this->getFileName();
196 msgs.push_back(m);
197 }
198 else
199 {
200 const CStatusMessage m = CStatusMessage(this).validationInfo(u"File '%1' existing")
201 << this->getFileName();
202 msgs.push_back(m);
203 }
204 }
205 else
206 {
207 const CStatusMessage m = CStatusMessage(this).validationError(u"Invalid model type to check: '%1'")
208 << this->getModelTypeAsString();
209 msgs.push_back(m);
210 }
211 return msgs;
212 }
213
215 {
216 const bool nw = this->getModelType() == CAircraftModel::TypeQueriedFromNetwork ||
218 this->getModelType() == CAircraftModel::TypeUnknown;
219 return nw;
220 }
221
223 {
224 m_callsign = callsign;
225 m_callsign.setTypeHint(CCallsign::Aircraft);
226 }
227
229 {
230 if (this->hasValidDbKey())
231 {
232 return this->hasModelString() ? this->getModelString() % this->getDbKeyAsStringInParentheses(" ") :
233 this->getDbKeyAsString();
234 }
235 else
236 {
237 return this->getModelString();
238 }
239 }
240
242 {
243 if (!this->hasModelStringAlias())
244 {
245 return m_modelString;
246 }
247 if (!this->hasModelString())
248 {
249 return m_modelStringAlias;
250 }
251 return m_modelString % u", " % m_modelStringAlias;
252 }
253
255 {
256 if (!this->hasModelStringAlias() || m_modelString.isEmpty())
257 {
258 return this->getModelStringAndDbKey();
259 }
260 if (!this->isLoadedFromDb())
261 {
262 return this->getAllModelStringsAndAliases();
263 }
264 return this->getAllModelStringsAndAliases() % " " % this->getDbKeyAsStringInParentheses();
265 }
266
267 bool CAircraftModel::isVtol() const { return this->getAircraftIcaoCode().isVtol(); }
268
270 {
271 if (index.isMyself())
272 {
273 return QVariant::fromValue(*this);
274 }
276 {
278 }
280 {
281 return IOrderable::propertyByIndex(index);
282 }
283
284 const auto i = index.frontCasted<ColumnIndex>();
285 switch (i)
286 {
287 case IndexModelString: return { m_modelString };
288 case IndexModelStringAlias: return { m_modelStringAlias };
290 case IndexHasQueriedModelString: return QVariant::fromValue(this->hasQueriedModelString());
291 case IndexModelType: return QVariant::fromValue(m_modelType);
292 case IndexModelTypeAsString: return { this->getModelTypeAsString() };
293 case IndexModelMode: return QVariant::fromValue(m_modelMode);
294 case IndexModelModeAsString: return QVariant::fromValue(this->getModelModeAsString());
295 case IndexModelModeAsIcon: return QVariant::fromValue(this->getModelModeAsIcon());
296 case IndexDistributor: return m_distributor.propertyByIndex(index.copyFrontRemoved());
297 case IndexSimulatorInfo: return m_simulator.propertyByIndex(index.copyFrontRemoved());
298 case IndexSimulatorInfoAsString: return { m_simulator.toQString() };
299 case IndexDescription: return { m_description };
300 case IndexName: return { m_name };
301 case IndexFileName: return { m_fileName };
302 case IndexCG: return m_cg.propertyByIndex(index.copyFrontRemoved());
303 case IndexSupportedParts: return { m_supportedParts };
304 case IndexFileTimestamp: return QVariant::fromValue(this->getFileTimestamp());
305 case IndexFileTimestampFormattedYmdhms: return QVariant::fromValue(this->getFormattedFileTimestampYmdhms());
306 case IndexAircraftIcaoCode: return m_aircraftIcao.propertyByIndex(index.copyFrontRemoved());
307 case IndexLivery: return m_livery.propertyByIndex(index.copyFrontRemoved());
308 case IndexCallsign: return m_callsign.propertyByIndex(index.copyFrontRemoved());
309 case IndexMembersDbStatus: return this->getMembersDbStatus();
310 default: return CValueObject::propertyByIndex(index);
311 }
312 }
313
315 {
316 if (index.isMyself())
317 {
318 (*this) = variant.value<CAircraftModel>();
319 return;
320 }
322 {
323 IOrderable::setPropertyByIndex(index, variant);
324 return;
325 }
327 {
329 return;
330 }
331
332 const auto i = index.frontCasted<ColumnIndex>();
333 switch (i)
334 {
335 case IndexModelString: m_modelString = variant.toString(); break;
336 case IndexModelStringAlias: m_modelStringAlias = variant.toString(); break;
337 case IndexAircraftIcaoCode: m_aircraftIcao.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
338 case IndexLivery: m_livery.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
339 case IndexDistributor: m_distributor.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
340 case IndexDescription: m_description = variant.toString(); break;
341 case IndexSimulatorInfo: m_simulator.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
342 case IndexName: m_name = variant.toString(); break;
343 case IndexCG: m_cg.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
344 case IndexSupportedParts: this->setSupportedParts(variant.toString()); break;
345 case IndexModelType: m_modelType = variant.value<ModelType>(); break;
346 case IndexFileName: m_fileName = variant.toString(); break;
347 case IndexCallsign:
348 m_callsign.setPropertyByIndex(index.copyFrontRemoved(), variant);
349 m_callsign.setTypeHint(CCallsign::Aircraft);
350 break;
351 case IndexFileTimestamp:
352 if (variant.canConvert<QDateTime>())
353 {
354 this->setFileTimestamp(variant.value<QDateTime>());
355 }
356 else if (variant.canConvert<qint64>())
357 {
358 m_fileTimestamp = variant.value<qint64>();
359 }
360 break;
361 case IndexModelMode:
362 if (static_cast<QMetaType::Type>(variant.typeId()) == QMetaType::QString)
363 {
364 this->setModelModeAsString(variant.toString());
365 }
366 else
367 {
368 m_modelMode = variant.value<ModelMode>();
369 }
370 break;
371 // no setter indexes ignored
372 case IndexHasQueriedModelString: break;
373 case IndexModelTypeAsString: break;
374 case IndexModelModeAsString: break;
375 case IndexModelModeAsIcon: break;
376 case IndexFileTimestampFormattedYmdhms: break;
377 case IndexSimulatorInfoAsString: break;
378 case IndexMembersDbStatus: break;
379
380 default: CValueObject::setPropertyByIndex(index, variant); break;
381 }
382 }
383
385 {
387 {
389 }
391 {
392 return IOrderable::comparePropertyByIndex(index, compareValue);
393 }
394 if (index.isMyself())
395 {
396 return m_modelString.compare(compareValue.getModelString(), Qt::CaseInsensitive);
397 }
398 const auto i = index.frontCasted<ColumnIndex>();
399 switch (i)
400 {
401 case IndexModelString: return m_modelString.compare(compareValue.getModelString(), Qt::CaseInsensitive);
402 case IndexModelStringAlias:
403 return m_modelStringAlias.compare(compareValue.getModelStringAlias(), Qt::CaseInsensitive);
407 case IndexHasQueriedModelString:
408 return Compare::compare(this->hasQueriedModelString(), compareValue.hasQueriedModelString());
409 case IndexAircraftIcaoCode:
410 return m_aircraftIcao.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getAircraftIcaoCode());
411 case IndexLivery: return m_livery.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getLivery());
412 case IndexDistributor:
413 return m_distributor.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getDistributor());
414 case IndexDescription: return m_description.compare(compareValue.getDescription(), Qt::CaseInsensitive);
415 case IndexName: return m_name.compare(compareValue.getName(), Qt::CaseInsensitive);
416 case IndexCallsign:
417 return m_callsign.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getCallsign());
418 case IndexFileName: return m_fileName.compare(compareValue.getFileName(), Qt::CaseInsensitive);
419 case IndexCG: return m_cg.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getCG());
420 case IndexSupportedParts: return m_supportedParts.compare(compareValue.getSupportedParts());
421 case IndexModelTypeAsString:
422 case IndexModelType: return Compare::compare(m_modelType, compareValue.getModelType());
423 case IndexSimulatorInfoAsString:
424 case IndexSimulatorInfo:
425 return m_simulator.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getSimulator());
426 case IndexFileTimestamp:
427 case IndexFileTimestampFormattedYmdhms: return Compare::compare(m_fileTimestamp, compareValue.m_fileTimestamp);
428 case IndexModelMode:
429 case IndexModelModeAsString:
430 case IndexModelModeAsIcon: return Compare::compare(m_modelMode, compareValue.getModelMode());
431 case IndexMembersDbStatus: return getMembersDbStatus().compare(compareValue.getMembersDbStatus());
432 default: break;
433 }
434 Q_ASSERT_X(false, Q_FUNC_INFO, "No comparison");
435 return 0;
436 }
437
439 {
440 if (m_aircraftIcao == aircraftIcaoCode)
441 {
442 return false;
443 }
444 m_aircraftIcao = aircraftIcaoCode;
445 return true;
446 }
447
449 {
450 m_aircraftIcao.setDesignator(designator);
451 }
452
454 const CAirlineIcaoCode &airlineIcaoCode)
455 {
456 m_aircraftIcao = aircraftIcaoCode;
457 m_livery.setAirlineIcaoCode(airlineIcaoCode);
458 }
459
461 {
462 return this->hasKnownAircraftDesignator() && m_livery.hasValidAirlineDesignator();
463 }
464
465 bool CAircraftModel::hasAircraftDesignator() const { return m_aircraftIcao.hasDesignator(); }
466
467 bool CAircraftModel::hasKnownAircraftDesignator() const { return m_aircraftIcao.hasKnownDesignator(); }
468
469 bool CAircraftModel::hasCategory() const { return m_aircraftIcao.hasCategory(); }
470
471 bool CAircraftModel::hasAirlineDesignator() const { return m_livery.hasValidAirlineDesignator(); }
472
477
479 {
480 return this->getAircraftIcaoCode().isMilitary() || this->getLivery().isMilitary();
481 }
482
483 bool CAircraftModel::isCivilian() const { return !this->isMilitary(); }
484
486 {
487 if (order < 0)
488 {
489 return false;
490 }
491 if (!m_distributor.isLoadedFromDb())
492 {
493 return false;
494 }
495 m_distributor.setOrder(order);
496 return true;
497 }
498
500 {
501 if (distributors.isEmpty())
502 {
503 return false;
504 }
505 bool found = false;
506 const int noDistributorOrder = distributors.size();
507 if (this->hasDbDistributor())
508 {
509 const CDistributor d = distributors.findByKeyOrAlias(m_distributor.getDbKey());
510 if (d.hasValidDbKey())
511 {
512 m_distributor.setOrder(d.getOrder());
513 found = true;
514 }
515 else
516 {
517 m_distributor.setOrder(noDistributorOrder);
518 }
519 }
520 else
521 {
522 m_distributor.setOrder(noDistributorOrder);
523 }
524 return found;
525 }
526
527 bool CAircraftModel::hasDbDistributor() const { return m_distributor.isLoadedFromDb(); }
528
530 {
531 return m_distributor.hasValidDbKey(); // key is valid, but not guaranteed from DB
532 }
533
535 {
536 if (!distributor.isLoadedFromDb())
537 {
538 return false;
539 }
540 if (!this->hasDbDistributor())
541 {
542 return false;
543 }
544 return m_distributor.getDbKey() == distributor.getDbKey();
545 }
546
548 {
549 if (distributors.isEmpty())
550 {
551 return false;
552 }
553 if (!this->hasDbDistributor())
554 {
555 return false;
556 }
557 return distributors.matchesAnyKeyOrAlias(m_distributor.getDbKey());
558 }
559
564
565 bool CAircraftModel::matchesMode(ModelModeFilter mode) const
566 {
567 if (mode == All)
568 {
569 return true;
570 }
571 return (mode & m_modelMode) > 0;
572 }
573
575 {
576 switch (this->getModelMode())
577 {
578 case Include: return CIcon::iconByIndex(CIcons::ModelInclude);
579 case Exclude: return CIcon::iconByIndex(CIcons::ModelExclude);
580 case Undefined: return CIcon::iconByIndex(CIcons::StandardIconUnknown16);
581 default: Q_ASSERT_X(false, Q_FUNC_INFO, "wrong mode"); break;
582 }
583 return CIcon::iconByIndex(CIcons::ModelInclude);
584 }
585
590
592 {
593 return (static_cast<int>(simulator.getSimulator()) & static_cast<int>(this->getSimulator().getSimulator())) > 0;
594 }
595
596 bool CAircraftModel::matchesSimulatorFlag(CSimulatorInfo::Simulator simulator) const
597 {
598 return (static_cast<int>(simulator) & static_cast<int>(this->getSimulator().getSimulator())) > 0;
599 }
600
606
608 {
609 return this->hasValidFileTimestamp() ? this->getFileTimestamp().toString("yyyy-MM-dd HH:mm:ss") : "";
610 }
611
612 bool CAircraftModel::hasValidFileTimestamp() const { return m_fileTimestamp >= 0; }
613
615 {
616 m_fileTimestamp = timestampUtc.isValid() ? timestampUtc.toMSecsSinceEpoch() : -1;
617 }
618
619 void CAircraftModel::setFileTimestamp(qint64 timestamp) { m_fileTimestamp = (timestamp < 0) ? -1 : timestamp; }
620
622 {
623 this->setFileName(fileInfo.absoluteFilePath());
624 const QDateTime modified = fileInfo.lastModified();
625 if (modified.isValid())
626 {
627 this->setFileTimestamp(modified);
628 this->setUtcTimestamp(modified);
629 }
630 else
631 {
632 const QDateTime created = fileInfo.lastModified();
633 this->setFileTimestamp(created);
634 this->setUtcTimestamp(created);
635 }
636 }
637
639 {
640 static const QString p("swift_");
641 return p;
642 }
643
645 {
646 return (liveryString.length() > liveryStringPrefix().length() &&
648 }
649
650 QString CAircraftModel::getSwiftLiveryString(bool aircraftIcao, bool livery, bool model) const
651 {
652 if (!aircraftIcao && !livery && !model)
653 {
654 return {};
655 }
656 const QString l =
657 (livery && this->getLivery().hasValidDbKey() ? u'l' % this->getLivery().getDbKeyAsString() : QString()) %
658 (aircraftIcao && this->getAircraftIcaoCode().hasValidDbKey() ?
659 QStringLiteral("a") % this->getAircraftIcaoCode().getDbKeyAsString() :
660 QString()) %
661 (model && this->hasValidDbKey() ? u'm' % this->getDbKeyAsString() : QString());
662
663 return l.isEmpty() ? QString() : liveryStringPrefix() % l;
664 }
665
667 {
668 return (sim.isFG()) ? this->getSwiftLiveryString(true, false, false) : this->getSwiftLiveryString();
669 }
670
672 {
673 // "swift_m22l33a11"
674 if (!CAircraftModel::isSwiftLiveryString(liveryString))
675 {
676 return {};
677 }
678
679 DBTripleIds ids;
680 const QString ls = liveryString.mid(liveryStringPrefix().length()).toLower();
681 for (int c = 0; c < ls.length(); c++)
682 {
683 const QChar m = ls[c];
684 if ((m == 'm' || m == 'a' || m == 'l') && (c + 1) < ls.length())
685 {
686 const int cs = c + 1;
687 int cc = cs;
688 while (cc < ls.length() && ls[cc].isDigit())
689 {
690 cc++;
691 } // find end of id
692 if (cc > cs)
693 {
694 const QString idString = ls.mid(cs, cc - cs);
695 const int id = idString.toInt();
696 c = cc - 1; // +1 again in for
697
698 if (m == 'm')
699 {
700 ids.model = id;
701 }
702 else if (m == 'a')
703 {
704 ids.aircraft = id;
705 }
706 else if (m == 'l')
707 {
708 ids.livery = id;
709 }
710 }
711 }
712 }
713 return ids;
714 }
715
716 void CAircraftModel::updateMissingParts(const CAircraftModel &otherModel, bool dbModelPriority)
717 {
718 if (dbModelPriority && !this->hasValidDbKey() && otherModel.hasValidDbKey())
719 {
720 // we have no DB data, but the other one has
721 // so we change roles. We take the DB object as base, and update our parts
722 CAircraftModel copy(otherModel);
723 copy.updateMissingParts(*this);
724 *this = copy;
725 return;
726 }
727
728 // local file names and file timestamp
729 this->updateLocalFileNames(otherModel);
730 if (m_fileTimestamp < 0 || otherModel.m_fileTimestamp > m_fileTimestamp)
731 {
732 this->setFileTimestamp(otherModel.getFileTimestamp());
733 }
734
735 // both are DB data, treat as being the same except for filename maybe
736 if (this->hasValidDbKey() && otherModel.hasValidDbKey())
737 {
738 return;
739 }
740
741 // update attributes where applicable
742 if (m_callsign.isEmpty())
743 {
744 this->setCallsign(otherModel.getCallsign());
745 }
746 if (m_modelString.isEmpty())
747 {
748 this->setModelString(otherModel.getModelString());
749 }
750 if (m_name.isEmpty())
751 {
752 this->setName(otherModel.getName());
753 }
754 if (m_modelType == TypeUnknown)
755 {
756 m_modelType = otherModel.getModelType();
757 }
758 if (m_modelMode == Undefined)
759 {
760 m_modelType = otherModel.getModelType();
761 }
762 if (m_description.isEmpty() || m_description.startsWith(CAircraftModel::autoGenerated(), Qt::CaseInsensitive))
763 {
764 this->setDescription(otherModel.getDescription());
765 }
766 if (this->getSimulator().isUnspecified())
767 {
768 // simulator can only be overridden as simulators can also be removed
769 this->setSimulator(otherModel.getSimulator());
770 }
771
773 m_livery.updateMissingParts(otherModel.getLivery());
774 m_aircraftIcao.updateMissingParts(otherModel.getAircraftIcaoCode());
775 m_distributor.updateMissingParts(otherModel.getDistributor());
776 }
777
779 {
780 if (otherModel.hasExistingCorrespondingFile())
781 {
782 this->setFileName(otherModel.getFileName());
783 }
784 }
785
787 {
788 return m_modelType == TypeQueriedFromNetwork && this->hasModelString();
789 }
790
792 {
793 return m_modelType == TypeManuallySet && this->hasModelString();
794 }
795
796 bool CAircraftModel::hasDescription(bool ignoreAutoGenerated) const
797 {
798 if (m_description.isEmpty())
799 {
800 return false;
801 }
802 if (!ignoreAutoGenerated)
803 {
804 return true;
805 }
806 return (!this->getDescription().startsWith(autoGenerated(), Qt::CaseInsensitive));
807 }
808
809 bool CAircraftModel::hasValidSimulator() const { return m_simulator.isAnySimulator(); }
810
812 {
813 return (this->isLoadedFromDb() ? QStringLiteral("M") : QStringLiteral("m")) %
814 (this->getDistributor().isLoadedFromDb() ? QStringLiteral("D") : QStringLiteral("d")) %
815 (this->getAircraftIcaoCode().isLoadedFromDb() ? QStringLiteral("A") : QStringLiteral("a")) %
817 QStringLiteral("C-") :
818 (this->getLivery().isLoadedFromDb() ? QStringLiteral("L") : QStringLiteral("l")) %
819 (this->getLivery().getAirlineIcaoCode().isLoadedFromDb() ? QStringLiteral("A") :
820 QStringLiteral("a")));
821 }
822
824
826 {
828 {
829 // this is already a local model, ignore
830 return;
831 }
832
834 {
835 // other local, priority
836 this->setFileName(model.getFileName());
837 return;
838 }
839
840 // both not local, override empty values
841 if (m_fileName.isEmpty())
842 {
843 this->setFileName(model.getFileName());
844 }
845 }
846
847 bool CAircraftModel::adjustLocalFileNames(const QString &newModelDir, const QString &stripModelDirIndicator)
848 {
849 if (!this->hasFileName())
850 {
851 return false;
852 }
854 int i = -1;
855 if (stripModelDirIndicator.isEmpty())
856 {
857 QString strip = md.mid(md.lastIndexOf('/'));
858 i = m_fileName.lastIndexOf(strip);
859 }
860 else
861 {
862 i = m_fileName.lastIndexOf(stripModelDirIndicator);
863 }
864 if (i < 0)
865 {
866 return false;
867 }
868 m_fileName = CFileUtils::appendFilePaths(newModelDir, m_fileName.mid(i));
869 return true;
870 }
871
873 {
874 if (!this->hasFileName())
875 {
876 return false;
877 }
879 if (!fi.exists())
880 {
881 return false;
882 }
883 const bool r = fi.isReadable();
884 return r;
885 }
886
888 {
889 if (!this->hasFileName())
890 {
891 return {};
892 }
894 return fi.absoluteDir();
895 }
896
898 {
899 if (!this->hasFileName())
900 {
901 return {};
902 }
903 return this->getFileDirectory().absolutePath();
904 }
905
907 {
908 const QString p(this->getFileDirectoryPath());
909 if (path.isEmpty() || p.isEmpty())
910 {
911 return false;
912 }
913 if (path.startsWith('/'))
914 {
915 if (path.endsWith('/'))
916 {
917 return p.contains(path.mid(1, path.length() - 2), cs);
918 }
919 return p.contains(path.mid(1));
920 }
921 if (path.endsWith('/'))
922 {
923 return p.contains(path.left(path.length() - 1), cs);
924 }
925 return (p.contains(path, cs));
926 }
927
928 bool CAircraftModel::matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const
929 {
930 return stringCompare(modelString, m_modelString, sensitivity);
931 }
932
934 {
935 if (this->matchesModelString(modelString, sensitivity))
936 {
937 return true;
938 }
939 return stringCompare(modelString, m_modelStringAlias, sensitivity);
940 }
941
942 int CAircraftModel::calculateScore(const CAircraftModel &compareModel, bool preferColorLiveries,
943 CStatusMessageList *log) const
944 {
945 const int icaoScore = this->getAircraftIcaoCode().calculateScore(compareModel.getAircraftIcaoCode(), log);
946 const int liveryScore = this->getLivery().calculateScore(compareModel.getLivery(), preferColorLiveries, log);
948 log, this->getCallsign(),
949 QStringLiteral("ICAO score: %1 | livery score: %2").arg(icaoScore).arg(liveryScore));
950 return qRound(0.5 * (icaoScore + liveryScore));
951 }
952
953 CStatusMessageList CAircraftModel::validate(bool withNestedObjects) const
954 {
955 static const CLogCategoryList cats(CLogCategoryList(this).withValidation());
957 if (!hasModelString())
958 {
959 msgs.push_back(
960 CStatusMessage(cats, CStatusMessage::SeverityError, u"Model: missing model string (aka key)"));
961 }
962 if (!hasValidSimulator())
963 {
964 msgs.push_back(CStatusMessage(cats, CStatusMessage::SeverityError, u"Model: no simulator set"));
965 }
966 // as of T34 made description optional, lines can be removed after 6/2017
967 // if (!hasDescription()) {msgs.push_back(CStatusMessage(cats, CStatusMessage::SeverityWarning, u"Model: no
968 // description")); }
969 if (withNestedObjects)
970 {
971 msgs.push_back(m_aircraftIcao.validate());
972 msgs.push_back(m_livery.validate());
973 msgs.push_back(m_distributor.validate());
974 }
975 return msgs;
976 }
977
979 CStatusMessage equalMessage(bool same, const CAircraftModel &model, const QString &description,
980 const QString &oldValue, const QString &newValue)
981 {
982 if (same)
983 {
985 u"Model '%1' same %2 '%3'");
986 return CStatusMessage(msgSame) << model.getModelStringAndDbKey() << description << newValue;
987 }
988 else
989 {
991 u"Model '%1' changed %2 '%3'->'%4'");
992 return CStatusMessage(msgDiff) << model.getModelStringAndDbKey() << description << oldValue << newValue;
993 }
994 }
995
997 {
998 if (!dbModel.isLoadedFromDb())
999 {
1001 u"No DB model yet");
1002 if (details)
1003 {
1004 details->push_back(msgNoDbModel);
1005 }
1006 return false;
1007 }
1008
1009 CStatusMessageList validationMsgs;
1010 bool changed = false;
1011 bool equal = dbModel.getLivery().isLoadedFromDb() && dbModel.getLivery().isDbEqual(this->getLivery());
1012 if (details)
1013 {
1014 validationMsgs.push_back(equalMessage(equal, *this, QStringLiteral("livery"),
1016 this->getLivery().getCombinedCodePlusInfoAndId()));
1017 }
1018 changed |= !equal;
1019
1020 equal = dbModel.getAircraftIcaoCode().isLoadedFromDb() &&
1022 if (details)
1023 {
1024 validationMsgs.push_back(equalMessage(equal, *this, QStringLiteral("aircraft ICAO"),
1026 this->getAircraftIcaoCode().getDesignatorDbKey()));
1027 }
1028 changed |= !equal;
1029
1030 equal = dbModel.getDistributor().isLoadedFromDb() && dbModel.getDistributor().isDbEqual(this->getDistributor());
1031 if (details)
1032 {
1033 validationMsgs.push_back(equalMessage(equal, *this, QStringLiteral("distributor"),
1034 dbModel.getDistributor().getDescription(),
1035 this->getDistributor().getDescription()));
1036 }
1037 changed |= !equal;
1038
1039 equal = dbModel.getSimulator() == this->getSimulator();
1040 if (details)
1041 {
1042 validationMsgs.push_back(equalMessage(equal, *this, QStringLiteral("simulator"),
1043 dbModel.getSimulator().toQString(),
1044 this->getSimulator().toQString()));
1045 }
1046 changed |= !equal;
1047
1048 equal = dbModel.getDescription() == this->getDescription();
1049 if (details)
1050 {
1051 validationMsgs.push_back(equalMessage(equal, *this, QStringLiteral("description"), dbModel.getDescription(),
1052 this->getDescription()));
1053 }
1054 changed |= !equal;
1055
1056 equal = dbModel.getName() == this->getName();
1057 if (details)
1058 {
1059 validationMsgs.push_back(
1060 equalMessage(equal, *this, QStringLiteral("name"), dbModel.getName(), this->getName()));
1061 }
1062 changed |= !equal;
1063
1064 equal = dbModel.getModelMode() == this->getModelMode();
1065 if (details)
1066 {
1067 validationMsgs.push_back(equalMessage(equal, *this, QStringLiteral("mode"), dbModel.getModelModeAsString(),
1068 this->getModelModeAsString()));
1069 }
1070 changed |= !equal;
1071
1072 equal = dbModel.getCG() == this->getCG();
1073 if (details)
1074 {
1075 validationMsgs.push_back(equalMessage(equal, *this, QStringLiteral("CG"), dbModel.getCG().toQString(true),
1076 this->getCG().toQString(true)));
1077 }
1078 changed |= !equal;
1079
1080 equal = dbModel.getSupportedParts() == this->getSupportedParts();
1081 if (details)
1082 {
1083 validationMsgs.push_back(equalMessage(equal, *this, QStringLiteral("Supported parts"),
1084 dbModel.getSupportedParts(), this->getSupportedParts()));
1085 }
1086 changed |= !equal;
1087
1088 // clean messages
1089 if (changed && details)
1090 {
1091 // we have a changed entity, remove the warnings as they are just noise
1093 }
1094
1095 if (details)
1096 {
1097 details->push_back(validationMsgs);
1098 }
1099 return !changed;
1100 }
1101
1103 {
1104 static const QString queried("queried");
1105 static const QString matching("matching");
1106 static const QString db("database");
1107 static const QString def("map.default");
1108 static const QString ownSim("own simulator");
1109 static const QString set("manually set");
1110 static const QString fsinn("FSInn");
1111 static const QString probe("probe");
1112 static const QString reverse("reverse lookup");
1113 static const QString unknown("unknown");
1114
1115 switch (type)
1116 {
1117 case TypeQueriedFromNetwork: return queried;
1118 case TypeModelMatching: return matching;
1119 case TypeDatabaseEntry: return db;
1120 case TypeManuallySet: return set;
1121 case TypeFSInnData: return fsinn;
1122 case TypeTerrainProbe: return probe;
1123 case TypeReverseLookup: return reverse;
1124 case TypeOwnSimulatorModel: return ownSim;
1125 case TypeModelMatchingDefaultModel: return def;
1126 case TypeUnknown:
1127 default: return unknown;
1128 }
1129 }
1130
1132 {
1134 if (n.count('/') < 2)
1135 {
1136 return n;
1137 }
1138 return n.section('/', -2, -1);
1139 }
1140
1142 {
1143 if (mode.isEmpty() || mode.startsWith('I', Qt::CaseInsensitive))
1144 {
1145 return Include;
1146 }
1147 if (mode.startsWith('E', Qt::CaseInsensitive))
1148 {
1149 return Exclude;
1150 }
1151 SWIFT_VERIFY_X(false, Q_FUNC_INFO, "wrong mode");
1152 return Include; // default
1153 }
1154
1156 {
1157 static const QString i("Include");
1158 static const QString e("Exclude");
1159
1160 switch (mode)
1161 {
1162 case Include: return i;
1163 case Exclude: return e;
1164 default: Q_ASSERT_X(false, Q_FUNC_INFO, "wrong mode");
1165 }
1166 return i; // default
1167 }
1168
1169 CAircraftModel CAircraftModel::fromDatabaseJsonBaseImpl(const QJsonObject &json, const QString &prefix,
1170 const CAircraftIcaoCode &aircraftIcao,
1171 const CLivery &livery, const CDistributor &distributor)
1172 {
1173 const QString modelString(json.value(prefix % u"modelstring").toString());
1174 const QString modelStringAlias(json.value(prefix % u"modelstringalias").toString());
1175 const QString modelDescription(json.value(prefix % u"description").toString());
1176 const QString modelName(json.value(prefix % u"name").toString());
1177 const QString modelMode(json.value(prefix % u"mode").toString());
1178 const QString parts(json.value(prefix % u"parts").toString());
1179
1180 // check for undefined to rule out 0ft values
1181 const QJsonValue cgjv = json.value(prefix % u"cgft");
1182 const CLength cg =
1183 (cgjv.isNull() || cgjv.isUndefined()) ? CLength::null() : CLength(cgjv.toDouble(), CLengthUnit::ft());
1184
1185 const CSimulatorInfo simInfo = CSimulatorInfo::fromDatabaseJson(json, prefix);
1186 CAircraftModel model(modelString, CAircraftModel::TypeDatabaseEntry, simInfo, modelName, modelDescription);
1187 model.setModelStringAlias(modelStringAlias);
1188 model.setModelModeAsString(modelMode);
1189 model.setSupportedParts(parts);
1190 model.setCG(cg);
1191 model.setKeyVersionTimestampFromDatabaseJson(json, prefix);
1192 model.setDistributor(distributor);
1193 model.setAircraftIcaoCode(aircraftIcao);
1194 model.setLivery(livery);
1195 return model;
1196 }
1197
1199 {
1200 static const QString prefixAircraftIcao("ac_");
1201 static const QString prefixLivery("liv_");
1202 static const QString prefixDistributor("dist_");
1203 const QString idDistributor = json.value(prefixDistributor % u"id").toString();
1204 const int idAircraftIcao = json.value(prefixAircraftIcao % u"id").toInt(-1);
1205 const int idLivery = json.value(prefixLivery % u"id").toInt(-1);
1206
1207 CDistributor distributor(CDistributor::fromDatabaseJson(json, prefixDistributor));
1208 CAircraftIcaoCode aircraftIcao(CAircraftIcaoCode::fromDatabaseJson(json, prefixAircraftIcao));
1209 CLivery livery(CLivery::fromDatabaseJson(json, prefixLivery));
1210
1211 if (!aircraftIcao.isLoadedFromDb() && idAircraftIcao >= 0)
1212 {
1213 aircraftIcao.setDbKey(idAircraftIcao);
1214 }
1215 if (!livery.isLoadedFromDb() && idLivery >= 0)
1216 {
1217 livery.setDbKey(idLivery);
1218 }
1219 if (!distributor.isLoadedFromDb() && !idDistributor.isEmpty())
1220 {
1221 distributor.setDbKey(idDistributor);
1222 }
1223
1224 // full model
1225 return CAircraftModel::fromDatabaseJsonBaseImpl(json, prefix, aircraftIcao, livery, distributor);
1226 }
1227
1229 const AircraftCategoryIdMap &categories,
1230 LiveryIdMap &liveries, DistributorIdMap &distributors,
1231 const QString &prefix)
1232 {
1233 static const QString prefixAircraftIcao("ac_");
1234 static const QString prefixLivery("liv_");
1235 static const QString prefixDistributor("dist_");
1236 const QString idDistributor = json.value(prefixDistributor % u"id").toString();
1237 const int idAircraftIcao = json.value(prefixAircraftIcao % u"id").toInt(-1);
1238 const int idLivery = json.value(prefixLivery % u"id").toInt(-1);
1239
1240 const bool cachedAircraftIcao = (idAircraftIcao >= 0) && aircraftIcaos.contains(idAircraftIcao);
1241 const bool cachedLivery = (idLivery >= 0) && liveries.contains(idLivery);
1242 const bool cachedDistributor = !idDistributor.isEmpty() && distributors.contains(idDistributor);
1243
1244 CAircraftIcaoCode aircraftIcao(cachedAircraftIcao ?
1245 aircraftIcaos[idAircraftIcao] :
1246 CAircraftIcaoCode::fromDatabaseJson(json, prefixAircraftIcao));
1247
1248 CLivery livery(cachedLivery ? liveries[idLivery] : CLivery::fromDatabaseJson(json, prefixLivery));
1249
1250 CDistributor distributor(cachedDistributor ? distributors[idDistributor] :
1251 CDistributor::fromDatabaseJson(json, prefixDistributor));
1252
1253 if (!aircraftIcao.isLoadedFromDb() && idAircraftIcao >= 0)
1254 {
1255 aircraftIcao.setDbKey(idAircraftIcao);
1256 }
1257 if (!livery.isLoadedFromDb() && idLivery >= 0)
1258 {
1259 livery.setDbKey(idLivery);
1260 }
1261 if (!distributor.isLoadedFromDb() && !idDistributor.isEmpty())
1262 {
1263 distributor.setDbKey(idDistributor);
1264 }
1265
1266 // update category
1267 if (!cachedAircraftIcao)
1268 {
1269 const int catId = aircraftIcao.getCategory().getDbKey();
1270 if (catId >= 0 && categories.contains(catId))
1271 {
1272 aircraftIcao.setCategory(categories[catId]);
1273 }
1274 }
1275
1276 // store in temp.cache
1277 if (!cachedAircraftIcao && aircraftIcao.isLoadedFromDb())
1278 {
1279 aircraftIcaos[aircraftIcao.getDbKey()] = aircraftIcao;
1280 }
1281 if (!cachedLivery && livery.isLoadedFromDb())
1282 {
1283 liveries[livery.getDbKey()] = livery;
1284 }
1285 if (!cachedDistributor && distributor.isLoadedFromDb())
1286 {
1287 distributors[distributor.getDbKey()] = distributor;
1288 }
1289
1290 // full model
1291 return CAircraftModel::fromDatabaseJsonBaseImpl(json, prefix, aircraftIcao, livery, distributor);
1292 }
1293
1295 {
1296 static const QString ag("swift auto generated");
1297 return ag;
1298 }
1299
1301 {
1302 if (p.isEmpty())
1303 {
1304 return {};
1305 }
1306 QString pc = removeChars(p.toUpper(), [](QChar c) { return !supportedParts().contains(c); });
1307 std::ranges::sort(pc);
1308 return pc;
1309 }
1310
1312 {
1313 static const QString p("EFGLS");
1314 return p;
1315 }
1316} // namespace swift::misc::simulation
QMap< int, CAircraftCategory > AircraftCategoryIdMap
Category/id map.
QMap< int, CAircraftIcaoCode > AircraftIcaoIdMap
Id/CAircraftIcaoCode map.
static const QString & getVersionString()
Version as QVersionNumber.
static Qt::CaseSensitivity osFileNameCaseSensitivity()
Case sensitivity for current OS.
static QString appendFilePaths(const QString &path1, const QString &path2)
Append file paths.
static QString fixWindowsUncPath(const QString &filePath)
UNC file paths on Qt start with "/", but UNC file paths only work when they start with "//".
static QString normalizeFilePathToQtStandard(const QString &filePath)
Normalize file path to Qt standard, e.g by turning \ to /.
Value object for icons. An icon is stored in the global icon repository and identified by its index....
Definition icon.h:39
static const CIcon & iconByIndex(CIcons::IconIndex index)
Icon for given index.
Definition icon.cpp:63
static const QString & validation()
Validation.
A sequence of log categories.
Derived & validationError(const char16_t(&format)[N])
Set the severity to error, providing a format string, and adding the validation category.
Derived & validationWarning(const char16_t(&format)[N])
Set the severity to warning, providing a format string, and adding the validation category.
Derived & validationInfo(const char16_t(&format)[N])
Set the severity to info, providing a format string, and adding the validation category.
Non-owning reference to a CPropertyIndex with a subset of its features.
Q_REQUIRED_RESULT CPropertyIndexRef copyFrontRemoved() const
Copy with first element removed.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
size_type size() const
Returns number of elements in the sequence.
Definition sequence.h:273
void push_back(const T &value)
Appends an element at the end of the sequence.
Definition sequence.h:308
bool isEmpty() const
Synonym for empty.
Definition sequence.h:285
Streamable status message, e.g.
static constexpr auto SeverityInfo
Status severities.
static constexpr auto SeverityError
Status severities.
static constexpr auto SeverityWarning
Status severities.
Status messages, e.g. from Core -> GUI.
void removeSeverity(CStatusMessage::StatusSeverity severity)
Remove given severity.
static bool canHandleIndex(CPropertyIndexRef index)
Can given index be handled.
Definition orderable.cpp:34
int comparePropertyByIndex(CPropertyIndexRef index, const IOrderable &compareValue) const
Compare for index.
Definition orderable.cpp:77
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
Definition orderable.cpp:61
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Definition orderable.cpp:44
int getOrder() const
Order.
Definition orderable.h:29
void updateMissingParts(const ITimestampBased &other)
Update missing parts.
QString getFormattedUtcTimestampYmdhms() const
As yyyy MM dd HH mm ss.
void setUtcTimestamp(const QDateTime &timestamp)
Set timestamp.
Value object for ICAO classification.
bool hasDesignator() const
Aircraft designator?
bool isVtol() const
Is VTOL aircraft (helicopter, tilt wing).
QString getDesignatorDbKey() const
Designator and DB key.
static CAircraftIcaoCode fromDatabaseJson(const QJsonObject &json, const QString &prefix=QString())
From our database JSON format.
int calculateScore(const CAircraftIcaoCode &otherCode, CStatusMessageList *log=nullptr) const
Considers rank, manufacturer and family 0..100.
const CAircraftCategory & getCategory() const
Get category.
void setDesignator(const QString &icaoDesignator)
Set ICAO designator, e.g. "B737".
void setCategory(const CAircraftCategory &category)
Set category.
Value object for ICAO classification.
Value object encapsulating information of a callsign.
Definition callsign.h:30
static void addLogDetailsToList(CStatusMessageList *log, const CCallsign &callsign, const QString &message, const QStringList &extraCategories={}, CStatusMessage::StatusSeverity s=CStatusMessage::SeverityInfo)
Specialized log for matching / reverse lookup.
Definition callsign.cpp:155
void setTypeHint(TypeHint hint)
Type hint.
Definition callsign.h:114
Value object encapsulating information about an airpot.
Definition livery.h:29
bool isMilitary() const
Military livery.
Definition livery.h:98
static CLivery fromDatabaseJson(const QJsonObject &json, const QString &prefix=QString("liv_"))
Object from JSON.
Definition livery.cpp:220
QString getCombinedCodePlusInfoAndId() const
Combined code, info, plus id.
Definition livery.cpp:69
bool isColorLivery() const
Color livery?
Definition livery.cpp:190
int calculateScore(const CLivery &otherLivery, bool preferColorLiveries=false, CStatusMessageList *log=nullptr) const
Score by comparison to another livery 0..100.
Definition livery.cpp:499
static const QString & boolToDbYN(bool v)
Bool to DB yes/no.
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
QJsonValue getDbKeyAsJsonValue() const
Key as JSON value, or null.
Definition datastore.cpp:91
QString getDbKeyAsString() const
DB key as string.
Definition datastore.cpp:33
bool isLoadedFromDb() const
Loaded from DB.
Definition datastore.cpp:58
static bool canHandleIndex(swift::misc::CPropertyIndexRef index)
Can given index be handled?
void setDbKey(int key)
Set the DB key.
Definition datastore.h:96
bool isDbEqual(const IDatastoreObjectWithIntegerKey &other) const
Same DB key and hence equal.
Definition datastore.h:105
QString getDbKeyAsStringInParentheses(const QString &prefix={}) const
Db key in parentheses, e.g. "(3)".
Definition datastore.cpp:42
int comparePropertyByIndex(CPropertyIndexRef index, const IDatastoreObjectWithIntegerKey &compareValue) const
Compare for index.
void setKeyVersionTimestampFromDatabaseJson(const QJsonObject &json, const QString &prefix=QString())
Set key and timestamp values.
bool hasValidDbKey() const
Has valid DB key.
Definition datastore.h:102
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
bool isLoadedFromDb() const
Loaded from DB.
Definition datastore.h:204
bool hasValidDbKey() const
Has valid DB key.
Definition datastore.h:195
const QString & getDbKey() const
Get DB key.
Definition datastore.h:180
bool isDbEqual(const IDatastoreObjectWithStringKey &other) const
Same DB key and hence equal.
Definition datastore.h:198
void setDbKey(const QString &key)
Set the DB key.
Definition datastore.h:192
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
Definition mixinindex.h:167
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Definition mixinindex.h:180
static void registerMetadata()
Register metadata.
QString toQString(bool i18n=false) const
Cast as QString.
Definition mixinstring.h:74
Physical unit length (length).
Definition length.h:18
Specialized class for distance units (meter, foot, nautical miles).
Definition units.h:95
static CLengthUnit ft()
Foot ft.
Definition units.h:157
QString valueRoundedWithUnit(const MU &unit, int digits=-1, bool withGroupSeparator=false, bool i18n=false) const
Value to QString with the given unit, e.g. "5.00m".
Aircraft model (used by another pilot, my models on disk).
void setFileTimestamp(const QDateTime &timestampUtc)
Set file timestamp.
QString getAllModelStringsAndAliases() const
Get model string and aliases.
CAircraftModel()=default
Default constructor.
QString getSwiftLiveryString(bool aircraftIcao=true, bool livery=true, bool model=true) const
swift livery string (to be sent via network)
void convertFromMemoizedJson(const QJsonObject &json, const MemoHelper::CUnmemoizer &)
From JSON with memoized members (used by CAircraftModelList).
bool hasValidFileTimestamp() const
Valid file timestamp?
void setName(const QString &name)
Name.
bool setDistributorOrder(int order)
Set the distributor order.
bool matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const
Matches model string?
bool hasValidSimulator() const
Valid simulator.
ModelMode getModelMode() const
Model mode.
bool hasValidAircraftAndAirlineDesignator() const
Valid airline and aircraft designator?
void updateByExistingDirectories(const CAircraftModel &otherModel)
Update the directories from other model.
bool hasKnownAircraftDesignator() const
Has known aircraft designator?
bool hasCategory() const
Assigned a category?
bool hasAirlineDesignator() const
Airline designator?
static CAircraftModel fromDatabaseJsonCaching(const QJsonObject &json, aviation::AircraftIcaoIdMap &aircraftIcaos, const aviation::AircraftCategoryIdMap &categories, aviation::LiveryIdMap &liveries, DistributorIdMap &distributors, const QString &prefix=QString("mod_"))
From swift DB JSON, caching during this process (faster).
bool hasExistingCorrespondingFile() const
Does the corresponding file exist?
bool hasManuallySetString() const
Model string which was manually set.
static const QString & supportedParts()
Supported parts.
const QString & getModelStringAlias() const
Model key, either queried or loaded from simulator model.
bool hasModelStringAlias() const
Non empty model string alias?
static DBTripleIds parseNetworkLiveryString(const QString &liveryString)
Split swift network string.
static const QString & liveryStringPrefix()
Livery string prefix.
void setModelStringAlias(const QString &alias)
Model string alias.
QString convertToQString(bool i18n=false) const
Cast as QString.
QString getMembersDbStatus() const
Info, which members (Livery, Aircraft ICAO, ...) are already based on DB data.
bool isInPath(const QString &path, Qt::CaseSensitivity cs) const
Is the file in the give path.
QString getFileDirectoryPath() const
Directory path if any.
ModelMode
Mode, decides if a model is supposed to be used in the model set for model matching or not....
int calculateScore(const CAircraftModel &compareModel, bool preferColorLiveries, CStatusMessageList *log=nullptr) const
Calculate score.
void setModelString(const QString &modelString)
Model string.
void setModelModeAsString(const QString &mode)
Set model mode as string.
const QString & getDescription() const
Descriptive text.
void setFileDetailsAndTimestamp(const QFileInfo &fileInfo)
Set file timestamp, timestamp and file name.
bool hasAircraftAndAirlineDesignator() const
Designators.
void updateLocalFileNames(const CAircraftModel &model)
Update file names from local model.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
const aviation::CCallsign & getCallsign() const
Corresponding callsign if applicable.
CSimulatorInfo getSimulator() const
Simulator info.
QString getAllModelStringsAliasesAndDbKey() const
Get model string and aliases.
void normalizeFileNameForDb()
File path for DB (absolute paths make no sense in DB).
@ TypeModelMatchingDefaultModel
a default model assigned by model matching
@ TypeTerrainProbe
peudo aircraft used for terrain probing (FSX)
@ TypeFSInnData
model based on FSD ICAO data
@ TypeQueriedFromNetwork
model was queried by network protocol (ICAO data)
@ TypeOwnSimulatorModel
represents own simulator model (AI model, model on disk)
@ TypeDatabaseEntry
used along with mapping definition
@ TypeModelMatching
model is result of model matching
static const QString & modelTypeToString(ModelType type)
Model type.
void setCallsign(const aviation::CCallsign &callsign)
Corresponding callsign if applicable.
bool isEqualForPublishing(const CAircraftModel &dbModel, CStatusMessageList *details=nullptr) const
Considered equal for publishing, compares if livery etc. are the same DB values.
bool canInitializeFromFsd() const
Can be initialized from FSD.
void setFileName(const QString &fileName)
File name.
bool hasDistributor() const
Distributor, but not necessarily loaded from DB.
const CDistributor & getDistributor() const
Get distributor.
static QString cleanUpPartsString(const QString &p)
Clean up parts string.
CStatusMessageList verifyModelData() const
Verify the model data.
QString getFormattedFileTimestampYmdhms() const
File timestamp.
const QString & getModelModeAsString() const
Model mode as string.
bool isCivilian() const
Civilian model?
const QString & getFileName() const
File name (corresponding data for simulator, only available if representing simulator model.
void setSupportedParts(const QString &supportedParts)
Supported parts.
bool adjustLocalFileNames(const QString &newModelDir, const QString &stripModelDirIndicator={})
Adjust file names to a new directory.
const QString & getModelTypeAsString() const
Model type.
static ModelMode modelModeFromString(const QString &mode)
Model mode.
const physical_quantities::CLength & getCG() const
Get center of gravity.
static void registerMetadata()
Register metadata.
bool matchesDbDistributor(const CDistributor &distributor) const
By distributor.
const aviation::CLivery & getLivery() const
Get livery.
bool hasAircraftDesignator() const
Has aircraft designator?
QJsonObject toDatabaseJson() const
To database JSON.
void setDescription(const QString &description)
Descriptive text.
void setSimulator(const CSimulatorInfo &simulator)
Set simulator info.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
bool matchesModelStringOrAlias(const QString &modelString, Qt::CaseSensitivity sensitivity) const
Matches model string or alias?
const CIcon & getModelModeAsIcon() const
Model mode as string.
void setCG(const physical_quantities::CLength &cg)
Get center of gravity.
CStatusMessageList validate(bool withNestedObjects) const
Validate.
bool matchesMode(simulation::CAircraftModel::ModelModeFilter mode) const
Matches given mode?
static const QString & modelModeToString(ModelMode mode)
Model mode.
const QString & getModelString() const
Model key, either queried or loaded from simulator model.
bool matchesFileName(const QString &fileName) const
Matching file name?
ModelType getModelType() const
Model type.
bool hasQueriedModelString() const
Queried model string?
static CAircraftModel fromDatabaseJson(const QJsonObject &json, const QString &prefix=QString("mod_"))
From swift DB JSON.
bool hasDbDistributor() const
Distributor loaded from DB.
QString getModelStringAndDbKey() const
Model string and DB key (if available).
bool matchesSimulatorFlag(CSimulatorInfo::Simulator simulator) const
Matches given simulator?
int comparePropertyByIndex(CPropertyIndexRef index, const CAircraftModel &compareValue) const
Compare for index.
const aviation::CAirlineIcaoCode & getAirlineIcaoCode() const
Airline ICAO code.
void setAircraftIcaoDesignator(const QString &designator)
Set aircraft ICAO code designator.
bool matchesAnyDbDistributor(const CDistributorList &distributors) const
By distributor.
QDateTime getFileTimestamp() const
Get timestamp.
QString asHtmlSummary(const QString &separator="<br>") const
As a brief HTML summary (e.g. used in tooltips).
const QString & getName() const
Name.
void setModelMode(ModelMode mode)
Set model mode.
const QString & getSupportedParts() const
Supported parts.
bool hasDescription(bool ignoreAutoGenerated=false) const
Description.
bool hasAnyModelString() const
Any model string or alias?
bool isMilitary() const
Military model?
QJsonObject toMemoizedJson(MemoHelper::CMemoizer &) const
To JSON with memoized members (used by CAircraftModelList).
static bool isSwiftLiveryString(const QString &liveryString)
swift livery string
bool hasModelString() const
Non empty model string?
void setLivery(const aviation::CLivery &livery)
Livery.
const aviation::CAircraftIcaoCode & getAircraftIcaoCode() const
Aircraft ICAO code.
void setDistributor(const CDistributor &distributor)
Set distributor.
void setAircraftIcaoCodes(const aviation::CAircraftIcaoCode &aircraftIcaoCode, const aviation::CAirlineIcaoCode &airlineIcaoCode)
Set ICAO codes.
bool setAircraftIcaoCode(const aviation::CAircraftIcaoCode &aircraftIcaoCode)
Set aircraft ICAO code.
QString toDatabaseJsonString(QJsonDocument::JsonFormat format=QJsonDocument::Compact) const
To database JSON.
static const QString & autoGenerated()
Hint, that model was automatically generated (e.g. by auto stashing).
ColumnIndex
Supposed to be used only in filter operations.
void updateMissingParts(const CAircraftModel &otherModel, bool dbModelPriority=true)
Update missing parts from another model.
bool matchesSimulator(const CSimulatorInfo &simulator) const
Matches given simulator?
Value object encapsulating information of software distributor.
Definition distributor.h:33
static CDistributor fromDatabaseJson(const QJsonObject &json, const QString &prefix=QString())
Object from JSON.
const QString & getDescription() const
Get description.
Definition distributor.h:56
Value object encapsulating a list of distributors.
CDistributor findByKeyOrAlias(const QString &keyOrAlias) const
Find by id or alias.
bool matchesAnyKeyOrAlias(const QString &keyOrAlias) const
At least is matching key or alias.
Simple hardcoded info about the corresponding simulator.
Simulator getSimulator() const
Simulator.
static CSimulatorInfo fromDatabaseJson(const QJsonObject &json, const QString &prefix)
From database JSON.
int compare(T a, T b)
Compare arithmetic values.
QMap< QString, CDistributor > DistributorIdMap
Distributor/id map.
constexpr auto introspect()
Obtain the CMetaClassIntrospector for the metaclass of T.
Definition metaclass.h:285
QMap< int, CLivery > LiveryIdMap
Id/CLivery map.
Definition livery.h:253
SWIFT_MISC_EXPORT QString inApostrophes(const QString &in, bool ignoreEmpty=false)
Return string in apostrophes.
QString removeChars(const QString &s, F predicate)
Return a string with characters removed that match the given predicate.
Definition stringutils.h:34
SWIFT_MISC_EXPORT bool stringCompare(const QString &c1, const QString &c2, Qt::CaseSensitivity cs)
String compare.
QDateTime fromMSecsSinceEpoch(qint64 msecs)
bool isValid() const const
qint64 toMSecsSinceEpoch() const const
QString toString(QStringView format) const const
QString absolutePath() const const
QDir absoluteDir() const const
QString absoluteFilePath() const const
bool exists(const QString &path)
bool isReadable() const const
QDateTime lastModified() const const
QByteArray toJson(QJsonDocument::JsonFormat format) const const
QJsonObject::iterator insert(QLatin1StringView key, const QJsonValue &value)
bool isNull() const const
bool isUndefined() const const
bool contains(const Key &key) const const
qsizetype count() const const
QString arg(Args &&... args) const const
int compare(QLatin1StringView s1, const QString &s2, Qt::CaseSensitivity cs)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
qsizetype lastIndexOf(QChar ch, Qt::CaseSensitivity cs) const const
QString left(qsizetype n) &&
qsizetype length() const const
QString mid(qsizetype position, qsizetype n) &&
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
QString section(QChar sep, qsizetype start, qsizetype end, QString::SectionFlags flags) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
int toInt(bool *ok, int base) const const
QString toLower() const const
QString toUpper() const const
CaseInsensitive
QTimeZone utc()
bool canConvert() const const
QVariant fromValue(T &&value)
QString toString() const const
int typeId() const const
T value() const &const
Simple literal type containing a single QLatin1String.
Definition metaclass.h:100
Type wrapper for passing MetaFlag to CMetaMember::has.
Definition metaclass.h:117
int livery
livery id, by that I have airline id
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition valueobject.h:67
#define SWIFT_VERIFY_X(COND, WHERE, WHAT)
A weaker kind of assert.
Definition verify.h:26