Allow to update model directories

This commit is contained in:
Klaus Basan
2019-05-03 16:55:58 +02:00
parent 71fbe5b604
commit 3be753a6a7
9 changed files with 163 additions and 24 deletions

View File

@@ -258,7 +258,7 @@ namespace BlackMisc
case IndexSupportedParts: return CVariant(m_supportedParts);
case IndexFileTimestamp: return CVariant::fromValue(this->getFileTimestamp());
case IndexFileTimestampFormattedYmdhms: return CVariant::fromValue(this->getFormattedFileTimestampYmdhms());
case IndexIconPath: return CVariant(m_iconPath);
case IndexIconPath: return CVariant(m_iconFile);
case IndexAircraftIcaoCode: return m_aircraftIcao.propertyByIndex(index.copyFrontRemoved());
case IndexLivery: return m_livery.propertyByIndex(index.copyFrontRemoved());
case IndexCallsign: return m_callsign.propertyByIndex(index.copyFrontRemoved());
@@ -284,7 +284,7 @@ namespace BlackMisc
case IndexDescription: m_description = variant.toQString(); break;
case IndexSimulatorInfo: m_simulator.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
case IndexName: m_name = variant.toQString(); break;
case IndexIconPath: m_iconPath = variant.toQString(); break;
case IndexIconPath: m_iconFile = variant.toQString(); break;
case IndexCG: m_cg.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
case IndexSupportedParts: this->setSupportedParts(variant.toQString()); break;
case IndexModelType: m_modelType = variant.value<ModelType>(); break;
@@ -345,7 +345,7 @@ namespace BlackMisc
case IndexName: return m_name.compare(compareValue.getName(), Qt::CaseInsensitive);
case IndexCallsign: return m_callsign.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getCallsign());
case IndexFileName: return m_fileName.compare(compareValue.getFileName(), Qt::CaseInsensitive);
case IndexIconPath: return m_iconPath.compare(compareValue.getIconPath(), Qt::CaseInsensitive);
case IndexIconPath: return m_iconFile.compare(compareValue.getIconFile(), Qt::CaseInsensitive);
case IndexCG: return m_cg.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getCG());
case IndexSupportedParts: return m_supportedParts.compare(compareValue.getSupportedParts());
case IndexModelTypeAsString:
@@ -567,10 +567,10 @@ namespace BlackMisc
CPixmap CAircraftModel::loadIcon(CStatusMessage &success) const
{
static const CStatusMessage noIcon(this, CStatusMessage::SeverityInfo, u"no icon");
if (m_iconPath.isEmpty()) { success = noIcon; return CPixmap(); }
if (m_iconFile.isEmpty()) { success = noIcon; return CPixmap(); }
// load from file
const CPixmap pm(CPixmap::loadFromFile(m_iconPath, success));
const CPixmap pm(CPixmap::loadFromFile(m_iconFile, success));
return pm;
}
@@ -659,6 +659,12 @@ namespace BlackMisc
m_distributor.updateMissingParts(otherModel.getDistributor());
}
void CAircraftModel::updateByExistingDirectories(const CAircraftModel &otherModel)
{
if (otherModel.hasExistingCorrespondingFile()) { this->setFileName(otherModel.getFileName()); }
if (otherModel.hasExistingIconFile()) { this->setIconFile(otherModel.getIconFile()); }
}
bool CAircraftModel::hasQueriedModelString() const
{
return m_modelType == TypeQueriedFromNetwork && this->hasModelString();
@@ -710,13 +716,13 @@ namespace BlackMisc
{
// other local, priority
this->setFileName(model.getFileName());
this->setIconPath(model.getIconPath());
this->setIconFile(model.getIconFile());
return;
}
// both not local, override empty values
if (m_fileName.isEmpty()) { this->setFileName(model.getFileName()); }
if (m_iconPath.isEmpty()) { this->setIconPath(model.getIconPath()); }
if (m_iconFile.isEmpty()) { this->setIconFile(model.getIconFile()); }
}
bool CAircraftModel::adjustLocalFileNames(const QString &newModelDir, const QString &stripModelDirIndicator)
@@ -760,6 +766,13 @@ namespace BlackMisc
return this->getFileDirectory().absolutePath();
}
bool CAircraftModel::hasExistingIconFile() const
{
if (m_iconFile.isEmpty()) { return false; }
const QFileInfo fi(m_iconFile);
return fi.exists();
}
bool CAircraftModel::matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const
{
return stringCompare(modelString, m_modelString, sensitivity);

View File

@@ -366,6 +366,10 @@ namespace BlackMisc
//! Update missing parts from another model
void updateMissingParts(const CAircraftModel &otherModel, bool dbModelPriority = true);
//! Update the directories from other model
//! \sa updateLocalFileNames
void updateByExistingDirectories(const CAircraftModel &otherModel);
//! Queried model string?
bool hasQueriedModelString() const;
@@ -450,11 +454,14 @@ namespace BlackMisc
//! File name
void setFileName(const QString &fileName) { m_fileName = fileName; }
//! File representing model
const QString &getIconPath() const { return m_iconPath; }
//! Icon file representing model
const QString &getIconFile() const { return m_iconFile; }
//! File representing model
void setIconPath(const QString &iconFile) { m_iconPath = iconFile; }
//! Icon file representing model
void setIconFile(const QString &iconFile) { m_iconFile = iconFile; }
//! Is the icon file existing?
bool hasExistingIconFile() const;
//! Get timestamp
QDateTime getFileTimestamp() const;
@@ -544,7 +551,7 @@ namespace BlackMisc
QString m_name; //!< Model name
QString m_description; //!< descriptive text
QString m_fileName; //!< file name
QString m_iconPath; //!< a file representing the aircraft as icon
QString m_iconFile; //!< a file representing the aircraft as icon
QString m_supportedParts; //!< supported parts
qint64 m_fileTimestamp = -1; //!< file timestamp of originating file (if applicable)
ModelType m_modelType = TypeUnknown; //!< model string is coming representing ...?
@@ -568,7 +575,7 @@ namespace BlackMisc
BLACK_METAMEMBER(name),
BLACK_METAMEMBER(description, 0, DisabledForComparison),
BLACK_METAMEMBER(fileName, 0, DisabledForComparison),
BLACK_METAMEMBER(iconPath, 0, DisabledForComparison),
BLACK_METAMEMBER(iconFile, 0, DisabledForComparison),
BLACK_METAMEMBER(fileTimestamp, 0, DisabledForComparison),
BLACK_METAMEMBER(modelType),
BLACK_METAMEMBER(modelMode)

View File

@@ -491,14 +491,14 @@ namespace BlackMisc
{
if (modelString.isEmpty()) { return {}; }
const CAircraftModel m(findFirstByModelStringOrDefault(modelString, Qt::CaseInsensitive));
return m.getIconPath();
return m.getIconFile();
}
QString CAircraftModelList::findModelIconPathByCallsign(const CCallsign &callsign) const
{
if (callsign.isEmpty()) { return {}; }
const CAircraftModel m(findFirstByCallsignOrDefault(callsign));
return m.getIconPath();
return m.getIconFile();
}
CAircraftModelList CAircraftModelList::findModelsWithoutExistingFile() const

View File

@@ -133,7 +133,7 @@ namespace BlackMisc
model.setName(this->getSimName());
model.setMSecsSinceEpoch(m_timestampMSecsSinceEpoch); // aircraft.cfg file timestamp
model.setFileTimestamp(m_timestampMSecsSinceEpoch);
model.setIconPath(this->getThumbnailFileNameChecked());
model.setIconFile(this->getThumbnailFileNameChecked());
const QString designator(CAircraftIcaoCode::normalizeDesignator(this->getAtcModel()));
CAircraftIcaoCode aircraft(

View File

@@ -381,7 +381,7 @@ namespace BlackMisc
QString getNetworkModelLiveryDifference() const;
//! \copydoc BlackMisc::Simulation::CAircraftModel::getIconPath
const QString &getIconPath() const { return m_models[CurrentModel].getIconPath(); }
const QString &getIconFile() const { return m_models[CurrentModel].getIconFile(); }
//! Get model string
const QString &getModelString() const { return m_models[CurrentModel].getModelString(); }