summaryrefslogtreecommitdiff
path: root/models
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2019-06-02 22:17:11 +0200
committerChristoph Berg <myon@debian.org>2019-06-02 22:17:11 +0200
commit851b658298afb9bafeda98ffbfa2ade612c656be (patch)
tree826d54e9dac4ce15fdd1b6af3360eeba7993a7d2 /models
parentb7238399ea4f1ca51d8f7b8f9220af3da0913edf (diff)
New upstream version 2.1.0~rc6+repackupstream/2.1.0_rc6+repack
Diffstat (limited to 'models')
-rw-r--r--models/CabrilloLog.cpp186
-rw-r--r--models/CabrilloLog.hpp20
-rw-r--r--models/FoxLog.cpp17
-rw-r--r--models/FrequencyList.cpp4
4 files changed, 176 insertions, 51 deletions
diff --git a/models/CabrilloLog.cpp b/models/CabrilloLog.cpp
index 1fee9b14..dfba3d43 100644
--- a/models/CabrilloLog.cpp
+++ b/models/CabrilloLog.cpp
@@ -12,6 +12,7 @@
#include <QDataStream>
#include "Configuration.hpp"
#include "Bands.hpp"
+#include "logbook/AD1CCty.hpp"
#include "qt_db_helpers.hpp"
#include "pimpl_impl.hpp"
@@ -19,42 +20,109 @@ class CabrilloLog::impl final
: public QSqlTableModel
{
public:
- impl (Configuration const *);
+ impl (CabrilloLog *, Configuration const *);
+
+ int columnCount (QModelIndex const& /*index */) const override
+ {
+ return QSqlTableModel::columnCount () + 1;
+ }
+
+ Qt::ItemFlags flags (QModelIndex const& index) const override
+ {
+ auto flags = QSqlTableModel::flags (index);
+ if (index.isValid () && index.column () == columnCount (index) - 1)
+ {
+ flags = Qt::ItemIsEnabled;
+ }
+ return flags;
+ }
+
+ QVariant data (QModelIndex const& model_index, int role) const override
+ {
+ QVariant value;
+ if (model_index.isValid () && model_index.column () == columnCount (model_index) - 1)
+ { // derive band column
+ if (Qt::DisplayRole == role)
+ {
+ value = configuration_->bands ()->find (QSqlTableModel::data (index (model_index.row (), fieldIndex ("frequency"))).toULongLong ());
+ }
+ }
+ else
+ {
+ value = QSqlTableModel::data (model_index, role);
+ if (model_index.column () == fieldIndex ("frequency") && Qt::DisplayRole == role)
+ {
+ value = Radio::frequency_MHz_string (value.value<Radio::Frequency> (), 3); // kHz precision
+ }
+ else if (model_index.column () == fieldIndex ("when")
+ && (Qt::DisplayRole == role || Qt::EditRole == role))
+ { // adjust date/time to Qt format
+ auto t = QDateTime::fromMSecsSinceEpoch (value.toULongLong () * 1000ull, Qt::UTC);
+ if (Qt::DisplayRole == role)
+ {
+ QLocale locale;
+ return locale.toString (t, locale.dateFormat (QLocale::ShortFormat) + " hh:mm:ss");
+ }
+ value = t;
+ }
+ }
+ return value;
+ }
QString cabrillo_frequency_string (Radio::Frequency frequency) const;
+ void create_table ();
+ CabrilloLog * self_;
Configuration const * configuration_;
QSqlQuery mutable dupe_query_;
QSqlQuery mutable export_query_;
+ bool adding_row_;
};
-CabrilloLog::impl::impl (Configuration const * configuration)
- : QSqlTableModel {}
+CabrilloLog::impl::impl (CabrilloLog * self, Configuration const * configuration)
+ : self_ {self}
, configuration_ {configuration}
+ , adding_row_ {false}
{
- if (!database ().tables ().contains ("cabrillo_log"))
+ if (!database ().tables ().contains ("cabrillo_log_v2"))
{
- QSqlQuery query;
- SQL_error_check (query, static_cast<bool (QSqlQuery::*) (QString const&)> (&QSqlQuery::exec),
- "CREATE TABLE cabrillo_log ("
- " id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"
- " frequency INTEGER NOT NULL,"
- " \"when\" DATETIME NOT NULL,"
- " call VARCHAR(20) NOT NULL,"
- " exchange_sent VARCHAR(32) NOT NULL,"
- " exchange_rcvd VARCHAR(32) NOT NULL,"
- " band VARCHAR(6) NOT NULL"
- ")");
+ create_table ();
}
+ setEditStrategy (QSqlTableModel::OnFieldChange);
+ setTable ("cabrillo_log_v2");
+ setHeaderData (fieldIndex ("frequency"), Qt::Horizontal, tr ("Freq(MHz)"));
+ setHeaderData (fieldIndex ("mode"), Qt::Horizontal, tr ("Mode"));
+ setHeaderData (fieldIndex ("when"), Qt::Horizontal, tr ("Date & Time(UTC)"));
+ setHeaderData (fieldIndex ("call"), Qt::Horizontal, tr ("Call"));
+ setHeaderData (fieldIndex ("exchange_sent"), Qt::Horizontal, tr ("Sent"));
+ setHeaderData (fieldIndex ("exchange_rcvd"), Qt::Horizontal, tr ("Rcvd"));
+ setHeaderData (columnCount (QModelIndex {}) - 1, Qt::Horizontal, tr ("Band"));
+
+ // This descending order by time is important, it makes the view
+ // place the latest row at the top, without this the model/view
+ // interactions are both sluggish and unhelpful.
+ setSort (fieldIndex ("when"), Qt::DescendingOrder);
+
+ connect (this, &CabrilloLog::impl::modelReset, self_, &CabrilloLog::data_changed);
+ connect (this, &CabrilloLog::impl::dataChanged, [this] (QModelIndex const& tl, QModelIndex const& br) {
+ if (!adding_row_ && !(tl == br)) // ignore single cell changes
+ // as a another change for the
+ // whole row will follow
+ {
+ Q_EMIT self_->data_changed ();
+ }
+ });
+
+ SQL_error_check (*this, &QSqlTableModel::select);
+
SQL_error_check (dupe_query_, &QSqlQuery::prepare,
"SELECT "
- " COUNT(*) "
+ " frequency "
" FROM "
- " cabrillo_log "
+ " cabrillo_log_v2 "
" WHERE "
- " call = :call "
- " AND band = :band");
+ " call = :call ");
SQL_error_check (export_query_, &QSqlQuery::prepare,
"SELECT "
@@ -64,32 +132,31 @@ CabrilloLog::impl::impl (Configuration const * configuration)
" , call"
" , exchange_rcvd"
" FROM "
- " cabrillo_log "
+ " cabrillo_log_v2 "
" ORDER BY "
" \"when\"");
-
- setEditStrategy (QSqlTableModel::OnFieldChange);
- setTable ("cabrillo_log");
- setHeaderData (fieldIndex ("frequency"), Qt::Horizontal, tr ("Freq(kHz)"));
- setHeaderData (fieldIndex ("when"), Qt::Horizontal, tr ("Date & Time(UTC)"));
- setHeaderData (fieldIndex ("call"), Qt::Horizontal, tr ("Call"));
- setHeaderData (fieldIndex ("exchange_sent"), Qt::Horizontal, tr ("Sent"));
- setHeaderData (fieldIndex ("exchange_rcvd"), Qt::Horizontal, tr ("Rcvd"));
- setHeaderData (fieldIndex ("band"), Qt::Horizontal, tr ("Band"));
-
- // This descending order by time is important, it makes the view
- // place the latest row at the top, without this the model/view
- // interactions are both sluggish and unhelpful.
- setSort (fieldIndex ("when"), Qt::DescendingOrder);
+}
- SQL_error_check (*this, &QSqlTableModel::select);
+void CabrilloLog::impl::create_table ()
+{
+ QSqlQuery query;
+ SQL_error_check (query, static_cast<bool (QSqlQuery::*) (QString const&)> (&QSqlQuery::exec),
+ "CREATE TABLE cabrillo_log_v2 ("
+ " id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"
+ " frequency INTEGER NOT NULL,"
+ " mode VARCHAR(6) NOT NULL,"
+ " \"when\" DATETIME NOT NULL,"
+ " call VARCHAR(20) NOT NULL,"
+ " exchange_sent VARCHAR(32) NOT NULL,"
+ " exchange_rcvd VARCHAR(32) NOT NULL"
+ ")");
}
// frequency here is in kHz
QString CabrilloLog::impl::cabrillo_frequency_string (Radio::Frequency frequency) const
{
QString result;
- auto band = configuration_->bands ()->find (frequency * 1000ull);
+ auto band = configuration_->bands ()->find (frequency);
if ("1mm" == band) result = "LIGHT";
else if ("2mm" == band) result = "241G";
else if ("2.5mm" == band) result = "134G";
@@ -107,12 +174,15 @@ QString CabrilloLog::impl::cabrillo_frequency_string (Radio::Frequency frequency
else if ("2m" == band) result = "144";
else if ("4m" == band) result = "70";
else if ("6m" == band) result = "50";
- else result = QString::number (frequency);
+ else result = QString::number (frequency / 1000ull);
return result;
}
-CabrilloLog::CabrilloLog (Configuration const * configuration)
- : m_ {configuration}
+#include "moc_CabrilloLog.cpp"
+
+CabrilloLog::CabrilloLog (Configuration const * configuration, QObject * parent)
+ : QObject {parent}
+ , m_ {this, configuration}
{
Q_ASSERT (configuration);
}
@@ -141,11 +211,12 @@ namespace
}
}
-bool CabrilloLog::add_QSO (Frequency frequency, QDateTime const& when, QString const& call
+bool CabrilloLog::add_QSO (Frequency frequency, QString const& mode, QDateTime const& when, QString const& call
, QString const& exchange_sent, QString const& exchange_received)
{
auto record = m_->record ();
- record.setValue ("frequency", frequency / 1000ull); // kHz
+ record.setValue ("frequency", frequency);
+ record.setValue ("mode", mode);
if (!when.isNull ())
{
record.setValue ("when", when.toMSecsSinceEpoch () / 1000ull);
@@ -157,15 +228,16 @@ bool CabrilloLog::add_QSO (Frequency frequency, QDateTime const& when, QString c
set_value_maybe_null (record, "call", call);
set_value_maybe_null (record, "exchange_sent", exchange_sent);
set_value_maybe_null (record, "exchange_rcvd", exchange_received);
- set_value_maybe_null (record, "band", m_->configuration_->bands ()->find (frequency));
if (m_->isDirty ())
{
m_->revert (); // discard any uncommitted changes
}
m_->setEditStrategy (QSqlTableModel::OnManualSubmit);
ConditionalTransaction transaction {*m_};
+ m_->adding_row_ = true;
auto ok = m_->insertRecord (-1, record);
transaction.submit ();
+ m_->adding_row_ = false;
m_->setEditStrategy (QSqlTableModel::OnFieldChange);
return ok;
}
@@ -173,10 +245,18 @@ bool CabrilloLog::add_QSO (Frequency frequency, QDateTime const& when, QString c
bool CabrilloLog::dupe (Frequency frequency, QString const& call) const
{
m_->dupe_query_.bindValue (":call", call);
- m_->dupe_query_.bindValue (":band", m_->configuration_->bands ()->find (frequency));
SQL_error_check (m_->dupe_query_, static_cast<bool (QSqlQuery::*) ()> (&QSqlQuery::exec));
- m_->dupe_query_.next ();
- return m_->dupe_query_.value (0).toInt ();
+ auto record = m_->dupe_query_.record ();
+ auto frequency_index = record.indexOf ("frequency");
+ while (m_->dupe_query_.next ())
+ {
+ if (m_->configuration_->bands ()->find (m_->dupe_query_.value (frequency_index).toULongLong ())
+ == m_->configuration_->bands ()->find (frequency))
+ {
+ return true;
+ }
+ }
+ return false;
}
void CabrilloLog::reset ()
@@ -191,6 +271,7 @@ void CabrilloLog::reset ()
transaction.submit ();
m_->select (); // to refresh views
m_->setEditStrategy (QSqlTableModel::OnFieldChange);
+ Q_EMIT data_changed ();
}
}
@@ -199,6 +280,7 @@ void CabrilloLog::export_qsos (QTextStream& stream) const
SQL_error_check (m_->export_query_, static_cast<bool (QSqlQuery::*) ()> (&QSqlQuery::exec));
auto record = m_->export_query_.record ();
auto frequency_index = record.indexOf ("frequency");
+ // auto mode_index = record.indexOf ("mode");
auto when_index = record.indexOf ("when");
auto call_index = record.indexOf ("call");
auto sent_index = record.indexOf ("exchange_sent");
@@ -215,3 +297,17 @@ void CabrilloLog::export_qsos (QTextStream& stream) const
.arg (m_->export_query_.value (rcvd_index).toString (), -13);
}
}
+
+auto CabrilloLog::unique_DXCC_entities (AD1CCty const * countries) const -> worked_set
+{
+ QSqlQuery q {"SELECT DISTINCT BAND, CALL FROM cabrillo_log_v2"};
+ auto band_index = q.record ().indexOf ("band");
+ auto call_index = q.record ().indexOf ("call");
+ worked_set entities;
+ while (q.next ())
+ {
+ entities << worked_item {q.value (band_index).toString ()
+ , countries->lookup (q.value (call_index).toString ()).primary_prefix};
+ }
+ return entities;
+}
diff --git a/models/CabrilloLog.hpp b/models/CabrilloLog.hpp
index 43b9e8f9..97d8f0d8 100644
--- a/models/CabrilloLog.hpp
+++ b/models/CabrilloLog.hpp
@@ -1,33 +1,43 @@
#ifndef CABRILLO_LOG_HPP_
#define CABRILLO_LOG_HPP_
-#include <boost/core/noncopyable.hpp>
+#include <QObject>
+#include <QSet>
+#include <QPair>
+#include <QString>
#include "Radio.hpp"
#include "pimpl_h.hpp"
class Configuration;
class QDateTime;
-class QString;
class QSqlTableModel;
class QTextStream;
+class AD1CCty;
class CabrilloLog final
- : private boost::noncopyable
+ : public QObject
{
+ Q_OBJECT
+
public:
using Frequency = Radio::Frequency;
+ using worked_item = QPair<QString, QString>;
+ using worked_set = QSet<worked_item>;
- explicit CabrilloLog (Configuration const *);
+ explicit CabrilloLog (Configuration const *, QObject * parent = nullptr);
~CabrilloLog ();
// returns false if insert fails
- bool add_QSO (Frequency, QDateTime const&, QString const& call
+ bool add_QSO (Frequency, QString const& mode, QDateTime const&, QString const& call
, QString const& report_sent, QString const& report_received);
bool dupe (Frequency, QString const& call) const;
QSqlTableModel * model ();
void reset ();
void export_qsos (QTextStream&) const;
+ worked_set unique_DXCC_entities (AD1CCty const *) const;
+
+ Q_SIGNAL void data_changed () const;
private:
class impl;
diff --git a/models/FoxLog.cpp b/models/FoxLog.cpp
index 773a5308..debb08af 100644
--- a/models/FoxLog.cpp
+++ b/models/FoxLog.cpp
@@ -21,6 +21,23 @@ class FoxLog::impl final
public:
impl (Configuration const * configuration);
+ QVariant data (QModelIndex const& index, int role) const
+ {
+ auto value = QSqlTableModel::data (index, role);
+ if (index.column () == fieldIndex ("when")
+ && (Qt::DisplayRole == role || Qt::EditRole == role))
+ {
+ auto t = QDateTime::fromMSecsSinceEpoch (value.toULongLong () * 1000ull, Qt::UTC);
+ if (Qt::DisplayRole == role)
+ {
+ QLocale locale;
+ return locale.toString (t, locale.dateFormat (QLocale::ShortFormat) + " hh:mm:ss");
+ }
+ value = t;
+ }
+ return value;
+ }
+
Configuration const * configuration_;
QSqlQuery mutable dupe_query_;
QSqlQuery mutable export_query_;
diff --git a/models/FrequencyList.cpp b/models/FrequencyList.cpp
index b135a512..c0170a49 100644
--- a/models/FrequencyList.cpp
+++ b/models/FrequencyList.cpp
@@ -127,7 +127,9 @@ namespace
{7074000, Modes::FT8, IARURegions::ALL},
{7076000, Modes::JT65, IARURegions::ALL},
{7078000, Modes::JT9, IARURegions::ALL},
- {7047000, Modes::FT4, IARURegions::ALL}, // provisional
+ {7047500, Modes::FT4, IARURegions::ALL}, // provisional - moved
+ // up 500Hz to clear
+ // W1AW code practice QRG
// Band plans (all USB dial unless stated otherwise)
//