Update editor data when stashed data are modified (e.g. by drag and drop)

This issue was discovered during testing for #640
This commit is contained in:
Klaus Basan
2016-05-06 18:16:47 +02:00
parent 96189f530b
commit f3ac18257f
10 changed files with 87 additions and 32 deletions

View File

@@ -68,25 +68,25 @@ namespace BlackGui
connect(ui->editor_Model, &CModelMappingForm::requestStash, this, &CDbMappingComponent::ps_stashCurrentModel); connect(ui->editor_Model, &CModelMappingForm::requestStash, this, &CDbMappingComponent::ps_stashCurrentModel);
connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected); connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected);
connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::modelDataChanged, this, &CDbMappingComponent::ps_onOwnModelsCountChanged); connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::modelDataChanged, this, &CDbMappingComponent::ps_onOwnModelsChanged);
connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::requestStash, this, &CDbMappingComponent::stashSelectedModels); connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::requestStash, this, &CDbMappingComponent::stashSelectedModels);
connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::toggledHighlightStashedModels, this, &CDbMappingComponent::ps_onStashedModelsChanged); connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::toggledHighlightStashedModels, this, &CDbMappingComponent::ps_onStashedModelsChanged);
connect(ui->comp_StashAircraft->view(), &CAircraftModelView::modelDataChanged, this, &CDbMappingComponent::ps_onStashCountChanged); connect(ui->comp_StashAircraft->view(), &CAircraftModelView::modelDataChanged, this, &CDbMappingComponent::ps_onStashedModelsDataChanged);
connect(ui->comp_StashAircraft->view(), &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected); connect(ui->comp_StashAircraft->view(), &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected);
connect(ui->comp_StashAircraft->view(), &CAircraftModelView::requestHandlingOfStashDrop, this, &CDbMappingComponent::ps_handleStashDropRequest); connect(ui->comp_StashAircraft->view(), &CAircraftModelView::requestHandlingOfStashDrop, this, &CDbMappingComponent::ps_handleStashDropRequest);
connect(ui->comp_StashAircraft, &CDbStashComponent::stashedModelsChanged, this, &CDbMappingComponent::ps_onStashedModelsChanged); connect(ui->comp_StashAircraft, &CDbStashComponent::stashedModelsChanged, this, &CDbMappingComponent::ps_onStashedModelsChanged);
connect(ui->comp_StashAircraft, &CDbStashComponent::modelsSuccessfullyPublished, this, &CDbMappingComponent::ps_onModelsSuccessfullyPublished); connect(ui->comp_StashAircraft, &CDbStashComponent::modelsSuccessfullyPublished, this, &CDbMappingComponent::ps_onModelsSuccessfullyPublished);
connect(ui->comp_OwnModelSet->view(), &CAircraftModelView::modelDataChanged, this, &CDbMappingComponent::ps_onModelSetCountChanged); connect(ui->comp_OwnModelSet->view(), &CAircraftModelView::modelDataChanged, this, &CDbMappingComponent::ps_onModelSetChanged);
connect(ui->tw_ModelsToBeMapped, &QTabWidget::currentChanged, this, &CDbMappingComponent::ps_tabIndexChanged); connect(ui->tw_ModelsToBeMapped, &QTabWidget::currentChanged, this, &CDbMappingComponent::ps_tabIndexChanged);
connect(ui->tw_ModelsToBeMapped, &QTabWidget::currentChanged, ui->comp_ModelMatcher , &CModelMatcherComponent::tabIndexChanged); connect(ui->tw_ModelsToBeMapped, &QTabWidget::currentChanged, ui->comp_ModelMatcher , &CModelMatcherComponent::tabIndexChanged);
connect(ui->comp_OwnModelSet->view(), &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected); connect(ui->comp_OwnModelSet->view(), &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected);
// initial values // initial values
this->ps_onModelSetCountChanged(ui->comp_OwnModelSet->view()->rowCount(), ui->comp_OwnModelSet->view()->hasFilter()); this->ps_onModelSetChanged(ui->comp_OwnModelSet->view()->rowCount(), ui->comp_OwnModelSet->view()->hasFilter());
this->ps_onStashCountChanged(ui->comp_StashAircraft->view()->rowCount(), ui->comp_StashAircraft->view()->hasFilter()); this->ps_onStashedModelsDataChanged(ui->comp_StashAircraft->view()->rowCount(), ui->comp_StashAircraft->view()->hasFilter());
// how to display forms // how to display forms
ui->editor_AircraftIcao->setSelectOnly(); ui->editor_AircraftIcao->setSelectOnly();
@@ -120,7 +120,7 @@ namespace BlackGui
{ {
this->m_vPilot1stInit = false; this->m_vPilot1stInit = false;
connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected); connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected);
connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::modelDataChanged, this, &CDbMappingComponent::ps_onVPilotCountChanged); connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::modelDataChanged, this, &CDbMappingComponent::ps_onVPilotDataChanged);
connect(&m_vPilotReader, &CVPilotRulesReader::readFinished, this, &CDbMappingComponent::ps_onLoadVPilotDataFinished); connect(&m_vPilotReader, &CVPilotRulesReader::readFinished, this, &CDbMappingComponent::ps_onLoadVPilotDataFinished);
connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::requestStash, this, &CDbMappingComponent::stashSelectedModels); connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::requestStash, this, &CDbMappingComponent::stashSelectedModels);
connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::toggledHighlightStashedModels, this, &CDbMappingComponent::ps_onStashedModelsChanged); connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::toggledHighlightStashedModels, this, &CDbMappingComponent::ps_onStashedModelsChanged);
@@ -142,7 +142,7 @@ namespace BlackGui
{ {
// create / restore tab // create / restore tab
this->ui->tw_ModelsToBeMapped->addTab(this->ui->tab_VPilot, tabName); this->ui->tw_ModelsToBeMapped->addTab(this->ui->tab_VPilot, tabName);
this->ps_onVPilotCountChanged( this->ps_onVPilotDataChanged(
this->ui->tvp_AircraftModelsForVPilot->rowCount(), this->ui->tvp_AircraftModelsForVPilot->rowCount(),
this->ui->tvp_AircraftModelsForVPilot->hasFilter()); this->ui->tvp_AircraftModelsForVPilot->hasFilter());
} }
@@ -227,6 +227,41 @@ namespace BlackGui
return this->ui->tw_ModelsToBeMapped->tabText(i); return this->ui->tw_ModelsToBeMapped->tabText(i);
} }
void CDbMappingComponent::updateEditorsWhenApplicable()
{
const CAircraftModel currentEditorModel(ui->editor_Model->getValue());
if (!currentEditorModel.hasModelString()) { return; } // no related model
const QString modelString(currentEditorModel.getModelString());
const CAircraftModel currentStashedModel(ui->comp_StashAircraft->getStashedModel(modelString));
if (!currentStashedModel.hasModelString()) { return; }
// we have found a model in the stashed models and this is the one currently displayed
// in the editors
bool updated = false;
const CLivery stashedLivery(currentStashedModel.getLivery());
if (stashedLivery.hasValidDbKey())
{
if (ui->editor_Livery->setValue(stashedLivery)) { updated = true; }
}
const CDistributor stashedDistributor(currentStashedModel.getDistributor());
if (stashedDistributor.hasValidDbKey())
{
if (ui->editor_Distributor->setValue(stashedDistributor)) { updated = true; }
}
const CAircraftIcaoCode stashedIcaoCode(currentStashedModel.getAircraftIcaoCode());
if (stashedIcaoCode.hasValidDbKey())
{
if (ui->editor_AircraftIcao->setValue(stashedIcaoCode)) { updated = true; }
}
if (updated)
{
CLogMessage(this).info("Updated editor data for '%1'") << modelString;
}
}
CAircraftModelList CDbMappingComponent::getSelectedModelsToStash() const CAircraftModelList CDbMappingComponent::getSelectedModelsToStash() const
{ {
if (!hasSelectedModelsToStash()) { return CAircraftModelList(); } if (!hasSelectedModelsToStash()) { return CAircraftModelList(); }
@@ -516,7 +551,7 @@ namespace BlackGui
emit this->requestUpdatedData(CEntityFlags::ModelEntity); emit this->requestUpdatedData(CEntityFlags::ModelEntity);
} }
void CDbMappingComponent::ps_onVPilotCountChanged(int count, bool withFilter) void CDbMappingComponent::ps_onVPilotDataChanged(int count, bool withFilter)
{ {
Q_UNUSED(count); Q_UNUSED(count);
Q_UNUSED(withFilter); Q_UNUSED(withFilter);
@@ -527,7 +562,7 @@ namespace BlackGui
this->ui->tw_ModelsToBeMapped->setTabText(i, o); this->ui->tw_ModelsToBeMapped->setTabText(i, o);
} }
void CDbMappingComponent::ps_onOwnModelsCountChanged(int count, bool withFilter) void CDbMappingComponent::ps_onOwnModelsChanged(int count, bool withFilter)
{ {
Q_UNUSED(count); Q_UNUSED(count);
Q_UNUSED(withFilter); Q_UNUSED(withFilter);
@@ -592,7 +627,7 @@ namespace BlackGui
Q_UNUSED(selectedItem); Q_UNUSED(selectedItem);
} }
void CDbMappingComponent::ps_onStashCountChanged(int count, bool withFilter) void CDbMappingComponent::ps_onStashedModelsDataChanged(int count, bool withFilter)
{ {
Q_UNUSED(count); Q_UNUSED(count);
Q_UNUSED(withFilter); Q_UNUSED(withFilter);
@@ -601,9 +636,12 @@ namespace BlackGui
const QString f = this->ui->comp_StashAircraft->view()->hasFilter() ? "F" : ""; const QString f = this->ui->comp_StashAircraft->view()->hasFilter() ? "F" : "";
o = CGuiUtility::replaceTabCountValue(o, this->ui->comp_StashAircraft->view()->rowCount()) + f; o = CGuiUtility::replaceTabCountValue(o, this->ui->comp_StashAircraft->view()->rowCount()) + f;
this->ui->tw_ModelsToBeMapped->setTabText(i, o); this->ui->tw_ModelsToBeMapped->setTabText(i, o);
// update editors
this->updateEditorsWhenApplicable();
} }
void CDbMappingComponent::ps_onModelSetCountChanged(int count, bool withFilter) void CDbMappingComponent::ps_onModelSetChanged(int count, bool withFilter)
{ {
Q_UNUSED(count); Q_UNUSED(count);
Q_UNUSED(withFilter); Q_UNUSED(withFilter);

View File

@@ -169,6 +169,9 @@ namespace BlackGui
void ps_digestStashedModelsChanged(); void ps_digestStashedModelsChanged();
private slots: private slots:
//! Tab index changed
void ps_tabIndexChanged(int index);
//! Load the vPilot rules //! Load the vPilot rules
void ps_loadVPilotData(); void ps_loadVPilotData();
@@ -178,6 +181,9 @@ namespace BlackGui
//! vPilot cached models changed //! vPilot cached models changed
void ps_onVPilotCacheChanged(); void ps_onVPilotCacheChanged();
//! vPilot data changed
void ps_onVPilotDataChanged(int count, bool withFilter);
//! Request update of vPilot data //! Request update of vPilot data
void ps_requestVPilotDataUpdate(); void ps_requestVPilotDataUpdate();
@@ -187,8 +193,8 @@ namespace BlackGui
//! Stashed models changed //! Stashed models changed
void ps_onStashedModelsChangedDigest(); void ps_onStashedModelsChangedDigest();
//! Tab index changed //! Stash has been changed
void ps_tabIndexChanged(int index); void ps_onStashedModelsDataChanged(int count, bool withFilter);
//! Models have been published successfully //! Models have been published successfully
void ps_onModelsSuccessfullyPublished(const BlackMisc::Simulation::CAircraftModelList &models); void ps_onModelsSuccessfullyPublished(const BlackMisc::Simulation::CAircraftModelList &models);
@@ -196,14 +202,11 @@ namespace BlackGui
//! Stash drop request //! Stash drop request
void ps_handleStashDropRequest(const BlackMisc::Aviation::CAirlineIcaoCode &code) const; void ps_handleStashDropRequest(const BlackMisc::Aviation::CAirlineIcaoCode &code) const;
//! Row count for vPilot data changed //! Model set has been changed
void ps_onVPilotCountChanged(int count, bool withFilter); void ps_onModelSetChanged(int count, bool withFilter);
//! Stash count has been changed //! Own models have been changed
void ps_onStashCountChanged(int count, bool withFilter); void ps_onOwnModelsChanged(int count, bool withFilter);
//! Model set count has been changed
void ps_onModelSetCountChanged(int count, bool withFilter);
//! Row has been selected //! Row has been selected
void ps_onModelRowSelected(const QModelIndex &index); void ps_onModelRowSelected(const QModelIndex &index);
@@ -229,9 +232,6 @@ namespace BlackGui
//! Open model modify dialog //! Open model modify dialog
void ps_modifyModelDialog(); void ps_modifyModelDialog();
//! Own models have been changed
void ps_onOwnModelsCountChanged(int count, bool withFilter);
//! Add to own model set //! Add to own model set
void ps_addToOwnModelSet(); void ps_addToOwnModelSet();
@@ -255,7 +255,6 @@ namespace BlackGui
bool m_withVPilot = false; //!< use vPilot extensions bool m_withVPilot = false; //!< use vPilot extensions
bool m_autoFilterInDbViews = false; //!< automatically filter the DB view by the current model bool m_autoFilterInDbViews = false; //!< automatically filter the DB view by the current model
//! Init vPilot if rights and suitable //! Init vPilot if rights and suitable
void initVPilotLoading(); void initVPilotLoading();
@@ -265,6 +264,9 @@ namespace BlackGui
//! Current tab text //! Current tab text
QString currentTabText() const; QString currentTabText() const;
//! Data have been changed and the editor data might need an update
void updateEditorsWhenApplicable();
// -------------------- component specific menus -------------------------- // -------------------- component specific menus --------------------------
//! The menu for loading and handling VPilot rules for mapping tasks //! The menu for loading and handling VPilot rules for mapping tasks

View File

@@ -150,6 +150,12 @@ namespace BlackGui
return this->ui->tvp_StashAircraftModels->derivedModel()->container(); return this->ui->tvp_StashAircraftModels->derivedModel()->container();
} }
CAircraftModel CDbStashComponent::getStashedModel(const QString &modelString) const
{
if (modelString.isEmpty() || ui->tvp_StashAircraftModels->isEmpty()) { return CAircraftModel(); }
return ui->tvp_StashAircraftModels->container().findFirstByModelStringOrDefault(modelString);
}
void CDbStashComponent::applyToSelected(const CLivery &livery, bool acceptWarnings) void CDbStashComponent::applyToSelected(const CLivery &livery, bool acceptWarnings)
{ {
if (!this->ui->tvp_StashAircraftModels->hasSelection()) { return; } if (!this->ui->tvp_StashAircraftModels->hasSelection()) { return; }

View File

@@ -74,6 +74,9 @@ namespace BlackGui
//! The stashed models //! The stashed models
const BlackMisc::Simulation::CAircraftModelList &getStashedModels() const; const BlackMisc::Simulation::CAircraftModelList &getStashedModels() const;
//! Model for model string
Simulation::CAircraftModel getStashedModel(const QString &modelString) const;
//! Apply livery to selected objects //! Apply livery to selected objects
void applyToSelected(const BlackMisc::Aviation::CLivery &livery, bool acceptWarnings = true); void applyToSelected(const BlackMisc::Aviation::CLivery &livery, bool acceptWarnings = true);

View File

@@ -42,9 +42,9 @@ namespace BlackGui
CAircraftIcaoForm::~CAircraftIcaoForm() CAircraftIcaoForm::~CAircraftIcaoForm()
{ } { }
void CAircraftIcaoForm::setValue(const BlackMisc::Aviation::CAircraftIcaoCode &icao) bool CAircraftIcaoForm::setValue(const BlackMisc::Aviation::CAircraftIcaoCode &icao)
{ {
if (icao == this->m_originalCode) { return; } if (icao == this->m_originalCode) { return false; }
this->m_originalCode = icao; this->m_originalCode = icao;
this->ui->le_Id->setText(icao.getDbKeyAsString()); this->ui->le_Id->setText(icao.getDbKeyAsString());
@@ -65,6 +65,7 @@ namespace BlackGui
CGuiUtility::setComboBoxValueByStartingString(this->ui->cb_Wtc, wtc, "unspecified"); CGuiUtility::setComboBoxValueByStartingString(this->ui->cb_Wtc, wtc, "unspecified");
this->ui->le_Updated->setText(icao.getFormattedUtcTimestampYmdhms()); this->ui->le_Updated->setText(icao.getFormattedUtcTimestampYmdhms());
return true;
} }
CAircraftIcaoCode CAircraftIcaoForm::getValue() const CAircraftIcaoCode CAircraftIcaoForm::getValue() const

View File

@@ -62,7 +62,7 @@ namespace BlackGui
public slots: public slots:
//! Set value //! Set value
void setValue(const BlackMisc::Aviation::CAircraftIcaoCode &icao); bool setValue(const BlackMisc::Aviation::CAircraftIcaoCode &icao);
private slots: private slots:
//! Variant has been dropped //! Variant has been dropped

View File

@@ -39,13 +39,17 @@ namespace BlackGui
CDistributorForm::~CDistributorForm() CDistributorForm::~CDistributorForm()
{ } { }
void CDistributorForm::setValue(const BlackMisc::Simulation::CDistributor &distributor) bool CDistributorForm::setValue(const BlackMisc::Simulation::CDistributor &distributor)
{ {
const CDistributor currentDistributor(this->getValue());
if (currentDistributor == distributor) { return false; }
this->ui->distributor_Selector->setDistributor(distributor); this->ui->distributor_Selector->setDistributor(distributor);
this->ui->le_Description->setText(distributor.getDescription()); this->ui->le_Description->setText(distributor.getDescription());
this->ui->le_Alias1->setText(distributor.getAlias1()); this->ui->le_Alias1->setText(distributor.getAlias1());
this->ui->le_Alias2->setText(distributor.getAlias2()); this->ui->le_Alias2->setText(distributor.getAlias2());
this->ui->le_Updated->setText(distributor.getFormattedUtcTimestampYmdhms()); this->ui->le_Updated->setText(distributor.getFormattedUtcTimestampYmdhms());
return true;
} }
CDistributor CDistributorForm::getValue() const CDistributor CDistributorForm::getValue() const

View File

@@ -62,7 +62,7 @@ namespace BlackGui
public slots: public slots:
//! Set value //! Set value
void setValue(const BlackMisc::Simulation::CDistributor &distributor = BlackMisc::Simulation::CDistributor()); bool setValue(const BlackMisc::Simulation::CDistributor &distributor = BlackMisc::Simulation::CDistributor());
private slots: private slots:
//! Variant has been dropped //! Variant has been dropped

View File

@@ -67,9 +67,9 @@ namespace BlackGui
return this->ui->editor_AirlineIcao->getValue(); return this->ui->editor_AirlineIcao->getValue();
} }
void CLiveryForm::setValue(const CLivery &livery) bool CLiveryForm::setValue(const CLivery &livery)
{ {
if (this->m_originalLivery == livery) { return; } if (this->m_originalLivery == livery) { return false; }
this->m_originalLivery = livery; this->m_originalLivery = livery;
this->ui->comp_LiverySelector->setLivery(livery); this->ui->comp_LiverySelector->setLivery(livery);
@@ -88,6 +88,7 @@ namespace BlackGui
{ {
this->ui->editor_AirlineIcao->setValue(livery.getAirlineIcaoCode()); this->ui->editor_AirlineIcao->setValue(livery.getAirlineIcaoCode());
} }
return true;
} }
CStatusMessageList CLiveryForm::validate(bool withNestedForms) const CStatusMessageList CLiveryForm::validate(bool withNestedForms) const

View File

@@ -67,7 +67,7 @@ namespace BlackGui
public slots: public slots:
//! Value //! Value
void setValue(const BlackMisc::Aviation::CLivery &livery); bool setValue(const BlackMisc::Aviation::CLivery &livery);
private slots: private slots:
//! Livery dropped //! Livery dropped