Files
pilotclient/samples/blackgui/mainwindow_atc.cpp
Klaus Basan af3a239e40 refs #139 added tab in GUI for changing hotkeys
In order to better identify the models, the model members have been prefixed with "model"
2014-02-26 03:38:31 +01:00

113 lines
3.4 KiB
C++

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "blackgui/atcstationlistmodel.h"
#include "blackcore/dbus_server.h"
#include "blackcore/context_network.h"
using namespace BlackCore;
using namespace BlackMisc;
using namespace BlackGui;
using namespace BlackMisc::Network;
using namespace BlackMisc::Aviation;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Geo;
using namespace BlackMisc::Settings;
/*
* Read booked stations
*/
void MainWindow::reloadAtcStationsBooked()
{
if (!this->isContextNetworkAvailableCheck()) return;
this->m_modelAtcListBooked->update(this->m_contextNetwork->getAtcStationsBooked());
this->ui->tv_AtcStationsBooked->resizeColumnsToContents();
this->ui->tv_AtcStationsBooked->resizeRowsToContents();
}
/*
* Read online stations
*/
void MainWindow::reloadAtcStationsOnline()
{
if (!this->isContextNetworkAvailableCheck()) return;
this->m_modelAtcListOnline->update(this->m_contextNetwork->getAtcStationsOnline());
this->ui->tv_AtcStationsOnline->resizeColumnsToContents();
this->ui->tv_AtcStationsOnline->resizeRowsToContents();
if (!this->m_contextNetwork->isConnected())
{
// clear metar/ATIS
this->ui->te_AtcStationsOnlineInfo->clear();
}
// after reloading, update cockpit based on better information
this->updateCockpitFromContext();
}
/*
* Station selected
*/
void MainWindow::onlineAtcStationSelected(QModelIndex index)
{
this->ui->te_AtcStationsOnlineInfo->setText(""); // reset
const CAtcStation stationClicked = this->m_modelAtcListOnline->at(index);
QString infoMessage;
if (stationClicked.hasAtis())
{
infoMessage.append(stationClicked.getAtis().getMessage());
}
if (stationClicked.hasMetar())
{
if (!infoMessage.isEmpty()) infoMessage.append("\n\n");
infoMessage.append(stationClicked.getMetar().getMessage());
}
this->ui->te_AtcStationsOnlineInfo->setText(infoMessage);
}
/*
* Get METAR
*/
void MainWindow::getMetar(const QString &airportIcaoCode)
{
if (!this->isContextNetworkAvailableCheck()) return;
if (!this->m_contextNetwork->isConnected()) return;
QString icao = airportIcaoCode.isEmpty() ? this->ui->le_AtcStationsOnlineMetar->text().trimmed().toUpper() : airportIcaoCode.trimmed().toUpper();
this->ui->le_AtcStationsOnlineMetar->setText(icao);
if (icao.length() != 4) return;
CInformationMessage metar = this->m_contextNetwork->getMetar(icao);
if (metar.getType() != CInformationMessage::METAR) return;
if (metar.isEmpty()) return;
this->ui->te_AtcStationsOnlineInfo->setText(metar.getMessage());
}
/*
* Get METAR
*/
void MainWindow::requestAtis()
{
if (!this->isContextNetworkAvailableCheck()) return;
if (!this->m_contextNetwork->isConnected()) return;
this->m_contextNetwork->requestAtisUpdates();
}
/*
* ATC station tab changed are changed
*/
void MainWindow::atcStationTabChanged(int /** tabIndex **/)
{
if (this->isContextNetworkAvailableCheck())
{
if (this->ui->tw_AtcStations->currentWidget() == this->ui->tb_AtcStationsBooked)
{
if (this->m_modelAtcListBooked->rowCount() < 1)
this->reloadAtcStationsBooked();
}
else if (this->ui->tw_AtcStations->currentWidget() == this->ui->tb_AtcStationsOnline)
{
this->reloadAtcStationsOnline();
}
}
}