2015-05-28 19:22:17 -04:00
|
|
|
#include "Modes.hpp"
|
|
|
|
|
2016-06-04 10:59:01 -04:00
|
|
|
#include <algorithm>
|
|
|
|
|
2015-05-28 19:22:17 -04:00
|
|
|
#include <QString>
|
|
|
|
#include <QVariant>
|
2016-06-04 10:59:01 -04:00
|
|
|
#include <QModelIndex>
|
2015-05-28 19:22:17 -04:00
|
|
|
|
2015-06-09 10:30:23 -04:00
|
|
|
#include "moc_Modes.cpp"
|
|
|
|
|
2015-05-28 19:22:17 -04:00
|
|
|
namespace
|
|
|
|
{
|
2016-06-04 10:59:01 -04:00
|
|
|
// human readable strings for each Mode enumeration value
|
2015-05-28 19:22:17 -04:00
|
|
|
char const * const mode_names[] =
|
2015-11-17 20:28:12 -05:00
|
|
|
{
|
2017-07-07 19:11:41 -04:00
|
|
|
"All",
|
2015-11-17 20:28:12 -05:00
|
|
|
"JT65",
|
|
|
|
"JT9",
|
|
|
|
"JT4",
|
|
|
|
"WSPR",
|
|
|
|
"Echo",
|
|
|
|
"ISCAT",
|
2016-06-08 17:20:58 -04:00
|
|
|
"MSK144",
|
2017-01-03 16:37:38 -05:00
|
|
|
"QRA64",
|
2017-06-17 09:48:45 -04:00
|
|
|
"FreqCal",
|
2019-01-18 11:51:15 -05:00
|
|
|
"FT8",
|
2020-06-16 15:56:15 -04:00
|
|
|
"FT4",
|
2020-07-23 13:51:05 -04:00
|
|
|
"FST4",
|
2020-09-25 15:38:20 -04:00
|
|
|
"FST4W",
|
2020-10-25 13:58:18 -04:00
|
|
|
"Q65"
|
2015-11-17 20:28:12 -05:00
|
|
|
};
|
2016-06-04 10:59:01 -04:00
|
|
|
std::size_t constexpr mode_names_size = sizeof (mode_names) / sizeof (mode_names[0]);
|
2015-05-28 19:22:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Modes::Modes (QObject * parent)
|
|
|
|
: QAbstractListModel {parent}
|
|
|
|
{
|
2016-06-04 10:59:01 -04:00
|
|
|
static_assert (mode_names_size == MODES_END_SENTINAL_AND_COUNT,
|
|
|
|
"mode_names array must match Mode enumeration");
|
2015-05-28 19:22:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
char const * Modes::name (Mode m)
|
|
|
|
{
|
|
|
|
return mode_names[static_cast<int> (m)];
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Modes::value (QString const& s) -> Mode
|
|
|
|
{
|
2016-06-04 10:59:01 -04:00
|
|
|
auto end = mode_names + mode_names_size;
|
2015-05-28 19:22:17 -04:00
|
|
|
auto p = std::find_if (mode_names, end
|
|
|
|
, [&s] (char const * const name) {
|
|
|
|
return name == s;
|
|
|
|
});
|
2017-07-07 19:11:41 -04:00
|
|
|
return p != end ? static_cast<Mode> (p - mode_names) : ALL;
|
2015-05-28 19:22:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant Modes::data (QModelIndex const& index, int role) const
|
|
|
|
{
|
|
|
|
QVariant item;
|
|
|
|
|
|
|
|
if (index.isValid ())
|
|
|
|
{
|
|
|
|
auto const& row = index.row ();
|
|
|
|
switch (role)
|
|
|
|
{
|
|
|
|
case Qt::ToolTipRole:
|
|
|
|
case Qt::AccessibleDescriptionRole:
|
|
|
|
item = tr ("Mode");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::EditRole:
|
|
|
|
item = static_cast<Mode> (row);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
case Qt::AccessibleTextRole:
|
|
|
|
item = mode_names[row];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::TextAlignmentRole:
|
|
|
|
item = Qt::AlignHCenter + Qt::AlignVCenter;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant Modes::headerData (int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
QVariant result;
|
|
|
|
|
|
|
|
if (Qt::DisplayRole == role && Qt::Horizontal == orientation)
|
|
|
|
{
|
|
|
|
result = tr ("Mode");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = QAbstractListModel::headerData (section, orientation, role);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ENUM_QDATASTREAM_OPS_IMPL (Modes, Mode);
|
|
|
|
ENUM_CONVERSION_OPS_IMPL (Modes, Mode);
|