swift
atcstationmodel.h
1 // SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #ifndef SWIFT_CORE_AFV_MODEL_ATCSTATIONMODEL_H
5 #define SWIFT_CORE_AFV_MODEL_ATCSTATIONMODEL_H
6 
7 #include <QAbstractListModel>
8 #include <QObject>
9 #include <QtGlobal>
10 
11 #include "core/afv/dto.h"
12 #include "core/swiftcoreexport.h"
13 
14 namespace swift::core::afv::model
15 {
18  {
19  public:
21  CSampleAtcStation() = default;
22 
24  CSampleAtcStation(const QString &callsign, const swift::core::afv::TransceiverDto &transceiver);
25 
28  const QString &callsign() const { return m_callsign; }
29  QString formattedFrequency() const;
30  double latitude() const;
31  double longitude() const;
32  double radioDistanceM() const;
33  quint32 frequency() const;
35 
36  private:
37  QString m_callsign;
38  TransceiverDto m_transceiver;
39  };
40 
41  inline bool operator==(const CSampleAtcStation &lhs, const CSampleAtcStation &rhs)
42  {
43  return lhs.callsign() == rhs.callsign() && qFuzzyCompare(lhs.latitude(), rhs.latitude()) &&
44  qFuzzyCompare(lhs.longitude(), rhs.longitude());
45  }
46 
48  class CSampleAtcStationModel : public QAbstractListModel
49  {
50  Q_OBJECT
51 
52  public:
55  {
56  CallsignRole = Qt::UserRole + 1,
57  LatitudeRole,
58  LongitudeRole,
59  RadioDistanceRole,
60  FrequencyRole,
61  FrequencyKhzRole
62  };
63 
65  CSampleAtcStationModel(QObject *parent = nullptr);
66 
68  ~CSampleAtcStationModel() override;
69 
71  void updateAtcStations(const QVector<CSampleAtcStation> &atcStations);
72 
74  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
75 
77  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
78 
79  protected:
81  QHash<int, QByteArray> roleNames() const override;
82 
83  private:
84  void addStation(const CSampleAtcStation &atcStation);
85  void removeStationAtPosition(int i);
86 
87  QList<CSampleAtcStation> m_atcStations;
88  };
89 } // namespace swift::core::afv::model
90 
91 #endif // SWIFT_CORE_AFV_MODEL_ATCSTATIONMODEL_H
const QString & callsign() const
Getter.
void updateAtcStations(const QVector< CSampleAtcStation > &atcStations)
Update the stations.
QHash< int, QByteArray > roleNames() const
copydoc QAbstractListModel::roleNames
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
copydoc QAbstractListModel::data
CSampleAtcStationModel(QObject *parent=nullptr)
Ctor.
int rowCount(const QModelIndex &parent=QModelIndex()) const
copydoc QAbstractListModel::rowCount
Transceiver DTO.
Definition: dto.h:117
#define SWIFT_CORE_EXPORT
Export a class or function from the library.