JS8Call-Improved master
Loading...
Searching...
No Matches
StationList.h
1#ifndef STATION_LIST_HPP__
2#define STATION_LIST_HPP__
3
4#include "JS8_Include/pimpl_h.h"
5#include "Radio.h"
6
7#include <QDateTime>
8#include <QList>
9#include <QSortFilterProxyModel>
10#include <QString>
11
12class Bands;
13
14//
15// Class StationList
16//
17// Encapsulates information about a collection of unique operating
18// stations per band. The implementation is a table model with the
19// first column being the unique (within the table rows) band name
20// and, the second the frequency offset for transverter usage and,
21// the third the antenna description. All are editable.
22//
23// Responsibilities
24//
25// Stores internally an unordered table of bands.
26//
27// If an ordered representaion is required then wrapping with an
28// appropriate proxy model is sufficient
29// e.g. QSortFilterProxyModel. A custom SortRole role is provided for
30// the band name column which returns a numeric value (Bands lower
31// frequency limit) which gives a strict frequency ordering by band.
32//
33// Collaborations
34//
35// Implements the QAbstractTableModel interface for a grid of bands
36// with offset frequencies and antenna descriptions.
37//
38// Uses the Bands model to lookup band information.
39//
40class StationList final : public QSortFilterProxyModel {
41 public:
42 using Frequency = Radio::Frequency;
43 using FrequencyDelta = Radio::FrequencyDelta;
44
45 //
46 // Struct Station
47 //
48 // Aggregation of fields that describe a radio station on a band.
49 //
50 struct Station {
51 QString band_name_;
52 Frequency frequency_;
53 QDateTime switch_at_;
54 QDateTime switch_until_;
55 QString description_;
56 };
57
58 using Stations = QList<Station>;
59
60 enum Column {
61 band_column,
62 frequency_column,
63 switch_at_column,
64 switch_until_column,
65 description_column
66 };
67
68 explicit StationList(Bands const *bands, QObject *parent = nullptr);
69 explicit StationList(Bands const *bands, Stations,
70 QObject *parent = nullptr);
72
73 // Load and query contents.
74 Stations station_list(Stations);
75 Stations const &station_list() const;
76
77 //
78 // Model API
79 //
80 QModelIndex add(Station); // Add a new Station
81 bool remove(Station); // Remove a Station
82 bool removeDisjointRows(QModelIndexList); // Remove one or more stations
83
84 // Custom sort role.
85 static int constexpr SortRole = Qt::UserRole;
86
87 private:
88 class impl;
89 pimpl<impl> m_;
90};
91
92// Station equivalence
93inline bool operator==(StationList::Station const &lhs,
94 StationList::Station const &rhs) {
95 return lhs.band_name_ == rhs.band_name_ &&
96 lhs.description_ == rhs.description_ &&
97 lhs.frequency_ == rhs.frequency_ &&
98 lhs.switch_at_ == rhs.switch_at_ &&
99 lhs.switch_until_ == rhs.switch_until_;
100}
101
102QDataStream &operator<<(QDataStream &, StationList::Station const &);
103QDataStream &operator>>(QDataStream &, StationList::Station &);
104
105#if !defined(QT_NO_DEBUG_STREAM)
106QDebug operator<<(QDebug debug, StationList::Station const &);
107#endif
108
109Q_DECLARE_METATYPE(StationList::Station);
110Q_DECLARE_METATYPE(StationList::Stations);
111
112#endif
Definition Bands.h:30
Definition qpriorityqueue.h:39
Definition StationList.h:40
Definition pimpl_h.h:16
Definition StationList.h:50