mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-02 07:05:38 +08:00
Ref T515, further utility functions to validate models
This commit is contained in:
committed by
Mat Sutcliffe
parent
bb9b5e8e97
commit
de680f4fcd
@@ -154,6 +154,11 @@ namespace BlackMisc
|
|||||||
.arg(this->getLivery().asHtmlSummary(" ")).replace(" ", " ");
|
.arg(this->getLivery().asHtmlSummary(" ")).replace(" ", " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CAircraftModel::matchesFileName(const QString &fileName) const
|
||||||
|
{
|
||||||
|
return stringCompare(fileName, m_fileName, CFileUtils::osFileNameCaseSensitivity());
|
||||||
|
}
|
||||||
|
|
||||||
CStatusMessageList CAircraftModel::verifyModelData() const
|
CStatusMessageList CAircraftModel::verifyModelData() const
|
||||||
{
|
{
|
||||||
CStatusMessageList msgs;
|
CStatusMessageList msgs;
|
||||||
@@ -744,15 +749,13 @@ namespace BlackMisc
|
|||||||
|
|
||||||
bool CAircraftModel::matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const
|
bool CAircraftModel::matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const
|
||||||
{
|
{
|
||||||
if (sensitivity == Qt::CaseInsensitive) { return caseInsensitiveStringCompare(modelString, m_modelString); }
|
return stringCompare(modelString, m_modelString, sensitivity);
|
||||||
return m_modelString == modelString;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CAircraftModel::matchesModelStringOrAlias(const QString &modelString, Qt::CaseSensitivity sensitivity) const
|
bool CAircraftModel::matchesModelStringOrAlias(const QString &modelString, Qt::CaseSensitivity sensitivity) const
|
||||||
{
|
{
|
||||||
if (this->matchesModelString(modelString, sensitivity)) { return true; }
|
if (this->matchesModelString(modelString, sensitivity)) { return true; }
|
||||||
if (sensitivity == Qt::CaseInsensitive) { return caseInsensitiveStringCompare(modelString, m_modelStringAlias); }
|
return stringCompare(modelString, m_modelStringAlias, sensitivity);
|
||||||
return m_modelStringAlias == modelString;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CAircraftModel::calculateScore(const CAircraftModel &compareModel, bool preferColorLiveries, CStatusMessageList *log) const
|
int CAircraftModel::calculateScore(const CAircraftModel &compareModel, bool preferColorLiveries, CStatusMessageList *log) const
|
||||||
|
|||||||
@@ -430,6 +430,9 @@ namespace BlackMisc
|
|||||||
//! File name?
|
//! File name?
|
||||||
bool hasFileName() const { return !m_fileName.isEmpty(); }
|
bool hasFileName() const { return !m_fileName.isEmpty(); }
|
||||||
|
|
||||||
|
//! Matching file name?
|
||||||
|
bool matchesFileName(const QString &fileName) const;
|
||||||
|
|
||||||
//! Does the corresponding file exist?
|
//! Does the corresponding file exist?
|
||||||
bool hasExistingCorrespondingFile() const;
|
bool hasExistingCorrespondingFile() const;
|
||||||
|
|
||||||
|
|||||||
@@ -688,6 +688,30 @@ namespace BlackMisc
|
|||||||
return this->removeIf(&CAircraftModel::getAircraftIcaoCode, aircraftIcao, &CAircraftModel::getAirlineIcaoCode, airline);
|
return this->removeIf(&CAircraftModel::getAircraftIcaoCode, aircraftIcao, &CAircraftModel::getAirlineIcaoCode, airline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CAircraftModelList::removeIfNotFsFamily()
|
||||||
|
{
|
||||||
|
if (this->isEmpty()) { return 0; }
|
||||||
|
CAircraftModelList fsOnly = this->getAllFsFamilyModels();
|
||||||
|
if (fsOnly.size() == this->size()) { return 0; }
|
||||||
|
const int delta = this->size() - fsOnly.size();
|
||||||
|
*this = fsOnly;
|
||||||
|
return delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
CAircraftModelList CAircraftModelList::removeIfFileButNotInSet(const QString &fileName, const QSet<QString> &modelStrings)
|
||||||
|
{
|
||||||
|
CAircraftModelList removed;
|
||||||
|
for (const CAircraftModel &model : *this)
|
||||||
|
{
|
||||||
|
if (!model.matchesFileName(fileName)) { continue; }
|
||||||
|
if (modelStrings.contains(model.getModelString())) { continue; }
|
||||||
|
removed.push_back(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->removeIfIn(removed);
|
||||||
|
return removed;
|
||||||
|
}
|
||||||
|
|
||||||
bool CAircraftModelList::replaceOrAddModelWithString(const CAircraftModel &addOrReplaceModel, Qt::CaseSensitivity sensitivity)
|
bool CAircraftModelList::replaceOrAddModelWithString(const CAircraftModel &addOrReplaceModel, Qt::CaseSensitivity sensitivity)
|
||||||
{
|
{
|
||||||
bool r = false;
|
bool r = false;
|
||||||
@@ -1013,6 +1037,18 @@ namespace BlackMisc
|
|||||||
return combinedCodes;
|
return combinedCodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSet<QString> CAircraftModelList::getAllFileNames() const
|
||||||
|
{
|
||||||
|
const bool cs = CFileUtils::isFileNameCaseSensitive();
|
||||||
|
QSet<QString> files;
|
||||||
|
for (const CAircraftModel &model : *this)
|
||||||
|
{
|
||||||
|
if (!model.hasFileName()) { continue; }
|
||||||
|
files.insert(cs ? model.getFileName() : model.getFileNameLowerCase());
|
||||||
|
}
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
QString CAircraftModelList::getCombinedTypesAsString(const QString &separator) const
|
QString CAircraftModelList::getCombinedTypesAsString(const QString &separator) const
|
||||||
{
|
{
|
||||||
return this->getCombinedTypes().values().join(separator);
|
return this->getCombinedTypes().values().join(separator);
|
||||||
@@ -1178,15 +1214,19 @@ namespace BlackMisc
|
|||||||
QSet<QString> workingFiles;
|
QSet<QString> workingFiles;
|
||||||
int failedFilesCount = 0;
|
int failedFilesCount = 0;
|
||||||
|
|
||||||
|
// sorting allows to skip multiple files as once when a file fails
|
||||||
|
CAircraftModelList sorted(*this);
|
||||||
|
if (!alreadySorted) { sorted.sortByFileName(); }
|
||||||
|
|
||||||
const bool caseSensitive = CFileUtils::isFileNameCaseSensitive();
|
const bool caseSensitive = CFileUtils::isFileNameCaseSensitive();
|
||||||
for (const CAircraftModel &model : *this)
|
for (const CAircraftModel &model : as_const(sorted))
|
||||||
{
|
{
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (!model.hasModelString())
|
if (!model.hasModelString())
|
||||||
{
|
{
|
||||||
const CStatusMessage m(this, CStatusMessage::SeverityError, "No model string");
|
const CStatusMessage m(this, CStatusMessage::SeverityError, "No model string", true);
|
||||||
msgs.push_back(m);
|
msgs.push_back(m);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -281,6 +281,14 @@ namespace BlackMisc
|
|||||||
//! \return number of elements removed
|
//! \return number of elements removed
|
||||||
int removeByAircraftAndAirline(const Aviation::CAircraftIcaoCode &aircraftIcao, const Aviation::CAirlineIcaoCode &airline);
|
int removeByAircraftAndAirline(const Aviation::CAircraftIcaoCode &aircraftIcao, const Aviation::CAirlineIcaoCode &airline);
|
||||||
|
|
||||||
|
//! Remove if NOT FS family model, ie. FSX/P3D/FS9
|
||||||
|
//! \return number of elements removed
|
||||||
|
int removeIfNotFsFamily();
|
||||||
|
|
||||||
|
//! Remove those models of a particular file, but not in the given set
|
||||||
|
//! \remark mostly used for FSX/FS9/P3D consolidation
|
||||||
|
CAircraftModelList removeIfFileButNotInSet(const QString &fileName, const QSet<QString> &modelStrings);
|
||||||
|
|
||||||
//! Replace or add based on model string
|
//! Replace or add based on model string
|
||||||
//! \return element removed?
|
//! \return element removed?
|
||||||
bool replaceOrAddModelWithString(const CAircraftModel &addOrReplaceModel, Qt::CaseSensitivity sensitivity);
|
bool replaceOrAddModelWithString(const CAircraftModel &addOrReplaceModel, Qt::CaseSensitivity sensitivity);
|
||||||
@@ -372,6 +380,9 @@ namespace BlackMisc
|
|||||||
//! All combined types
|
//! All combined types
|
||||||
QSet<QString> getCombinedTypes() const;
|
QSet<QString> getCombinedTypes() const;
|
||||||
|
|
||||||
|
//! All file names
|
||||||
|
QSet<QString> getAllFileNames() const;
|
||||||
|
|
||||||
//! All combined types as string
|
//! All combined types as string
|
||||||
QString getCombinedTypesAsString(const QString &separator = ", ") const;
|
QString getCombinedTypesAsString(const QString &separator = ", ") const;
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,16 @@ namespace BlackMisc
|
|||||||
return titles;
|
return titles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSet<QString> CAircraftCfgEntriesList::getTitleSetUpperCase() const
|
||||||
|
{
|
||||||
|
QSet<QString> titlesUc;
|
||||||
|
for (const CAircraftCfgEntries &entries : *this)
|
||||||
|
{
|
||||||
|
titlesUc.insert(entries.getTitle().toUpper());
|
||||||
|
}
|
||||||
|
return titlesUc;
|
||||||
|
}
|
||||||
|
|
||||||
QString CAircraftCfgEntriesList::getTitlesAsString(bool sorted, const QString &separator) const
|
QString CAircraftCfgEntriesList::getTitlesAsString(bool sorted, const QString &separator) const
|
||||||
{
|
{
|
||||||
return this->getTitles(sorted).join(separator);
|
return this->getTitles(sorted).join(separator);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
#include <QSet>
|
||||||
#include <Qt>
|
#include <Qt>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
@@ -49,6 +50,9 @@ namespace BlackMisc
|
|||||||
//! All titles (aka model names)
|
//! All titles (aka model names)
|
||||||
QStringList getTitles(bool sorted = false) const;
|
QStringList getTitles(bool sorted = false) const;
|
||||||
|
|
||||||
|
//! Titles as set in upper case
|
||||||
|
QSet<QString> getTitleSetUpperCase() const;
|
||||||
|
|
||||||
//! All titles as string
|
//! All titles as string
|
||||||
QString getTitlesAsString(bool sorted, const QString &separator = ", ") const;
|
QString getTitlesAsString(bool sorted, const QString &separator = ", ") const;
|
||||||
|
|
||||||
|
|||||||
@@ -369,6 +369,16 @@ namespace BlackMisc
|
|||||||
return m_counts[CSimulatorInfo::NumberOfSimulators];
|
return m_counts[CSimulatorInfo::NumberOfSimulators];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CCountPerSimulator::getCountForFsFamilySimulators() const
|
||||||
|
{
|
||||||
|
return this->getCount(CSimulatorInfo::fsx()) + this->getCount(CSimulatorInfo::p3d()) + this->getCount(CSimulatorInfo::fs9());
|
||||||
|
}
|
||||||
|
|
||||||
|
int CCountPerSimulator::getCountForFsxFamilySimulators() const
|
||||||
|
{
|
||||||
|
return this->getCount(CSimulatorInfo::fsx()) + this->getCount(CSimulatorInfo::p3d());
|
||||||
|
}
|
||||||
|
|
||||||
int CCountPerSimulator::getMaximum() const
|
int CCountPerSimulator::getMaximum() const
|
||||||
{
|
{
|
||||||
return *std::min_element(m_counts.begin(), m_counts.end());
|
return *std::min_element(m_counts.begin(), m_counts.end());
|
||||||
|
|||||||
@@ -222,9 +222,15 @@ namespace BlackMisc
|
|||||||
//! Object count for given simulator
|
//! Object count for given simulator
|
||||||
int getCount(const CSimulatorInfo &simulator) const;
|
int getCount(const CSimulatorInfo &simulator) const;
|
||||||
|
|
||||||
//! Unkown count
|
//! Unknown count
|
||||||
int getCountForUnknownSimulators() const;
|
int getCountForUnknownSimulators() const;
|
||||||
|
|
||||||
|
//! P3D, FSX, or FS9
|
||||||
|
int getCountForFsFamilySimulators() const;
|
||||||
|
|
||||||
|
//! P3D or FSX
|
||||||
|
int getCountForFsxFamilySimulators() const;
|
||||||
|
|
||||||
//! Set count
|
//! Set count
|
||||||
void setCount(int count, const CSimulatorInfo &simulator);
|
void setCount(int count, const CSimulatorInfo &simulator);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user