mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 09:15:34 +08:00
refs #571, consolidate with own models or DB models when stashed (goal: better defaults)
* improved missing parts updates * sync. with own and DB models
This commit is contained in:
@@ -225,6 +225,16 @@ namespace BlackMisc
|
||||
|
||||
void CAirlineIcaoCode::updateMissingParts(const CAirlineIcaoCode &otherIcaoCode)
|
||||
{
|
||||
if (!this->hasValidDbKey() && otherIcaoCode.hasValidDbKey())
|
||||
{
|
||||
// we have no DB data, but the other one has
|
||||
// so we change roles. We take the DB object as base, and update our parts
|
||||
CAirlineIcaoCode copy(otherIcaoCode);
|
||||
copy.updateMissingParts(*this);
|
||||
*this = copy;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->hasValidDesignator()) { this->setDesignator(otherIcaoCode.getDesignator()); }
|
||||
if (!this->hasValidCountry()) { this->setCountry(otherIcaoCode.getCountry()); }
|
||||
if (!this->hasName()) { this->setName(otherIcaoCode.getName()); }
|
||||
|
||||
@@ -143,7 +143,8 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
QString combinedCode(json.value(prefix + "combinedcode").toString());
|
||||
if (combinedCode.isEmpty()) {
|
||||
if (combinedCode.isEmpty())
|
||||
{
|
||||
CLivery liveryStub; // only consists of id, maybe id and timestamp
|
||||
liveryStub.setKeyAndTimestampFromDatabaseJson(json, prefix);
|
||||
return liveryStub;
|
||||
@@ -235,6 +236,8 @@ namespace BlackMisc
|
||||
|
||||
int CLivery::comparePropertyByIndex(const CLivery &compareValue, const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return this->getCombinedCode().compare(compareValue.getCombinedCode()); }
|
||||
if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { return IDatastoreObjectWithIntegerKey::comparePropertyByIndex(compareValue, index);}
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
@@ -259,6 +262,16 @@ namespace BlackMisc
|
||||
|
||||
void CLivery::updateMissingParts(const CLivery &otherLivery)
|
||||
{
|
||||
if (!this->hasValidDbKey() && otherLivery.hasValidDbKey())
|
||||
{
|
||||
// we have no DB data, but the other one has
|
||||
// so we change roles. We take the DB object as base, and update our parts
|
||||
CLivery copy(otherLivery);
|
||||
copy.updateMissingParts(*this);
|
||||
*this = copy;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->m_colorFuselage.isValid()) { this->setColorFuselage(otherLivery.getColorFuselage()); }
|
||||
if (!this->m_colorTail.isValid()) { this->setColorTail(otherLivery.getColorTail()); }
|
||||
if (this->m_combinedCode.isEmpty()) { this->setCombinedCode(otherLivery.getCombinedCode());}
|
||||
|
||||
@@ -259,25 +259,35 @@ namespace BlackMisc
|
||||
return this->m_livery.hasValidAirlineDesignator();
|
||||
}
|
||||
|
||||
void CAircraftModel::updateMissingParts(const CAircraftModel &model)
|
||||
void CAircraftModel::updateMissingParts(const CAircraftModel &otherModel)
|
||||
{
|
||||
if (this->m_modelString.isEmpty()) { this->setModelString(model.getModelString()); }
|
||||
if (this->m_description.isEmpty()) { this->setDescription(model.getDescription()); }
|
||||
if (this->m_fileName.isEmpty()) { this->setFileName(model.getFileName()); }
|
||||
if (this->m_callsign.isEmpty()) { this->setCallsign(model.getCallsign()); }
|
||||
if (this->m_modelType == TypeUnknown) { this->m_modelType = model.getModelType(); }
|
||||
if (!this->hasValidDbKey() && otherModel.hasValidDbKey())
|
||||
{
|
||||
// we have no DB data, but the other one has
|
||||
// so we change roles. We take the DB object as base, and update our parts
|
||||
CAircraftModel copy(otherModel);
|
||||
copy.updateMissingParts(*this);
|
||||
*this = copy;
|
||||
return;
|
||||
}
|
||||
|
||||
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_callsign.isEmpty()) { this->setCallsign(otherModel.getCallsign()); }
|
||||
if (this->m_modelType == TypeUnknown) { this->m_modelType = otherModel.getModelType(); }
|
||||
if (this->m_simulator.isUnspecified())
|
||||
{
|
||||
this->setSimulatorInfo(model.getSimulatorInfo());
|
||||
this->setSimulatorInfo(otherModel.getSimulatorInfo());
|
||||
}
|
||||
else
|
||||
{
|
||||
this->m_simulator.add(model.getSimulatorInfo());
|
||||
this->m_simulator.add(otherModel.getSimulatorInfo());
|
||||
}
|
||||
|
||||
this->m_livery.updateMissingParts(model.getLivery());
|
||||
this->m_aircraftIcao.updateMissingParts(model.getAircraftIcaoCode());
|
||||
this->m_distributor.updateMissingParts(model.getDistributor());
|
||||
this->m_livery.updateMissingParts(otherModel.getLivery());
|
||||
this->m_aircraftIcao.updateMissingParts(otherModel.getAircraftIcaoCode());
|
||||
this->m_distributor.updateMissingParts(otherModel.getDistributor());
|
||||
}
|
||||
|
||||
bool CAircraftModel::hasQueriedModelString() const
|
||||
|
||||
@@ -210,7 +210,7 @@ namespace BlackMisc
|
||||
void setFileName(const QString &fileName) { m_fileName = fileName; }
|
||||
|
||||
//! Update missing parts from another model
|
||||
void updateMissingParts(const CAircraftModel &model);
|
||||
void updateMissingParts(const CAircraftModel &otherModel);
|
||||
|
||||
//! Queried model string?
|
||||
bool hasQueriedModelString() const;
|
||||
|
||||
@@ -115,6 +115,16 @@ namespace BlackMisc
|
||||
|
||||
void CDistributor::updateMissingParts(const CDistributor &otherDistributor)
|
||||
{
|
||||
if (!this->hasValidDbKey() && otherDistributor.hasValidDbKey())
|
||||
{
|
||||
// we have no DB data, but the other one has
|
||||
// so we change roles. We take the DB object as base, and update our parts
|
||||
CDistributor copy(otherDistributor);
|
||||
copy.updateMissingParts(*this);
|
||||
*this = copy;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->hasAlias1()) { this->setAlias1(otherDistributor.getAlias1()); }
|
||||
if (!this->hasAlias2()) { this->setAlias1(otherDistributor.getAlias2()); }
|
||||
if (!this->hasDescription()) { this->setDescription(otherDistributor.getDescription()); }
|
||||
@@ -129,7 +139,8 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
QString description(json.value(prefix + "description").toString());
|
||||
if (description.isEmpty()) {
|
||||
if (description.isEmpty())
|
||||
{
|
||||
// stub, only key, maybe also timestamps
|
||||
CDistributor distributorStub;
|
||||
distributorStub.setKeyAndTimestampFromDatabaseJson(json, prefix);
|
||||
|
||||
Reference in New Issue
Block a user