mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
refs #720, file name handling in models
* normalize file name before writing to DB * use local file paths for local models * display "C" for color liveries
This commit is contained in:
committed by
Mathew Sutcliffe
parent
1a4b0c5e76
commit
364914cc31
@@ -13,6 +13,7 @@
|
||||
#include "blackmisc/icon.h"
|
||||
#include "blackmisc/iconlist.h"
|
||||
#include "blackmisc/icons.h"
|
||||
#include "blackmisc/fileutils.h"
|
||||
#include "blackmisc/logcategory.h"
|
||||
#include "blackmisc/logcategorylist.h"
|
||||
#include "blackmisc/simulation/aircraftmodel.h"
|
||||
@@ -434,12 +435,10 @@ namespace BlackMisc
|
||||
return;
|
||||
}
|
||||
|
||||
this->updateByLocalFileNames(otherModel);
|
||||
if (this->m_callsign.isEmpty()) { this->setCallsign(otherModel.getCallsign()); }
|
||||
if (this->m_modelString.isEmpty()) { this->setModelString(otherModel.getModelString()); }
|
||||
if (this->m_description.isEmpty()) { this->setDescription(otherModel.getDescription()); }
|
||||
if (this->m_fileName.isEmpty()) { this->setFileName(otherModel.getFileName()); }
|
||||
if (this->m_iconPath.isEmpty()) { this->setIconPath(otherModel.getIconPath()); }
|
||||
if (this->m_callsign.isEmpty()) { this->setCallsign(otherModel.getCallsign()); }
|
||||
if (this->m_modelType == TypeUnknown) { this->m_modelType = otherModel.getModelType(); }
|
||||
if (this->m_modelMode == Undefined) { this->m_modelType = otherModel.getModelType(); }
|
||||
if (this->m_simulator.isUnspecified())
|
||||
@@ -476,11 +475,44 @@ namespace BlackMisc
|
||||
QString s(hasValidDbKey() ? "M" : "m");
|
||||
s = s.append(getDistributor().hasValidDbKey() ? 'D' : 'd');
|
||||
s = s.append(getAircraftIcaoCode().hasValidDbKey() ? 'A' : 'a');
|
||||
s = s.append(getLivery().hasValidDbKey() ? 'L' : 'l');
|
||||
s = s.append(getLivery().getAirlineIcaoCode().hasValidDbKey() ? 'A' : 'a');
|
||||
if (getLivery().isLoadedFromDb() && getLivery().isColorLivery())
|
||||
{
|
||||
s = s.append("C-");
|
||||
}
|
||||
else
|
||||
{
|
||||
s = s.append(getLivery().isLoadedFromDb() ? 'L' : 'l');
|
||||
s = s.append(getLivery().getAirlineIcaoCode().hasValidDbKey() ? 'A' : 'a');
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
void CAircraftModel::normalizeFileNameForDb()
|
||||
{
|
||||
this->m_fileName = CAircraftModel::normalizeFileNameForDb(this->m_fileName);
|
||||
}
|
||||
|
||||
void CAircraftModel::updateByLocalFileNames(const CAircraftModel &model)
|
||||
{
|
||||
if (this->getModelType() == CAircraftModel::TypeOwnSimulatorModel)
|
||||
{
|
||||
// this is local model, ignore
|
||||
return;
|
||||
}
|
||||
|
||||
if (model.getModelType() == CAircraftModel::TypeOwnSimulatorModel)
|
||||
{
|
||||
// other local, priority
|
||||
this->setFileName(model.getFileName());
|
||||
this->setIconPath(model.getIconPath());
|
||||
return;
|
||||
}
|
||||
|
||||
// both not local, override empty values
|
||||
if (this->m_fileName.isEmpty()) { this->setFileName(model.getFileName()); }
|
||||
if (this->m_iconPath.isEmpty()) { this->setIconPath(model.getIconPath()); }
|
||||
}
|
||||
|
||||
bool CAircraftModel::matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const
|
||||
{
|
||||
return this->m_modelString.length() == modelString.length() &&
|
||||
@@ -519,6 +551,13 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
QString CAircraftModel::normalizeFileNameForDb(const QString &filePath)
|
||||
{
|
||||
QString n = CFileUtils::normalizeFilePathToQtStandard(filePath).toUpper();
|
||||
if (n.count('/') < 2) { return n; }
|
||||
return n.section('/', -2, -1);
|
||||
}
|
||||
|
||||
CAircraftModel::ModelMode CAircraftModel::modelModeFromString(const QString &mode)
|
||||
{
|
||||
if (mode.isEmpty() || mode.startsWith('I', Qt::CaseInsensitive)) { return Include;}
|
||||
|
||||
@@ -313,6 +313,12 @@ namespace BlackMisc
|
||||
//! 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
|
||||
void updateByLocalFileNames(const CAircraftModel &model);
|
||||
|
||||
//! Matches model string?
|
||||
bool matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const;
|
||||
|
||||
@@ -328,10 +334,13 @@ namespace BlackMisc
|
||||
//! Model type
|
||||
static QString modelTypeToString(ModelType type);
|
||||
|
||||
//! File path used for DB
|
||||
static QString normalizeFileNameForDb(const QString &filePath);
|
||||
|
||||
//! Model mode
|
||||
static ModelMode modelModeFromString(const QString &mode);
|
||||
|
||||
//! Model mode
|
||||
//! Model mode-
|
||||
static const QString &modelModeToString(ModelMode mode);
|
||||
|
||||
//! From swift DB JSON
|
||||
|
||||
@@ -503,6 +503,14 @@ namespace BlackMisc
|
||||
return found;
|
||||
}
|
||||
|
||||
void CAircraftModelList::normalizeFileNamesForDb()
|
||||
{
|
||||
for (CAircraftModel &model : *this)
|
||||
{
|
||||
model.normalizeFileNameForDb();
|
||||
}
|
||||
}
|
||||
|
||||
QStringList CAircraftModelList::toCompleterStrings(bool sorted) const
|
||||
{
|
||||
QStringList c;
|
||||
@@ -557,7 +565,9 @@ namespace BlackMisc
|
||||
QJsonArray array;
|
||||
for (const CAircraftModel &model : *this)
|
||||
{
|
||||
QJsonValue v(model.toDatabaseJson());
|
||||
CAircraftModel copy(model);
|
||||
copy.normalizeFileNameForDb();
|
||||
QJsonValue v(copy.toDatabaseJson());
|
||||
array.append(v);
|
||||
}
|
||||
return array;
|
||||
|
||||
@@ -192,6 +192,9 @@ namespace BlackMisc
|
||||
//! From given CDistributorList update the model`s distributor order
|
||||
int updateDistributorOrder(const CDistributorList &distributors);
|
||||
|
||||
//! File name normalized for DB
|
||||
void normalizeFileNamesForDb();
|
||||
|
||||
//! Completer strings
|
||||
QStringList toCompleterStrings(bool sorted = true) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user