JS8Call-Improved master
Loading...
Searching...
No Matches
Bands.h
1#ifndef BANDS_HPP__
2#define BANDS_HPP__
3
4#include "Radio.h"
5
6#include <QAbstractTableModel>
7
8//
9// Class Bands
10//
11// Encapsulates information about amateur radio bands as defined by
12// the ADIF specification. The model is immutable. The rows are
13// stored in asscending order of frequency.
14//
15// Responsibilities
16//
17// Provides a well known band name mapped to lower and upper
18// frequency limits. Also provides a convenience operation to
19// determine the band name for any given frequency, the result of
20// which may be null if the given frequency doesn't lie within a
21// recognised band.
22//
23// Collaborations
24//
25// Implements the QAbstractTableModel interface as an immutable table
26// where rows are bands and columns are band name, lower frequency
27// limit and, upper ferquency limit respectively.
28//
29
30class Bands final : public QAbstractTableModel {
31 public:
32 using Frequency = Radio::Frequency;
33
34 // an iterator that meets the requirements of the C++ for range statement
35 class const_iterator {
36 public:
37 const_iterator(int row) : row_{row} {}
38
39 QString operator*();
40 bool operator!=(const_iterator const &) const;
41 const_iterator &operator++();
42
43 private:
44 int row_;
45 };
46
47 explicit Bands(QObject *parent = nullptr);
48
49 //
50 // Model API
51 //
52 QString find(Frequency) const; // find band Frequency is in
53 int find(QString const &) const; // find row of band (-1 if not valid)
54 bool findFreq(QString const &band, Radio::Frequency *pFreqLower,
55 Radio::Frequency *pFreqHigher) const;
56
57 static QString const &oob();
58
59 // Iterators
60 const_iterator begin() const;
61 const_iterator end() const;
62
63 // Custom role for sorting.
64 static int constexpr SortRole = Qt::UserRole;
65
66 // Implement the QAbstractTableModel interface
67 int rowCount(QModelIndex const &parent = QModelIndex{}) const override;
68 int columnCount(QModelIndex const &parent = QModelIndex{}) const override;
69 Qt::ItemFlags flags(QModelIndex const & = QModelIndex{}) const override;
70 QVariant headerData(int section, Qt::Orientation,
71 int = Qt::DisplayRole) const override;
72
73 // The value return for the Qt::DisplayRole role for the root of the
74 // model (invalid index) is a special string representing out of
75 // band.
76 //
77 // All columns return a number for the custom role SortRole, this
78 // number defines a strict frequency order for the rows.
79 QVariant data(QModelIndex const &,
80 int role = Qt::DisplayRole) const override;
81};
82
83#endif
Definition Bands.h:35
QString operator*()
Dereference the iterator to get the band name.
Definition Bands.cpp:292
const_iterator & operator++()
Increment the iterator.
Definition Bands.cpp:309
bool operator!=(const_iterator const &) const
Compare two iterators for inequality.
Definition Bands.cpp:300
QString find(Frequency) const
Find the band that contains the given frequency.
Definition Bands.cpp:76
static QString const & oob()
Get Out Of Band name.
Definition Bands.cpp:133
bool findFreq(QString const &band, Radio::Frequency *pFreqLower, Radio::Frequency *pFreqHigher) const
Find the frequency bounds for the given band name.
Definition Bands.cpp:113
Qt::ItemFlags flags(QModelIndex const &=QModelIndex{}) const override
Get item flags for the given index.
Definition Bands.cpp:161
int columnCount(QModelIndex const &parent=QModelIndex{}) const override
Get number of columns in the model.
Definition Bands.cpp:151
const_iterator begin() const
Get begin iterator.
Definition Bands.cpp:319
int rowCount(QModelIndex const &parent=QModelIndex{}) const override
Get number of rows in the model.
Definition Bands.cpp:141
const_iterator end() const
Get end iterator.
Definition Bands.cpp:326
QVariant data(QModelIndex const &, int role=Qt::DisplayRole) const override
Get data for the given index and role.
Definition Bands.cpp:172
QVariant headerData(int section, Qt::Orientation, int=Qt::DisplayRole) const override
Get header data for the given section, orientation, and role.
Definition Bands.cpp:264