1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
#include "Bands.hpp"
#include <algorithm>
#include <QString>
#include <QVariant>
namespace
{
// Local structure to hold a single ADIF band definition.
struct ADIF_band
{
char const * const name_;
Radio::Frequency lower_bound_;
Radio::Frequency upper_bound_;
};
// Table of ADIF band definitions as defined in the ADIF
// specification.
ADIF_band constexpr ADIF_bands[] = {
{"2190m", 136000u, 137000u},
{"630m", 472000u, 479000u},
{"560m", 501000u, 504000u},
{"160m", 1800000u, 2000000u},
{"80m", 3500000u, 4000000u},
{"60m", 5102000u, 5406500u},
{"40m", 7000000u, 7300000u},
{"30m", 10000000u, 10150000u},
{"20m", 14000000u, 14350000u},
{"17m", 18068000u, 18168000u},
{"15m", 21000000u, 21450000u},
{"12m", 24890000u, 24990000u},
{"10m", 28000000u, 29700000u},
{"6m", 50000000u, 54000000u},
{"4m", 70000000u, 71000000u},
{"2m", 144000000u, 148000000u},
{"1.25m", 222000000u, 225000000u},
{"70cm", 420000000u, 450000000u},
{"33cm", 902000000u, 928000000u},
{"23cm", 1240000000u, 1300000000u},
{"13cm", 2300000000u, 2450000000u},
{"9cm", 3300000000u, 3500000000u},
{"6cm", 5650000000u, 5925000000u},
{"3cm", 10000000000u, 10500000000u},
{"1.25cm", 24000000000u, 24250000000u},
{"6mm", 47000000000u, 47200000000u},
{"4mm", 75500000000u, 81000000000u},
{"2.5mm", 119980000000u, 120020000000u},
{"2mm", 142000000000u, 149000000000u},
{"1mm", 241000000000u, 250000000000u},
};
auto constexpr out_of_band = "OOB";
int constexpr table_rows ()
{
return sizeof (ADIF_bands) / sizeof (ADIF_bands[0]);
}
}
Bands::Bands (QObject * parent)
: QAbstractTableModel {parent}
{
}
QModelIndex Bands::find (QVariant const& v) const
{
auto f = v.value<Radio::Frequency> ();
auto end_iter = ADIF_bands + table_rows ();
auto row_iter = std::find_if (ADIF_bands, end_iter, [f] (ADIF_band const& band) {
return band.lower_bound_ <= f && f <= band.upper_bound_;
});
if (row_iter != end_iter)
{
return index (row_iter - ADIF_bands, 0); // return the band row index
}
return QModelIndex {};
}
int Bands::rowCount (QModelIndex const& parent) const
{
return parent.isValid () ? 0 : table_rows ();
}
int Bands::columnCount (QModelIndex const& parent) const
{
return parent.isValid () ? 0 : 3;
}
Qt::ItemFlags Bands::flags (QModelIndex const& index) const
{
return QAbstractTableModel::flags (index) | Qt::ItemIsDropEnabled;
}
QVariant Bands::data (QModelIndex const& index, int role) const
{
QVariant item;
if (!index.isValid ())
{
// Hijack root for OOB string.
if (Qt::DisplayRole == role)
{
item = out_of_band;
}
}
else
{
auto row = index.row ();
auto column = index.column ();
if (row < table_rows ())
{
switch (role)
{
case Qt::ToolTipRole:
case Qt::AccessibleDescriptionRole:
switch (column)
{
case 0: item = tr ("Band name"); break;
case 1: item = tr ("Lower frequency limit"); break;
case 2: item = tr ("Upper frequency limit"); break;
}
break;
case SortRole:
case Qt::DisplayRole:
case Qt::EditRole:
switch (column)
{
case 0:
if (SortRole == role)
{
// band name sorts by lower bound
item = ADIF_bands[row].lower_bound_;
}
else
{
item = ADIF_bands[row].name_;
}
break;
case 1: item = ADIF_bands[row].lower_bound_; break;
case 2: item = ADIF_bands[row].upper_bound_; break;
}
break;
case Qt::AccessibleTextRole:
switch (column)
{
case 0: item = ADIF_bands[row].name_; break;
case 1: item = ADIF_bands[row].lower_bound_; break;
case 2: item = ADIF_bands[row].upper_bound_; break;
}
break;
case Qt::TextAlignmentRole:
switch (column)
{
case 0:
item = Qt::AlignHCenter + Qt::AlignVCenter;
break;
case 1:
case 2:
item = Qt::AlignRight + Qt::AlignVCenter;
break;
}
break;
}
}
}
return item;
}
QVariant Bands::headerData (int section, Qt::Orientation orientation, int role) const
{
QVariant result;
if (Qt::DisplayRole == role && Qt::Horizontal == orientation)
{
switch (section)
{
case 0: result = tr ("Band"); break;
case 1: result = tr ("Lower Limit"); break;
case 2: result = tr ("Upper Limit"); break;
}
}
else
{
result = QAbstractTableModel::headerData (section, orientation, role);
}
return result;
}
|