From 24bc57ac32974fe19ad423582c42860dbe28a8fc Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 19 May 2020 01:13:35 +0200 Subject: [PATCH] [Weather] Allow to trigger reload of weather from UI --- .../context/contextsimulatorimpl.cpp | 4 +- src/blackgui/components/weathercomponent.cpp | 25 ++++++----- src/blackgui/components/weathercomponent.h | 6 ++- src/blackgui/components/weathercomponent.ui | 42 +++++++++++++++++-- 4 files changed, 58 insertions(+), 19 deletions(-) diff --git a/src/blackcore/context/contextsimulatorimpl.cpp b/src/blackcore/context/contextsimulatorimpl.cpp index b710a026d..457046dcf 100644 --- a/src/blackcore/context/contextsimulatorimpl.cpp +++ b/src/blackcore/context/contextsimulatorimpl.cpp @@ -77,7 +77,6 @@ namespace BlackCore m_plugins->collectPlugins(); this->restoreSimulatorPlugins(); - connect(&m_weatherManager, &CWeatherManager::weatherGridReceived, this, &CContextSimulator::weatherGridReceived, Qt::QueuedConnection); connect(&m_weatherManager, &CWeatherManager::weatherGridReceived, this, &CContextSimulator::onWeatherGridReceived, Qt::QueuedConnection); connect(&m_aircraftMatcher, &CAircraftMatcher::setupChanged, this, &CContextSimulator::matchingSetupChanged); connect(&CCentralMultiSimulatorModelSetCachesProvider::modelCachesInstance(), &CCentralMultiSimulatorModelSetCachesProvider::cacheChanged, this, &CContextSimulator::modelSetChanged); @@ -882,6 +881,9 @@ namespace BlackCore void CContextSimulator::onWeatherGridReceived(const CWeatherGrid &weatherGrid, const CIdentifier &identifier) { + if (!sApp || sApp->isShuttingDown()) { return; } + emit this->weatherGridReceived(weatherGrid, identifier); + if (!this->isSimulatorPluginAvailable()) { return; } if (!m_simulatorPlugin.second) { return; } diff --git a/src/blackgui/components/weathercomponent.cpp b/src/blackgui/components/weathercomponent.cpp index 8e58d8f13..8246dfb81 100644 --- a/src/blackgui/components/weathercomponent.cpp +++ b/src/blackgui/components/weathercomponent.cpp @@ -50,6 +50,7 @@ namespace BlackGui m_coordinateDialog->showElevation(false); m_coordinateDialog->setReadOnly(ui->cb_UseOwnAcftPosition->isChecked()); connect(ui->pb_SetPosition, &QPushButton::clicked, this, &CWeatherComponent::showCoordinateDialog); + connect(ui->pb_Update, &QPushButton::clicked, this, &CWeatherComponent::updateWeatherInformationForced); m_weatherScenarios = CWeatherGrid::getAllScenarios(); for (const auto &scenario : as_const(m_weatherScenarios)) @@ -76,11 +77,9 @@ namespace BlackGui QPointer myself(this); QTimer::singleShot(1000, this, [ = ] { - if (myself) - { - myself->updateWeatherInformation(); - myself->updateWeatherInfoLine(); - } + if (!myself) { return; } + myself->updateWeatherInformation(true); + myself->updateWeatherInfoLine(); }); } @@ -90,7 +89,7 @@ namespace BlackGui bool CWeatherComponent::setParentDockWidgetInfoArea(CDockWidgetInfoArea *parentDockableWidget) { CEnableForDockWidgetInfoArea::setParentDockWidgetInfoArea(parentDockableWidget); - bool c = connect(this->getParentInfoArea(), &CInfoArea::changedInfoAreaTabBarIndex, this, &CWeatherComponent::infoAreaTabBarChanged, Qt::QueuedConnection); + const bool c = connect(this->getParentInfoArea(), &CInfoArea::changedInfoAreaTabBarIndex, this, &CWeatherComponent::infoAreaTabBarChanged, Qt::QueuedConnection); Q_ASSERT_X(c, Q_FUNC_INFO, "failed connect"); Q_ASSERT_X(parentDockableWidget, Q_FUNC_INFO, "missing parent"); return c && parentDockableWidget; @@ -123,7 +122,7 @@ namespace BlackGui m_coordinateDialog->setCoordinate(c); ui->pb_SetPosition->setText("Select Position"); } - updateWeatherInformation(); + updateWeatherInformation(false); } void CWeatherComponent::toggleWeatherActivation() @@ -154,7 +153,7 @@ namespace BlackGui m_lastOwnAircraftPosition = {}; const CWeatherScenario scenario = m_weatherScenarios[index]; m_weatherScenarioSetting.set(scenario); - this->updateWeatherInformation(); + this->updateWeatherInformation(false); this->updateWeatherInfoLine(); } @@ -185,7 +184,7 @@ namespace BlackGui } } - void CWeatherComponent::updateWeatherInformation() + void CWeatherComponent::updateWeatherInformation(bool forceRealWeatherReload) { setWeatherGrid({}); ui->lbl_Status->setText({}); @@ -212,7 +211,7 @@ namespace BlackGui if (CWeatherScenario::isRealWeatherScenario(scenario)) { - if (m_lastOwnAircraftPosition.isNull() || + if (m_lastOwnAircraftPosition.isNull() || forceRealWeatherReload || calculateGreatCircleDistance(position, m_lastOwnAircraftPosition).value(CLengthUnit::km()) > 20) { this->requestWeatherGrid(position); @@ -244,10 +243,10 @@ namespace BlackGui void CWeatherComponent::setupConnections() { // UI connections + connect(m_coordinateDialog.data(), &CCoordinateDialog::changedCoordinate, this, &CWeatherComponent::updateWeatherInformationForced); + connect(&m_weatherUpdateTimer, &QTimer::timeout, this, &CWeatherComponent::updateWeatherInformationChecked); connect(ui->cb_weatherScenario, qOverload(&QComboBox::currentIndexChanged), this, &CWeatherComponent::setWeatherScenario); - connect(m_coordinateDialog.data(), &CCoordinateDialog::changedCoordinate, this, &CWeatherComponent::updateWeatherInformation); - connect(ui->cb_UseOwnAcftPosition, &QCheckBox::toggled, this, &CWeatherComponent::toggleUseOwnAircraftPosition); - connect(&m_weatherUpdateTimer, &QTimer::timeout, this, &CWeatherComponent::updateWeatherInformation); + connect(ui->cb_UseOwnAcftPosition, &QCheckBox::toggled, this, &CWeatherComponent::toggleUseOwnAircraftPosition); connect(ui->pb_ActivateWeather, &QPushButton::clicked, this, &CWeatherComponent::toggleWeatherActivation); // Context connections diff --git a/src/blackgui/components/weathercomponent.h b/src/blackgui/components/weathercomponent.h index 73e39c9bf..cc1e89a80 100644 --- a/src/blackgui/components/weathercomponent.h +++ b/src/blackgui/components/weathercomponent.h @@ -65,7 +65,9 @@ namespace BlackGui void setCavok(); void updateWeatherInfoLine(); - void updateWeatherInformation(); + void updateWeatherInformationForced() { this->updateWeatherInformation(true); } + void updateWeatherInformationChecked() { this->updateWeatherInformation(false); } + void updateWeatherInformation(bool forceRealWeatherReload); void onWeatherGridReceived(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier); void setupConnections(); @@ -78,7 +80,7 @@ namespace BlackGui QScopedPointer ui; QScopedPointer m_coordinateDialog { new CCoordinateDialog(this) }; QVector m_weatherScenarios; - QTimer m_weatherUpdateTimer; + QTimer m_weatherUpdateTimer; //!< this is the timer for weather updates BlackMisc::Geo::CCoordinateGeodetic m_lastOwnAircraftPosition; BlackMisc::CSetting m_weatherScenarioSetting { this, &CWeatherComponent::onScenarioChanged }; BlackCore::CActionBindings m_hotkeyBindings; //!< allow binding of hotkey diff --git a/src/blackgui/components/weathercomponent.ui b/src/blackgui/components/weathercomponent.ui index d2241dc43..ae00ccd88 100644 --- a/src/blackgui/components/weathercomponent.ui +++ b/src/blackgui/components/weathercomponent.ui @@ -34,27 +34,52 @@ + + + 0 + 100 + + Weather Control + + 4 + + + 4 + + + 4 + + + 4 + - Activate + activate - + info goes here + + + + update + + + @@ -100,7 +125,7 @@ - Show Position + show Position @@ -267,6 +292,17 @@
blackgui/views/windlayerview.h
+ + cb_weatherScenario + pb_ActivateWeather + pb_Update + cb_UseOwnAcftPosition + pb_SetPosition + tw_weatherGrid + tvp_TemperatureLayers + tvp_CloudLayers + tvp_WindLayers +