diff --git a/src/blackgui/components/dbautostashingcomponent.cpp b/src/blackgui/components/dbautostashingcomponent.cpp index 8f2f4e2ed..b683491d3 100644 --- a/src/blackgui/components/dbautostashingcomponent.cpp +++ b/src/blackgui/components/dbautostashingcomponent.cpp @@ -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()})); diff --git a/src/blackgui/components/dbautostashingcomponent.h b/src/blackgui/components/dbautostashingcomponent.h index cd6b48cce..e64f36377 100644 --- a/src/blackgui/components/dbautostashingcomponent.h +++ b/src/blackgui/components/dbautostashingcomponent.h @@ -30,11 +30,9 @@ namespace BlackMisc namespace Simulation { class CAircraftModel; } } namespace Ui { class CDbAutoStashingComponent; } - namespace BlackGui { namespace Views { class CAircraftModelView; } - namespace Components { /*! @@ -78,6 +76,9 @@ namespace BlackGui //! Data have been read void ps_entitiesRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState readState, int count); + //! Reset the description settings + void ps_resetDescription(); + private: QScopedPointer ui; @@ -105,7 +106,13 @@ namespace BlackGui //! Try stashing a model //! \param model this model can be updated with consolidated data //! \return true means stashing is possible - bool tryToStashModel(BlackMisc::Simulation::CAircraftModel &model); + bool tryToStashModel(BlackMisc::Simulation::CAircraftModel &model, const BlackMisc::Aviation::CLivery &tempLivery); + + //! Set the model description + void setModelDescription(BlackMisc::Simulation::CAircraftModel &model, const QString &description) const; + + //! Get the temp.livery if available + static BlackMisc::Aviation::CLivery getTempLivery(); //! Categories const BlackMisc::CLogCategoryList &categgories(); diff --git a/src/blackgui/components/dbautostashingcomponent.ui b/src/blackgui/components/dbautostashingcomponent.ui index 94656fade..0702722a1 100644 --- a/src/blackgui/components/dbautostashingcomponent.ui +++ b/src/blackgui/components/dbautostashingcomponent.ui @@ -6,8 +6,8 @@ 0 0 - 420 - 357 + 453 + 413 @@ -16,48 +16,14 @@ - - - - 0 - - - - - - - true - - - all - - - - - + + - Remove stashed - - - true + Description: - - - - Max stashed: - - - - - - - max.models stashed - - - - + QAbstractItemView::NoSelection @@ -67,7 +33,14 @@ - + + + + All: + + + + Qt::Horizontal @@ -77,10 +50,13 @@ - - - - All: + + + + 255 + + + Override description in model @@ -94,23 +70,6 @@ - - - - Description: - - - - - - - 255 - - - Override description in model - - - @@ -121,7 +80,7 @@ - + QFrame::StyledPanel @@ -199,6 +158,106 @@ + + + + max.models to be stashed + + + + + + + + 2 + + + 1 + + + 2 + + + 1 + + + + + all + + + + + + + apply only if description is empty + + + empty only + + + true + + + + + + + + + + reset description + + + + + + + 0 + + + + + + + Max stashed: + + + + + + + true + + + all + + + + + + + Remove stashed + + + true + + + + + + + Livery: + + + + + + + use 'temp' livery if not resolved + + + @@ -210,6 +269,23 @@
blackgui/views/statusmessageview.h
+ + rb_Selected + le_Selected + rb_All + le_All + le_MaxModelsStashed + pb_ResetDescription + le_Description + rb_DescriptionAll + rb_DescriptionEmptyOnly + cb_UseTempLivery + tvp_StatusMessages + le_Stashed + le_NoData + le_ValidationFailed + cb_RemovedChecked +