WSJT-X/Bands.hpp
Bill Somerville a1a6d1bc06 Add mode dependent working frequencies
Working frequencies are mode dependent  and a reset to defaults button
has been added.

Also re-factored much of the model  and item delegate code to simplify
several  of the  model  implementations. Introduced  a single  routine
called from main to register the custom types with Qt.

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@5453 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
2015-05-28 23:22:17 +00:00

69 lines
2.0 KiB
C++

#ifndef BANDS_HPP__
#define BANDS_HPP__
#include <QAbstractTableModel>
#include "Radio.hpp"
//
// Class Bands
//
// Encapsulates information about amateur radio bands as defined by
// the ADIF specification. The model is immutable. The rows are
// stored in asscending order of frequency.
//
// Responsibilities
//
// Provides a well known band name mapped to lower and upper
// frequency limits. Also provides a convenience operation to
// determine the band details for any given frequency, the result of
// which may be invalid if the given frequency doesn't lie within a
// recognised band.
//
// Collaborations
//
// Implements the QAbstractTableModel interface as an immutable table
// where rows are bands and columns are band name, lower frequency
// limit and, upper ferquency limit respectively.
//
class Bands final
: public QAbstractTableModel
{
public:
using Frequency = Radio::Frequency;
struct ADIFBand
{
char const * const name_;
Radio::Frequency lower_bound_;
Radio::Frequency upper_bound_;
};
explicit Bands (QObject * parent = nullptr);
//
// Model API
//
ADIFBand const * find (Frequency) const; // find band Frequency is in
ADIFBand const * out_of_band () const;
// Custom role for sorting.
static int constexpr SortRole = Qt::UserRole;
// Implement the QAbstractTableModel interface
int rowCount (QModelIndex const& parent = QModelIndex {}) const override;
int columnCount (QModelIndex const& parent = QModelIndex {}) const override;
Qt::ItemFlags flags (QModelIndex const& = QModelIndex {}) const override;
QVariant headerData (int section, Qt::Orientation, int = Qt::DisplayRole) const override;
// The value return for the Qt::DisplayRole role for the root of the
// model (invalid index) is a special string representing out of
// band.
//
// All columns return a number for the custom role SortRole, this
// number defines a strict frequency order for the rows.
QVariant data (QModelIndex const&, int role = Qt::DisplayRole) const override;
};
#endif