mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 12:55:31 +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
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
|
||||
Reference in New Issue
Block a user