From 6364853264906b55784a350eee952ad156fcb5aa Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 8 Jan 2016 00:43:11 +0100 Subject: [PATCH] refs #568, adjusted GUI components * use incremental updates * use new signatures * handle successfully published models * some custom menus are gone, because they are now part of the specialized views --- .../components/datainfoareacomponent.cpp | 17 ++++++ .../components/datainfoareacomponent.h | 5 +- .../components/datamaininfoareacomponent.cpp | 1 + .../components/dbaircrafticaocomponent.cpp | 2 +- .../components/dbairlineicaocomponent.cpp | 2 +- .../components/dbcountrycomponent.cpp | 2 +- .../components/dbdistributorcomponent.cpp | 2 +- src/blackgui/components/dbliverycomponent.cpp | 2 +- .../components/dbmappingcomponent.cpp | 22 ++++++-- src/blackgui/components/dbmappingcomponent.h | 9 +++- src/blackgui/components/dbmodelcomponent.cpp | 19 +++++-- src/blackgui/components/dbmodelcomponent.h | 7 +++ src/blackgui/components/dbstashcomponent.cpp | 54 ++++++++++++++----- src/blackgui/components/dbstashcomponent.h | 24 +++++---- .../infobarwebreadersstatuscomponent.cpp | 5 ++ 15 files changed, 134 insertions(+), 39 deletions(-) diff --git a/src/blackgui/components/datainfoareacomponent.cpp b/src/blackgui/components/datainfoareacomponent.cpp index 21d67d3fc..2eb9f0dc5 100644 --- a/src/blackgui/components/datainfoareacomponent.cpp +++ b/src/blackgui/components/datainfoareacomponent.cpp @@ -10,11 +10,14 @@ #include "ui_datainfoareacomponent.h" #include "blackgui/components/logcomponent.h" #include "blackgui/components/datainfoareacomponent.h" +#include "blackmisc/network/entityflags.h" #include "blackcore/webdataservices.h" #include "blackmisc/icons.h" #include "blackmisc/logmessage.h" +#include "blackmisc/verify.h" using namespace BlackMisc; +using namespace BlackMisc::Network; using namespace BlackGui; using namespace BlackGui::Components; @@ -151,5 +154,19 @@ namespace BlackGui return CIcons::empty(); } } + + void CDataInfoAreaComponent::requestUpdatedData(CEntityFlags::Entity entity) + { + bool requested = false; + if (entity.testFlag(CEntityFlags::ModelEntity)) + { + this->ui->comp_DbModels->requestUpdatedData(); + requested = true; + } + + // sanity + BLACK_VERIFY_X(requested, Q_FUNC_INFO, "Entity not supported"); + Q_UNUSED(requested); + } } // ns } // ns diff --git a/src/blackgui/components/datainfoareacomponent.h b/src/blackgui/components/datainfoareacomponent.h index 401bfd72f..1394a80be 100644 --- a/src/blackgui/components/datainfoareacomponent.h +++ b/src/blackgui/components/datainfoareacomponent.h @@ -33,7 +33,7 @@ namespace BlackGui class CDbCountryComponent; /** - * Main info area for data entry tool + * Info area containing the DB data (models, liveries ...) */ class BLACKGUI_EXPORT CDataInfoAreaComponent : public BlackGui::CInfoArea, @@ -89,6 +89,9 @@ namespace BlackGui //! Load from resource dir bool readDbDataFromResourceDir(); + //! Load new data (based on timestamp, incremental) + void requestUpdatedData(BlackMisc::Network::CEntityFlags::Entity entity); + protected: //! \copydoc CInfoArea::getPreferredSizeWhenFloating virtual QSize getPreferredSizeWhenFloating(int areaIndex) const override; diff --git a/src/blackgui/components/datamaininfoareacomponent.cpp b/src/blackgui/components/datamaininfoareacomponent.cpp index a944e9115..08237b253 100644 --- a/src/blackgui/components/datamaininfoareacomponent.cpp +++ b/src/blackgui/components/datamaininfoareacomponent.cpp @@ -33,6 +33,7 @@ namespace BlackGui connect(ui->comp_Mapping, &CDbMappingComponent::filterByLivery, ui->comp_DataInfoArea->getLiveryComponent(), &CDbLiveryComponent::filter); connect(ui->comp_Mapping, &CDbMappingComponent::filterByAircraftIcao, ui->comp_DataInfoArea->getAircraftComponent(), &CDbAircraftIcaoComponent::filter); + connect(ui->comp_Mapping, &CDbMappingComponent::requestUpdatedData, ui->comp_DataInfoArea, &CDataInfoAreaComponent::requestUpdatedData); } CDataMainInfoAreaComponent::~CDataMainInfoAreaComponent() diff --git a/src/blackgui/components/dbaircrafticaocomponent.cpp b/src/blackgui/components/dbaircrafticaocomponent.cpp index d63aae668..a961da01e 100644 --- a/src/blackgui/components/dbaircrafticaocomponent.cpp +++ b/src/blackgui/components/dbaircrafticaocomponent.cpp @@ -68,7 +68,7 @@ namespace BlackGui void CDbAircraftIcaoComponent::ps_reload() { if (!hasProvider()) { return; } - triggerRead(CEntityFlags::AircraftIcaoEntity); + triggerRead(CEntityFlags::AircraftIcaoEntity, QDateTime()); } } // ns diff --git a/src/blackgui/components/dbairlineicaocomponent.cpp b/src/blackgui/components/dbairlineicaocomponent.cpp index 17985eaee..39fcd0a60 100644 --- a/src/blackgui/components/dbairlineicaocomponent.cpp +++ b/src/blackgui/components/dbairlineicaocomponent.cpp @@ -63,7 +63,7 @@ namespace BlackGui void CDbAirlineIcaoComponent::ps_reload() { if (!hasProvider()) { return; } - triggerRead(CEntityFlags::AirlineIcaoEntity); + triggerRead(CEntityFlags::AirlineIcaoEntity, QDateTime()); } } // ns diff --git a/src/blackgui/components/dbcountrycomponent.cpp b/src/blackgui/components/dbcountrycomponent.cpp index 185924c88..d012cc25f 100644 --- a/src/blackgui/components/dbcountrycomponent.cpp +++ b/src/blackgui/components/dbcountrycomponent.cpp @@ -63,7 +63,7 @@ namespace BlackGui void CDbCountryComponent::ps_reload() { if (!hasProvider()) { return; } - triggerRead(CEntityFlags::CountryEntity); + triggerRead(CEntityFlags::CountryEntity, QDateTime()); } } // ns } // ns diff --git a/src/blackgui/components/dbdistributorcomponent.cpp b/src/blackgui/components/dbdistributorcomponent.cpp index 0ed1abbce..2dc6f3390 100644 --- a/src/blackgui/components/dbdistributorcomponent.cpp +++ b/src/blackgui/components/dbdistributorcomponent.cpp @@ -59,7 +59,7 @@ namespace BlackGui void CDbDistributorComponent::ps_reload() { if (!hasProvider()) { return; } - triggerRead(CEntityFlags::DistributorEntity); + triggerRead(CEntityFlags::DistributorEntity, QDateTime()); } } // ns } // ns diff --git a/src/blackgui/components/dbliverycomponent.cpp b/src/blackgui/components/dbliverycomponent.cpp index 8c9254d54..a18bb8073 100644 --- a/src/blackgui/components/dbliverycomponent.cpp +++ b/src/blackgui/components/dbliverycomponent.cpp @@ -67,7 +67,7 @@ namespace BlackGui void CDbLiveryComponent::ps_reload() { if (!hasProvider()) { return; } - triggerRead(CEntityFlags::LiveryEntity); + triggerRead(CEntityFlags::LiveryEntity, QDateTime()); } } // ns diff --git a/src/blackgui/components/dbmappingcomponent.cpp b/src/blackgui/components/dbmappingcomponent.cpp index 356c5d0a1..da1c8591e 100644 --- a/src/blackgui/components/dbmappingcomponent.cpp +++ b/src/blackgui/components/dbmappingcomponent.cpp @@ -18,6 +18,7 @@ using namespace BlackCore; using namespace BlackMisc; using namespace BlackMisc::Aviation; +using namespace BlackMisc::Network; using namespace BlackMisc::Simulation; using namespace BlackMisc::Simulation::FsCommon; using namespace BlackGui; @@ -53,6 +54,7 @@ namespace BlackGui connect(ui->comp_StashAircraft->getView(), &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected); connect(ui->comp_StashAircraft->getView(), &CAircraftModelView::requestHandlingOfStashDrop, this, &CDbMappingComponent::ps_handleStashDropRequest); connect(ui->comp_StashAircraft, &CDbStashComponent::stashedModelsChanged, this, &CDbMappingComponent::ps_onStashedModelsChanged); + connect(ui->comp_StashAircraft, &CDbStashComponent::modelsSuccessfullyPublished, this, &CDbMappingComponent::ps_onModelsSuccessfullyPublished); ui->tvp_OwnAircraftModels->setDisplayAutomatically(true); ui->tvp_OwnAircraftModels->setCustomMenu(new CMappingSimulatorModelMenu(this)); @@ -181,9 +183,9 @@ namespace BlackGui switch (tab) { case TabOwnModels: - return ui->tvp_OwnAircraftModels->hasModelsToStash(); + return ui->tvp_OwnAircraftModels->hasSelectedModelsToStash(); case TabVPliot: - return ui->tvp_AircraftModelsForVPilot->hasModelsToStash(); + return ui->tvp_AircraftModelsForVPilot->hasSelectedModelsToStash(); default: break; } @@ -266,12 +268,16 @@ namespace BlackGui { const CAircraftModel model(getAircraftModel()); CStatusMessageList msgs(this->validateCurrentModel(true)); + if (!msgs.hasErrorMessages()) + { + msgs.push_back( + this->ui->comp_StashAircraft->stashModel(model, true) + ); + } if (msgs.hasErrorMessages()) { this->showMessages(msgs); - return; } - this->ui->comp_StashAircraft->stashModel(model, true); } void CDbMappingComponent::resizeForSelect() @@ -372,6 +378,12 @@ namespace BlackGui } } + void CDbMappingComponent::ps_onModelsSuccessfullyPublished(const CAircraftModelList &models) + { + if (models.isEmpty()) { return; } + emit this->requestUpdatedData(CEntityFlags::ModelEntity); + } + void CDbMappingComponent::ps_onVPilotCountChanged(int count, bool withFilter) { if (!m_withVPilot) { return; } @@ -434,7 +446,7 @@ namespace BlackGui ); if (msgs.hasWarningOrErrorMessages()) { - // maybe log, popup? + this->showMessages(msgs); } } diff --git a/src/blackgui/components/dbmappingcomponent.h b/src/blackgui/components/dbmappingcomponent.h index fcf5fc1f8..844d1a463 100644 --- a/src/blackgui/components/dbmappingcomponent.h +++ b/src/blackgui/components/dbmappingcomponent.h @@ -23,6 +23,7 @@ #include "blackmisc/simulation/aircraftmodelloader.h" #include "blackmisc/simulation/fscommon/vpilotrulesreader.h" #include "blackmisc/network/webdataservicesprovider.h" +#include "blackmisc/network/entityflags.h" #include "blackmisc/statusmessagelist.h" #include #include @@ -102,6 +103,9 @@ namespace BlackGui //! Request to filter by distributor void filterByDistributor(const BlackMisc::Simulation::CDistributor &distributor); + //! Request new data + void requestUpdatedData(BlackMisc::Network::CEntityFlags::Entity entities); + public slots: //! Validate, empty list means OK BlackMisc::CStatusMessageList validateCurrentModel(bool withNestedForms) const; @@ -122,12 +126,15 @@ namespace BlackGui //! Data for vPilot have been loaded void ps_onLoadVPilotDataFinished(bool success); - //! vPilot cached changed + //! vPilot cached models changed void ps_onVPilotCacheChanged(); //! Stashed models changed void ps_onStashedModelsChanged(); + //! Models have been published successfully + void ps_onModelsSuccessfullyPublished(const BlackMisc::Simulation::CAircraftModelList &models); + //! Stash drop request void ps_handleStashDropRequest(const BlackMisc::Aviation::CAirlineIcaoCode &code) const; diff --git a/src/blackgui/components/dbmodelcomponent.cpp b/src/blackgui/components/dbmodelcomponent.cpp index 6847e99b2..de6066b87 100644 --- a/src/blackgui/components/dbmodelcomponent.cpp +++ b/src/blackgui/components/dbmodelcomponent.cpp @@ -10,11 +10,13 @@ #include "dbmodelcomponent.h" #include "dbmappingcomponent.h" #include "blackgui/stylesheetutility.h" +#include "blackmisc/simulation/aircraftmodel.h" #include "ui_dbmodelcomponent.h" #include using namespace BlackMisc; using namespace BlackMisc::Network; +using namespace BlackMisc::Simulation; using namespace BlackGui::Views; using namespace BlackGui::Models; @@ -57,6 +59,17 @@ namespace BlackGui } } + void CDbModelComponent::requestUpdatedData() + { + QDateTime ts; + if (!this->ui->tvp_AircraftModel->isEmpty()) + { + CAircraftModel model(this->ui->tvp_AircraftModel->container().latestObject()); + ts = model.getUtcTimestamp(); + } + this->triggerRead(CEntityFlags::ModelEntity, ts); + } + void CDbModelComponent::ps_modelsRead(CEntityFlags::Entity entity, CEntityFlags::ReadState readState, int count) { Q_UNUSED(count); @@ -64,15 +77,15 @@ namespace BlackGui { if (readState == CEntityFlags::ReadFinished || readState == CEntityFlags::ReadFinishedRestricted) { - this->ui->tvp_AircraftModel->updateContainer(this->getModels()); + this->ui->tvp_AircraftModel->updateContainerMaybeAsync(this->getModels()); } } } void CDbModelComponent::ps_reload() { - if (!hasProvider()) { return; } - triggerRead(CEntityFlags::ModelEntity); + if (!this->hasProvider()) { return; } + this->triggerRead(CEntityFlags::ModelEntity, QDateTime()); } void CDbModelComponent::ps_onStyleSheetChanged() diff --git a/src/blackgui/components/dbmodelcomponent.h b/src/blackgui/components/dbmodelcomponent.h index bf5b5b3be..41d7e6b8d 100644 --- a/src/blackgui/components/dbmodelcomponent.h +++ b/src/blackgui/components/dbmodelcomponent.h @@ -48,6 +48,13 @@ namespace BlackGui //! Set the provider virtual void setProvider(BlackMisc::Network::IWebDataServicesProvider *webDataReaderProvider) override; + //! Get latest model if any + BlackMisc::Simulation::CAircraftModel getLatestModel() const; + + public slots: + //! Load new data + void requestUpdatedData(); + private slots: //! Models have been read void ps_modelsRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState readState, int count); diff --git a/src/blackgui/components/dbstashcomponent.cpp b/src/blackgui/components/dbstashcomponent.cpp index a45341902..3e0a020f5 100644 --- a/src/blackgui/components/dbstashcomponent.cpp +++ b/src/blackgui/components/dbstashcomponent.cpp @@ -12,7 +12,6 @@ #include "ui_dbstashcomponent.h" #include "blackgui/views/aircraftmodelview.h" #include "blackmisc/icons.h" -#include "blackmisc/verify.h" using namespace BlackMisc; using namespace BlackMisc::Simulation; @@ -48,7 +47,7 @@ namespace BlackGui connect(this->ui->pb_Livery, &QPushButton::pressed, this, &CDbStashComponent::ps_copyOverPartsToSelected); connect(this->ui->pb_Distributor, &QPushButton::pressed, this, &CDbStashComponent::ps_copyOverPartsToSelected); - ui->tvp_StashAircraftModels->setCustomMenu(new CStashModelsMenu(this, true)); + ui->tvp_StashAircraftModels->menuAddItems(CAircraftModelView::MenuRemoveSelectedRows); this->enableButtonRow(); } @@ -93,10 +92,6 @@ namespace BlackGui this->ui->tvp_StashAircraftModels->insert(model); } } - else - { - this->showMessage(m); - } return m; } @@ -112,6 +107,18 @@ namespace BlackGui return msgs; } + int CDbStashComponent::unstashModels(QList keys) + { + if (keys.isEmpty()) { return 0; } + return this->ui->tvp_StashAircraftModels->removeDbKeys(keys); + } + + int CDbStashComponent::unstashModels(QStringList modelStrings) + { + if (modelStrings.isEmpty()) { return 0; } + return this->ui->tvp_StashAircraftModels->removeModelsWithModelString(modelStrings); + } + const Views::CAircraftModelView *CDbStashComponent::getView() const { return ui->tvp_StashAircraftModels; @@ -208,9 +215,26 @@ namespace BlackGui void CDbStashComponent::ps_publishResponse(const CAircraftModelList &publishedModels, const CAircraftModelList &skippedModels, const CStatusMessageList &msgs) { + if (!publishedModels.isEmpty()) + { + emit this->modelsSuccessfullyPublished(publishedModels); + } + if (!msgs.isEmpty()) { - this->showMessages(msgs); + if (publishedModels.isEmpty()) + { + this->showMessages(msgs); + } + else + { + QString confirm("Remove %1 published models?"); + auto lambda = [this, publishedModels]() + { + this->unstashModels(publishedModels.getModelStrings(false)); + }; + this->showMessagesWithConfirmation(msgs, confirm.arg(publishedModels.size()), lambda, QMessageBox::Ok); + } } Q_UNUSED(publishedModels); @@ -319,6 +343,16 @@ namespace BlackGui return true; } + bool CDbStashComponent::showMessagesWithConfirmation(const CStatusMessageList &msgs, const QString &confirmation, std::function okLambda, int defaultButton, bool onlyErrors, int timeoutMs) + { + if (msgs.isEmpty()) { return false; } + if (!msgs.hasErrorMessages() && onlyErrors) { return false; } + BLACK_VERIFY_X(this->getMappingComponent(), Q_FUNC_INFO, "missing mapping component"); + if (!this->getMappingComponent()) { return false; } + this->getMappingComponent()->showMessagesWithConfirmation(msgs, confirmation, okLambda, defaultButton, timeoutMs); + return true; + } + bool CDbStashComponent::showMessage(const CStatusMessage &msg, int timeoutMs) { if (msg.isEmpty()) { return false; } @@ -327,11 +361,5 @@ namespace BlackGui this->getMappingComponent()->showMessage(msg, timeoutMs); return true; } - - void CDbStashComponent::CStashModelsMenu::customMenu(QMenu &menu) const - { - menu.addAction(CIcons::database16(), "Unstash", this->parent(), SLOT(ps_onUnstashPressed())); - nestedCustomMenu(menu); - } } // ns } // ns diff --git a/src/blackgui/components/dbstashcomponent.h b/src/blackgui/components/dbstashcomponent.h index 4d967ccc9..c6e036176 100644 --- a/src/blackgui/components/dbstashcomponent.h +++ b/src/blackgui/components/dbstashcomponent.h @@ -16,6 +16,7 @@ #include "blackgui/components/dbmappingcomponentaware.h" #include "blackgui/menudelegate.h" #include "blackgui/views/aircraftmodelview.h" +#include "blackmisc/verify.h" #include "blackmisc/network/webdataservicesprovider.h" #include #include @@ -60,6 +61,12 @@ namespace BlackGui //! Stash given models BlackMisc::CStatusMessageList stashModels(const BlackMisc::Simulation::CAircraftModelList &models); + //! Unstash given models with keys + int unstashModels(QList keys); + + //! Unstash given models by model string + int unstashModels(QStringList modelStrings); + //! The embedded view const BlackGui::Views::CAircraftModelView *getView() const; @@ -94,6 +101,9 @@ namespace BlackGui //! Stashed models have been changed void stashedModelsChanged(); + //! Models succesfully published + void modelsSuccessfullyPublished(const BlackMisc::Simulation::CAircraftModelList &publishedModels); + private slots: //! Unstash pressed void ps_onUnstashPressed(); @@ -121,6 +131,9 @@ namespace BlackGui //! Display messages bool showMessages(const BlackMisc::CStatusMessageList &msgs, bool onlyErrors = false, int timeoutMs = -1); + //! Display messages with confirmation + bool showMessagesWithConfirmation(const BlackMisc::CStatusMessageList &msgs, const QString &confirmation, std::function okLambda, int defaultButton, bool onlyErrors = false, int timeoutMs = -1); + //! Display message bool showMessage(const BlackMisc::CStatusMessage &msg, int timeoutMs = -1); @@ -138,17 +151,6 @@ namespace BlackGui //! Get the selected only models or all models depending on checkbox BlackMisc::Simulation::CAircraftModelList getSelectedOrAllModels() const; - - //! Custom menu for the stashed models - class CStashModelsMenu : public BlackGui::IMenuDelegate - { - public: - //! Constructor - CStashModelsMenu(CDbStashComponent *parent, bool separatorAtEnd) : IMenuDelegate(parent, separatorAtEnd) {} - - //! \copydoc IMenuDelegate::customMenu - virtual void customMenu(QMenu &menu) const override; - }; }; } // ns } // ns diff --git a/src/blackgui/components/infobarwebreadersstatuscomponent.cpp b/src/blackgui/components/infobarwebreadersstatuscomponent.cpp index 6aca5f0eb..8ff77b69d 100644 --- a/src/blackgui/components/infobarwebreadersstatuscomponent.cpp +++ b/src/blackgui/components/infobarwebreadersstatuscomponent.cpp @@ -11,6 +11,7 @@ #include "ui_infobarwebreadersstatuscomponent.h" #include "blackcore/webreaderflags.h" #include "blackmisc/icons.h" +#include "blackmisc/verify.h" using namespace BlackGui; using namespace BlackMisc; @@ -93,6 +94,7 @@ namespace BlackGui switch (readState) { case CEntityFlags::ReadFinished: + case CEntityFlags::ReadFinishedRestricted: led->setOn(true, blinkTime); break; case CEntityFlags::StartRead: @@ -101,6 +103,9 @@ namespace BlackGui case CEntityFlags::ReadFailed: led->setTriState(2 * blinkTime); break; + default: + BLACK_VERIFY_X(false, Q_FUNC_INFO, "read state not handled"); + break; } }