2015-05-28 19:22:17 -04:00
|
|
|
#include "Bands.hpp"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <QVariant>
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
// Table of ADIF band definitions as defined in the ADIF
|
2017-09-16 16:27:13 -04:00
|
|
|
// specification as at ADIF v3.0.6
|
2015-05-31 07:51:31 -04:00
|
|
|
struct ADIFBand
|
|
|
|
{
|
|
|
|
char const * const name_;
|
|
|
|
Radio::Frequency lower_bound_;
|
|
|
|
Radio::Frequency upper_bound_;
|
|
|
|
} constexpr ADIF_bands[] = {
|
2020-08-15 21:56:48 -04:00
|
|
|
{"2190m", 135700u, 137800u},
|
2015-05-28 19:22:17 -04:00
|
|
|
{"630m", 472000u, 479000u},
|
|
|
|
{"560m", 501000u, 504000u},
|
|
|
|
{"160m", 1800000u, 2000000u},
|
|
|
|
{"80m", 3500000u, 4000000u},
|
2017-09-16 16:27:13 -04:00
|
|
|
{"60m", 5060000u, 5450000u},
|
2015-05-28 19:22:17 -04:00
|
|
|
{"40m", 7000000u, 7300000u},
|
2020-08-15 21:56:48 -04:00
|
|
|
{"30m", 10100000u, 10150000u},
|
2015-05-28 19:22:17 -04:00
|
|
|
{"20m", 14000000u, 14350000u},
|
|
|
|
{"17m", 18068000u, 18168000u},
|
|
|
|
{"15m", 21000000u, 21450000u},
|
|
|
|
{"12m", 24890000u, 24990000u},
|
|
|
|
{"10m", 28000000u, 29700000u},
|
2020-09-07 15:36:09 -04:00
|
|
|
{"8m", 40000000u, 45000000u},
|
2015-05-28 19:22:17 -04:00
|
|
|
{"6m", 50000000u, 54000000u},
|
2020-09-07 15:36:09 -04:00
|
|
|
{"5m", 54000001u, 69900000u},
|
2015-05-28 19:22:17 -04:00
|
|
|
{"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},
|
|
|
|
};
|
|
|
|
|
2015-05-31 07:51:31 -04:00
|
|
|
QString const oob_name {QObject::tr ("OOB")};
|
2015-05-28 19:22:17 -04:00
|
|
|
|
|
|
|
int constexpr table_rows ()
|
|
|
|
{
|
2019-07-02 21:12:27 -04:00
|
|
|
return sizeof ADIF_bands / sizeof ADIF_bands[0];
|
2015-05-28 19:22:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 07:56:25 -04:00
|
|
|
#include "moc_Bands.cpp"
|
|
|
|
|
2015-05-28 19:22:17 -04:00
|
|
|
Bands::Bands (QObject * parent)
|
|
|
|
: QAbstractTableModel {parent}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-05-31 07:51:31 -04:00
|
|
|
QString Bands::find (Frequency f) const
|
2015-05-28 19:22:17 -04:00
|
|
|
{
|
2015-05-31 07:51:31 -04:00
|
|
|
QString result;
|
2015-05-28 19:22:17 -04:00
|
|
|
auto const& end_iter = ADIF_bands + table_rows ();
|
|
|
|
auto const& row_iter = std::find_if (ADIF_bands, end_iter, [f] (ADIFBand const& band) {
|
|
|
|
return band.lower_bound_ <= f && f <= band.upper_bound_;
|
|
|
|
});
|
|
|
|
if (row_iter != end_iter)
|
|
|
|
{
|
2015-05-31 07:51:31 -04:00
|
|
|
result = row_iter->name_;
|
2015-05-28 19:22:17 -04:00
|
|
|
}
|
2015-05-31 07:51:31 -04:00
|
|
|
return result;
|
2015-05-28 19:22:17 -04:00
|
|
|
}
|
|
|
|
|
2015-06-05 20:06:46 -04:00
|
|
|
int Bands::find (QString const& band) const
|
|
|
|
{
|
|
|
|
int result {-1};
|
2019-07-02 21:12:27 -04:00
|
|
|
for (auto i = 0; i < table_rows (); ++i)
|
2015-06-05 20:06:46 -04:00
|
|
|
{
|
|
|
|
if (band == ADIF_bands[i].name_)
|
|
|
|
{
|
|
|
|
result = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-05-31 07:51:31 -04:00
|
|
|
QString const& Bands::oob ()
|
2015-05-28 19:22:17 -04:00
|
|
|
{
|
2015-05-31 07:51:31 -04:00
|
|
|
return oob_name;
|
2015-05-28 19:22:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2015-05-31 07:51:31 -04:00
|
|
|
item = oob_name;
|
2015-05-28 19:22:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2015-05-31 07:51:40 -04:00
|
|
|
|
|
|
|
QString Bands::const_iterator::operator * ()
|
|
|
|
{
|
|
|
|
return ADIF_bands[row_].name_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Bands::const_iterator::operator != (const_iterator const& rhs) const
|
|
|
|
{
|
|
|
|
return row_ != rhs.row_;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Bands::const_iterator::operator ++ () -> const_iterator&
|
|
|
|
{
|
|
|
|
++row_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Bands::begin () const -> Bands::const_iterator
|
|
|
|
{
|
|
|
|
return const_iterator (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Bands::end () const -> Bands::const_iterator
|
|
|
|
{
|
|
|
|
return const_iterator (table_rows ());
|
|
|
|
}
|