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"
|
2017-07-07 19:11:41 -04:00
|
|
|
#include "IARURegions.hpp"
|
2015-05-28 19:22:17 -04:00
|
|
|
#include "Modes.hpp"
|
|
|
|
|
|
|
|
class Bands;
|
2015-04-05 21:57:47 -04:00
|
|
|
|
|
|
|
//
|
2017-08-09 12:06:17 -04:00
|
|
|
// Class FrequencyList_v2
|
2015-04-05 21:57:47 -04:00
|
|
|
//
|
2015-05-31 07:51:40 -04:00
|
|
|
// Encapsulates a collection of frequencies with associated modes.
|
2017-07-07 19:11:41 -04:00
|
|
|
// The implementation is a table containing the list of IARU region,
|
|
|
|
// Frequency and mode tuples which are editable. A third column is
|
|
|
|
// modeled in the model which is an immutable double representation
|
|
|
|
// of the corresponding Frequency item scaled to mega-Hertz.
|
2015-04-05 21:57:47 -04:00
|
|
|
//
|
2017-07-07 19:11:41 -04:00
|
|
|
// The list is ordered. A filter on IARU region and mode is
|
|
|
|
// available and is set by the filter(Region, Mode) method. The
|
|
|
|
// Region value IARURegions::ALL and the Mode value Modes::ALL may be
|
|
|
|
// optionally given which passes all rows in the filtered column.
|
2015-04-05 21:57:47 -04:00
|
|
|
//
|
|
|
|
// Responsibilities
|
|
|
|
//
|
2017-07-07 19:11:41 -04:00
|
|
|
// Stores internally a list of unique region, frequency mode tuples.
|
|
|
|
// Provides methods to add and delete list elements. Provides range
|
2015-05-31 07:51:40 -04:00
|
|
|
// iterators for a filtered view of the underlying table.
|
2015-04-05 21:57:47 -04:00
|
|
|
//
|
|
|
|
// Collaborations
|
|
|
|
//
|
|
|
|
// Implements the QSortFilterProxyModel interface for a list of spot
|
|
|
|
// frequencies.
|
|
|
|
//
|
2017-08-09 12:06:17 -04:00
|
|
|
class FrequencyList_v2 final
|
2015-04-05 21:57:47 -04:00
|
|
|
: public QSortFilterProxyModel
|
|
|
|
{
|
2015-05-28 19:22:17 -04:00
|
|
|
Q_OBJECT;
|
|
|
|
|
2015-04-05 21:57:47 -04:00
|
|
|
public:
|
2017-07-07 19:11:41 -04:00
|
|
|
using Region = IARURegions::Region;
|
2015-04-05 21:57:47 -04:00
|
|
|
using Frequency = Radio::Frequency;
|
2015-05-28 19:22:17 -04:00
|
|
|
using Mode = Modes::Mode;
|
|
|
|
|
|
|
|
struct Item
|
|
|
|
{
|
|
|
|
Frequency frequency_;
|
|
|
|
Mode mode_;
|
2017-07-07 19:11:41 -04:00
|
|
|
Region region_;
|
2015-05-28 19:22:17 -04:00
|
|
|
};
|
|
|
|
using FrequencyItems = QList<Item>;
|
2015-05-31 07:51:40 -04:00
|
|
|
using BandSet = QSet<QString>;
|
2015-05-28 19:22:17 -04:00
|
|
|
|
2017-07-07 19:11:41 -04:00
|
|
|
enum Column {region_column, mode_column, frequency_column, frequency_mhz_column, SENTINAL};
|
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:
|
2017-08-09 12:06:17 -04:00
|
|
|
const_iterator (FrequencyList_v2 const * parent, int row)
|
2015-05-31 07:51:31 -04:00
|
|
|
: parent_ {parent}
|
|
|
|
, row_ {row}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-08 18:58:09 -05:00
|
|
|
Item const& operator * () const;
|
|
|
|
Item const * operator -> () const;
|
2015-05-31 07:51:31 -04:00
|
|
|
bool operator != (const_iterator const&) const;
|
2017-01-08 18:58:09 -05:00
|
|
|
bool operator == (const_iterator const&) const;
|
2015-05-31 07:51:31 -04:00
|
|
|
const_iterator& operator ++ ();
|
|
|
|
|
|
|
|
private:
|
2017-08-09 12:06:17 -04:00
|
|
|
FrequencyList_v2 const * parent_;
|
2015-05-31 07:51:31 -04:00
|
|
|
int row_;
|
|
|
|
};
|
|
|
|
|
2017-08-09 12:06:17 -04:00
|
|
|
explicit FrequencyList_v2 (Bands const *, QObject * parent = nullptr);
|
|
|
|
~FrequencyList_v2 ();
|
2015-04-05 21:57:47 -04:00
|
|
|
|
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;
|
2017-07-07 19:11:41 -04:00
|
|
|
FrequencyItems frequency_list (QModelIndexList const&) const;
|
|
|
|
void frequency_list_merge (FrequencyItems const&);
|
2015-05-28 19:22:17 -04:00
|
|
|
|
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
|
2015-05-31 07:51:40 -04:00
|
|
|
// access the underlying list of rows.
|
2015-05-31 07:51:31 -04:00
|
|
|
const_iterator begin () const;
|
|
|
|
const_iterator end () const;
|
|
|
|
|
2017-01-12 16:03:30 -05:00
|
|
|
// Find a row with a given frequency
|
|
|
|
const_iterator find (Frequency) const;
|
|
|
|
|
2015-05-31 07:51:40 -04:00
|
|
|
// Bands of the frequencies
|
2017-07-07 19:11:41 -04:00
|
|
|
BandSet all_bands (Region = IARURegions::ALL, Mode = Modes::ALL) const;
|
2015-05-31 07:51:40 -04:00
|
|
|
BandSet filtered_bands () const;
|
|
|
|
|
2015-05-31 07:51:31 -04:00
|
|
|
// Find the row of the nearest best working frequency given a
|
2015-05-31 07:51:40 -04:00
|
|
|
// frequency. Returns -1 if no suitable working frequency is found
|
|
|
|
// in the list.
|
2015-05-31 07:51:31 -04:00
|
|
|
int best_working_frequency (Frequency) const;
|
2015-05-28 19:22:17 -04:00
|
|
|
|
2015-05-31 07:51:40 -04:00
|
|
|
// Find the row of the nearest best working frequency given a band
|
|
|
|
// name. Returns -1 if no suitable working frequency is found in the
|
|
|
|
// list.
|
|
|
|
int best_working_frequency (QString const& band) const;
|
|
|
|
|
2015-05-28 19:22:17 -04:00
|
|
|
// Set filter
|
2017-07-07 19:11:41 -04:00
|
|
|
Q_SLOT void filter (Region, Mode);
|
2015-05-28 19:22:17 -04:00
|
|
|
|
|
|
|
// 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
|
2017-08-09 12:06:17 -04:00
|
|
|
bool operator == (FrequencyList_v2::Item const& lhs, FrequencyList_v2::Item const& rhs)
|
2015-05-28 19:22:17 -04:00
|
|
|
{
|
|
|
|
return
|
|
|
|
lhs.frequency_ == rhs.frequency_
|
2017-07-07 19:11:41 -04:00
|
|
|
&& lhs.region_ == rhs.region_
|
2015-05-28 19:22:17 -04:00
|
|
|
&& lhs.mode_ == rhs.mode_;
|
|
|
|
}
|
|
|
|
|
2017-08-09 12:06:17 -04:00
|
|
|
QDataStream& operator << (QDataStream&, FrequencyList_v2::Item const&);
|
|
|
|
QDataStream& operator >> (QDataStream&, FrequencyList_v2::Item&);
|
2015-05-28 19:22:17 -04:00
|
|
|
|
|
|
|
#if !defined (QT_NO_DEBUG_STREAM)
|
2017-08-09 12:06:17 -04:00
|
|
|
QDebug operator << (QDebug, FrequencyList_v2::Item const&);
|
2015-05-28 19:22:17 -04:00
|
|
|
#endif
|
|
|
|
|
2017-08-09 12:06:17 -04:00
|
|
|
Q_DECLARE_METATYPE (FrequencyList_v2::Item);
|
|
|
|
Q_DECLARE_METATYPE (FrequencyList_v2::FrequencyItems);
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Obsolete version of FrequencyList no longer used but needed to
|
|
|
|
// allow loading and saving of old settings contents without damage
|
|
|
|
//
|
|
|
|
class FrequencyList final
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using Frequency = Radio::Frequency;
|
|
|
|
using Mode = Modes::Mode;
|
|
|
|
|
|
|
|
struct Item
|
|
|
|
{
|
|
|
|
Frequency frequency_;
|
|
|
|
Mode mode_;
|
|
|
|
};
|
|
|
|
using FrequencyItems = QList<Item>;
|
|
|
|
|
|
|
|
private:
|
|
|
|
FrequencyItems frequency_list_;
|
|
|
|
};
|
|
|
|
|
|
|
|
QDataStream& operator << (QDataStream&, FrequencyList::Item const&);
|
|
|
|
QDataStream& operator >> (QDataStream&, FrequencyList::Item&);
|
|
|
|
|
2015-05-28 19:22:17 -04:00
|
|
|
Q_DECLARE_METATYPE (FrequencyList::Item);
|
|
|
|
Q_DECLARE_METATYPE (FrequencyList::FrequencyItems);
|
|
|
|
|
2015-04-05 21:57:47 -04:00
|
|
|
#endif
|