refs #617, allow to use CGuiActionBindHandler with buttons

* used for weather enable/disable
* use actionBindWasDestroyed when corresponding BlackCore::CActionBind is destroyed
This commit is contained in:
Klaus Basan
2017-02-03 20:43:33 +01:00
committed by Mathew Sutcliffe
parent 1889270011
commit 74d608b5df
5 changed files with 101 additions and 31 deletions

View File

@@ -11,6 +11,7 @@
#include "blackgui/infoarea.h"
#include "blackgui/views/viewbase.h"
#include "blackgui/guiapplication.h"
#include "blackgui/guiactionbind.h"
#include "blackcore/context/contextapplication.h"
#include "blackcore/context/contextsimulator.h"
#include "blackcore/context/contextownaircraft.h"
@@ -43,21 +44,24 @@ namespace BlackGui
ui(new Ui::CWeatherComponent)
{
ui->setupUi(this);
m_weatherScenarios = CWeatherGrid::getAllScenarios();
for (const auto &scenario : m_weatherScenarios)
m_weatherScenarios = CWeatherGrid::getAllScenarios();
for (const auto &scenario : as_const(m_weatherScenarios))
{
ui->cb_weatherScenario->addItem(scenario.getName(), QVariant::fromValue(scenario));
}
auto scenario = m_weatherScenarioSetting.get();
ui->cb_weatherScenario->setCurrentIndex(scenario.getIndex());
const auto scenario = m_weatherScenarioSetting.get();
ui->cb_weatherScenario->setCurrentIndex(scenario.getIndex());
ui->pb_ActivateWeather->setIcon(CIcons::metar());
setupConnections();
setupInputValidators();
setupCompleter();
// hotkeys
m_hotkeyBindings.append(CGuiActionBindHandler::bindButton(ui->pb_ActivateWeather, "Weather/Toggle weather", true));
// Set interval to 5 min
m_weatherUpdateTimer.setInterval(1000 * 60 * 5);
@@ -146,7 +150,7 @@ namespace BlackGui
{
Q_ASSERT(sGui->getIContextOwnAircraft());
position = sGui->getIContextOwnAircraft()->getOwnAircraft().getPosition();
if(position == CCoordinateGeodetic())
if (position == CCoordinateGeodetic())
{
ui->le_LatOrIcao->setText("N/A");
ui->le_Lon->setText("N/A");
@@ -187,7 +191,7 @@ namespace BlackGui
if (CWeatherScenario::isRealWeatherScenario(scenario))
{
if (!useOwnAcftPosition ||
calculateGreatCircleDistance(position, m_lastOwnAircraftPosition).value(CLengthUnit::km()) > 20 )
calculateGreatCircleDistance(position, m_lastOwnAircraftPosition).value(CLengthUnit::km()) > 20)
{
requestWeatherGrid(position);
m_lastOwnAircraftPosition = position;
@@ -201,7 +205,7 @@ namespace BlackGui
void CWeatherComponent::weatherGridReceived(const CWeatherGrid &weatherGrid, const CIdentifier &identifier)
{
if(!isMyIdentifier(identifier)) { return; }
if (!isMyIdentifier(identifier)) { return; }
ui->lb_Status->setText({});
setWeatherGrid(weatherGrid);
}

View File

@@ -12,8 +12,9 @@
#ifndef BLACKGUI_WEATHERCOMPONENT_H
#define BLACKGUI_WEATHERCOMPONENT_H
#include "blackgui/blackguiexport.h"
#include "blackgui/components/enablefordockwidgetinfoarea.h"
#include "blackgui/blackguiexport.h"
#include "blackcore/actionbind.h"
#include "blackmisc/geo/coordinategeodetic.h"
#include "blackmisc/simulation/simulatorsettings.h"
#include "blackmisc/weather/weatherscenario.h"
@@ -77,6 +78,7 @@ namespace BlackGui
QTimer m_weatherUpdateTimer { this };
BlackMisc::Geo::CCoordinateGeodetic m_lastOwnAircraftPosition;
BlackMisc::CSetting<BlackMisc::Simulation::TSelectedWeatherScenario> m_weatherScenarioSetting { this };
BlackCore::CActionBindings m_hotkeyBindings;
bool m_isWeatherActivated = false;
};
} // namespace