Small improvements of auto stash component

- airline can be set in model
- fallback if there is no airline, but livery code
This commit is contained in:
Klaus Basan
2018-08-22 01:32:42 +02:00
parent 48738c87ab
commit 9ec59514dc
5 changed files with 87 additions and 56 deletions

View File

@@ -65,10 +65,10 @@ namespace BlackGui
ui->le_MaxModelsStashed->setValidator(new QIntValidator(10, CDbStashComponent::MaxModelPublished, this));
Q_ASSERT_X(this->getMappingComponent(), Q_FUNC_INFO, "Expect mapping componet");
connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CDbAutoStashingComponent::ps_entitiesRead);
connect(ui->tb_ResetDescription, &QToolButton::clicked, this, &CDbAutoStashingComponent::ps_resetDescription);
connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CDbAutoStashingComponent::onEntitiesRead);
connect(ui->tb_ResetDescription, &QToolButton::clicked, this, &CDbAutoStashingComponent::resetDescription);
this->ps_resetDescription();
this->resetDescription();
}
CDbAutoStashingComponent::~CDbAutoStashingComponent()
@@ -76,22 +76,22 @@ namespace BlackGui
void CDbAutoStashingComponent::accept()
{
switch (this->m_state)
switch (m_state)
{
case Running: return;
case Completed:
{
if (!this->m_modelsToStash.isEmpty())
if (!m_modelsToStash.isEmpty())
{
// this removes previously stashed models
this->getMappingComponent()->replaceStashedModelsUnvalidated(this->m_modelsToStash);
this->getMappingComponent()->replaceStashedModelsUnvalidated(m_modelsToStash);
if (ui->cb_RemovedChecked->isChecked())
{
this->currentModelView()->removeModelsWithModelString(this->m_modelsToStash);
this->currentModelView()->removeModelsWithModelString(m_modelsToStash);
}
const CStatusMessage stashedMsg(this, CStatusMessage::SeverityInfo, QString("Auto stashed %1 models").arg(m_modelsToStash.size()));
this->addStatusMessage(stashedMsg);
this->m_modelsToStash.clear();
m_modelsToStash.clear();
}
QDialog::accept();
break;
@@ -121,14 +121,14 @@ namespace BlackGui
this->setVisible(true);
}
void CDbAutoStashingComponent::ps_entitiesRead(CEntityFlags::Entity entity, CEntityFlags::ReadState readState, int count)
void CDbAutoStashingComponent::onEntitiesRead(CEntityFlags::Entity entity, CEntityFlags::ReadState readState, int count)
{
if (readState != CEntityFlags::ReadFinished) { return; }
Q_UNUSED(count);
Q_UNUSED(entity);
}
void CDbAutoStashingComponent::ps_resetDescription()
void CDbAutoStashingComponent::resetDescription()
{
ui->rb_DescriptionEmptyOnly->setChecked(true);
ui->le_Description->setText(CAircraftModel::autoGenerated());
@@ -136,12 +136,12 @@ namespace BlackGui
void CDbAutoStashingComponent::initGui()
{
this->m_state = Idle;
m_state = Idle;
ui->bb_AutoStashing->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
ui->tvp_StatusMessages->clear();
this->m_noData = 0;
this->m_noValidationFailed = 0;
this->m_noStashed = 0;
m_noData = 0;
m_noValidationFailed = 0;
m_noStashed = 0;
this->updateProgressIndicator(0);
if (!this->currentModelView())
@@ -182,9 +182,9 @@ namespace BlackGui
if (percent > 100) { percent = 100; }
if (percent < 0) { percent = 0; }
ui->pb_StashingProgress->setValue(percent);
ui->le_Stashed->setText(QString::number(this->m_noStashed));
ui->le_NoData->setText(QString::number(this->m_noData));
ui->le_ValidationFailed->setText(QString::number(this->m_noValidationFailed));
ui->le_Stashed->setText(QString::number(m_noStashed));
ui->le_NoData->setText(QString::number(m_noData));
ui->le_ValidationFailed->setText(QString::number(m_noValidationFailed));
}
int CDbAutoStashingComponent::getSelectedOrAllCount() const
@@ -231,9 +231,10 @@ namespace BlackGui
Q_ASSERT_X(this->currentModelView(), Q_FUNC_INFO, "No view");
const CAircraftModelList models(ui->rb_Selected->isChecked() ? this->currentModelView()->selectedObjects() : this->currentModelView()->containerOrFilteredContainer());
if (models.isEmpty()) { return; }
if (!sGui || sGui->isShuttingDown()) { return; }
// we have data and are good to go
this->m_state = Running;
m_state = Running;
const int all = models.size();
// maximum
@@ -284,16 +285,15 @@ namespace BlackGui
this->updateProgressIndicator(100);
sGui->processEventsToRefreshGui();
const CStatusMessage stashedMsg(this, CStatusMessage::SeverityInfo, QString("Ready to auto stashed %1 models").arg(autoStashed.size()));
const CStatusMessage stashedMsg(this, CStatusMessage::SeverityInfo, QString("Ready to auto stash %1 models").arg(autoStashed.size()));
this->addStatusMessage(stashedMsg);
this->m_modelsToStash = autoStashed;
this->m_state = Completed;
m_modelsToStash = autoStashed;
m_state = Completed;
}
bool CDbAutoStashingComponent::tryToStashModel(CAircraftModel &model, const CLivery &tempLivery)
{
const bool useTempLivery = tempLivery.isLoadedFromDb();
bool stashed = false;
// no airline and no livery, here replaced by temp livery
if (useTempLivery && !model.hasAirlineDesignator() && !model.getLivery().hasValidDbKey())
@@ -305,39 +305,60 @@ namespace BlackGui
if (!model.hasModelString())
{
this->addStatusMessage(CStatusMessage(this, CStatusMessage::SeverityError, "No model string"));
this->m_noData++;
m_noData++;
return false;
}
else if (!model.hasAircraftDesignator())
if (!model.hasAircraftDesignator())
{
this->addStatusMessage(CStatusMessage(this, CStatusMessage::SeverityError, "No aircraft designator"), model);
this->m_noData++;
m_noData++;
return false;
}
else if (!model.hasAirlineDesignator() && !model.getLivery().hasValidDbKey())
if (!model.hasAirlineDesignator() && !model.getLivery().hasValidDbKey())
{
// no valid airline and NO DB livery
// we try one fallback
const QString liveryCombinedCode = model.getLivery().getCombinedCode();
bool fallback = false;
if (liveryCombinedCode.length() == 3 || liveryCombinedCode.length() == 4)
{
// could we use the combined code as airline
if (CAirlineIcaoCode::isValidAirlineDesignator(liveryCombinedCode))
{
model.setAirlineIcaoDesignator(liveryCombinedCode);
fallback = true;
}
}
// if there is no livery (normal) we need an airline
this->addStatusMessage(CStatusMessage(this, CStatusMessage::SeverityError, "No airline designator"), model);
this->m_noData++;
if (!fallback)
{
this->addStatusMessage(CStatusMessage(this, CStatusMessage::SeverityError, "No airline designator"), model);
m_noData++;
return false;
}
}
// stash here consolidates with DB data and validates
bool stashed = false;
const CAircraftModel stashModel(this->getMappingComponent()->consolidateModel(model));
CStatusMessageList validationMsgs(stashModel.validate(true));
validationMsgs.removeWarningsAndBelow();
CStatusMessage msg = validationMsgs.toSingleMessage();
if (msg.getSeverity() == CStatusMessage::SeverityError)
{
m_noValidationFailed++;
}
else
{
// stash here consolidates with DB data and validates
CAircraftModel stashModel(this->getMappingComponent()->consolidateModel(model));
CStatusMessageList validationMsgs(stashModel.validate(true));
validationMsgs.removeWarningsAndBelow();
CStatusMessage msg = validationMsgs.toSingleMessage();
if (msg.getSeverity() == CStatusMessage::SeverityError)
{
this->m_noValidationFailed++;
}
else
{
msg = CStatusMessage(this, CStatusMessage::SeverityInfo, "Stashed succesfully");
stashed = true;
this->m_noStashed++;
model = stashModel;
}
this->addStatusMessage(msg, stashModel);
msg = CStatusMessage(this, CStatusMessage::SeverityInfo, "Stashed succesfully");
stashed = true;
m_noStashed++;
model = stashModel;
}
this->addStatusMessage(msg, stashModel);
return stashed;
}