diff --git a/src/blackgui/components/dbstashcomponent.cpp b/src/blackgui/components/dbstashcomponent.cpp index f1101c587..1a1054672 100644 --- a/src/blackgui/components/dbstashcomponent.cpp +++ b/src/blackgui/components/dbstashcomponent.cpp @@ -225,10 +225,13 @@ namespace BlackGui void CDbStashComponent::ps_onPublishPressed() { if (this->ui->tvp_StashAircraftModels->isEmpty()) {return; } - if (!this->validateAndDisplay()) { return; } + + // get models right here, because later steps might affect selection CAircraftModelList models(getSelectedOrAllModels()); if (models.isEmpty()) { return; } + // validate + if (!this->validateAndDisplay()) { return; } CStatusMessageList msgs; if (models.size() > MaxModelPublished) { @@ -339,7 +342,7 @@ namespace BlackGui CAircraftModelList CDbStashComponent::getSelectedOrAllModels() const { bool selectedOnly = ui->cb_SelectedOnly->isChecked(); - const CAircraftModelList models(selectedOnly ? this->ui->tvp_StashAircraftModels->selectedObjects() : this->ui->tvp_StashAircraftModels->container()); + const CAircraftModelList models(selectedOnly ? this->ui->tvp_StashAircraftModels->selectedObjects() : this->ui->tvp_StashAircraftModels->containerOrFilteredContainer()); return models; } @@ -351,13 +354,11 @@ namespace BlackGui // we try to best update by DB data here if (!dbModel.hasValidDbKey()) { - // we have no(!) DB model, so we update ecach of it subobjects + // we have no(!) DB model, so we update each of it subobjects CAircraftModel consolidatedModel(model); // copy over - if (!consolidatedModel.getLivery().hasValidDbKey() && consolidatedModel.hasAirlineDesignator()) + if (!consolidatedModel.getLivery().hasValidDbKey()) { - // we try to find a DB livery for the airline - // maybe slow because all liveries always copied over - CLivery dbLivery(this->getLiveries().findStdLiveryByAirlineIcaoDesignator(model.getAirlineIcaoCode())); + const CLivery dbLivery(this->smartLiverySelector(consolidatedModel.getLivery())); if (dbLivery.hasValidDbKey()) { consolidatedModel.setLivery(dbLivery); @@ -366,7 +367,7 @@ namespace BlackGui if (!consolidatedModel.getAircraftIcaoCode().hasValidDbKey() && consolidatedModel.hasAircraftDesignator()) { // try to find DB aircraft ICAO here - CAircraftIcaoCode dbIcao(this->getAircraftIcaoCodeForDesignator(consolidatedModel.getAircraftIcaoCode().getDesignator())); + const CAircraftIcaoCode dbIcao(this->smartAircraftIcaoSelector(consolidatedModel.getAircraftIcaoCode())); if (dbIcao.hasValidDbKey()) { consolidatedModel.setAircraftIcaoCode(dbIcao); @@ -407,12 +408,7 @@ namespace BlackGui CAircraftModel CDbStashComponent::consolidateModel(const CAircraftModel &model) const { CAircraftModel stashModel(model); - - // merge with own models if any - if (stashModel.getModelType() != CAircraftModel::TypeOwnSimulatorModel) - { - stashModel = this->consolidateWithOwnModels(stashModel); - } + bool ownModel = stashModel.getModelType() == CAircraftModel::TypeOwnSimulatorModel; // merge with DB data if any if (!stashModel.hasValidDbKey()) @@ -420,6 +416,12 @@ namespace BlackGui stashModel = this->consolidateWithDbData(stashModel); } + // merge with own models if any + if (!ownModel) + { + stashModel = this->consolidateWithOwnModels(stashModel); + } + return stashModel; } diff --git a/src/blackmisc/aviation/aircrafticaocodelist.cpp b/src/blackmisc/aviation/aircrafticaocodelist.cpp index e32ecab68..32ad87bba 100644 --- a/src/blackmisc/aviation/aircrafticaocodelist.cpp +++ b/src/blackmisc/aviation/aircrafticaocodelist.cpp @@ -135,29 +135,40 @@ namespace BlackMisc if (c.hasCompleteData()) { return c; } } - CAircraftIcaoCodeList codes(*this); // copy and reduce + CAircraftIcaoCodeList codes; if (icaoPattern.hasKnownDesignator()) { const QString d(icaoPattern.getDesignator()); - codes = codes.findByDesignator(d); + codes = this->findByDesignator(d); - // we have an exact match + // we have one exact match if (codes.size() == 1) { return codes.front(); } if (codes.isEmpty()) { // now we search if the ICAO designator is // actually an IATA code - codes = codes.findByIataCode(d); + codes = this->findByIataCode(d); + + // we have one exact match + if (codes.size() == 1) { return codes.front(); } + if (codes.isEmpty()) { - // still empty, bye - return icaoPattern; + // still empty, try to find by family + codes = this->findByFamily(d); + + // we have one exact match + if (codes.size() == 1) { return codes.front(); } + + // still empty, hopeless + if (codes.isEmpty()) { return icaoPattern; } + + // continue here, we have more than one code and + // will try to further reduce } } codes.sortByRank(); - - // intentionally continue here } // further reduce by manufacturer @@ -166,7 +177,6 @@ namespace BlackMisc const QString m(icaoPattern.getManufacturer()); codes = codes.findByManufacturer(m); if (codes.size() == 1) { return codes.front(); } - if (codes.isEmpty()) { return icaoPattern; } // intentionally continue here } diff --git a/src/blackmisc/aviation/aircrafticaocodelist.h b/src/blackmisc/aviation/aircrafticaocodelist.h index b3cd7be80..fbec727ca 100644 --- a/src/blackmisc/aviation/aircrafticaocodelist.h +++ b/src/blackmisc/aviation/aircrafticaocodelist.h @@ -62,7 +62,7 @@ namespace BlackMisc //! Find by designator, then best match by rank CAircraftIcaoCode findFirstByDesignatorAndRank(const QString &designator) const; - //! Best selection by given pattern + //! Best selection by given pattern, also searches IATA and family information CAircraftIcaoCode smartAircraftIcaoSelector(const CAircraftIcaoCode &icaoPattern) const; //! Sort by rank