JS8Call-Improved master
Loading...
Searching...
No Matches
FrequencyList.h
1#ifndef FREQUENCY_LIST_HPP__
2#define FREQUENCY_LIST_HPP__
3
4#include "IARURegions.h"
5#include "JS8_Include/pimpl_h.h"
6#include "Modes.h"
7#include "Radio.h"
8
9#include <QList>
10#include <QSortFilterProxyModel>
11
12class Bands;
13
14//
15// Class FrequencyList_v3
16//
17// Encapsulates a collection of frequencies with associated modes.
18// The implementation is a table containing the list of IARU region,
19// Frequency and mode tuples which are editable. A third column is
20// modeled in the model which is an immutable double representation
21// of the corresponding Frequency item scaled to mega-Hertz. The final,
22// column column allows entry of a description for the entry.
23//
24// The list is ordered. A filter on IARU region and mode is
25// available and is set by the filter(Region, Mode) method. The
26// Region value IARURegions::ALL and the Mode value Modes::ALL may be
27// optionally given which passes all rows in the filtered column.
28//
29// Responsibilities
30//
31// Stores internally a list of unique region, frequency mode tuples.
32// Provides methods to add and delete list elements. Provides range
33// iterators for a filtered view of the underlying table.
34//
35// Collaborations
36//
37// Implements the QSortFilterProxyModel interface for a list of spot
38// frequencies.
39//
40class FrequencyList_v3 final : public QSortFilterProxyModel {
41 Q_OBJECT;
42
43 public:
44 using Region = IARURegions::Region;
45 using Frequency = Radio::Frequency;
46 using Mode = Modes::Mode;
47
48 struct Item {
49 Frequency frequency_;
50 Mode mode_;
51 Region region_;
52 QString description_;
53 };
54 using FrequencyItems = QList<Item>;
55 using BandSet = QSet<QString>;
56
57 enum Column {
58 region_column,
59 mode_column,
60 frequency_column,
61 frequency_mhz_column,
62 description_column,
63 SENTINAL
64 };
65
66 // an iterator that meets the requirements of the C++ for range statement
67 class const_iterator {
68 public:
69 const_iterator(FrequencyList_v3 const *parent, int row)
70 : parent_{parent}, row_{row} {}
71
72 Item const &operator*() const;
73 Item const *operator->() const;
74 bool operator!=(const_iterator const &) const;
75 bool operator==(const_iterator const &) const;
76 const_iterator &operator++();
77
78 private:
79 FrequencyList_v3 const *parent_;
80 int row_;
81 };
82
83 explicit FrequencyList_v3(Bands const *, QObject *parent = nullptr);
84 ~FrequencyList_v3();
85
86 // Load and store underlying items
87 FrequencyItems frequency_list(FrequencyItems);
88 FrequencyItems const &frequency_list() const;
89 FrequencyItems frequency_list(QModelIndexList const &) const;
90 void frequency_list_merge(FrequencyItems const &);
91
92 // Iterators for the sorted and filtered items
93 //
94 // Note that these iterators are on the final sorted and filtered
95 // rows, if you need to access the underlying unfiltered and
96 // unsorted frequencies then use the frequency_list() member to
97 // access the underlying list of rows.
98 const_iterator begin() const;
99 const_iterator end() const;
100
101 // Find a row with a given frequency
102 const_iterator find(Frequency) const;
103
104 // Bands of the frequencies
105 BandSet all_bands(Region = IARURegions::ALL, Mode = Modes::ALL) const;
106 BandSet filtered_bands() const;
107
108 // Find the row of the nearest best working frequency given a
109 // frequency. Returns -1 if no suitable working frequency is found
110 // in the list.
111 int best_working_frequency(Frequency) const;
112
113 // Find the row of the nearest best working frequency given a band
114 // name. Returns -1 if no suitable working frequency is found in the
115 // list.
116 int best_working_frequency(QString const &band) const;
117
118 // Set filter
119 Q_SLOT void filter(Region, Mode);
120
121 // Reset
122 Q_SLOT void reset_to_defaults();
123
124 // Model API
125 QModelIndex add(Item);
126 bool remove(Item);
127 bool removeDisjointRows(QModelIndexList);
128
129 // Proxy API
130 bool filterAcceptsRow(int source_row,
131 QModelIndex const &parent) const override;
132
133 // Custom roles.
134 static int constexpr SortRole = Qt::UserRole;
135
136 private:
137 class impl;
138 pimpl<impl> m_;
139};
140
141inline bool operator==(FrequencyList_v3::Item const &lhs,
142 FrequencyList_v3::Item const &rhs) {
143 return lhs.frequency_ == rhs.frequency_ && lhs.region_ == rhs.region_ &&
144 lhs.mode_ == rhs.mode_ && lhs.description_ == rhs.description_;
145}
146
147QDataStream &operator<<(QDataStream &, FrequencyList_v3::Item const &);
148QDataStream &operator>>(QDataStream &, FrequencyList_v3::Item &);
149
150#if !defined(QT_NO_DEBUG_STREAM)
151QDebug operator<<(QDebug, FrequencyList_v3::Item const &);
152#endif
153
154Q_DECLARE_METATYPE(FrequencyList_v3::Item);
155Q_DECLARE_METATYPE(FrequencyList_v3::FrequencyItems);
156
157//
158// Obsolete versions of FrequencyList no longer used but needed to
159// allow loading and saving of old settings contents without damage
160//
161
162class FrequencyList_v2 final {
163public:
164 using Region = IARURegions::Region;
165 using Frequency = Radio::Frequency;
166 using Mode = Modes::Mode;
167
168 struct Item {
169 Frequency frequency_;
170 Mode mode_;
171 Region region_;
172 };
173 using FrequencyItems = QList<Item>;
174
175private:
176 FrequencyItems frequency_list_;
177};
178
179
180QDataStream &operator<<(QDataStream &, FrequencyList_v2::Item const &);
181QDataStream &operator>>(QDataStream &, FrequencyList_v2::Item &);
182
183Q_DECLARE_METATYPE(FrequencyList_v2::Item);
184Q_DECLARE_METATYPE(FrequencyList_v2::FrequencyItems);
185
186class FrequencyList final {
187 public:
188 using Frequency = Radio::Frequency;
189 using Mode = Modes::Mode;
190
191 struct Item {
192 Frequency frequency_;
193 Mode mode_;
194 };
195 using FrequencyItems = QList<Item>;
196
197 private:
198 FrequencyItems frequency_list_;
199};
200
201QDataStream &operator<<(QDataStream &, FrequencyList::Item const &);
202QDataStream &operator>>(QDataStream &, FrequencyList::Item &);
203
204Q_DECLARE_METATYPE(FrequencyList::Item);
205Q_DECLARE_METATYPE(FrequencyList::FrequencyItems);
206
207#endif
Definition Bands.h:30
Definition FrequencyList.h:162
Definition FrequencyList.h:67
Definition FrequencyList.cpp:64
Definition FrequencyList.h:186
Definition qpriorityqueue.h:39
Definition pimpl_h.h:16
Definition FrequencyList.h:191
Definition FrequencyList.h:168
Definition FrequencyList.h:48