refs #745, allow to decide which descriptions are overridden in auto stashing

* adjusted CAircraftModel to ignore auto generated message
* radio buttons in GUI to select all/non-empty descriptions
* allow to use the temp. livery
This commit is contained in:
Klaus Basan
2016-08-27 00:35:30 +02:00
parent 58faed5ea7
commit a49b98166c
3 changed files with 222 additions and 95 deletions

View File

@@ -39,6 +39,7 @@
using namespace BlackCore;
using namespace BlackMisc;
using namespace BlackMisc::Aviation;
using namespace BlackMisc::Network;
using namespace BlackMisc::Simulation;
using namespace BlackGui::Views;
@@ -53,12 +54,15 @@ namespace BlackGui
ui(new Ui::CDbAutoStashingComponent)
{
ui->setupUi(this);
this->ui->tvp_StatusMessages->setResizeMode(CAircraftModelView::ResizingAuto);
this->ui->tvp_StatusMessages->menuAddItems(CAircraftModelView::MenuSave);
this->ui->le_MaxModelsStashed->setValidator(new QIntValidator(10, CDbStashComponent::MaxModelPublished, this));
ui->tvp_StatusMessages->setResizeMode(CAircraftModelView::ResizingAuto);
ui->tvp_StatusMessages->menuAddItems(CAircraftModelView::MenuSave);
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->pb_ResetDescription, &QPushButton::clicked, this, &CDbAutoStashingComponent::ps_resetDescription);
this->ps_resetDescription();
}
CDbAutoStashingComponent::~CDbAutoStashingComponent()
@@ -73,7 +77,7 @@ namespace BlackGui
{
// this removes previously stashed models
this->getMappingComponent()->replaceStashedModelsUnvalidated(this->m_modelsToStash);
if (this->ui->cb_RemovedChecked->isChecked())
if (ui->cb_RemovedChecked->isChecked())
{
this->currentModelView()->removeModelsWithModelString(this->m_modelsToStash);
}
@@ -100,7 +104,7 @@ namespace BlackGui
void CDbAutoStashingComponent::showLastResults()
{
this->ui->bb_AutoStashing->setStandardButtons(QDialogButtonBox::Close);
ui->bb_AutoStashing->setStandardButtons(QDialogButtonBox::Close);
this->setVisible(true);
}
@@ -111,11 +115,17 @@ namespace BlackGui
Q_UNUSED(entity);
}
void CDbAutoStashingComponent::ps_resetDescription()
{
ui->rb_DescriptionEmptyOnly->setChecked(true);
ui->le_Description->setText(CAircraftModel::autoGenerated());
}
void CDbAutoStashingComponent::initGui()
{
this->m_state = Idle;
this->ui->bb_AutoStashing->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
this->ui->tvp_StatusMessages->clear();
ui->bb_AutoStashing->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
ui->tvp_StatusMessages->clear();
this->m_noData = 0;
this->m_noValidationFailed = 0;
this->m_noStashed = 0;
@@ -130,26 +140,26 @@ namespace BlackGui
{
int selected = this->currentModelView()->selectedRowCount();
int all = this->currentModelView()->rowCount();
this->ui->le_Selected->setText(QString::number(selected));
ui->le_Selected->setText(QString::number(selected));
QString allStr(QString::number(all));
if (all > CDbStashComponent::MaxModelPublished)
{
allStr += " (Max." + QString::number(CDbStashComponent::MaxModelPublished) + ")";
}
this->ui->le_All->setText(allStr);
if (this->ui->le_MaxModelsStashed->text().isEmpty())
ui->le_All->setText(allStr);
if (ui->le_MaxModelsStashed->text().isEmpty())
{
this->ui->le_MaxModelsStashed->setText(all > 100 ? "100" : "");
ui->le_MaxModelsStashed->setText(all > 100 ? "100" : "");
}
if (selected > 0)
{
this->ui->rb_Selected->setChecked(true);
this->ui->rb_Selected->setEnabled(true);
ui->rb_Selected->setChecked(true);
ui->rb_Selected->setEnabled(true);
}
else
{
this->ui->rb_All->setChecked(true);
this->ui->rb_Selected->setEnabled(false);
ui->rb_All->setChecked(true);
ui->rb_Selected->setEnabled(false);
}
}
}
@@ -158,16 +168,16 @@ namespace BlackGui
{
if (percent > 100) { percent = 100; }
if (percent < 0) { percent = 0; }
this->ui->pb_StashingProgress->setValue(percent);
this->ui->le_Stashed->setText(QString::number(this->m_noStashed));
this->ui->le_NoData->setText(QString::number(this->m_noData));
this->ui->le_ValidationFailed->setText(QString::number(this->m_noValidationFailed));
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));
}
int CDbAutoStashingComponent::getSelectedOrAllCount() const
{
if (!this->currentModelView()) { return 0; }
if (this->ui->rb_Selected->isChecked())
if (ui->rb_Selected->isChecked())
{
return this->currentModelView()->selectedRowCount();
}
@@ -185,7 +195,7 @@ namespace BlackGui
void CDbAutoStashingComponent::addStatusMessage(const CStatusMessage &msg)
{
if (msg.isEmpty()) { return; }
this->ui->tvp_StatusMessages->insert(msg);
ui->tvp_StatusMessages->insert(msg);
}
void CDbAutoStashingComponent::addStatusMessage(const CStatusMessage &msg, const CAircraftModel &model)
@@ -195,18 +205,18 @@ namespace BlackGui
{
CStatusMessage prefixMessage(msg);
prefixMessage.prependMessage(QString(model.getModelString() + ", " + model.getMembersDbStatus() + ": "));
this->ui->tvp_StatusMessages->insert(prefixMessage);
ui->tvp_StatusMessages->insert(prefixMessage);
}
else
{
this->ui->tvp_StatusMessages->insert(msg);
ui->tvp_StatusMessages->insert(msg);
}
}
void CDbAutoStashingComponent::tryToStashModels()
{
Q_ASSERT_X(this->currentModelView(), Q_FUNC_INFO, "No view");
const CAircraftModelList models(this->ui->rb_Selected->isChecked() ? this->currentModelView()->selectedObjects() : this->currentModelView()->containerOrFilteredContainer());
const CAircraftModelList models(ui->rb_Selected->isChecked() ? this->currentModelView()->selectedObjects() : this->currentModelView()->containerOrFilteredContainer());
if (models.isEmpty()) { return; }
// we have data and are good to go
@@ -214,23 +224,29 @@ namespace BlackGui
const int all = models.size();
// maximum
const QString maxStr(this->ui->le_MaxModelsStashed->text());
const QString maxStr(ui->le_MaxModelsStashed->text());
bool okMaxStr = true;
int max = maxStr.isEmpty() ? CDbStashComponent::MaxModelPublished : maxStr.toInt(&okMaxStr);
if (!okMaxStr || max > all) { max = all; }
// override description
const QString description(this->ui->le_Description->text().trimmed());
const QString description(ui->le_Description->text().trimmed());
// temp livery if applicable
const CLivery tempLivery(ui->cb_UseTempLivery->isChecked() ? getTempLivery() : CLivery());
int c = 0;
CAircraftModelList autoStashed;
for (const CAircraftModel &model : models)
{
CAircraftModel stashModel(model);
bool stashed = this->tryToStashModel(stashModel);
const bool stashed = this->tryToStashModel(stashModel, tempLivery);
if (stashed)
{
if (!description.isEmpty()) { stashModel.setDescription(description); }
if (!description.isEmpty())
{
this->setModelDescription(stashModel, description);
}
autoStashed.push_back(stashModel);
}
@@ -260,10 +276,17 @@ namespace BlackGui
this->m_state = Completed;
}
bool CDbAutoStashingComponent::tryToStashModel(CAircraftModel &model)
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())
{
model.setLivery(tempLivery);
}
//! Some upfront tests
if (!model.hasModelString())
{
@@ -304,6 +327,27 @@ namespace BlackGui
return stashed;
}
void CDbAutoStashingComponent::setModelDescription(CAircraftModel &model, const QString &description) const
{
if (description.isEmpty()) { return; }
if (ui->rb_All->isChecked())
{
model.setDescription(description);
}
else
{
// only for "empty" ones
if (model.hasDescription(true)) { return; }
model.setDescription(description);
}
}
BlackMisc::Aviation::CLivery CDbAutoStashingComponent::getTempLivery()
{
if (!sGui || !sGui->hasWebDataServices()) { return CLivery(); }
return sGui->getWebDataServices()->getTempLiveryOrDefault();
}
const CLogCategoryList &CDbAutoStashingComponent::categgories()
{
static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::guiComponent() }).join({ CLogCategory::mapping()}));