diff options
Diffstat (limited to 'models')
| -rw-r--r-- | models/CabrilloLog.cpp | 55 | ||||
| -rw-r--r-- | models/DecodeHighlightingModel.cpp | 15 | ||||
| -rw-r--r-- | models/FoxLog.cpp | 91 | ||||
| -rw-r--r-- | models/FoxLog.hpp | 5 | ||||
| -rw-r--r-- | models/FrequencyList.cpp | 6 |
5 files changed, 152 insertions, 20 deletions
diff --git a/models/CabrilloLog.cpp b/models/CabrilloLog.cpp index aaedd3bd..1fee9b14 100644 --- a/models/CabrilloLog.cpp +++ b/models/CabrilloLog.cpp @@ -21,6 +21,8 @@ class CabrilloLog::impl final public: impl (Configuration const *); + QString cabrillo_frequency_string (Radio::Frequency frequency) const; + Configuration const * configuration_; QSqlQuery mutable dupe_query_; QSqlQuery mutable export_query_; @@ -46,10 +48,25 @@ CabrilloLog::impl::impl (Configuration const * configuration) } SQL_error_check (dupe_query_, &QSqlQuery::prepare, - "SELECT COUNT(*) FROM cabrillo_log WHERE call = :call AND band = :band"); + "SELECT " + " COUNT(*) " + " FROM " + " cabrillo_log " + " WHERE " + " call = :call " + " AND band = :band"); SQL_error_check (export_query_, &QSqlQuery::prepare, - "SELECT frequency, \"when\", exchange_sent, call, exchange_rcvd FROM cabrillo_log ORDER BY \"when\""); + "SELECT " + " frequency" + " , \"when\"" + " , exchange_sent" + " , call" + " , exchange_rcvd" + " FROM " + " cabrillo_log " + " ORDER BY " + " \"when\""); setEditStrategy (QSqlTableModel::OnFieldChange); setTable ("cabrillo_log"); @@ -68,6 +85,32 @@ CabrilloLog::impl::impl (Configuration const * configuration) SQL_error_check (*this, &QSqlTableModel::select); } +// frequency here is in kHz +QString CabrilloLog::impl::cabrillo_frequency_string (Radio::Frequency frequency) const +{ + QString result; + auto band = configuration_->bands ()->find (frequency * 1000ull); + if ("1mm" == band) result = "LIGHT"; + else if ("2mm" == band) result = "241G"; + else if ("2.5mm" == band) result = "134G"; + else if ("4mm" == band) result = "75G"; + else if ("6mm" == band) result = "47G"; + else if ("1.25cm" == band) result = "24G"; + else if ("3cm" == band) result = "10G"; + else if ("6cm" == band) result = "5.7G"; + else if ("9cm" == band) result = "3.4G"; + else if ("13cm" == band) result = "2.3G"; + else if ("23cm" == band) result = "1.2G"; + else if ("33cm" == band) result = "902"; + else if ("70cm" == band) result = "432"; + else if ("1.25m" == band) result = "222"; + else if ("2m" == band) result = "144"; + else if ("4m" == band) result = "70"; + else if ("6m" == band) result = "50"; + else result = QString::number (frequency); + return result; +} + CabrilloLog::CabrilloLog (Configuration const * configuration) : m_ {configuration} { @@ -138,6 +181,8 @@ bool CabrilloLog::dupe (Frequency frequency, QString const& call) const void CabrilloLog::reset () { + // synchronize model + while (m_->canFetchMore ()) m_->fetchMore (); if (m_->rowCount ()) { m_->setEditStrategy (QSqlTableModel::OnManualSubmit); @@ -160,12 +205,10 @@ void CabrilloLog::export_qsos (QTextStream& stream) const auto rcvd_index = record.indexOf ("exchange_rcvd"); while (m_->export_query_.next ()) { - auto frequency = m_->export_query_.value (frequency_index).value<Radio::Frequency> (); auto my_call = m_->configuration_->my_callsign (); - frequency = frequency > 50000000ull ? frequency / 1000ull : frequency; stream << QString {"QSO: %1 DG %2 %3 %4 %5 %6\n"} - .arg (frequency, 5) - .arg (QDateTime::fromMSecsSinceEpoch (m_->export_query_.value (when_index).toULongLong () * 1000ull, Qt::UTC).toString ("yyyy-MM-dd hhmm")) + .arg (m_->cabrillo_frequency_string (m_->export_query_.value (frequency_index).value<Radio::Frequency> ()), 5) + .arg (QDateTime::fromMSecsSinceEpoch (m_->export_query_.value (when_index).toULongLong () * 1000ull, Qt::UTC).toString ("yyyy-MM-dd hhmm")) .arg (my_call, -12) .arg (m_->export_query_.value (sent_index).toString (), -13) .arg (m_->export_query_.value (call_index).toString (), -12) diff --git a/models/DecodeHighlightingModel.cpp b/models/DecodeHighlightingModel.cpp index 6425a1a5..4a1205eb 100644 --- a/models/DecodeHighlightingModel.cpp +++ b/models/DecodeHighlightingModel.cpp @@ -155,25 +155,30 @@ QVariant DecodeHighlightingModel::data (const QModelIndex& index, int role) cons if (index.isValid () && index.row () < rowCount ()) { auto const& item = m_->data_[index.row ()]; + auto fg_unset = Qt::NoBrush == item.foreground_.style (); + auto bg_unset = Qt::NoBrush == item.background_.style (); switch (role) { case Qt::CheckStateRole: result = item.enabled_ ? Qt::Checked : Qt::Unchecked; break; case Qt::DisplayRole: - return QString {"%1 [f/g:%2, b/g:%3]"} + return QString {"%1%2%3%4%4%5%6"} .arg (highlight_name (item.type_)) - .arg (item.foreground_.style () != Qt::NoBrush ? QString {"#%1"}.arg (item.foreground_.color ().rgb () & 0xffffff, 6, 16, QChar {'0'}) : QString {"unset"}) - .arg (item.background_.style () != Qt::NoBrush ? QString {"#%1"}.arg (item.background_.color ().rgb () & 0xffffff, 6, 16, QChar {'0'}) : QString {"unset"}); + .arg (fg_unset || bg_unset ? QString {" ["} : QString {}) + .arg (fg_unset ? QString {"f/g unset"} : QString {}) + .arg (fg_unset && bg_unset ? QString {" "} : QString {}) + .arg (bg_unset ? QString {"b/g unset"} : QString {}) + .arg (fg_unset || bg_unset ? QString {"]"} : QString {}); break; case Qt::ForegroundRole: - if (Qt::NoBrush != item.foreground_.style ()) + if (!fg_unset) { result = item.foreground_; } break; case Qt::BackgroundRole: - if (Qt::NoBrush != item.background_.style ()) + if (!bg_unset) { result = item.background_; } diff --git a/models/FoxLog.cpp b/models/FoxLog.cpp index 1f985f62..773a5308 100644 --- a/models/FoxLog.cpp +++ b/models/FoxLog.cpp @@ -9,7 +9,9 @@ #include <QSqlRecord> #include <QSqlError> #include <QSqlQuery> +#include <QTextStream> #include <QDebug> +#include "Configuration.hpp" #include "qt_db_helpers.hpp" #include "pimpl_impl.hpp" @@ -17,12 +19,15 @@ class FoxLog::impl final : public QSqlTableModel { public: - impl (); + impl (Configuration const * configuration); + Configuration const * configuration_; QSqlQuery mutable dupe_query_; + QSqlQuery mutable export_query_; }; -FoxLog::impl::impl () +FoxLog::impl::impl (Configuration const * configuration) + : configuration_ {configuration} { if (!database ().tables ().contains ("fox_log")) { @@ -41,7 +46,26 @@ FoxLog::impl::impl () } SQL_error_check (dupe_query_, &QSqlQuery::prepare, - "SELECT COUNT(*) FROM fox_log WHERE call = :call AND band = :band"); + "SELECT " + " COUNT(*) " + " FROM " + " fox_log " + " WHERE " + " call = :call " + " AND band = :band"); + + SQL_error_check (export_query_, &QSqlQuery::prepare, + "SELECT " + " band" + " , \"when\"" + " , call" + " , grid" + " , report_sent" + " , report_rcvd " + " FROM " + " fox_log " + " ORDER BY " + " \"when\""); setEditStrategy (QSqlTableModel::OnFieldChange); setTable ("fox_log"); @@ -60,7 +84,8 @@ FoxLog::impl::impl () SQL_error_check (*this, &QSqlTableModel::select); } -FoxLog::FoxLog () +FoxLog::FoxLog (Configuration const * configuration) + : m_ {configuration} { } @@ -132,6 +157,8 @@ bool FoxLog::dupe (QString const& call, QString const& band) const void FoxLog::reset () { + // synchronize model + while (m_->canFetchMore ()) m_->fetchMore (); if (m_->rowCount ()) { m_->setEditStrategy (QSqlTableModel::OnManualSubmit); @@ -142,3 +169,59 @@ void FoxLog::reset () m_->setEditStrategy (QSqlTableModel::OnFieldChange); } } + +namespace +{ + struct ADIF_field + { + explicit ADIF_field (QString const& name, QString const& value) + : name_ {name} + , value_ {value} + { + } + + QString name_; + QString value_; + }; + + QTextStream& operator << (QTextStream& os, ADIF_field const& field) + { + if (field.value_.size ()) + { + os << QString {"<%1:%2>%3 "}.arg (field.name_).arg (field.value_.size ()).arg (field.value_); + } + return os; + } +} + +void FoxLog::export_qsos (QTextStream& out) const +{ + out << "WSJT-X FT8 DXpedition Mode Fox Log\n<eoh>"; + + SQL_error_check (m_->export_query_, static_cast<bool (QSqlQuery::*) ()> (&QSqlQuery::exec)); + auto record = m_->export_query_.record (); + auto band_index = record.indexOf ("band"); + auto when_index = record.indexOf ("when"); + auto call_index = record.indexOf ("call"); + auto grid_index = record.indexOf ("grid"); + auto sent_index = record.indexOf ("report_sent"); + auto rcvd_index = record.indexOf ("report_rcvd"); + while (m_->export_query_.next ()) + { + auto when = QDateTime::fromMSecsSinceEpoch (m_->export_query_.value (when_index).toULongLong () * 1000ull, Qt::UTC); + out << '\n' + << ADIF_field {"band", m_->export_query_.value (band_index).toString ()} + << ADIF_field {"mode", "FT8"} + << ADIF_field {"qso_date", when.toString ("yyyyMMdd")} + << ADIF_field {"time_on", when.toString ("hhmmss")} + << ADIF_field {"call", m_->export_query_.value (call_index).toString ()} + << ADIF_field {"gridsquare", m_->export_query_.value (grid_index).toString ()} + << ADIF_field {"rst_sent", m_->export_query_.value (sent_index).toString ()} + << ADIF_field {"rst_rcvd", m_->export_query_.value (rcvd_index).toString ()} + << ADIF_field {"station_callsign", m_->configuration_->my_callsign ()} + << ADIF_field {"my_gridsquare", m_->configuration_->my_grid ()} + << ADIF_field {"operator", m_->configuration_->opCall ()} + << "<eor>"; + } + out << endl; +} diff --git a/models/FoxLog.hpp b/models/FoxLog.hpp index caa8e358..9af0b254 100644 --- a/models/FoxLog.hpp +++ b/models/FoxLog.hpp @@ -7,12 +7,14 @@ class QDateTime; class QString; class QSqlTableModel; +class QTextStream; +class Configuration; class FoxLog final : private boost::noncopyable { public: - explicit FoxLog (); + explicit FoxLog (Configuration const *); ~FoxLog (); // returns false if insert fails, dupe call+band @@ -23,6 +25,7 @@ public: QSqlTableModel * model (); void reset (); + void export_qsos (QTextStream&) const; private: class impl; diff --git a/models/FrequencyList.cpp b/models/FrequencyList.cpp index 55844bdf..e57977d1 100644 --- a/models/FrequencyList.cpp +++ b/models/FrequencyList.cpp @@ -68,7 +68,6 @@ namespace {7038600, Modes::WSPR, IARURegions::ALL}, {7074000, Modes::FT8, IARURegions::ALL}, {7076000, Modes::JT65, IARURegions::ALL}, - {7078000, Modes::FT8, IARURegions::ALL}, {7078000, Modes::JT9, IARURegions::ALL}, {10136000, Modes::FT8, IARURegions::ALL}, @@ -79,7 +78,6 @@ namespace {14095600, Modes::WSPR, IARURegions::ALL}, {14074000, Modes::FT8, IARURegions::ALL}, {14076000, Modes::JT65, IARURegions::ALL}, - {14078000, Modes::FT8, IARURegions::ALL}, {14078000, Modes::JT9, IARURegions::ALL}, {18100000, Modes::FT8, IARURegions::ALL}, @@ -106,8 +104,8 @@ namespace {50276000, Modes::JT65, IARURegions::R2}, {50276000, Modes::JT65, IARURegions::R3}, {50380000, Modes::MSK144, IARURegions::R1}, - {50280000, Modes::MSK144, IARURegions::R2}, - {50280000, Modes::MSK144, IARURegions::R3}, + {50260000, Modes::MSK144, IARURegions::R2}, + {50260000, Modes::MSK144, IARURegions::R3}, {50293000, Modes::WSPR, IARURegions::R2}, {50293000, Modes::WSPR, IARURegions::R3}, {50310000, Modes::JT65, IARURegions::ALL}, |
