mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
refs #720, stash component
* use centralized consolidation function (removed local duplicate) * renamings
This commit is contained in:
committed by
Mathew Sutcliffe
parent
fa4b90c43a
commit
ecfe4ab1fc
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "blackcore/db/databasewriter.h"
|
#include "blackcore/db/databasewriter.h"
|
||||||
|
#include "blackcore/db/databaseutils.h"
|
||||||
#include "blackcore/application.h"
|
#include "blackcore/application.h"
|
||||||
#include "blackcore/webdataservices.h"
|
#include "blackcore/webdataservices.h"
|
||||||
#include "blackgui/components/dbmappingcomponent.h"
|
#include "blackgui/components/dbmappingcomponent.h"
|
||||||
@@ -76,7 +77,7 @@ namespace BlackGui
|
|||||||
ui->tvp_StashAircraftModels->setHighlightModelStringsColor(Qt::red);
|
ui->tvp_StashAircraftModels->setHighlightModelStringsColor(Qt::red);
|
||||||
this->enableButtonRow();
|
this->enableButtonRow();
|
||||||
|
|
||||||
connect(sApp->getWebDataServices()->getDatabaseWriter(), &CDatabaseWriter::published, this, &CDbStashComponent::ps_publishResponse);
|
connect(sApp->getWebDataServices()->getDatabaseWriter(), &CDatabaseWriter::publishedModels, this, &CDbStashComponent::ps_publishedModelsResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
CDbStashComponent::~CDbStashComponent()
|
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();
|
this->ui->tvp_StashAircraftModels->hideLoadIndicator();
|
||||||
if (!publishedModels.isEmpty())
|
if (!publishedModels.isEmpty())
|
||||||
@@ -282,7 +283,7 @@ namespace BlackGui
|
|||||||
QString confirm("Remove %1 published models?");
|
QString confirm("Remove %1 published models?");
|
||||||
auto lambda = [this, publishedModels]()
|
auto lambda = [this, publishedModels]()
|
||||||
{
|
{
|
||||||
this->unstashModels(publishedModels.getModelStrings(false));
|
this->unstashModels(publishedModels.getModelStringList(false));
|
||||||
};
|
};
|
||||||
this->showMessagesWithConfirmation(msgs, confirm.arg(publishedModels.size()), lambda, QMessageBox::Ok);
|
this->showMessagesWithConfirmation(msgs, confirm.arg(publishedModels.size()), lambda, QMessageBox::Ok);
|
||||||
}
|
}
|
||||||
@@ -321,7 +322,7 @@ namespace BlackGui
|
|||||||
if (msgs.hasWarningOrErrorMessages())
|
if (msgs.hasWarningOrErrorMessages())
|
||||||
{
|
{
|
||||||
this->showMessages(msgs);
|
this->showMessages(msgs);
|
||||||
this->ui->tvp_StashAircraftModels->setHighlightModelStrings(invalidModels.getModelStrings(false));
|
this->ui->tvp_StashAircraftModels->setHighlightModelStrings(invalidModels.getModelStringList(false));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -364,51 +365,8 @@ namespace BlackGui
|
|||||||
|
|
||||||
CAircraftModel CDbStashComponent::consolidateWithDbData(const CAircraftModel &model) const
|
CAircraftModel CDbStashComponent::consolidateWithDbData(const CAircraftModel &model) const
|
||||||
{
|
{
|
||||||
if (!model.hasModelString()) { return model; }
|
const CAircraftModel consolidatedModel = CDatabaseUtils::consolidateModelWithDbData(model, true);
|
||||||
CAircraftModel dbModel(sApp->getWebDataServices()->getModelForModelString(model.getModelString()));
|
return consolidatedModel;
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CAircraftModel CDbStashComponent::consolidateWithOwnModels(const CAircraftModel &model) const
|
CAircraftModel CDbStashComponent::consolidateWithOwnModels(const CAircraftModel &model) const
|
||||||
|
|||||||
@@ -146,9 +146,9 @@ namespace BlackGui
|
|||||||
void ps_onPublishPressed();
|
void ps_onPublishPressed();
|
||||||
|
|
||||||
//! Publish response received
|
//! Publish response received
|
||||||
void ps_publishResponse(const BlackMisc::Simulation::CAircraftModelList &publishedModels,
|
void ps_publishedModelsResponse(const BlackMisc::Simulation::CAircraftModelList &publishedModels,
|
||||||
const BlackMisc::Simulation::CAircraftModelList &skippedModels,
|
const BlackMisc::Simulation::CAircraftModelList &skippedModels,
|
||||||
const BlackMisc::CStatusMessageList &msgs);
|
const BlackMisc::CStatusMessageList &msgs);
|
||||||
|
|
||||||
//! Copy over values
|
//! Copy over values
|
||||||
void ps_copyOverPartsToSelected();
|
void ps_copyOverPartsToSelected();
|
||||||
@@ -186,7 +186,7 @@ namespace BlackGui
|
|||||||
//! Consolidate with any DB data (if available).
|
//! Consolidate with any DB data (if available).
|
||||||
BlackMisc::Simulation::CAircraftModel consolidateWithDbData(const BlackMisc::Simulation::CAircraftModel &model) const;
|
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;
|
BlackMisc::Simulation::CAircraftModel consolidateWithOwnModels(const BlackMisc::Simulation::CAircraftModel &model) const;
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
Reference in New Issue
Block a user