mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-12 07:15:34 +08:00
134
src/blackgui/atcstationcomponent.cpp
Normal file
134
src/blackgui/atcstationcomponent.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
#include "blackmisc/avinformationmessage.h"
|
||||
#include "atcstationcomponent.h"
|
||||
#include "ui_atcstationcomponent.h"
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackCore;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
|
||||
CAtcStationComponent::CAtcStationComponent(QWidget *parent) :
|
||||
QTabWidget(parent), CRuntimeBasedComponent(nullptr, false), ui(new Ui::CAtcStationComponent), m_timerComponent(nullptr)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->m_timerComponent = new CTimerBasedComponent(SLOT(update()), this);
|
||||
this->ui->tvp_AtcStationsBooked->setStationMode(CAtcStationListModel::StationsBooked);
|
||||
|
||||
// Signal / Slots
|
||||
bool connected = this->connect(this->ui->le_AtcStationsOnlineMetar, SIGNAL(returnPressed()), this, SLOT(getMetar()));
|
||||
Q_ASSERT(connected);
|
||||
connected = this->connect(this->ui->pb_AtcStationsLoadMetar, SIGNAL(clicked()), this, SLOT(getMetar()));
|
||||
Q_ASSERT(connected);
|
||||
this->connect(this, &QTabWidget::currentChanged, this, &CAtcStationComponent::atcStationsTabChanged);
|
||||
this->connect(this->ui->pb_ReloadAtcStationsBooked, &QPushButton::clicked, this, &CAtcStationComponent::reloadAtcStationsBooked);
|
||||
this->connect(this->ui->tvp_AtcStationsOnline, &QTableView::clicked, this, &CAtcStationComponent::onlineAtcStationSelected);
|
||||
this->connect(this->ui->pb_AtcStationsAtisReload, &QPushButton::clicked, this, &CAtcStationComponent::requestAtis);
|
||||
}
|
||||
|
||||
CAtcStationComponent::~CAtcStationComponent()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void CAtcStationComponent::runtimeHasBeenSet()
|
||||
{
|
||||
Q_ASSERT(this->getRuntime());
|
||||
Q_ASSERT(this->getIContextNetwork());
|
||||
this->connect(this->getIContextNetwork(), &IContextNetwork::changedAtcStationsOnline, this, &CAtcStationComponent::changedAtcStationsOnline);
|
||||
this->connect(this->getIContextNetwork(), &IContextNetwork::changedAtcStationsBooked, this, &CAtcStationComponent::changedAtcStationsBooked);
|
||||
}
|
||||
|
||||
void CAtcStationComponent::update()
|
||||
{
|
||||
Q_ASSERT(this->ui->tvp_AtcStationsBooked);
|
||||
Q_ASSERT(this->ui->tvp_AtcStationsOnline);
|
||||
Q_ASSERT(this->getIContextNetwork());
|
||||
|
||||
if (this->getIContextNetwork()->isConnected())
|
||||
{
|
||||
// initial read for bookings
|
||||
if (this->ui->tvp_AtcStationsBooked->isEmpty()) this->reloadAtcStationsBooked();
|
||||
|
||||
// update
|
||||
if (this->m_timestampOnlineStationsChanged.isNull() || this->m_timestampLastReadOnlineStations.isNull() ||
|
||||
(this->m_timestampOnlineStationsChanged > this->m_timestampLastReadOnlineStations))
|
||||
{
|
||||
this->ui->tvp_AtcStationsOnline->update(this->getIContextNetwork()->getAtcStationsOnline());
|
||||
this->m_timestampLastReadOnlineStations = QDateTime::currentDateTimeUtc();
|
||||
this->m_timestampOnlineStationsChanged = this->m_timestampLastReadOnlineStations;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->ui->le_AtcStationsOnlineMetar->clear();
|
||||
}
|
||||
}
|
||||
|
||||
void CAtcStationComponent::reloadAtcStationsBooked()
|
||||
{
|
||||
Q_ASSERT(this->ui->tvp_AtcStationsBooked);
|
||||
Q_ASSERT(this->getIContextNetwork());
|
||||
|
||||
if (this->getIContextNetwork()->isConnected())
|
||||
{
|
||||
this->ui->tvp_AtcStationsBooked->update(this->getIContextNetwork()->getAtcStationsBooked());
|
||||
this->m_timestampLastReadBookedStations = QDateTime::currentDateTimeUtc();
|
||||
}
|
||||
}
|
||||
|
||||
void CAtcStationComponent::changedAtcStationsOnline()
|
||||
{
|
||||
this->m_timestampOnlineStationsChanged = QDateTime::currentDateTimeUtc();
|
||||
}
|
||||
|
||||
void CAtcStationComponent::changedAtcStationsBooked()
|
||||
{
|
||||
this->reloadAtcStationsBooked();
|
||||
}
|
||||
|
||||
void CAtcStationComponent::getMetar(const QString &airportIcaoCode)
|
||||
{
|
||||
if (!this->getIContextNetwork()->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->getIContextNetwork()->getMetar(icao);
|
||||
if (metar.getType() != CInformationMessage::METAR) return;
|
||||
if (metar.isEmpty()) return;
|
||||
this->ui->te_AtcStationsOnlineInfo->setText(metar.getMessage());
|
||||
}
|
||||
|
||||
void CAtcStationComponent::onlineAtcStationSelected(QModelIndex index)
|
||||
{
|
||||
this->ui->te_AtcStationsOnlineInfo->setText(""); // reset
|
||||
const CAtcStation stationClicked = this->ui->tvp_AtcStationsOnline->derivedModel()->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);
|
||||
}
|
||||
|
||||
void CAtcStationComponent::atcStationsTabChanged()
|
||||
{
|
||||
if (this->currentWidget() == this->ui->tb_AtcStationsOnline)
|
||||
{
|
||||
if (this->m_timestampLastReadBookedStations.isNull())
|
||||
this->reloadAtcStationsBooked();
|
||||
}
|
||||
}
|
||||
|
||||
void CAtcStationComponent::requestAtis()
|
||||
{
|
||||
if (!this->getIContextNetwork()->isConnected()) return;
|
||||
this->getIContextNetwork()->requestAtisUpdates();
|
||||
}
|
||||
}
|
||||
78
src/blackgui/atcstationcomponent.h
Normal file
78
src/blackgui/atcstationcomponent.h
Normal file
@@ -0,0 +1,78 @@
|
||||
#ifndef BLACKGUI_ATCSTATIONCOMPONENT_H
|
||||
#define BLACKGUI_ATCSTATIONCOMPONENT_H
|
||||
|
||||
#include "blackgui/runtimebasedcomponent.h"
|
||||
#include "blackgui/timerbasedcomponent.h"
|
||||
#include <QTabWidget>
|
||||
#include <QModelIndex>
|
||||
|
||||
namespace Ui { class CAtcStationComponent; }
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
/*!
|
||||
* \brief ATC stations component
|
||||
*/
|
||||
class CAtcStationComponent : public QTabWidget, public CRuntimeBasedComponent
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
explicit CAtcStationComponent(QWidget *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
~CAtcStationComponent();
|
||||
|
||||
//! Timer for updating
|
||||
CTimerBasedComponent *getTimerComponent() { return this->m_timerComponent; }
|
||||
|
||||
protected:
|
||||
//! \copydoc CRuntimeBasedComponent::runtimeHasBeenSet
|
||||
void runtimeHasBeenSet() override;
|
||||
|
||||
public slots:
|
||||
//! Update users
|
||||
void update();
|
||||
|
||||
//! \copydoc CTimerBasedComponent::setUpdateIntervalSeconds
|
||||
void setUpdateIntervalSeconds(int seconds) { Q_ASSERT(this->m_timerComponent); this->m_timerComponent->setUpdateIntervalSeconds(seconds); }
|
||||
|
||||
//! \copydoc CTimerBasedComponent::setUpdateInterval
|
||||
void setUpdateInterval(int milliSeconds) { Q_ASSERT(this->m_timerComponent); this->m_timerComponent->setUpdateInterval(milliSeconds); }
|
||||
|
||||
//! \copydoc CTimerBasedComponent::stopTimer
|
||||
void stopTimer() { Q_ASSERT(this->m_timerComponent); this->m_timerComponent->stopTimer(); }
|
||||
|
||||
//! Get METAR for given ICAO airport code
|
||||
void getMetar(const QString &airportIcaoCode = "");
|
||||
|
||||
private slots:
|
||||
|
||||
//! Request new ATIS
|
||||
void requestAtis();
|
||||
|
||||
//! Online ATC station selected
|
||||
void onlineAtcStationSelected(QModelIndex index);
|
||||
|
||||
//! Tab changed
|
||||
void atcStationsTabChanged();
|
||||
|
||||
//! Booked stations
|
||||
void reloadAtcStationsBooked();
|
||||
|
||||
//! Booked stations changed
|
||||
void changedAtcStationsBooked();
|
||||
|
||||
//! Online stations changed
|
||||
void changedAtcStationsOnline();
|
||||
|
||||
private:
|
||||
Ui::CAtcStationComponent *ui;
|
||||
CTimerBasedComponent *m_timerComponent;
|
||||
QDateTime m_timestampLastReadOnlineStations;
|
||||
QDateTime m_timestampOnlineStationsChanged;
|
||||
QDateTime m_timestampLastReadBookedStations;
|
||||
};
|
||||
}
|
||||
#endif // guard
|
||||
299
src/blackgui/atcstationcomponent.ui
Normal file
299
src/blackgui/atcstationcomponent.ui
Normal file
@@ -0,0 +1,299 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CAtcStationComponent</class>
|
||||
<widget class="QTabWidget" name="CAtcStationComponent">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>501</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>TabWidget</string>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tb_AtcStationsOnline">
|
||||
<attribute name="title">
|
||||
<string>Online</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="vl_AtcStationsOnline">
|
||||
<property name="spacing">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="BlackGui::CAtcStationView" name="tvp_AtcStationsOnline">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="gb_AtcStationsOnlineInfo">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>110</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Info (ATIS, METAR, ...)</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="vl_AtcStationsOnlineAtisGroup">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>12</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="te_AtcStationsOnlineInfo">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>100</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="fr_AtcStationsOnlineBottom">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>25</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_6">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetDefaultConstraint</enum>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="pb_AtcStationsLoadMetar">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Load METAR</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="pb_AtcStationsAtisReload">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Reload ATIS</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLineEdit" name="le_AtcStationsOnlineMetar">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string extracomment="Airport ICAO code"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>EDDF</string>
|
||||
</property>
|
||||
<property name="maxLength">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="frame">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tb_AtcStationsBooked">
|
||||
<attribute name="title">
|
||||
<string>Booked</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="vl_AtcStationsBooked">
|
||||
<property name="spacing">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="BlackGui::CAtcStationView" name="tvp_AtcStationsBooked">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pb_ReloadAtcStationsBooked">
|
||||
<property name="text">
|
||||
<string>Reload</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>BlackGui::CAtcStationView</class>
|
||||
<extends>QTableView</extends>
|
||||
<header>blackgui/atcstationview.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user