mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 07:35:48 +08:00
Ref T247, utility functions to validate model set
This commit is contained in:
@@ -25,8 +25,8 @@
|
||||
#include <QString>
|
||||
#include <QtGlobal>
|
||||
#include <QStringBuilder>
|
||||
#include <QFileInfo>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Db;
|
||||
|
||||
@@ -553,7 +553,7 @@ namespace BlackMisc
|
||||
{
|
||||
if (this->getModelType() == CAircraftModel::TypeOwnSimulatorModel)
|
||||
{
|
||||
// this is local model, ignore
|
||||
// this is already a local model, ignore
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -570,6 +570,32 @@ namespace BlackMisc
|
||||
if (m_iconPath.isEmpty()) { this->setIconPath(model.getIconPath()); }
|
||||
}
|
||||
|
||||
bool CAircraftModel::adjustLocalFileNames(const QString &newModelDir, const QString &stripModelDirIndicator)
|
||||
{
|
||||
if (!this->hasFileName()) { return false; }
|
||||
const QString md = CFileUtils::normalizeFilePathToQtStandard(newModelDir);
|
||||
int i = -1;
|
||||
if (stripModelDirIndicator.isEmpty())
|
||||
{
|
||||
QString strip = md.mid(md.lastIndexOf('/'));
|
||||
i = m_fileName.lastIndexOf(strip);
|
||||
}
|
||||
else
|
||||
{
|
||||
i = m_fileName.lastIndexOf(stripModelDirIndicator);
|
||||
}
|
||||
if (i < 0) { return false; }
|
||||
m_fileName = CFileUtils::appendFilePaths(newModelDir, m_fileName.mid(i));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CAircraftModel::existsCorrespondingFile() const
|
||||
{
|
||||
if (!this->hasFileName()) { return false; }
|
||||
const QFileInfo fi(this->getFileName());
|
||||
return (fi.exists() && fi.isReadable());
|
||||
}
|
||||
|
||||
bool CAircraftModel::matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const
|
||||
{
|
||||
return m_modelString.length() == modelString.length() &&
|
||||
|
||||
@@ -50,8 +50,8 @@ namespace BlackMisc
|
||||
//! \remarks Simulator independent class, supposed to be common denominator
|
||||
class BLACKMISC_EXPORT CAircraftModel :
|
||||
public CValueObject<CAircraftModel>,
|
||||
public BlackMisc::Db::IDatastoreObjectWithIntegerKey,
|
||||
public BlackMisc::IOrderable
|
||||
public Db::IDatastoreObjectWithIntegerKey, // also ITimestampBased
|
||||
public IOrderable
|
||||
{
|
||||
public:
|
||||
//! Model type
|
||||
@@ -295,6 +295,63 @@ namespace BlackMisc
|
||||
//! Matches given simulator?
|
||||
bool matchesSimulatorFlag(CSimulatorInfo::Simulator simulator) const;
|
||||
|
||||
//! swift livery string (to be sent via network), "liveryCode [modelString]";
|
||||
//! \sa splitNetworkLiveryString
|
||||
QString getSwiftLiveryString() const;
|
||||
|
||||
//! Update missing parts from another model
|
||||
void updateMissingParts(const CAircraftModel &otherModel, bool dbModelPriority = true);
|
||||
|
||||
//! Queried model string?
|
||||
bool hasQueriedModelString() const;
|
||||
|
||||
//! Model string which was manually set
|
||||
bool hasManuallySetString() const;
|
||||
|
||||
//! Non empty model string
|
||||
bool hasModelString() const { return !m_modelString.isEmpty(); }
|
||||
|
||||
//! Description
|
||||
bool hasDescription(bool ignoreAutoGenerated = false) const;
|
||||
|
||||
//! Valid simulator
|
||||
bool hasValidSimulator() const;
|
||||
|
||||
//! Info, which members (Livery, Aircraft ICAO, ...) are already based on DB data
|
||||
QString getMembersDbStatus() const;
|
||||
|
||||
//! Matches model string?
|
||||
bool matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const;
|
||||
|
||||
//! Calculate score
|
||||
int calculateScore(const CAircraftModel &compareModel, bool preferColorLiveries, CStatusMessageList *log = nullptr) const;
|
||||
|
||||
//! Validate
|
||||
CStatusMessageList validate(bool withNestedObjects) const;
|
||||
|
||||
//! Considered equal for publishing, compares if livery etc. are the same DB values
|
||||
bool isEqualForPublishing(const CAircraftModel &dbModel, CStatusMessageList *details = nullptr) const;
|
||||
|
||||
//! Helper class used by implementation.
|
||||
using MemoHelper = CMemoHelper<Aviation::CAircraftIcaoCode, Aviation::CLivery, CDistributor>;
|
||||
|
||||
//! To JSON with memoized members (used by CAircraftModelList)
|
||||
QJsonObject toMemoizedJson(MemoHelper::CMemoizer &) const;
|
||||
|
||||
//! From JSON with memoized members (used by CAircraftModelList)
|
||||
void convertFromMemoizedJson(const QJsonObject &json, const MemoHelper::CUnmemoizer &);
|
||||
|
||||
//! To database JSON
|
||||
QJsonObject toDatabaseJson() const;
|
||||
|
||||
//! To database JSON
|
||||
QString toDatabaseJsonString(QJsonDocument::JsonFormat format = QJsonDocument::Compact) const;
|
||||
|
||||
//! As a brief HTML summary (e.g. used in tooltips)
|
||||
QString asHtmlSummary(const QString &separator = "<br>") const;
|
||||
|
||||
// ---------------- simulator file related functions -------------------
|
||||
|
||||
//! File name (corresponding data for simulator, only available if representing simulator model
|
||||
QString getFileName() const { return m_fileName; }
|
||||
|
||||
@@ -328,66 +385,20 @@ namespace BlackMisc
|
||||
//! Load icon from disk
|
||||
CPixmap loadIcon(CStatusMessage &success) const;
|
||||
|
||||
//! swift livery string (to be sent via network), "liveryCode [modelString]";
|
||||
//! \sa splitNetworkLiveryString
|
||||
QString getSwiftLiveryString() const;
|
||||
|
||||
//! Update missing parts from another model
|
||||
void updateMissingParts(const CAircraftModel &otherModel, bool dbModelPriority = true);
|
||||
|
||||
//! Queried model string?
|
||||
bool hasQueriedModelString() const;
|
||||
|
||||
//! Model string which was manually set
|
||||
bool hasManuallySetString() const;
|
||||
|
||||
//! Non empty model string
|
||||
bool hasModelString() const { return !m_modelString.isEmpty(); }
|
||||
|
||||
//! Description
|
||||
bool hasDescription(bool ignoreAutoGenerated = false) const;
|
||||
|
||||
//! Valid simulator
|
||||
bool hasValidSimulator() const;
|
||||
|
||||
//! Info, which members (Livery, Aircraft ICAO, ...) are already based on DB data
|
||||
QString getMembersDbStatus() const;
|
||||
|
||||
//! File path for DB (absolute paths make no sense in DB)
|
||||
void normalizeFileNameForDb();
|
||||
|
||||
//! If we have local file names, we use those namesx
|
||||
//! Update file names from local model
|
||||
//! \remark if we have local file names, we use those names
|
||||
void updateLocalFileNames(const CAircraftModel &model);
|
||||
|
||||
//! Matches model string?
|
||||
bool matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const;
|
||||
//! Adjust file names to a new directory
|
||||
bool adjustLocalFileNames(const QString &newModelDir, const QString &stripModelDirIndicator = {});
|
||||
|
||||
//! Calculate score
|
||||
int calculateScore(const CAircraftModel &compareModel, bool preferColorLiveries, CStatusMessageList *log = nullptr) const;
|
||||
//! Does the corresponding file exist?
|
||||
bool existsCorrespondingFile() const;
|
||||
|
||||
//! Validate
|
||||
CStatusMessageList validate(bool withNestedObjects) const;
|
||||
|
||||
//! Considered equal for publishing, compares if livery etc. are the same DB values
|
||||
bool isEqualForPublishing(const CAircraftModel &dbModel, CStatusMessageList *details = nullptr) const;
|
||||
|
||||
//! Helper class used by implementation.
|
||||
using MemoHelper = CMemoHelper<Aviation::CAircraftIcaoCode, Aviation::CLivery, CDistributor>;
|
||||
|
||||
//! To JSON with memoized members (used by CAircraftModelList)
|
||||
QJsonObject toMemoizedJson(MemoHelper::CMemoizer &) const;
|
||||
|
||||
//! From JSON with memoized members (used by CAircraftModelList)
|
||||
void convertFromMemoizedJson(const QJsonObject &json, const MemoHelper::CUnmemoizer &);
|
||||
|
||||
//! To database JSON
|
||||
QJsonObject toDatabaseJson() const;
|
||||
|
||||
//! To database JSON
|
||||
QString toDatabaseJsonString(QJsonDocument::JsonFormat format = QJsonDocument::Compact) const;
|
||||
|
||||
//! As a brief HTML summary (e.g. used in tooltips)
|
||||
QString asHtmlSummary(const QString &separator = "<br>") const;
|
||||
// ---------------- end file related functions --------------
|
||||
|
||||
//! Model type
|
||||
static QString modelTypeToString(ModelType type);
|
||||
|
||||
@@ -321,6 +321,22 @@ namespace BlackMisc
|
||||
return m.getIconPath();
|
||||
}
|
||||
|
||||
CAircraftModelList CAircraftModelList::findModelsWithoutExistingFile() const
|
||||
{
|
||||
return this->findBy([](const CAircraftModel & model)
|
||||
{
|
||||
return !model.existsCorrespondingFile();
|
||||
});
|
||||
}
|
||||
|
||||
CAircraftModelList CAircraftModelList::findModelsWithExistingFile() const
|
||||
{
|
||||
return this->findBy([](const CAircraftModel & model)
|
||||
{
|
||||
return model.existsCorrespondingFile();
|
||||
});
|
||||
}
|
||||
|
||||
QString CAircraftModelList::designatorToFamily(const CAircraftIcaoCode &aircraftIcaoCode) const
|
||||
{
|
||||
if (aircraftIcaoCode.hasFamily()) { return aircraftIcaoCode.getFamily(); }
|
||||
|
||||
@@ -124,7 +124,7 @@ namespace BlackMisc
|
||||
//! Find by livery code
|
||||
CAircraftModelList findByLiveryCode(const Aviation::CLivery &livery) const;
|
||||
|
||||
//! With file name
|
||||
//! Models with file name
|
||||
CAircraftModelList findWithFileName() const;
|
||||
|
||||
//! All models from given distributors
|
||||
@@ -178,6 +178,12 @@ namespace BlackMisc
|
||||
//! Model icon path
|
||||
QString findModelIconPathByCallsign(const Aviation::CCallsign &callsign) const;
|
||||
|
||||
//! Find models where the filename is not set or the file no longer exists
|
||||
CAircraftModelList findModelsWithoutExistingFile() const;
|
||||
|
||||
//! Find models where the filename is set and the file exists
|
||||
CAircraftModelList findModelsWithExistingFile() const;
|
||||
|
||||
//! All models of the FS (FSX, P3D, FS9) family
|
||||
CAircraftModelList getAllFsFamilyModels() const;
|
||||
|
||||
@@ -290,7 +296,7 @@ namespace BlackMisc
|
||||
//! From given CDistributorList update the model`s distributor order
|
||||
int updateDistributorOrder(const CDistributorList &distributors);
|
||||
|
||||
//! File name normalized for DB
|
||||
//! All file names normalized for DB
|
||||
void normalizeFileNamesForDb();
|
||||
|
||||
//! Score by aircraft ICAO code
|
||||
|
||||
Reference in New Issue
Block a user