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:
Klaus Basan
2016-01-12 01:21:26 +01:00
parent 9f646f215c
commit 6625b83c5e
9 changed files with 130 additions and 35 deletions

View File

@@ -177,7 +177,7 @@ namespace BlackGui
if (this->m_modelLoader) { this->m_modelLoader->gracefulShutdown(); }
}
bool CDbMappingComponent::hasModelsToStash() const
bool CDbMappingComponent::hasSelectedModelsToStash() const
{
TabIndex tab = currentTabIndex();
switch (tab)
@@ -208,9 +208,9 @@ namespace BlackGui
}
}
CAircraftModelList CDbMappingComponent::getModelsToStash() const
CAircraftModelList CDbMappingComponent::getSelectedModelsToStash() const
{
if (!hasModelsToStash()) { return CAircraftModelList(); }
if (!hasSelectedModelsToStash()) { return CAircraftModelList(); }
TabIndex tab = currentTabIndex();
switch (tab)
{
@@ -234,13 +234,18 @@ namespace BlackGui
return ui->comp_StashAircraft->getStashedModelStrings();
}
CAircraftModel CDbMappingComponent::getOwnModelForModelString(const QString &modelString)
{
return m_cachedOwnModels.get().findFirstByModelString(modelString);
}
CDbMappingComponent::TabIndex CDbMappingComponent::currentTabIndex() const
{
int t = ui->tw_ModelsToBeMapped->currentIndex();
return static_cast<TabIndex>(t);
}
bool CDbMappingComponent::isStashedView() const
bool CDbMappingComponent::isStashedTab() const
{
return currentTabIndex() == TabStash;
}
@@ -266,7 +271,7 @@ namespace BlackGui
void CDbMappingComponent::ps_stashCurrentModel()
{
const CAircraftModel model(getAircraftModel());
const CAircraftModel model(getEditorAircraftModel());
CStatusMessageList msgs(this->validateCurrentModel(true));
if (!msgs.hasErrorMessages())
{
@@ -439,10 +444,10 @@ namespace BlackGui
void CDbMappingComponent::stashSelectedModels()
{
if (!this->hasModelsToStash()) { return; }
if (!this->hasSelectedModelsToStash()) { return; }
CStatusMessageList msgs =
this->ui->comp_StashAircraft->stashModels(
this->getModelsToStash()
this->getSelectedModelsToStash()
);
if (msgs.hasWarningOrErrorMessages())
{
@@ -515,7 +520,7 @@ namespace BlackGui
this->ui->tvp_OwnAircraftModels->hideLoadIndicator();
}
CAircraftModel CDbMappingComponent::getAircraftModel() const
CAircraftModel CDbMappingComponent::getEditorAircraftModel() const
{
CAircraftModel model(ui->editor_Model->getValue());
model.setDistributor(ui->editor_Distributor->getValue());

View File

@@ -72,26 +72,29 @@ namespace BlackGui
bool withVPilot() const { return m_withVPilot; }
//! Any models which can be stashed
bool hasModelsToStash() const;
bool hasSelectedModelsToStash() const;
//! The models to be stashed from currently activated tab (table view)
BlackMisc::Simulation::CAircraftModelList getModelsToStash() const;
//! Models to be stashed from currently activated tab (table view)
BlackMisc::Simulation::CAircraftModelList getSelectedModelsToStash() const;
//! Stashed models
const BlackMisc::Simulation::CAircraftModelList &getStashedModels() const;
//! Stashed models trings
//! Stashed model strings
QStringList getStashedModelStrings() const;
//! Own (installed) model for given model string
BlackMisc::Simulation::CAircraftModel getOwnModelForModelString(const QString &modelString);
//! Current tab index
TabIndex currentTabIndex() const;
//! Is stashed view
bool isStashedView() const;
bool isStashedTab() const;
//! Unvalidated consolidated aircraft model from the subparts (icao, distributor)
//! \note not guaranteed to be valid, just snapshot of as it state
BlackMisc::Simulation::CAircraftModel getAircraftModel() const;
//! Unvalidated consolidated aircraft model from the editor subparts (icao, distributor)
//! \note not guaranteed to be valid, just a snapshot of its current editor state
BlackMisc::Simulation::CAircraftModel getEditorAircraftModel() const;
public slots:
//! Stash model
@@ -177,7 +180,7 @@ namespace BlackGui
BlackMisc::Simulation::FsCommon::CVPilotRulesReader m_vPilotReader; //!< read vPilot rules
BlackMisc::CData<BlackCore::Data::VPilotAircraftModels> m_cachedVPilotModels { this, &CDbMappingComponent::ps_onVPilotCacheChanged }; //!< cache for latest vPilot rules
std::unique_ptr<BlackMisc::Simulation::IAircraftModelLoader> m_modelLoader; //!< read own aircraft models
BlackMisc::CData<BlackCore::Data::OwnSimulatorAircraftModels> m_cachedOwnModels { this }; //!< cache for latest models
BlackMisc::CData<BlackCore::Data::OwnSimulatorAircraftModels> m_cachedOwnModels { this }; //!< cache for own installed models
BlackMisc::CData<BlackCore::Data::AuthenticatedUser> m_user {this, &CDbMappingComponent::ps_userChanged};
bool m_vPilot1stInit = true;
bool m_withVPilot = false;

View File

@@ -12,6 +12,7 @@
#include "ui_dbstashcomponent.h"
#include "blackgui/views/aircraftmodelview.h"
#include "blackmisc/icons.h"
#include "blackmisc/simulation/aircraftmodel.h"
using namespace BlackMisc;
using namespace BlackMisc::Simulation;
@@ -82,16 +83,30 @@ namespace BlackGui
CStatusMessage CDbStashComponent::stashModel(const CAircraftModel &model, bool replace)
{
CStatusMessage m(validateStashModel(model, replace));
CAircraftModel pushModel(model);
// merge with own models if any
if (pushModel.getModelType() != CAircraftModel::TypeOwnSimulatorModel)
{
pushModel = this->consolidateWithOwnModels(pushModel);
}
// merge with DB data if any
if (!pushModel.hasValidDbKey())
{
pushModel = this->consolidateWithDbData(pushModel);
}
CStatusMessage m(validateStashModel(pushModel, replace));
if (!m.isWarningOrAbove())
{
if (replace)
{
this->ui->tvp_StashAircraftModels->replaceOrAdd(&CAircraftModel::getModelString, model.getModelString(), model);
this->ui->tvp_StashAircraftModels->replaceOrAdd(&CAircraftModel::getModelString, pushModel.getModelString(), pushModel);
}
else
{
this->ui->tvp_StashAircraftModels->insert(model);
this->ui->tvp_StashAircraftModels->insert(pushModel);
}
}
return m;
@@ -313,6 +328,28 @@ namespace BlackGui
return models;
}
CAircraftModel CDbStashComponent::consolidateWithDbData(const CAircraftModel &model)
{
if (!model.hasModelString()) { return model; }
CAircraftModel dbModel(this->getModelForModelString(model.getModelString()));
if (!dbModel.hasValidDbKey()) { return model; }
// use DB model as base, update everything else
dbModel.updateMissingParts(model);
return dbModel;
}
CAircraftModel CDbStashComponent::consolidateWithOwnModels(const CAircraftModel &model)
{
if (!model.hasModelString()) { return model; }
if (model.getModelType() == CAircraftModel::TypeOwnSimulatorModel) { return model; }
CAircraftModel ownModel(this->getMappingComponent()->getOwnModelForModelString(model.getModelString()));
if (!ownModel.hasModelString()) { return model; }
ownModel.updateMissingParts(model);
return ownModel;
}
void CDbStashComponent::ps_copyOverPartsToSelected()
{
QObject *sender = QObject::sender();
@@ -320,7 +357,7 @@ namespace BlackGui
if (!this->getMappingComponent()) { return; }
if (!this->ui->tvp_StashAircraftModels->hasSelection()) { return; }
CAircraftModel model(this->getMappingComponent()->getAircraftModel());
CAircraftModel model(this->getMappingComponent()->getEditorAircraftModel());
if (sender == this->ui->pb_AircraftIcao)
{
this->applyToSelected(model.getAircraftIcaoCode());

View File

@@ -152,6 +152,12 @@ namespace BlackGui
//! Get the selected only models or all models depending on checkbox
BlackMisc::Simulation::CAircraftModelList getSelectedOrAllModels() const;
//! Consolidate with any DB data (if available).
BlackMisc::Simulation::CAircraftModel consolidateWithDbData(const BlackMisc::Simulation::CAircraftModel &model);
//! Consolidate with own models (if available).
BlackMisc::Simulation::CAircraftModel consolidateWithOwnModels(const BlackMisc::Simulation::CAircraftModel &model);
};
} // ns
} // ns