From be94da004892b183694b047eeb0b3e6e524b8cbd Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 2 Oct 2016 23:51:48 +0200 Subject: [PATCH] refs #743, adjustments of auto stashing dialog * using BlackCore::IProgressIndicator * log categories --- .../components/dbautostashingcomponent.cpp | 77 ++++---- .../components/dbautostashingcomponent.h | 16 +- .../components/dbautostashingcomponent.ui | 164 ++++++++++-------- 3 files changed, 144 insertions(+), 113 deletions(-) diff --git a/src/blackgui/components/dbautostashingcomponent.cpp b/src/blackgui/components/dbautostashingcomponent.cpp index b683491d3..a076f9f6e 100644 --- a/src/blackgui/components/dbautostashingcomponent.cpp +++ b/src/blackgui/components/dbautostashingcomponent.cpp @@ -48,6 +48,12 @@ namespace BlackGui { namespace Components { + const CLogCategoryList &CDbAutoStashingComponent::getLogCategories() + { + static const BlackMisc::CLogCategoryList cats { CLogCategory::mapping(), CLogCategory::guiComponent() }; + return cats; + } + CDbAutoStashingComponent::CDbAutoStashingComponent(QWidget *parent) : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint), CDbMappingComponentAware(qobject_cast(parent)), @@ -60,7 +66,7 @@ namespace BlackGui 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); + connect(ui->tb_ResetDescription, &QToolButton::clicked, this, &CDbAutoStashingComponent::ps_resetDescription); this->ps_resetDescription(); } @@ -70,30 +76,37 @@ namespace BlackGui void CDbAutoStashingComponent::accept() { - if (m_state == Running) { return; } - if (m_state == Completed) + switch (this->m_state) { - if (!this->m_modelsToStash.isEmpty()) + case Running: return; + case Completed: { - // this removes previously stashed models - this->getMappingComponent()->replaceStashedModelsUnvalidated(this->m_modelsToStash); - if (ui->cb_RemovedChecked->isChecked()) + if (!this->m_modelsToStash.isEmpty()) { - this->currentModelView()->removeModelsWithModelString(this->m_modelsToStash); + // this removes previously stashed models + this->getMappingComponent()->replaceStashedModelsUnvalidated(this->m_modelsToStash); + if (ui->cb_RemovedChecked->isChecked()) + { + this->currentModelView()->removeModelsWithModelString(this->m_modelsToStash); + } + const CStatusMessage stashedMsg(this, CStatusMessage::SeverityInfo, QString("Auto stashed %1 models").arg(m_modelsToStash.size())); + this->addStatusMessage(stashedMsg); + this->m_modelsToStash.clear(); } - const CStatusMessage stashedMsg(categgories(), CStatusMessage::SeverityInfo, QString("Auto stashed %1 models").arg(m_modelsToStash.size())); - this->addStatusMessage(stashedMsg); - this->m_modelsToStash.clear(); + QDialog::accept(); + break; + } + default: + { + if (this->getSelectedOrAllCount() < 1) + { + const CStatusMessage m(this, CStatusMessage::SeverityError, "No data, nothing to do"); + this->addStatusMessage(m); + QDialog::accept(); + } + this->tryToStashModels(); } - QDialog::accept(); } - if (this->getSelectedOrAllCount() < 1) - { - const CStatusMessage m(categgories(), CStatusMessage::SeverityError, "No data, nothing to do"); - this->addStatusMessage(m); - QDialog::accept(); - } - this->tryToStashModels(); } int CDbAutoStashingComponent::exec() @@ -129,11 +142,11 @@ namespace BlackGui this->m_noData = 0; this->m_noValidationFailed = 0; this->m_noStashed = 0; - this->updateGuiValues(0); + this->updateProgressIndicator(0); if (!this->currentModelView()) { - const CStatusMessage m(categgories(), CStatusMessage::SeverityError, "No data for auto stashing"); + const CStatusMessage m(this, CStatusMessage::SeverityError, "No data for auto stashing"); this->addStatusMessage(m); } else @@ -164,7 +177,7 @@ namespace BlackGui } } - void CDbAutoStashingComponent::updateGuiValues(int percent) + void CDbAutoStashingComponent::updateProgressIndicator(int percent) { if (percent > 100) { percent = 100; } if (percent < 0) { percent = 0; } @@ -262,15 +275,15 @@ namespace BlackGui int maxPercent = autoStashed.size() * 100 / max; if (maxPercent > percent) { percent = maxPercent; } } - this->updateGuiValues(percent); + this->updateProgressIndicator(percent); } if (autoStashed.size() >= max) { break; } } - this->updateGuiValues(100); + this->updateProgressIndicator(100); sGui->processEventsToRefreshGui(); - const CStatusMessage stashedMsg(categgories(), CStatusMessage::SeverityInfo, QString("Ready to auto stashed %1 models").arg(autoStashed.size())); + const CStatusMessage stashedMsg(this, CStatusMessage::SeverityInfo, QString("Ready to auto stashed %1 models").arg(autoStashed.size())); this->addStatusMessage(stashedMsg); this->m_modelsToStash = autoStashed; this->m_state = Completed; @@ -290,18 +303,18 @@ namespace BlackGui //! Some upfront tests if (!model.hasModelString()) { - this->addStatusMessage(CStatusMessage(this->categgories(), CStatusMessage::SeverityError, "No model string")); + this->addStatusMessage(CStatusMessage(this, CStatusMessage::SeverityError, "No model string")); this->m_noData++; } else if (!model.hasAircraftDesignator()) { - this->addStatusMessage(CStatusMessage(this->categgories(), CStatusMessage::SeverityError, "No aircraft designator"), model); + this->addStatusMessage(CStatusMessage(this, CStatusMessage::SeverityError, "No aircraft designator"), model); this->m_noData++; } else if (!model.hasAirlineDesignator() && !model.getLivery().hasValidDbKey()) { // if there is no livery (normal) we need an airline - this->addStatusMessage(CStatusMessage(this->categgories(), CStatusMessage::SeverityError, "No airline designator"), model); + this->addStatusMessage(CStatusMessage(this, CStatusMessage::SeverityError, "No airline designator"), model); this->m_noData++; } else @@ -317,7 +330,7 @@ namespace BlackGui } else { - msg = CStatusMessage(categgories(), CStatusMessage::SeverityInfo, "Stashed succesfully"); + msg = CStatusMessage(this, CStatusMessage::SeverityInfo, "Stashed succesfully"); stashed = true; this->m_noStashed++; model = stashModel; @@ -347,11 +360,5 @@ namespace BlackGui 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()})); - return cats; - } } // ns } // ns diff --git a/src/blackgui/components/dbautostashingcomponent.h b/src/blackgui/components/dbautostashingcomponent.h index e64f36377..1c07bcecd 100644 --- a/src/blackgui/components/dbautostashingcomponent.h +++ b/src/blackgui/components/dbautostashingcomponent.h @@ -14,6 +14,7 @@ #include "blackgui/blackguiexport.h" #include "blackgui/components/dbmappingcomponentaware.h" +#include "blackcore/progress.h" #include "blackmisc/network/entityflags.h" #include "blackmisc/simulation/aircraftmodellist.h" #include "blackmisc/statusmessage.h" @@ -40,7 +41,8 @@ namespace BlackGui */ class BLACKGUI_EXPORT CDbAutoStashingComponent : public QDialog, - public BlackGui::Components::CDbMappingComponentAware + public BlackGui::Components::CDbMappingComponentAware, + public BlackCore::IProgressIndicator { Q_OBJECT @@ -53,6 +55,9 @@ namespace BlackGui Completed }; + //! Log categories + static const BlackMisc::CLogCategoryList &getLogCategories(); + //! Constructor explicit CDbAutoStashingComponent(QWidget *parent = nullptr); @@ -62,6 +67,9 @@ namespace BlackGui //! At least run once and completed bool isCompleted() const { return m_state == Completed; } + //! \copydoc BlackCore::IProgressIndicator::updateProgressIndicator + virtual void updateProgressIndicator(int percent) override; + public slots: //! \copydoc QDialog::accept virtual void accept() override; @@ -85,9 +93,6 @@ namespace BlackGui //! Init the component void initGui(); - //! Update GUI values - void updateGuiValues(int percent); - //! Number of all or selected models int getSelectedOrAllCount() const; @@ -114,9 +119,6 @@ namespace BlackGui //! Get the temp.livery if available static BlackMisc::Aviation::CLivery getTempLivery(); - //! Categories - const BlackMisc::CLogCategoryList &categgories(); - int m_noStashed = 0; //!< stashed models int m_noData = 0; //!< not stashed because no data int m_noValidationFailed = 0; //!< not stashed because validation failed diff --git a/src/blackgui/components/dbautostashingcomponent.ui b/src/blackgui/components/dbautostashingcomponent.ui index 0702722a1..d53f5c6c3 100644 --- a/src/blackgui/components/dbautostashingcomponent.ui +++ b/src/blackgui/components/dbautostashingcomponent.ui @@ -6,10 +6,16 @@ 0 0 - 453 - 413 + 600 + 416 + + + 600 + 400 + + Auto stashing @@ -36,7 +42,7 @@ - All: + all @@ -50,16 +56,6 @@ - - - - 255 - - - Override description in model - - - @@ -73,7 +69,7 @@ - Selected: + selected true @@ -158,58 +154,6 @@ - - - - max.models to be stashed - - - - - - - - 2 - - - 1 - - - 2 - - - 1 - - - - - all - - - - - - - apply only if description is empty - - - empty only - - - true - - - - - - - - - - reset description - - - @@ -251,13 +195,92 @@ - + + + + max.models to be stashed + + + + + + + 255 + + + Override description in model + + + + use 'temp' livery if not resolved + + + + + 2 + + + 1 + + + 2 + + + 1 + + + + + all + + + + + + + apply only if description is empty + + + empty only + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + reset description + + + + :/diagona/icons/diagona/icons/cross-white.png:/diagona/icons/diagona/icons/cross-white.png + + + + + + @@ -275,10 +298,7 @@ rb_All le_All le_MaxModelsStashed - pb_ResetDescription le_Description - rb_DescriptionAll - rb_DescriptionEmptyOnly cb_UseTempLivery tvp_StatusMessages le_Stashed @@ -286,7 +306,9 @@ le_ValidationFailed cb_RemovedChecked - + + + bb_AutoStashing