mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 12:35:43 +08:00
Ref T731, moved AFV station model and client to BlackCore::Afv
* the QML map can also be used in dialog * ATC station list also can be used in BlackCore
This commit is contained in:
committed by
Mat Sutcliffe
parent
66b02e61c5
commit
992d624c18
@@ -24,9 +24,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
|||||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||||
|
|
||||||
HEADERS += *.h
|
HEADERS += *.h
|
||||||
HEADERS += $$PWD/models/*.h
|
|
||||||
SOURCES += *.cpp
|
SOURCES += *.cpp
|
||||||
SOURCES += $$PWD/models/*.cpp
|
|
||||||
|
|
||||||
DEFINES += _USE_MATH_DEFINES
|
DEFINES += _USE_MATH_DEFINES
|
||||||
RESOURCES += qml/qml.qrc
|
RESOURCES += qml/qml.qrc
|
||||||
|
|||||||
@@ -1,91 +0,0 @@
|
|||||||
#include "afvmapreader.h"
|
|
||||||
#include "blackcore/application.h"
|
|
||||||
#include "dto.h"
|
|
||||||
#include <QEventLoop>
|
|
||||||
#include <QNetworkReply>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QJsonArray>
|
|
||||||
|
|
||||||
using namespace BlackCore::Afv;
|
|
||||||
|
|
||||||
AFVMapReader::AFVMapReader(QObject *parent) : QObject(parent)
|
|
||||||
{
|
|
||||||
m_model = new CSampleAtcStationModel(this);
|
|
||||||
m_timer = new QTimer(this);
|
|
||||||
connect(m_timer, &QTimer::timeout, this, &AFVMapReader::updateFromMap);
|
|
||||||
m_timer->start(3000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AFVMapReader::updateFromMap()
|
|
||||||
{
|
|
||||||
if (! sApp) { return; }
|
|
||||||
|
|
||||||
QEventLoop loop;
|
|
||||||
connect(sApp->getNetworkAccessManager(), &QNetworkAccessManager::finished, &loop, &QEventLoop::quit);
|
|
||||||
QNetworkReply *reply = sApp->getNetworkAccessManager()->get(QNetworkRequest(QUrl("https://afv-map.vatsim.net/atis-map-data")));
|
|
||||||
while (! reply->isFinished()) { loop.exec(); }
|
|
||||||
QByteArray jsonData = reply->readAll();
|
|
||||||
reply->deleteLater();
|
|
||||||
|
|
||||||
if (jsonData.isEmpty()) { return; }
|
|
||||||
|
|
||||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
|
|
||||||
if (jsonDoc.isObject())
|
|
||||||
{
|
|
||||||
QJsonObject rootObject = jsonDoc.object();
|
|
||||||
QVector<CSampleAtcStation> transceivers;
|
|
||||||
|
|
||||||
if (rootObject.contains("controllers"))
|
|
||||||
{
|
|
||||||
QJsonObject otherObject = rootObject.value("controllers").toObject();
|
|
||||||
for (auto it = otherObject.begin(); it != otherObject.end(); ++it)
|
|
||||||
{
|
|
||||||
QString callsign = it.key();
|
|
||||||
if (it.value().isObject())
|
|
||||||
{
|
|
||||||
QJsonObject stationObject = it.value().toObject();
|
|
||||||
if (stationObject.contains("transceivers"))
|
|
||||||
{
|
|
||||||
QJsonArray txArray = stationObject.value("transceivers").toArray();
|
|
||||||
for (auto jt = txArray.begin(); jt != txArray.end(); ++jt)
|
|
||||||
{
|
|
||||||
TransceiverDto transceiver = TransceiverDto::fromJson(jt->toObject());
|
|
||||||
transceivers.push_back( { callsign, transceiver} );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rootObject.contains("other") && rootObject.value("other").isObject())
|
|
||||||
{
|
|
||||||
QJsonObject otherObject = rootObject.value("other").toObject();
|
|
||||||
for (auto it = otherObject.begin(); it != otherObject.end(); ++it)
|
|
||||||
{
|
|
||||||
QString callsign = it.key();
|
|
||||||
if (it.value().isObject())
|
|
||||||
{
|
|
||||||
QJsonObject stationObject = it.value().toObject();
|
|
||||||
if (stationObject.contains("transceivers"))
|
|
||||||
{
|
|
||||||
QJsonArray txArray = stationObject.value("transceivers").toArray();
|
|
||||||
for (auto jt = txArray.begin(); jt != txArray.end(); ++jt)
|
|
||||||
{
|
|
||||||
TransceiverDto transceiver = TransceiverDto::fromJson(jt->toObject());
|
|
||||||
transceivers.push_back( { callsign, transceiver} );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (transceivers.isEmpty()) { return; }
|
|
||||||
transceivers.erase(std::remove_if(transceivers.begin(), transceivers.end(), [this](const CSampleAtcStation &s)
|
|
||||||
{
|
|
||||||
return s.callsign() == m_callsign;
|
|
||||||
}),
|
|
||||||
transceivers.end());
|
|
||||||
m_model->updateAtcStations(transceivers);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
/* Copyright (C) 2019
|
|
||||||
* swift Project Community / Contributors
|
|
||||||
*
|
|
||||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
|
||||||
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
|
||||||
* or distributed except according to the terms contained in the LICENSE file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BLACKSAMPLE_AFVMAPREADER_H
|
|
||||||
#define BLACKSAMPLE_AFVMAPREADER_H
|
|
||||||
|
|
||||||
#include "models/atcstationmodel.h"
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
//! Map reader
|
|
||||||
class AFVMapReader : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
Q_PROPERTY(CSampleAtcStationModel* atcStationModel READ getAtcStationModel CONSTANT)
|
|
||||||
|
|
||||||
public:
|
|
||||||
//! Ctor
|
|
||||||
AFVMapReader(QObject *parent = nullptr);
|
|
||||||
|
|
||||||
Q_INVOKABLE void setOwnCallsign(const QString &callsign) { m_callsign = callsign; }
|
|
||||||
|
|
||||||
void updateFromMap();
|
|
||||||
|
|
||||||
CSampleAtcStationModel *getAtcStationModel() { return m_model; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
CSampleAtcStationModel *m_model = nullptr;
|
|
||||||
QTimer *m_timer = nullptr;
|
|
||||||
QString m_callsign;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // guard
|
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
// #include "voiceclientui.h"
|
// #include "voiceclientui.h"
|
||||||
|
|
||||||
#include "models/atcstationmodel.h"
|
#include "blackcore/afv/model/atcstationmodel.h"
|
||||||
#include "clients/afvclient.h"
|
#include "blackcore/afv/model/afvmapreader.h"
|
||||||
#include "afvmapreader.h"
|
#include "blackcore/afv/clients/afvclient.h"
|
||||||
|
|
||||||
#include "blackcore/application.h"
|
#include "blackcore/application.h"
|
||||||
|
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
@@ -12,6 +13,7 @@
|
|||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
using namespace BlackCore::Afv::Clients;
|
using namespace BlackCore::Afv::Clients;
|
||||||
|
using namespace BlackCore::Afv::Model;
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@@ -20,7 +22,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
BlackCore::CApplication a("sampleafvclient", BlackMisc::CApplicationInfo::Sample);
|
BlackCore::CApplication a("sampleafvclient", BlackMisc::CApplicationInfo::Sample);
|
||||||
|
|
||||||
AFVMapReader *afvMapReader = new AFVMapReader(&a);
|
CAfvMapReader *afvMapReader = new CAfvMapReader(&a);
|
||||||
afvMapReader->updateFromMap();
|
afvMapReader->updateFromMap();
|
||||||
|
|
||||||
CAfvClient voiceClient("https://voice1.vatsim.uk");
|
CAfvClient voiceClient("https://voice1.vatsim.uk");
|
||||||
|
|||||||
@@ -1,118 +0,0 @@
|
|||||||
/* Copyright (C) 2019
|
|
||||||
* swift Project Community / Contributors
|
|
||||||
*
|
|
||||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
|
||||||
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
|
||||||
* or distributed except according to the terms contained in the LICENSE file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "atcstationmodel.h"
|
|
||||||
#include "dto.h"
|
|
||||||
#include <QtMath>
|
|
||||||
|
|
||||||
using namespace BlackCore::Afv;
|
|
||||||
|
|
||||||
CSampleAtcStation::CSampleAtcStation(const QString &callsign, const TransceiverDto &transceiver) :
|
|
||||||
m_callsign(callsign),
|
|
||||||
m_transceiver(transceiver)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
double CSampleAtcStation::latitude() const
|
|
||||||
{
|
|
||||||
return m_transceiver.LatDeg;
|
|
||||||
}
|
|
||||||
|
|
||||||
double CSampleAtcStation::longitude() const
|
|
||||||
{
|
|
||||||
return m_transceiver.LonDeg;
|
|
||||||
}
|
|
||||||
|
|
||||||
quint32 CSampleAtcStation::frequency() const
|
|
||||||
{
|
|
||||||
return m_transceiver.frequency;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CSampleAtcStation::formattedFrequency() const
|
|
||||||
{
|
|
||||||
return QString::number(m_transceiver.frequency / 1000000.0, 'f', 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
double CSampleAtcStation::radioDistanceM() const
|
|
||||||
{
|
|
||||||
double sqrtAltM = qSqrt(m_transceiver.HeightMslM);
|
|
||||||
const double radioFactor = 4193.18014745372;
|
|
||||||
|
|
||||||
return radioFactor * sqrtAltM;
|
|
||||||
}
|
|
||||||
|
|
||||||
CSampleAtcStationModel::CSampleAtcStationModel(QObject *parent) :
|
|
||||||
QAbstractListModel(parent)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
CSampleAtcStationModel::~CSampleAtcStationModel() {}
|
|
||||||
|
|
||||||
void CSampleAtcStationModel::updateAtcStations(const QVector<CSampleAtcStation> &atcStations)
|
|
||||||
{
|
|
||||||
// Add stations which didn't exist yet
|
|
||||||
for (const auto &station : atcStations)
|
|
||||||
{
|
|
||||||
if (! m_atcStations.contains(station)) { addStation(station); }
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove all stations which are no longer there
|
|
||||||
for (int i = m_atcStations.size() - 1; i >= 0; i--)
|
|
||||||
{
|
|
||||||
CSampleAtcStation &station = m_atcStations[i];
|
|
||||||
if (! m_atcStations.contains(station))
|
|
||||||
{
|
|
||||||
removeStationAtPosition(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSampleAtcStationModel::addStation(const CSampleAtcStation &atcStation)
|
|
||||||
{
|
|
||||||
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
|
||||||
m_atcStations << atcStation;
|
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSampleAtcStationModel::removeStationAtPosition(int i)
|
|
||||||
{
|
|
||||||
beginRemoveRows(QModelIndex(), i, i);
|
|
||||||
m_atcStations.removeAt(i);
|
|
||||||
endRemoveRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
int CSampleAtcStationModel::rowCount(const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
Q_UNUSED(parent);
|
|
||||||
return m_atcStations.count();
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant CSampleAtcStationModel::data(const QModelIndex &index, int role) const
|
|
||||||
{
|
|
||||||
if (index.row() < 0 || index.row() >= m_atcStations.count())
|
|
||||||
return QVariant();
|
|
||||||
|
|
||||||
const CSampleAtcStation &atcStation = m_atcStations[index.row()];
|
|
||||||
if (role == CallsignRole) return atcStation.callsign();
|
|
||||||
if (role == LatitudeRole) return atcStation.latitude();
|
|
||||||
if (role == LongitudeRole) return atcStation.longitude();
|
|
||||||
if (role == RadioDistanceRole) return atcStation.radioDistanceM();
|
|
||||||
if (role == FrequencyRole) return atcStation.formattedFrequency();
|
|
||||||
if (role == FrequencyKhzRole) return atcStation.frequency() / 1000;
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
QHash<int, QByteArray> CSampleAtcStationModel::roleNames() const
|
|
||||||
{
|
|
||||||
QHash<int, QByteArray> roles;
|
|
||||||
roles[CallsignRole] = "callsign";
|
|
||||||
roles[LatitudeRole] = "latitude";
|
|
||||||
roles[LongitudeRole] = "longitude";
|
|
||||||
roles[RadioDistanceRole] = "radioDistanceM";
|
|
||||||
roles[FrequencyRole] = "frequencyAsString";
|
|
||||||
roles[FrequencyKhzRole] = "frequencyKhz";
|
|
||||||
return roles;
|
|
||||||
}
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
/* Copyright (C) 2019
|
|
||||||
* swift Project Community / Contributors
|
|
||||||
*
|
|
||||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
|
||||||
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
|
||||||
* or distributed except according to the terms contained in the LICENSE file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BLACKSAMPLE_MODELS_ATCSTATIONMODEL_H
|
|
||||||
#define BLACKSAMPLE_MODELS_ATCSTATIONMODEL_H
|
|
||||||
|
|
||||||
#include "dto.h"
|
|
||||||
#include <QtGlobal>
|
|
||||||
#include <QAbstractListModel>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
//! Sample ATC station
|
|
||||||
class CSampleAtcStation
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
//! Ctor
|
|
||||||
CSampleAtcStation() {}
|
|
||||||
|
|
||||||
//! Ctor
|
|
||||||
CSampleAtcStation(const QString &callsign, const BlackCore::Afv::TransceiverDto &transceiver);
|
|
||||||
|
|
||||||
//! Getter @{
|
|
||||||
const QString &callsign() const { return m_callsign; }
|
|
||||||
QString formattedFrequency() const;
|
|
||||||
double latitude() const;
|
|
||||||
double longitude() const;
|
|
||||||
double radioDistanceM() const;
|
|
||||||
quint32 frequency() const;
|
|
||||||
//! @}
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString m_callsign;
|
|
||||||
BlackCore::Afv::TransceiverDto m_transceiver;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline bool operator==(const CSampleAtcStation &lhs, const CSampleAtcStation &rhs)
|
|
||||||
{
|
|
||||||
return lhs.callsign() == rhs.callsign() &&
|
|
||||||
qFuzzyCompare(lhs.latitude(), rhs.latitude()) &&
|
|
||||||
qFuzzyCompare(lhs.longitude(), rhs.longitude());
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Sample list model
|
|
||||||
class CSampleAtcStationModel : public QAbstractListModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
//! Roles for model
|
|
||||||
enum AtcStationRoles
|
|
||||||
{
|
|
||||||
CallsignRole = Qt::UserRole + 1,
|
|
||||||
LatitudeRole,
|
|
||||||
LongitudeRole,
|
|
||||||
RadioDistanceRole,
|
|
||||||
FrequencyRole,
|
|
||||||
FrequencyKhzRole
|
|
||||||
};
|
|
||||||
|
|
||||||
//! Ctor
|
|
||||||
CSampleAtcStationModel(QObject *parent = nullptr);
|
|
||||||
|
|
||||||
//! Dtor
|
|
||||||
virtual ~CSampleAtcStationModel() override;
|
|
||||||
|
|
||||||
//! Update the stations
|
|
||||||
void updateAtcStations(const QVector<CSampleAtcStation> &atcStations);
|
|
||||||
|
|
||||||
//! copydoc QAbstractListModel::rowCount
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
|
|
||||||
//! copydoc QAbstractListModel::data
|
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
//! copydoc QAbstractListModel::roleNames
|
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void addStation(const CSampleAtcStation &atcStation);
|
|
||||||
void removeStationAtPosition(int i);
|
|
||||||
|
|
||||||
QList<CSampleAtcStation> m_atcStations;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // guard
|
|
||||||
@@ -88,7 +88,6 @@ namespace BlackCore
|
|||||||
void setTransmittingTransceivers(const QVector<TxTransceiverDto> &transceivers);
|
void setTransmittingTransceivers(const QVector<TxTransceiverDto> &transceivers);
|
||||||
|
|
||||||
Q_INVOKABLE void setPtt(bool active);
|
Q_INVOKABLE void setPtt(bool active);
|
||||||
|
|
||||||
Q_INVOKABLE void setLoopBack(bool on) { m_loopbackOn = on; }
|
Q_INVOKABLE void setLoopBack(bool on) { m_loopbackOn = on; }
|
||||||
|
|
||||||
//! Input volume in DB, +-18DB @{
|
//! Input volume in DB, +-18DB @{
|
||||||
|
|||||||
99
src/blackcore/afv/model/afvmapreader.cpp
Normal file
99
src/blackcore/afv/model/afvmapreader.cpp
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
#include "afvmapreader.h"
|
||||||
|
#include "blackcore/application.h"
|
||||||
|
#include "blackcore/afv/dto.h"
|
||||||
|
#include <QEventLoop>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
|
||||||
|
namespace BlackCore
|
||||||
|
{
|
||||||
|
namespace Afv
|
||||||
|
{
|
||||||
|
namespace Model
|
||||||
|
{
|
||||||
|
CAfvMapReader::CAfvMapReader(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
m_model = new CSampleAtcStationModel(this);
|
||||||
|
m_timer = new QTimer(this);
|
||||||
|
connect(m_timer, &QTimer::timeout, this, &CAfvMapReader::updateFromMap);
|
||||||
|
m_timer->start(3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAfvMapReader::updateFromMap()
|
||||||
|
{
|
||||||
|
if (!sApp || sApp->isShuttingDown()) { return; }
|
||||||
|
|
||||||
|
QEventLoop loop;
|
||||||
|
connect(sApp->getNetworkAccessManager(), &QNetworkAccessManager::finished, &loop, &QEventLoop::quit);
|
||||||
|
QNetworkReply *reply = sApp->getNetworkAccessManager()->get(QNetworkRequest(QUrl("https://afv-map.vatsim.net/atis-map-data")));
|
||||||
|
while (! reply->isFinished()) { loop.exec(); }
|
||||||
|
QByteArray jsonData = reply->readAll();
|
||||||
|
reply->deleteLater();
|
||||||
|
|
||||||
|
if (jsonData.isEmpty()) { return; }
|
||||||
|
|
||||||
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
|
||||||
|
if (jsonDoc.isObject())
|
||||||
|
{
|
||||||
|
QJsonObject rootObject = jsonDoc.object();
|
||||||
|
QVector<CSampleAtcStation> transceivers;
|
||||||
|
|
||||||
|
if (rootObject.contains("controllers"))
|
||||||
|
{
|
||||||
|
QJsonObject otherObject = rootObject.value("controllers").toObject();
|
||||||
|
for (auto it = otherObject.begin(); it != otherObject.end(); ++it)
|
||||||
|
{
|
||||||
|
QString callsign = it.key();
|
||||||
|
if (it.value().isObject())
|
||||||
|
{
|
||||||
|
QJsonObject stationObject = it.value().toObject();
|
||||||
|
if (stationObject.contains("transceivers"))
|
||||||
|
{
|
||||||
|
QJsonArray txArray = stationObject.value("transceivers").toArray();
|
||||||
|
for (auto jt = txArray.begin(); jt != txArray.end(); ++jt)
|
||||||
|
{
|
||||||
|
TransceiverDto transceiver = TransceiverDto::fromJson(jt->toObject());
|
||||||
|
transceivers.push_back({ callsign, transceiver});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rootObject.contains("other") && rootObject.value("other").isObject())
|
||||||
|
{
|
||||||
|
QJsonObject otherObject = rootObject.value("other").toObject();
|
||||||
|
for (auto it = otherObject.begin(); it != otherObject.end(); ++it)
|
||||||
|
{
|
||||||
|
QString callsign = it.key();
|
||||||
|
if (it.value().isObject())
|
||||||
|
{
|
||||||
|
QJsonObject stationObject = it.value().toObject();
|
||||||
|
if (stationObject.contains("transceivers"))
|
||||||
|
{
|
||||||
|
QJsonArray txArray = stationObject.value("transceivers").toArray();
|
||||||
|
for (auto jt = txArray.begin(); jt != txArray.end(); ++jt)
|
||||||
|
{
|
||||||
|
TransceiverDto transceiver = TransceiverDto::fromJson(jt->toObject());
|
||||||
|
transceivers.push_back({ callsign, transceiver});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (transceivers.isEmpty()) { return; }
|
||||||
|
transceivers.erase(std::remove_if(transceivers.begin(), transceivers.end(), [this](const CSampleAtcStation & s)
|
||||||
|
{
|
||||||
|
return s.callsign() == m_callsign;
|
||||||
|
}),
|
||||||
|
transceivers.end());
|
||||||
|
m_model->updateAtcStations(transceivers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // ns
|
||||||
|
} // ns
|
||||||
|
} // ns
|
||||||
49
src/blackcore/afv/model/afvmapreader.h
Normal file
49
src/blackcore/afv/model/afvmapreader.h
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/* Copyright (C) 2019
|
||||||
|
* swift Project Community / Contributors
|
||||||
|
*
|
||||||
|
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
|
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
||||||
|
* or distributed except according to the terms contained in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BLACKCORE_AFV_AFVMAPREADER_H
|
||||||
|
#define BLACKCORE_AFV_AFVMAPREADER_H
|
||||||
|
|
||||||
|
#include "atcstationmodel.h"
|
||||||
|
#include "blackcore/blackcoreexport.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
namespace BlackCore
|
||||||
|
{
|
||||||
|
namespace Afv
|
||||||
|
{
|
||||||
|
namespace Model
|
||||||
|
{
|
||||||
|
//! Map reader
|
||||||
|
class BLACKCORE_EXPORT CAfvMapReader : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(CSampleAtcStationModel *atcStationModel READ getAtcStationModel CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
//! Ctor
|
||||||
|
CAfvMapReader(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
Q_INVOKABLE void setOwnCallsign(const QString &callsign) { m_callsign = callsign; }
|
||||||
|
|
||||||
|
void updateFromMap();
|
||||||
|
|
||||||
|
CSampleAtcStationModel *getAtcStationModel() { return m_model; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
CSampleAtcStationModel *m_model = nullptr;
|
||||||
|
QTimer *m_timer = nullptr;
|
||||||
|
QString m_callsign;
|
||||||
|
};
|
||||||
|
} // ns
|
||||||
|
} // ns
|
||||||
|
} // ns
|
||||||
|
|
||||||
|
#endif // guard
|
||||||
126
src/blackcore/afv/model/atcstationmodel.cpp
Normal file
126
src/blackcore/afv/model/atcstationmodel.cpp
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
/* Copyright (C) 2019
|
||||||
|
* swift Project Community / Contributors
|
||||||
|
*
|
||||||
|
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
|
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
||||||
|
* or distributed except according to the terms contained in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "atcstationmodel.h"
|
||||||
|
#include <QtMath>
|
||||||
|
|
||||||
|
using namespace BlackCore::Afv;
|
||||||
|
|
||||||
|
namespace BlackCore
|
||||||
|
{
|
||||||
|
namespace Afv
|
||||||
|
{
|
||||||
|
namespace Model
|
||||||
|
{
|
||||||
|
CSampleAtcStation::CSampleAtcStation(const QString &callsign, const TransceiverDto &transceiver) :
|
||||||
|
m_callsign(callsign),
|
||||||
|
m_transceiver(transceiver)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
double CSampleAtcStation::latitude() const
|
||||||
|
{
|
||||||
|
return m_transceiver.LatDeg;
|
||||||
|
}
|
||||||
|
|
||||||
|
double CSampleAtcStation::longitude() const
|
||||||
|
{
|
||||||
|
return m_transceiver.LonDeg;
|
||||||
|
}
|
||||||
|
|
||||||
|
quint32 CSampleAtcStation::frequency() const
|
||||||
|
{
|
||||||
|
return m_transceiver.frequency;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CSampleAtcStation::formattedFrequency() const
|
||||||
|
{
|
||||||
|
return QString::number(m_transceiver.frequency / 1000000.0, 'f', 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
double CSampleAtcStation::radioDistanceM() const
|
||||||
|
{
|
||||||
|
double sqrtAltM = qSqrt(m_transceiver.HeightMslM);
|
||||||
|
const double radioFactor = 4193.18014745372;
|
||||||
|
|
||||||
|
return radioFactor * sqrtAltM;
|
||||||
|
}
|
||||||
|
|
||||||
|
CSampleAtcStationModel::CSampleAtcStationModel(QObject *parent) :
|
||||||
|
QAbstractListModel(parent)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
CSampleAtcStationModel::~CSampleAtcStationModel() {}
|
||||||
|
|
||||||
|
void CSampleAtcStationModel::updateAtcStations(const QVector<CSampleAtcStation> &atcStations)
|
||||||
|
{
|
||||||
|
// Add stations which didn't exist yet
|
||||||
|
for (const auto &station : atcStations)
|
||||||
|
{
|
||||||
|
if (! m_atcStations.contains(station)) { addStation(station); }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove all stations which are no longer there
|
||||||
|
for (int i = m_atcStations.size() - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
CSampleAtcStation &station = m_atcStations[i];
|
||||||
|
if (! m_atcStations.contains(station))
|
||||||
|
{
|
||||||
|
removeStationAtPosition(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSampleAtcStationModel::addStation(const CSampleAtcStation &atcStation)
|
||||||
|
{
|
||||||
|
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
||||||
|
m_atcStations << atcStation;
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSampleAtcStationModel::removeStationAtPosition(int i)
|
||||||
|
{
|
||||||
|
beginRemoveRows(QModelIndex(), i, i);
|
||||||
|
m_atcStations.removeAt(i);
|
||||||
|
endRemoveRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
int CSampleAtcStationModel::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(parent)
|
||||||
|
return m_atcStations.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant CSampleAtcStationModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (index.row() < 0 || index.row() >= m_atcStations.count())
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
const CSampleAtcStation &atcStation = m_atcStations[index.row()];
|
||||||
|
if (role == CallsignRole) return atcStation.callsign();
|
||||||
|
if (role == LatitudeRole) return atcStation.latitude();
|
||||||
|
if (role == LongitudeRole) return atcStation.longitude();
|
||||||
|
if (role == RadioDistanceRole) return atcStation.radioDistanceM();
|
||||||
|
if (role == FrequencyRole) return atcStation.formattedFrequency();
|
||||||
|
if (role == FrequencyKhzRole) return atcStation.frequency() / 1000;
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> CSampleAtcStationModel::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> roles;
|
||||||
|
roles[CallsignRole] = "callsign";
|
||||||
|
roles[LatitudeRole] = "latitude";
|
||||||
|
roles[LongitudeRole] = "longitude";
|
||||||
|
roles[RadioDistanceRole] = "radioDistanceM";
|
||||||
|
roles[FrequencyRole] = "frequencyAsString";
|
||||||
|
roles[FrequencyKhzRole] = "frequencyKhz";
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
105
src/blackcore/afv/model/atcstationmodel.h
Normal file
105
src/blackcore/afv/model/atcstationmodel.h
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
/* Copyright (C) 2019
|
||||||
|
* swift Project Community / Contributors
|
||||||
|
*
|
||||||
|
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
|
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
||||||
|
* or distributed except according to the terms contained in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BLACKCORE_AFV_MODEL_ATCSTATIONMODEL_H
|
||||||
|
#define BLACKCORE_AFV_MODEL_ATCSTATIONMODEL_H
|
||||||
|
|
||||||
|
#include "blackcore/afv/dto.h"
|
||||||
|
#include "blackcore/blackcoreexport.h"
|
||||||
|
|
||||||
|
#include <QtGlobal>
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
namespace BlackCore
|
||||||
|
{
|
||||||
|
namespace Afv
|
||||||
|
{
|
||||||
|
namespace Model
|
||||||
|
{
|
||||||
|
//! Sample ATC station
|
||||||
|
class BLACKCORE_EXPORT CSampleAtcStation
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! Ctor
|
||||||
|
CSampleAtcStation() {}
|
||||||
|
|
||||||
|
//! Ctor
|
||||||
|
CSampleAtcStation(const QString &callsign, const BlackCore::Afv::TransceiverDto &transceiver);
|
||||||
|
|
||||||
|
//! Getter @{
|
||||||
|
const QString &callsign() const { return m_callsign; }
|
||||||
|
QString formattedFrequency() const;
|
||||||
|
double latitude() const;
|
||||||
|
double longitude() const;
|
||||||
|
double radioDistanceM() const;
|
||||||
|
quint32 frequency() const;
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_callsign;
|
||||||
|
TransceiverDto m_transceiver;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline bool operator==(const CSampleAtcStation &lhs, const CSampleAtcStation &rhs)
|
||||||
|
{
|
||||||
|
return lhs.callsign() == rhs.callsign() &&
|
||||||
|
qFuzzyCompare(lhs.latitude(), rhs.latitude()) &&
|
||||||
|
qFuzzyCompare(lhs.longitude(), rhs.longitude());
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Sample list model
|
||||||
|
class CSampleAtcStationModel : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
//! Roles for model
|
||||||
|
enum AtcStationRoles
|
||||||
|
{
|
||||||
|
CallsignRole = Qt::UserRole + 1,
|
||||||
|
LatitudeRole,
|
||||||
|
LongitudeRole,
|
||||||
|
RadioDistanceRole,
|
||||||
|
FrequencyRole,
|
||||||
|
FrequencyKhzRole
|
||||||
|
};
|
||||||
|
|
||||||
|
//! Ctor
|
||||||
|
CSampleAtcStationModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
//! Dtor
|
||||||
|
virtual ~CSampleAtcStationModel() override;
|
||||||
|
|
||||||
|
//! Update the stations
|
||||||
|
void updateAtcStations(const QVector<CSampleAtcStation> &atcStations);
|
||||||
|
|
||||||
|
//! copydoc QAbstractListModel::rowCount
|
||||||
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
|
||||||
|
//! copydoc QAbstractListModel::data
|
||||||
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//! copydoc QAbstractListModel::roleNames
|
||||||
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void addStation(const CSampleAtcStation &atcStation);
|
||||||
|
void removeStationAtPosition(int i);
|
||||||
|
|
||||||
|
QList<CSampleAtcStation> m_atcStations;
|
||||||
|
};
|
||||||
|
} // ns
|
||||||
|
} // ns
|
||||||
|
} // ns
|
||||||
|
|
||||||
|
#endif // guard
|
||||||
@@ -33,6 +33,7 @@ HEADERS += $$PWD/afv/audio/*.h
|
|||||||
HEADERS += $$PWD/afv/clients/*.h
|
HEADERS += $$PWD/afv/clients/*.h
|
||||||
HEADERS += $$PWD/afv/crypto/*.h
|
HEADERS += $$PWD/afv/crypto/*.h
|
||||||
HEADERS += $$PWD/afv/connection/*.h
|
HEADERS += $$PWD/afv/connection/*.h
|
||||||
|
HEADERS += $$PWD/afv/model/*.h
|
||||||
|
|
||||||
SOURCES += *.cpp
|
SOURCES += *.cpp
|
||||||
SOURCES += $$PWD/context/*.cpp
|
SOURCES += $$PWD/context/*.cpp
|
||||||
@@ -44,6 +45,7 @@ SOURCES += $$PWD/afv/audio/*.cpp
|
|||||||
SOURCES += $$PWD/afv/clients/*.cpp
|
SOURCES += $$PWD/afv/clients/*.cpp
|
||||||
SOURCES += $$PWD/afv/crypto/*.cpp
|
SOURCES += $$PWD/afv/crypto/*.cpp
|
||||||
SOURCES += $$PWD/afv/connection/*.cpp
|
SOURCES += $$PWD/afv/connection/*.cpp
|
||||||
|
SOURCES += $$PWD/afv/model/*.cpp
|
||||||
|
|
||||||
LIBS *= \
|
LIBS *= \
|
||||||
-lvatlib \
|
-lvatlib \
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
load(common_pre)
|
load(common_pre)
|
||||||
|
|
||||||
QT += core dbus gui network svg widgets quickwidgets
|
QT += core dbus gui network svg widgets multimedia quickwidgets
|
||||||
|
|
||||||
TARGET = blackgui
|
TARGET = blackgui
|
||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
|
|||||||
@@ -8,8 +8,15 @@
|
|||||||
|
|
||||||
//! \file
|
//! \file
|
||||||
|
|
||||||
|
#include "blackcore/afv/clients/afvclient.h"
|
||||||
|
#include "blackcore/afv/model/afvmapreader.h"
|
||||||
|
|
||||||
#include "afvmapdialog.h"
|
#include "afvmapdialog.h"
|
||||||
#include "ui_afvmapdialog.h"
|
#include "ui_afvmapdialog.h"
|
||||||
|
#include <QQmlContext>
|
||||||
|
|
||||||
|
using namespace BlackCore::Afv::Model;
|
||||||
|
using namespace BlackCore::Afv::Clients;
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
@@ -20,6 +27,13 @@ namespace BlackGui
|
|||||||
ui(new Ui::CAfvMapDialog)
|
ui(new Ui::CAfvMapDialog)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
m_afvMapReader = new CAfvMapReader(this);
|
||||||
|
m_afvMapReader->updateFromMap();
|
||||||
|
m_afvClient = new CAfvClient("https://voice1.vatsim.uk");
|
||||||
|
|
||||||
|
QQmlContext *ctxt = ui->qw_AfvMap->rootContext();
|
||||||
|
ctxt->setContextProperty("afvMapReader", m_afvMapReader);
|
||||||
|
ctxt->setContextProperty("voiceClient", m_afvClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
CAfvMapDialog::~CAfvMapDialog() { }
|
CAfvMapDialog::~CAfvMapDialog() { }
|
||||||
|
|||||||
@@ -15,6 +15,14 @@
|
|||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
|
|
||||||
|
namespace BlackCore
|
||||||
|
{
|
||||||
|
namespace Afv
|
||||||
|
{
|
||||||
|
namespace Model { class CAfvMapReader; }
|
||||||
|
namespace Clients { class CAfvClient; }
|
||||||
|
}
|
||||||
|
}
|
||||||
namespace Ui { class CAfvMapDialog; }
|
namespace Ui { class CAfvMapDialog; }
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
@@ -34,6 +42,8 @@ namespace BlackGui
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QScopedPointer<Ui::CAfvMapDialog> ui;
|
QScopedPointer<Ui::CAfvMapDialog> ui;
|
||||||
|
BlackCore::Afv::Model::CAfvMapReader *m_afvMapReader = nullptr;
|
||||||
|
BlackCore::Afv::Clients::CAfvClient *m_afvClient = nullptr;
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -638,6 +638,7 @@ bool SwiftGuiStd::startAFVMap()
|
|||||||
if (!m_mapDialog)
|
if (!m_mapDialog)
|
||||||
{
|
{
|
||||||
m_mapDialog.reset(new CAfvMapDialog(this));
|
m_mapDialog.reset(new CAfvMapDialog(this));
|
||||||
|
m_mapDialog->setWindowModality(Qt::NonModal);
|
||||||
}
|
}
|
||||||
m_mapDialog->exec();
|
m_mapDialog->exec();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user