From e810dfecf59283ee21289419c29e90c84990f282 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 29 Dec 2018 10:02:02 +0100 Subject: [PATCH] Ref T489, display read state in model component for livery, airline, aircraft * similar to model component * distributor/countries too few data to benefit, hence not implemented --- .../components/dbaircrafticaocomponent.cpp | 22 ++++++++++++++++--- .../components/dbaircrafticaocomponent.h | 13 ++++++----- .../components/dbairlineicaocomponent.cpp | 20 +++++++++++++++-- .../components/dbairlineicaocomponent.h | 8 +++++-- src/blackgui/components/dbliverycomponent.cpp | 20 +++++++++++++++-- src/blackgui/components/dbliverycomponent.h | 13 ++++++----- 6 files changed, 75 insertions(+), 21 deletions(-) diff --git a/src/blackgui/components/dbaircrafticaocomponent.cpp b/src/blackgui/components/dbaircrafticaocomponent.cpp index 18799eb01..a6171bd3a 100644 --- a/src/blackgui/components/dbaircrafticaocomponent.cpp +++ b/src/blackgui/components/dbaircrafticaocomponent.cpp @@ -18,6 +18,7 @@ #include #include +#include using namespace BlackCore; using namespace BlackMisc::Network; @@ -30,19 +31,20 @@ namespace BlackGui namespace Components { CDbAircraftIcaoComponent::CDbAircraftIcaoComponent(QWidget *parent) : - QFrame(parent), + COverlayMessagesFrame(parent), ui(new Ui::CDbAircraftIcaoComponent) { ui->setupUi(this); this->setViewWithIndicator(ui->tvp_AircraftIcao); ui->tvp_AircraftIcao->setResizeMode(CAircraftIcaoCodeView::ResizingOff); - connect(ui->tvp_AircraftIcao, &CAircraftIcaoCodeView::requestNewBackendData, this, &CDbAircraftIcaoComponent::onReload); ui->tvp_AircraftIcao->allowDragDrop(true, false); ui->tvp_AircraftIcao->setFilterWidget(ui->filter_AircraftIcao); ui->tvp_AircraftIcao->menuAddItems(CViewBaseNonTemplate::MenuCopy); + connect(ui->tvp_AircraftIcao, &CAircraftIcaoCodeView::requestNewBackendData, this, &CDbAircraftIcaoComponent::onReload); connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CDbAircraftIcaoComponent::onIcaoRead, Qt::QueuedConnection); + connect(sGui->getWebDataServices(), &CWebDataServices::entityDownloadProgress, this, &CDbAircraftIcaoComponent::onEntityDownloadProgress, Qt::QueuedConnection); this->onIcaoRead(CEntityFlags::AircraftIcaoEntity, CEntityFlags::ReadFinished, sGui->getWebDataServices()->getAircraftIcaoCodesCount()); } @@ -63,10 +65,24 @@ namespace BlackGui { Q_UNUSED(count); if (!sGui || sGui->isShuttingDown() || !sGui->getWebDataServices()) { return; } - if (entity.testFlag(CEntityFlags::AircraftIcaoEntity) && CEntityFlags::isFinishedReadState(readState)) + if (!entity.testFlag(CEntityFlags::AircraftIcaoEntity) && CEntityFlags::isFinishedReadState(readState)) { return; } + + if (CEntityFlags::isFinishedReadState(readState)) { + this->showOverlayHTMLMessage(QStringLiteral("Updating"), 2000); ui->tvp_AircraftIcao->updateContainerMaybeAsync(sGui->getWebDataServices()->getAircraftIcaoCodes()); } + else + { + this->showOverlayHTMLMessage(u"Current state: " % CEntityFlags::stateToString(readState), 10000); + } + } + + void CDbAircraftIcaoComponent::onEntityDownloadProgress(CEntityFlags::Entity entity, int logId, int progress, qint64 current, qint64 max, const QUrl &url) + { + if (CEntityFlags::AircraftIcaoEntity != entity) { return; } + this->showDownloadProgress(progress, current, max, url, 5000); + Q_UNUSED(logId); } void CDbAircraftIcaoComponent::onReload() diff --git a/src/blackgui/components/dbaircrafticaocomponent.h b/src/blackgui/components/dbaircrafticaocomponent.h index bbead5c11..5b0ef33b9 100644 --- a/src/blackgui/components/dbaircrafticaocomponent.h +++ b/src/blackgui/components/dbaircrafticaocomponent.h @@ -12,19 +12,18 @@ #ifndef BLACKGUI_COMPONENTS_DBAIRCRAFTICAOCOMPONENT_H #define BLACKGUI_COMPONENTS_DBAIRCRAFTICAOCOMPONENT_H -#include "blackgui/blackguiexport.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" +#include "blackgui/overlaymessagesframe.h" #include "blackgui/enableforviewbasedindicator.h" +#include "blackgui/blackguiexport.h" #include "blackmisc/network/entityflags.h" #include #include #include -class QWidget; - -namespace BlackMisc { namespace Aviation { class CAircraftIcaoCode; } } namespace Ui { class CDbAircraftIcaoComponent; } +namespace BlackMisc { namespace Aviation { class CAircraftIcaoCode; } } namespace BlackGui { namespace Views { class CAircraftIcaoCodeView; } @@ -34,7 +33,7 @@ namespace BlackGui * DB aircraft ICAO data */ class BLACKGUI_EXPORT CDbAircraftIcaoComponent : - public QFrame, + public COverlayMessagesFrame, public CEnableForDockWidgetInfoArea, public CEnableForViewBasedIndicator { @@ -50,7 +49,6 @@ namespace BlackGui //! Get the view BlackGui::Views::CAircraftIcaoCodeView *view() const; - public slots: //! Filter by ICAO as default void filter(const BlackMisc::Aviation::CAircraftIcaoCode &icao); @@ -58,6 +56,9 @@ namespace BlackGui //! ICAO codes have been read void onIcaoRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState readState, int count); + //! Download progress for an entity + void onEntityDownloadProgress(BlackMisc::Network::CEntityFlags::Entity entity, int logId, int progress, qint64 current, qint64 max, const QUrl &url); + //! Reload models void onReload(); diff --git a/src/blackgui/components/dbairlineicaocomponent.cpp b/src/blackgui/components/dbairlineicaocomponent.cpp index 9d737e749..68d6307ed 100644 --- a/src/blackgui/components/dbairlineicaocomponent.cpp +++ b/src/blackgui/components/dbairlineicaocomponent.cpp @@ -17,6 +17,7 @@ #include #include +#include using namespace BlackCore; using namespace BlackMisc::Network; @@ -28,7 +29,7 @@ namespace BlackGui namespace Components { CDbAirlineIcaoComponent::CDbAirlineIcaoComponent(QWidget *parent) : - QFrame(parent), + COverlayMessagesFrame(parent), ui(new Ui::CDbAirlineIcaoComponent) { Q_ASSERT_X(sGui, Q_FUNC_INFO, "Missing sGui"); @@ -43,6 +44,7 @@ namespace BlackGui connect(ui->tvp_AirlineIcao, &CAirlineIcaoCodeView::requestNewBackendData, this, &CDbAirlineIcaoComponent::onReload); connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CDbAirlineIcaoComponent::onIcaoRead, Qt::QueuedConnection); + connect(sGui->getWebDataServices(), &CWebDataServices::entityDownloadProgress, this, &CDbAirlineIcaoComponent::onEntityDownloadProgress, Qt::QueuedConnection); this->onIcaoRead(CEntityFlags::AirlineIcaoEntity, CEntityFlags::ReadFinished, sGui->getWebDataServices()->getAirlineIcaoCodesCount()); } @@ -58,10 +60,24 @@ namespace BlackGui { Q_UNUSED(count); if (!sGui || sGui->isShuttingDown() || !sGui->hasWebDataServices()) { return; } - if (entity.testFlag(CEntityFlags::AirlineIcaoEntity) && CEntityFlags::isFinishedReadState(readState)) + if (!entity.testFlag(CEntityFlags::AirlineIcaoEntity) && CEntityFlags::isFinishedReadState(readState)) { return; } + + if (CEntityFlags::isFinishedReadState(readState)) { + this->showOverlayHTMLMessage(QStringLiteral("Updating"), 2000); ui->tvp_AirlineIcao->updateContainerMaybeAsync(sGui->getWebDataServices()->getAirlineIcaoCodes()); } + else + { + this->showOverlayHTMLMessage(u"Current state: " % CEntityFlags::stateToString(readState), 10000); + } + } + + void CDbAirlineIcaoComponent::onEntityDownloadProgress(CEntityFlags::Entity entity, int logId, int progress, qint64 current, qint64 max, const QUrl &url) + { + if (CEntityFlags::AirlineIcaoEntity != entity) { return; } + this->showDownloadProgress(progress, current, max, url, 5000); + Q_UNUSED(logId); } void CDbAirlineIcaoComponent::onReload() diff --git a/src/blackgui/components/dbairlineicaocomponent.h b/src/blackgui/components/dbairlineicaocomponent.h index 36ee8542f..ece80dd13 100644 --- a/src/blackgui/components/dbairlineicaocomponent.h +++ b/src/blackgui/components/dbairlineicaocomponent.h @@ -12,9 +12,10 @@ #ifndef BLACKGUI_COMPONENTS_DBAIRLINEICAOCOMPONENT_H #define BLACKGUI_COMPONENTS_DBAIRLINEICAOCOMPONENT_H -#include "blackgui/blackguiexport.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" +#include "blackgui/overlaymessagesframe.h" #include "blackgui/enableforviewbasedindicator.h" +#include "blackgui/blackguiexport.h" #include "blackmisc/network/entityflags.h" #include @@ -31,7 +32,7 @@ namespace BlackGui * Airline ICAO code */ class BLACKGUI_EXPORT CDbAirlineIcaoComponent : - public QFrame, + public COverlayMessagesFrame, public CEnableForDockWidgetInfoArea, public CEnableForViewBasedIndicator { @@ -51,6 +52,9 @@ namespace BlackGui //! ICAO codes have been read void onIcaoRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState readState, int count); + //! Download progress for an entity + void onEntityDownloadProgress(BlackMisc::Network::CEntityFlags::Entity entity, int logId, int progress, qint64 current, qint64 max, const QUrl &url); + //! Reload models void onReload(); diff --git a/src/blackgui/components/dbliverycomponent.cpp b/src/blackgui/components/dbliverycomponent.cpp index 2d1d54b37..afd5ac8d6 100644 --- a/src/blackgui/components/dbliverycomponent.cpp +++ b/src/blackgui/components/dbliverycomponent.cpp @@ -16,6 +16,7 @@ #include "ui_dbliverycomponent.h" #include +#include using namespace BlackCore; using namespace BlackGui::Views; @@ -26,7 +27,7 @@ namespace BlackGui namespace Components { CDbLiveryComponent::CDbLiveryComponent(QWidget *parent) : - QFrame(parent), + COverlayMessagesFrame(parent), ui(new Ui::CDbLiveryComponent) { ui->setupUi(this); @@ -39,6 +40,7 @@ namespace BlackGui ui->tvp_Liveries->menuAddItems(CViewBaseNonTemplate::MenuCopy); connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CDbLiveryComponent::onLiveriesRead, Qt::QueuedConnection); + connect(sGui->getWebDataServices(), &CWebDataServices::entityDownloadProgress, this, &CDbLiveryComponent::onEntityDownloadProgress, Qt::QueuedConnection); this->onLiveriesRead(CEntityFlags::LiveryEntity, CEntityFlags::ReadFinished, sGui->getWebDataServices()->getLiveriesCount()); } @@ -64,10 +66,24 @@ namespace BlackGui { Q_UNUSED(count); if (!sGui || sGui->isShuttingDown() || !sGui->getWebDataServices()) { return; } - if (entity.testFlag(CEntityFlags::LiveryEntity) && CEntityFlags::isFinishedReadState(readState)) + if (!entity.testFlag(CEntityFlags::LiveryEntity) && CEntityFlags::isFinishedReadState(readState)) { return; } + + if (CEntityFlags::isFinishedReadState(readState)) { + this->showOverlayHTMLMessage(QStringLiteral("Updating"), 2000); ui->tvp_Liveries->updateContainerMaybeAsync(sGui->getWebDataServices()->getLiveries()); } + else + { + this->showOverlayHTMLMessage(u"Current state: " % CEntityFlags::stateToString(readState), 10000); + } + } + + void CDbLiveryComponent::onEntityDownloadProgress(CEntityFlags::Entity entity, int logId, int progress, qint64 current, qint64 max, const QUrl &url) + { + if (CEntityFlags::LiveryEntity != entity) { return; } + this->showDownloadProgress(progress, current, max, url, 5000); + Q_UNUSED(logId); } void CDbLiveryComponent::onReload() diff --git a/src/blackgui/components/dbliverycomponent.h b/src/blackgui/components/dbliverycomponent.h index 38fee0eb5..b77f5d5c5 100644 --- a/src/blackgui/components/dbliverycomponent.h +++ b/src/blackgui/components/dbliverycomponent.h @@ -12,18 +12,17 @@ #ifndef BLACKGUI_COMPONENTS_DBLIVERYCOMPONENT_H #define BLACKGUI_COMPONENTS_DBLIVERYCOMPONENT_H -#include "blackgui/blackguiexport.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" +#include "blackgui/overlaymessagesframe.h" #include "blackgui/enableforviewbasedindicator.h" -#include "blackmisc/network/entityflags.h" +#include "blackgui/blackguiexport.h" #include "blackmisc/aviation/airlineicaocode.h" +#include "blackmisc/network/entityflags.h" #include #include #include -class QWidget; - namespace BlackMisc { namespace Aviation { class CLivery; } } namespace Ui { class CDbLiveryComponent; } namespace BlackGui @@ -35,7 +34,7 @@ namespace BlackGui * Liveries from DB */ class BLACKGUI_EXPORT CDbLiveryComponent : - public QFrame, + public COverlayMessagesFrame, public CEnableForDockWidgetInfoArea, public BlackGui::CEnableForViewBasedIndicator { @@ -51,7 +50,6 @@ namespace BlackGui //! The livery view BlackGui::Views::CLiveryView *view(); - public slots: //! Filter by livery void filter(const BlackMisc::Aviation::CLivery &livery); @@ -62,6 +60,9 @@ namespace BlackGui //! Liveries codes have been read void onLiveriesRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState readState, int count); + //! Download progress for an entity + void onEntityDownloadProgress(BlackMisc::Network::CEntityFlags::Entity entity, int logId, int progress, qint64 current, qint64 max, const QUrl &url); + //! Reload models void onReload();