From ecfe4ab1fca2946f0bf90a607aab1b226a45b5f5 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 9 Aug 2016 02:16:12 +0200 Subject: [PATCH] refs #720, stash component * use centralized consolidation function (removed local duplicate) * renamings --- src/blackgui/components/dbstashcomponent.cpp | 56 +++----------------- src/blackgui/components/dbstashcomponent.h | 8 +-- 2 files changed, 11 insertions(+), 53 deletions(-) diff --git a/src/blackgui/components/dbstashcomponent.cpp b/src/blackgui/components/dbstashcomponent.cpp index 876b85b24..791d0a21d 100644 --- a/src/blackgui/components/dbstashcomponent.cpp +++ b/src/blackgui/components/dbstashcomponent.cpp @@ -8,6 +8,7 @@ */ #include "blackcore/db/databasewriter.h" +#include "blackcore/db/databaseutils.h" #include "blackcore/application.h" #include "blackcore/webdataservices.h" #include "blackgui/components/dbmappingcomponent.h" @@ -76,7 +77,7 @@ namespace BlackGui ui->tvp_StashAircraftModels->setHighlightModelStringsColor(Qt::red); this->enableButtonRow(); - connect(sApp->getWebDataServices()->getDatabaseWriter(), &CDatabaseWriter::published, this, &CDbStashComponent::ps_publishResponse); + connect(sApp->getWebDataServices()->getDatabaseWriter(), &CDatabaseWriter::publishedModels, this, &CDbStashComponent::ps_publishedModelsResponse); } CDbStashComponent::~CDbStashComponent() @@ -263,7 +264,7 @@ namespace BlackGui } } - void CDbStashComponent::ps_publishResponse(const CAircraftModelList &publishedModels, const CAircraftModelList &skippedModels, const CStatusMessageList &msgs) + void CDbStashComponent::ps_publishedModelsResponse(const CAircraftModelList &publishedModels, const CAircraftModelList &skippedModels, const CStatusMessageList &msgs) { this->ui->tvp_StashAircraftModels->hideLoadIndicator(); if (!publishedModels.isEmpty()) @@ -282,7 +283,7 @@ namespace BlackGui QString confirm("Remove %1 published models?"); auto lambda = [this, publishedModels]() { - this->unstashModels(publishedModels.getModelStrings(false)); + this->unstashModels(publishedModels.getModelStringList(false)); }; this->showMessagesWithConfirmation(msgs, confirm.arg(publishedModels.size()), lambda, QMessageBox::Ok); } @@ -321,7 +322,7 @@ namespace BlackGui if (msgs.hasWarningOrErrorMessages()) { this->showMessages(msgs); - this->ui->tvp_StashAircraftModels->setHighlightModelStrings(invalidModels.getModelStrings(false)); + this->ui->tvp_StashAircraftModels->setHighlightModelStrings(invalidModels.getModelStringList(false)); return false; } else @@ -364,51 +365,8 @@ namespace BlackGui CAircraftModel CDbStashComponent::consolidateWithDbData(const CAircraftModel &model) const { - if (!model.hasModelString()) { return model; } - CAircraftModel dbModel(sApp->getWebDataServices()->getModelForModelString(model.getModelString())); - - // we try to best update by DB data here - if (!dbModel.hasValidDbKey()) - { - // we have no(!) DB model, so we update each of it subobjects - CAircraftModel consolidatedModel(model); // copy over - if (!consolidatedModel.getLivery().hasValidDbKey()) - { - const CLivery dbLivery(sApp->getWebDataServices()->smartLiverySelector(consolidatedModel.getLivery())); - if (dbLivery.hasValidDbKey()) - { - consolidatedModel.setLivery(dbLivery); - } - } - if (!consolidatedModel.getAircraftIcaoCode().hasValidDbKey() && consolidatedModel.hasAircraftDesignator()) - { - // try to find DB aircraft ICAO here - const CAircraftIcaoCode dbIcao(sGui->getWebDataServices()->smartAircraftIcaoSelector(consolidatedModel.getAircraftIcaoCode())); - if (dbIcao.hasValidDbKey()) - { - consolidatedModel.setAircraftIcaoCode(dbIcao); - } - } - - // key alone here can be misleading, as the key can be valid but no DB key - // mostly happens when key is an alias - QString keyOrAlias(consolidatedModel.getDistributor().getDbKey()); - CDistributor dbDistributor(sGui->getWebDataServices()->getDistributors().findByKeyOrAlias(keyOrAlias)); - - // if no distributor is found, it is now empty because it was invalid - // otherwise replaced with the current DB data - consolidatedModel.setDistributor(dbDistributor); - - // copy over - dbModel = consolidatedModel; - } - - bool someDbData = dbModel.hasValidDbKey() || dbModel.getLivery().hasValidDbKey() || dbModel.getAircraftIcaoCode().hasValidDbKey(); - if (!someDbData) { return model; } - - // use DB model as base, update everything else - dbModel.updateMissingParts(model); - return dbModel; + const CAircraftModel consolidatedModel = CDatabaseUtils::consolidateModelWithDbData(model, true); + return consolidatedModel; } CAircraftModel CDbStashComponent::consolidateWithOwnModels(const CAircraftModel &model) const diff --git a/src/blackgui/components/dbstashcomponent.h b/src/blackgui/components/dbstashcomponent.h index 26e1e93ff..dac33c050 100644 --- a/src/blackgui/components/dbstashcomponent.h +++ b/src/blackgui/components/dbstashcomponent.h @@ -146,9 +146,9 @@ namespace BlackGui void ps_onPublishPressed(); //! Publish response received - void ps_publishResponse(const BlackMisc::Simulation::CAircraftModelList &publishedModels, - const BlackMisc::Simulation::CAircraftModelList &skippedModels, - const BlackMisc::CStatusMessageList &msgs); + void ps_publishedModelsResponse(const BlackMisc::Simulation::CAircraftModelList &publishedModels, + const BlackMisc::Simulation::CAircraftModelList &skippedModels, + const BlackMisc::CStatusMessageList &msgs); //! Copy over values void ps_copyOverPartsToSelected(); @@ -186,7 +186,7 @@ namespace BlackGui //! Consolidate with any DB data (if available). BlackMisc::Simulation::CAircraftModel consolidateWithDbData(const BlackMisc::Simulation::CAircraftModel &model) const; - //! Consolidate with own models (if available). + //! Consolidate with own models (if available). This updates mostly with model description, path etc. BlackMisc::Simulation::CAircraftModel consolidateWithOwnModels(const BlackMisc::Simulation::CAircraftModel &model) const; }; } // ns