summaryrefslogtreecommitdiff
path: root/StationList.hpp
diff options
context:
space:
mode:
authorIain R. Learmonth <irl@debian.org>2015-10-18 18:51:00 +0100
committerIain R. Learmonth <irl@debian.org>2015-10-18 18:51:00 +0100
commitd63dd8d081a6fcd0715cd13f26df59fb831769d2 (patch)
treeb9c1f6245147a310aac3762630bad389bbb57335 /StationList.hpp
parentc720a3d55c5ec832c29cb7ce50b6fb4b70c55b11 (diff)
Imported Upstream version 1.5.0upstream/1.5.0
Diffstat (limited to 'StationList.hpp')
-rw-r--r--StationList.hpp102
1 files changed, 102 insertions, 0 deletions
diff --git a/StationList.hpp b/StationList.hpp
new file mode 100644
index 00000000..75f64127
--- /dev/null
+++ b/StationList.hpp
@@ -0,0 +1,102 @@
+#ifndef STATION_LIST_HPP__
+#define STATION_LIST_HPP__
+
+#include <QSortFilterProxyModel>
+#include <QString>
+#include <QList>
+
+#include "pimpl_h.hpp"
+
+#include "Radio.hpp"
+
+class Bands;
+
+//
+// Class StationList
+//
+// Encapsulates information about a collection of unique operating
+// stations per band. The implementation is a table model with the
+// first column being the unique (within the table rows) band name
+// and, the second the frequency offset for transverter usage and,
+// the third the antenna description. All are editable.
+//
+// Responsibilities
+//
+// Stores internally an unordered table of bands.
+//
+// If an ordered representaion is required then wrapping with an
+// appropriate proxy model is sufficient
+// e.g. QSortFilterProxyModel. A custom SortRole role is provided for
+// the band name column which returns a numeric value (Bands lower
+// frequency limit) which gives a strict frequency ordering by band.
+//
+// Collaborations
+//
+// Implements the QAbstractTableModel interface for a grid of bands
+// with offset frequencies and antenna descriptions.
+//
+// Uses the QAbstractItemModel interface of the bands model to lookup
+// band information.
+//
+class StationList final
+ : public QSortFilterProxyModel
+{
+public:
+ using Frequency = Radio::Frequency;
+ using FrequencyDelta = Radio::FrequencyDelta;
+
+ //
+ // Struct Station
+ //
+ // Aggregation of fields that describe a radio station on a band.
+ //
+ struct Station
+ {
+ QString band_name_;
+ FrequencyDelta offset_;
+ QString antenna_description_;
+ };
+
+ using Stations = QList<Station>;
+
+ explicit StationList (Bands const * bands, QObject * parent = nullptr);
+ explicit StationList (Bands const * bands, Stations, QObject * parent = nullptr);
+ ~StationList ();
+
+ // Load and store contents.
+ StationList& operator = (Stations);
+ Stations stations () const;
+
+ //
+ // Model API
+ //
+ QModelIndex add (Station); // Add a new Station
+ bool remove (Station); // Remove a Station
+ bool removeDisjointRows (QModelIndexList); // Remove one or more stations
+ FrequencyDelta offset (Frequency) const; // Return the offset to be used for a Frequency
+
+ // Custom sort role.
+ static int constexpr SortRole = Qt::UserRole;
+
+private:
+ class impl;
+ pimpl<impl> m_;
+};
+
+#if !defined (QT_NO_DEBUG_STREAM)
+QDebug operator << (QDebug debug, StationList::Station const&);
+#endif
+
+// Station equivalence
+inline
+bool operator == (StationList::Station const& lhs, StationList::Station const& rhs)
+{
+ return lhs.band_name_ == rhs.band_name_
+ && lhs.offset_ == rhs.offset_
+ && lhs.antenna_description_ == rhs.antenna_description_;
+}
+
+Q_DECLARE_METATYPE (StationList::Station);
+Q_DECLARE_METATYPE (StationList::Stations);
+
+#endif