mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-27 14:48:46 -05:00
a1a6d1bc06
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
104 lines
2.3 KiB
C++
104 lines
2.3 KiB
C++
#ifndef FREQUENCY_LIST_HPP__
|
|
#define FREQUENCY_LIST_HPP__
|
|
|
|
#include "pimpl_h.hpp"
|
|
|
|
#include <QList>
|
|
#include <QSortFilterProxyModel>
|
|
|
|
#include "Radio.hpp"
|
|
#include "Modes.hpp"
|
|
|
|
class Bands;
|
|
|
|
//
|
|
// 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
|
|
{
|
|
Q_OBJECT;
|
|
|
|
public:
|
|
using Frequency = Radio::Frequency;
|
|
using Mode = Modes::Mode;
|
|
|
|
struct Item
|
|
{
|
|
Frequency frequency_;
|
|
Mode mode_;
|
|
};
|
|
using FrequencyItems = QList<Item>;
|
|
|
|
enum Column {mode_column, frequency_column, frequency_mhz_column};
|
|
|
|
explicit FrequencyList (Bands const *, QObject * parent = nullptr);
|
|
~FrequencyList ();
|
|
|
|
// Load and store contents
|
|
FrequencyItems frequency_list (FrequencyItems);
|
|
FrequencyItems const& frequency_list () const;
|
|
|
|
// Find nearest best working frequency given a frequency and mode
|
|
QModelIndex best_working_frequency (Frequency, Mode) const;
|
|
|
|
// Set filter
|
|
void filter (Mode);
|
|
|
|
// Reset
|
|
Q_SLOT void reset_to_defaults ();
|
|
|
|
// Model API
|
|
QModelIndex add (Item);
|
|
bool remove (Item);
|
|
bool removeDisjointRows (QModelIndexList);
|
|
|
|
// Proxy API
|
|
bool filterAcceptsRow (int source_row, QModelIndex const& parent) const override;
|
|
|
|
// Custom roles.
|
|
static int constexpr SortRole = Qt::UserRole;
|
|
|
|
private:
|
|
class impl;
|
|
pimpl<impl> m_;
|
|
};
|
|
|
|
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);
|
|
|
|
#endif
|