Ref T730, namespace for BlackCore::Afv

* added namespace
* removed some *.pri files and added files to blackcore.pro
* added copyright etc.
This commit is contained in:
Klaus Basan
2019-09-19 00:56:54 +02:00
committed by Mat Sutcliffe
parent d064da13b5
commit 384aa3ce19
46 changed files with 2985 additions and 2916 deletions

View File

@@ -4,7 +4,7 @@ QT += dbus network multimedia gui quick
CONFIG += c++14
CONFIG -= app_bundle
CONFIG += blackmisc blackcore blackconfig
CONFIG += blackmisc blackcore blackconfig
DEPENDPATH += . $$SourceRoot/src/blackmisc
INCLUDEPATH += . $$SourceRoot/src
@@ -23,19 +23,13 @@ DEFINES += QT_DEPRECATED_WARNINGS
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
afvmapreader.cpp \
models/atcstationmodel.cpp \
main.cpp \
HEADERS += \
models/atcstationmodel.h \
afvmapreader.h \
HEADERS += *.h
HEADERS += $$PWD/models/*.h
SOURCES += *.cpp
SOURCES += $$PWD/models/*.cpp
DEFINES += _USE_MATH_DEFINES
RESOURCES += \
qml/qml.qrc
RESOURCES += qml/qml.qrc
DESTDIR = $$DestRoot/bin

View File

@@ -7,12 +7,14 @@
#include <QJsonObject>
#include <QJsonArray>
using namespace BlackCore::Afv;
AFVMapReader::AFVMapReader(QObject *parent) : QObject(parent)
{
model = new AtcStationModel(this);
timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &AFVMapReader::updateFromMap);
timer->start(3000);
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()
@@ -32,7 +34,7 @@ void AFVMapReader::updateFromMap()
if (jsonDoc.isObject())
{
QJsonObject rootObject = jsonDoc.object();
QVector<AtcStation> transceivers;
QVector<CSampleAtcStation> transceivers;
if (rootObject.contains("controllers"))
{
@@ -79,11 +81,11 @@ void AFVMapReader::updateFromMap()
}
if (transceivers.isEmpty()) { return; }
transceivers.erase(std::remove_if(transceivers.begin(), transceivers.end(), [this](const AtcStation &s)
transceivers.erase(std::remove_if(transceivers.begin(), transceivers.end(), [this](const CSampleAtcStation &s)
{
return s.callsign() == m_callsign;
}),
transceivers.end());
model->updateAtcStations(transceivers);
m_model->updateAtcStations(transceivers);
}
}

View File

@@ -1,28 +1,39 @@
#ifndef AFVMAPREADER_H
#define AFVMAPREADER_H
/* 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(AtcStationModel* atcStationModel READ getAtcStationModel CONSTANT)
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();
AtcStationModel *getAtcStationModel() { return model; }
CSampleAtcStationModel *getAtcStationModel() { return m_model; }
private:
AtcStationModel *model = nullptr;
QTimer *timer = nullptr;
CSampleAtcStationModel *m_model = nullptr;
QTimer *m_timer = nullptr;
QString m_callsign;
};
#endif // AFVMAPREADER_H
#endif // guard

View File

@@ -1,4 +1,5 @@
// #include "voiceclientui.h"
#include "models/atcstationmodel.h"
#include "clients/afvclient.h"
#include "afvmapreader.h"
@@ -10,6 +11,8 @@
#include <QPointer>
#include <QThread>
using namespace BlackCore::Afv::Clients;
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

View File

@@ -1,34 +1,43 @@
/* 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>
AtcStation::AtcStation(const QString &callsign, const TransceiverDto &transceiver) :
using namespace BlackCore::Afv;
CSampleAtcStation::CSampleAtcStation(const QString &callsign, const TransceiverDto &transceiver) :
m_callsign(callsign),
m_transceiver(transceiver)
{ }
double AtcStation::latitude() const
double CSampleAtcStation::latitude() const
{
return m_transceiver.LatDeg;
}
double AtcStation::longitude() const
double CSampleAtcStation::longitude() const
{
return m_transceiver.LonDeg;
}
quint32 AtcStation::frequency() const
quint32 CSampleAtcStation::frequency() const
{
return m_transceiver.frequency;
}
QString AtcStation::formattedFrequency() const
QString CSampleAtcStation::formattedFrequency() const
{
return QString::number(m_transceiver.frequency / 1000000.0, 'f', 3);
}
double AtcStation::radioDistanceM() const
double CSampleAtcStation::radioDistanceM() const
{
double sqrtAltM = qSqrt(m_transceiver.HeightMslM);
const double radioFactor = 4193.18014745372;
@@ -36,20 +45,13 @@ double AtcStation::radioDistanceM() const
return radioFactor * sqrtAltM;
}
QString AtcStation::callsign() const
{
return m_callsign;
}
AtcStationModel::AtcStationModel(QObject *parent) :
CSampleAtcStationModel::CSampleAtcStationModel(QObject *parent) :
QAbstractListModel(parent)
{
{ }
}
CSampleAtcStationModel::~CSampleAtcStationModel() {}
AtcStationModel::~AtcStationModel() {}
void AtcStationModel::updateAtcStations(const QVector<AtcStation> &atcStations)
void CSampleAtcStationModel::updateAtcStations(const QVector<CSampleAtcStation> &atcStations)
{
// Add stations which didn't exist yet
for (const auto &station : atcStations)
@@ -60,7 +62,7 @@ void AtcStationModel::updateAtcStations(const QVector<AtcStation> &atcStations)
// Remove all stations which are no longer there
for (int i = m_atcStations.size() - 1; i >= 0; i--)
{
AtcStation &station = m_atcStations[i];
CSampleAtcStation &station = m_atcStations[i];
if (! m_atcStations.contains(station))
{
removeStationAtPosition(i);
@@ -68,48 +70,42 @@ void AtcStationModel::updateAtcStations(const QVector<AtcStation> &atcStations)
}
}
void AtcStationModel::addStation(const AtcStation &atcStation)
void CSampleAtcStationModel::addStation(const CSampleAtcStation &atcStation)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_atcStations << atcStation;
endInsertRows();
}
void AtcStationModel::removeStationAtPosition(int i)
void CSampleAtcStationModel::removeStationAtPosition(int i)
{
beginRemoveRows(QModelIndex(), i, i);
m_atcStations.removeAt(i);
endRemoveRows();
}
int AtcStationModel::rowCount(const QModelIndex &parent) const
int CSampleAtcStationModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return m_atcStations.count();
}
QVariant AtcStationModel::data(const QModelIndex &index, int role) const
QVariant CSampleAtcStationModel::data(const QModelIndex &index, int role) const
{
if (index.row() < 0 || index.row() >= m_atcStations.count())
return QVariant();
const AtcStation &atcStation = m_atcStations[index.row()];
if (role == CallsignRole)
return atcStation.callsign();
else if (role == LatitudeRole)
return atcStation.latitude();
else if (role == LongitudeRole)
return atcStation.longitude();
else if (role == RadioDistanceRole)
return atcStation.radioDistanceM();
else if (role == FrequencyRole)
return atcStation.formattedFrequency();
else if (role == FrequencyKhzRole)
return atcStation.frequency() / 1000;
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> AtcStationModel::roleNames() const
QHash<int, QByteArray> CSampleAtcStationModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[CallsignRole] = "callsign";

View File

@@ -1,5 +1,13 @@
#ifndef ATCSTATIONMODEL_H
#define ATCSTATIONMODEL_H
/* 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>
@@ -7,40 +15,48 @@
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QObject>
class AtcStation
//! Sample ATC station
class CSampleAtcStation
{
public:
AtcStation() {}
AtcStation(const QString &callsign, const TransceiverDto &transceiver);
//! Ctor
CSampleAtcStation() {}
QString callsign() const;
//! 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;
quint32 frequency() const;
QString formattedFrequency() const;
double radioDistanceM() const;
quint32 frequency() const;
//! @}
private:
QString m_callsign;
TransceiverDto m_transceiver;
BlackCore::Afv::TransceiverDto m_transceiver;
};
inline bool operator==(const AtcStation& lhs, const AtcStation& rhs)
inline bool operator==(const CSampleAtcStation &lhs, const CSampleAtcStation &rhs)
{
return lhs.callsign() == rhs.callsign() &&
qFuzzyCompare(lhs.latitude(), rhs.latitude()) &&
qFuzzyCompare(lhs.longitude(), rhs.longitude());
qFuzzyCompare(lhs.latitude(), rhs.latitude()) &&
qFuzzyCompare(lhs.longitude(), rhs.longitude());
}
class AtcStationModel : public QAbstractListModel
//! Sample list model
class CSampleAtcStationModel : public QAbstractListModel
{
Q_OBJECT
public:
enum AtcStationRoles {
//! Roles for model
enum AtcStationRoles
{
CallsignRole = Qt::UserRole + 1,
LatitudeRole,
LongitudeRole,
@@ -49,22 +65,30 @@ public:
FrequencyKhzRole
};
AtcStationModel(QObject *parent = nullptr);
virtual ~AtcStationModel();
//! Ctor
CSampleAtcStationModel(QObject *parent = nullptr);
void updateAtcStations(const QVector<AtcStation> &atcStations);
//! Dtor
virtual ~CSampleAtcStationModel() override;
int rowCount(const QModelIndex & parent = QModelIndex()) const override;
//! Update the stations
void updateAtcStations(const QVector<CSampleAtcStation> &atcStations);
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
//! 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 AtcStation &atcStation);
void addStation(const CSampleAtcStation &atcStation);
void removeStationAtPosition(int i);
QList<AtcStation> m_atcStations;
QList<CSampleAtcStation> m_atcStations;
};
#endif // ATCSTATIONMODEL_H
#endif // guard