2015-04-05 21:57:47 -04:00
|
|
|
#ifndef FREQUENCY_LIST_HPP__
|
|
|
|
#define FREQUENCY_LIST_HPP__
|
|
|
|
|
|
|
|
#include "pimpl_h.hpp"
|
|
|
|
|
2015-05-28 19:22:17 -04:00
|
|
|
#include <QList>
|
2015-04-05 21:57:47 -04:00
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
|
|
|
|
#include "Radio.hpp"
|
2015-05-28 19:22:17 -04:00
|
|
|
#include "Modes.hpp"
|
|
|
|
|
|
|
|
class Bands;
|
2015-04-05 21:57:47 -04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Class FrequencyList
|
|
|
|
//
|
|
|
|
// Encapsulates a collection of frequencies. The implementation is a
|
|
|
|
// table containing the list of Frequency type elements which is
|
|
|
|
// editable and a second column which is an immutable double
|
|
|
|
// representation of the corresponding Frequency item scaled to
|
|
|
|
// mega-Hertz.
|
|
|
|
//
|
|
|
|
// The list is ordered.
|
|
|
|
//
|
|
|
|
// Responsibilities
|
|
|
|
//
|
|
|
|
// Stores internally a list of unique frequencies. Provides methods
|
|
|
|
// to add and delete list elements.
|
|
|
|
//
|
|
|
|
// Collaborations
|
|
|
|
//
|
|
|
|
// Implements the QSortFilterProxyModel interface for a list of spot
|
|
|
|
// frequencies.
|
|
|
|
//
|
|
|
|
class FrequencyList final
|
|
|
|
: public QSortFilterProxyModel
|
|
|
|
{
|
2015-05-28 19:22:17 -04:00
|
|
|
Q_OBJECT;
|
|
|
|
|
2015-04-05 21:57:47 -04:00
|
|
|
public:
|
|
|
|
using Frequency = Radio::Frequency;
|
2015-05-28 19:22:17 -04:00
|
|
|
using Mode = Modes::Mode;
|
|
|
|
|
|
|
|
struct Item
|
|
|
|
{
|
|
|
|
Frequency frequency_;
|
|
|
|
Mode mode_;
|
|
|
|
};
|
|
|
|
using FrequencyItems = QList<Item>;
|
|
|
|
|
|
|
|
enum Column {mode_column, frequency_column, frequency_mhz_column};
|
2015-04-05 21:57:47 -04:00
|
|
|
|
2015-05-31 07:51:31 -04:00
|
|
|
// an iterator that meets the requirements of the C++ for range statement
|
|
|
|
class const_iterator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
const_iterator (FrequencyList const * parent, int row)
|
|
|
|
: parent_ {parent}
|
|
|
|
, row_ {row}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Item const& operator * ();
|
|
|
|
bool operator != (const_iterator const&) const;
|
|
|
|
const_iterator& operator ++ ();
|
|
|
|
|
|
|
|
private:
|
|
|
|
FrequencyList const * parent_;
|
|
|
|
int row_;
|
|
|
|
};
|
|
|
|
|
2015-05-28 19:22:17 -04:00
|
|
|
explicit FrequencyList (Bands const *, QObject * parent = nullptr);
|
2015-04-05 21:57:47 -04:00
|
|
|
~FrequencyList ();
|
|
|
|
|
2015-05-31 07:51:31 -04:00
|
|
|
// Load and store underlying items
|
2015-05-28 19:22:17 -04:00
|
|
|
FrequencyItems frequency_list (FrequencyItems);
|
|
|
|
FrequencyItems const& frequency_list () const;
|
|
|
|
|
2015-05-31 07:51:31 -04:00
|
|
|
// Iterators for the sorted and filtered items
|
|
|
|
//
|
|
|
|
// Note that these iterators are on the final sorted and filtered
|
|
|
|
// rows, if you need to access the underlying unfiltered and
|
|
|
|
// unsorted frequencies then use the frequency_list() member to
|
|
|
|
// access the underlying list of rows
|
|
|
|
const_iterator begin () const;
|
|
|
|
const_iterator end () const;
|
|
|
|
|
|
|
|
// Find the row of the nearest best working frequency given a
|
|
|
|
// frequency and mode
|
|
|
|
int best_working_frequency (Frequency) const;
|
2015-05-28 19:22:17 -04:00
|
|
|
|
|
|
|
// Set filter
|
|
|
|
void filter (Mode);
|
|
|
|
|
|
|
|
// Reset
|
|
|
|
Q_SLOT void reset_to_defaults ();
|
2015-04-05 21:57:47 -04:00
|
|
|
|
|
|
|
// Model API
|
2015-05-28 19:22:17 -04:00
|
|
|
QModelIndex add (Item);
|
|
|
|
bool remove (Item);
|
2015-04-05 21:57:47 -04:00
|
|
|
bool removeDisjointRows (QModelIndexList);
|
|
|
|
|
2015-05-28 19:22:17 -04:00
|
|
|
// Proxy API
|
|
|
|
bool filterAcceptsRow (int source_row, QModelIndex const& parent) const override;
|
|
|
|
|
2015-04-05 21:57:47 -04:00
|
|
|
// Custom roles.
|
|
|
|
static int constexpr SortRole = Qt::UserRole;
|
|
|
|
|
|
|
|
private:
|
|
|
|
class impl;
|
|
|
|
pimpl<impl> m_;
|
|
|
|
};
|
|
|
|
|
2015-05-28 19:22:17 -04:00
|
|
|
inline
|
|
|
|
bool operator == (FrequencyList::Item const& lhs, FrequencyList::Item const& rhs)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
lhs.frequency_ == rhs.frequency_
|
|
|
|
&& lhs.mode_ == rhs.mode_;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDataStream& operator << (QDataStream&, FrequencyList::Item const&);
|
|
|
|
QDataStream& operator >> (QDataStream&, FrequencyList::Item&);
|
|
|
|
|
|
|
|
#if !defined (QT_NO_DEBUG_STREAM)
|
|
|
|
QDebug operator << (QDebug, FrequencyList::Item const&);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE (FrequencyList::Item);
|
|
|
|
Q_DECLARE_METATYPE (FrequencyList::FrequencyItems);
|
|
|
|
|
2015-04-05 21:57:47 -04:00
|
|
|
#endif
|