Moving toward multiplier and dupe detection for contest modes

There's not  much to show  for this so far  but some of  the necessary
infrastructure is in place.
This commit is contained in:
Bill Somerville 2019-05-30 22:20:09 +01:00
parent 425b0e89a8
commit 19c46774b4
No known key found for this signature in database
GPG Key ID: D864B06D1E81618F
31 changed files with 473 additions and 128 deletions

View File

@ -237,6 +237,7 @@ set (wsjt_qt_CXXSRCS
models/FrequencyList.cpp
models/StationList.cpp
widgets/FrequencyLineEdit.cpp
widgets/FrequencyDeltaLineEdit.cpp
item_delegates/CandidateKeyFilter.cpp
item_delegates/ForeignKeyDelegate.cpp
validators/LiveFrequencyValidator.cpp
@ -279,9 +280,12 @@ set (wsjt_qt_CXXSRCS
widgets/CabrilloLogWindow.cpp
item_delegates/CallsignDelegate.cpp
item_delegates/MaidenheadLocatorDelegate.cpp
item_delegates/FrequencyDelegate.cpp
item_delegates/FrequencyDeltaDelegate.cpp
models/CabrilloLog.cpp
logbook/AD1CCty.cpp
logbook/WorkedBefore.cpp
logbook/Multiplier.cpp
)
set (wsjt_qtmm_CXXSRCS

View File

@ -167,8 +167,11 @@
#include "MetaDataRegistry.hpp"
#include "SettingsGroup.hpp"
#include "widgets/FrequencyLineEdit.hpp"
#include "widgets/FrequencyDeltaLineEdit.hpp"
#include "item_delegates/CandidateKeyFilter.hpp"
#include "item_delegates/ForeignKeyDelegate.hpp"
#include "item_delegates/FrequencyDelegate.hpp"
#include "item_delegates/FrequencyDeltaDelegate.hpp"
#include "TransceiverFactory.hpp"
#include "Transceiver.hpp"
#include "models/Bands.hpp"
@ -1122,6 +1125,7 @@ Configuration::impl::impl (Configuration * self, QNetworkAccessManager * network
ui_->frequencies_table_view->setColumnHidden (FrequencyList_v2::frequency_mhz_column, true);
// delegates
ui_->frequencies_table_view->setItemDelegateForColumn (FrequencyList_v2::frequency_column, new FrequencyDelegate {this});
ui_->frequencies_table_view->setItemDelegateForColumn (FrequencyList_v2::region_column, new ForeignKeyDelegate {&regions_, 0, this});
ui_->frequencies_table_view->setItemDelegateForColumn (FrequencyList_v2::mode_column, new ForeignKeyDelegate {&modes_, 0, this});
@ -1160,6 +1164,7 @@ Configuration::impl::impl (Configuration * self, QNetworkAccessManager * network
ui_->stations_table_view->sortByColumn (StationList::band_column, Qt::AscendingOrder);
// stations delegates
ui_->stations_table_view->setItemDelegateForColumn (StationList::offset_column, new FrequencyDeltaDelegate {this});
ui_->stations_table_view->setItemDelegateForColumn (StationList::band_column, new ForeignKeyDelegate {&bands_, &next_stations_, 0, StationList::band_column, this});
// stations actions

View File

@ -14,7 +14,6 @@
#include "WFPalette.hpp"
#include "models/IARURegions.hpp"
#include "models/DecodeHighlightingModel.hpp"
#include "widgets/FrequencyLineEdit.hpp"
#include "widgets/DateTimeEdit.hpp"
namespace
@ -51,9 +50,6 @@ void register_types ()
// used as signal/slot connection arguments since the new Qt 5.5
// Q_ENUM macro only seems to register the unqualified name
item_editor_factory->registerEditor (qMetaTypeId<Radio::Frequency> (), new QStandardItemEditorCreator<FrequencyLineEdit> ());
//auto frequency_delta_type_id = qRegisterMetaType<Radio::FrequencyDelta> ("FrequencyDelta");
item_editor_factory->registerEditor (qMetaTypeId<Radio::FrequencyDelta> (), new QStandardItemEditorCreator<FrequencyDeltaLineEdit> ());
item_editor_factory->registerEditor (qMetaTypeId<QDateTime> (), new QStandardItemEditorCreator<DateTimeEdit> ());
// Frequency list model

View File

@ -74,14 +74,14 @@ namespace Radio
}
QString frequency_MHz_string (Frequency f, QLocale const& locale)
QString frequency_MHz_string (Frequency f, int precision, QLocale const& locale)
{
return locale.toString (f / MHz_factor, 'f', frequency_precsion);
return locale.toString (f / MHz_factor, 'f', precision);
}
QString frequency_MHz_string (FrequencyDelta d, QLocale const& locale)
QString frequency_MHz_string (FrequencyDelta d, int precision, QLocale const& locale)
{
return locale.toString (d / MHz_factor, 'f', frequency_precsion);
return locale.toString (d / MHz_factor, 'f', precision);
}
QString pretty_frequency_MHz_string (Frequency f, QLocale const& locale)

View File

@ -42,8 +42,8 @@ namespace Radio
//
// Frequency type formatting
//
QString UDP_EXPORT frequency_MHz_string (Frequency, QLocale const& = QLocale ());
QString UDP_EXPORT frequency_MHz_string (FrequencyDelta, QLocale const& = QLocale ());
QString UDP_EXPORT frequency_MHz_string (Frequency, int precision = 6, QLocale const& = QLocale ());
QString UDP_EXPORT frequency_MHz_string (FrequencyDelta, int precision = 6, QLocale const& = QLocale ());
QString UDP_EXPORT pretty_frequency_MHz_string (Frequency, QLocale const& = QLocale ());
QString UDP_EXPORT pretty_frequency_MHz_string (double, int scale, QLocale const& = QLocale ());
QString UDP_EXPORT pretty_frequency_MHz_string (FrequencyDelta, QLocale const& = QLocale ());

View File

@ -0,0 +1,27 @@
#include "FrequencyDelegate.hpp"
#include "widgets/FrequencyLineEdit.hpp"
FrequencyDelegate::FrequencyDelegate (QObject * parent)
: QStyledItemDelegate {parent}
{
}
QWidget * FrequencyDelegate::createEditor (QWidget * parent, QStyleOptionViewItem const&
, QModelIndex const&) const
{
auto * editor = new FrequencyLineEdit {parent};
editor->setFrame (false);
return editor;
}
void FrequencyDelegate::setEditorData (QWidget * editor, QModelIndex const& index) const
{
static_cast<FrequencyLineEdit *> (editor)->frequency (index.model ()->data (index, Qt::EditRole).value<Radio::Frequency> ());
}
void FrequencyDelegate::setModelData (QWidget * editor, QAbstractItemModel * model, QModelIndex const& index) const
{
model->setData (index, static_cast<FrequencyLineEdit *> (editor)->frequency (), Qt::EditRole);
}

View File

@ -0,0 +1,21 @@
#ifndef FREQUENCY_DELEGATE_HPP_
#define FREQUENCY_DELEGATE_HPP_
#include <QStyledItemDelegate>
//
// Class FrequencyDelegate
//
// Item delegate for editing a frequency in Hertz but displayed in MHz
//
class FrequencyDelegate final
: public QStyledItemDelegate
{
public:
explicit FrequencyDelegate (QObject * parent = nullptr);
QWidget * createEditor (QWidget * parent, QStyleOptionViewItem const&, QModelIndex const&) const override;
void setEditorData (QWidget * editor, QModelIndex const&) const override;
void setModelData (QWidget * editor, QAbstractItemModel *, QModelIndex const&) const override;
};
#endif

View File

@ -0,0 +1,26 @@
#include "FrequencyDeltaDelegate.hpp"
#include "widgets/FrequencyDeltaLineEdit.hpp"
FrequencyDeltaDelegate::FrequencyDeltaDelegate (QObject * parent)
: QStyledItemDelegate {parent}
{
}
QWidget * FrequencyDeltaDelegate::createEditor (QWidget * parent, QStyleOptionViewItem const&
, QModelIndex const&) const
{
auto * editor = new FrequencyDeltaLineEdit {parent};
editor->setFrame (false);
return editor;
}
void FrequencyDeltaDelegate::setEditorData (QWidget * editor, QModelIndex const& index) const
{
static_cast<FrequencyDeltaLineEdit *> (editor)->frequency_delta (index.model ()->data (index, Qt::EditRole).value<Radio::FrequencyDelta> ());
}
void FrequencyDeltaDelegate::setModelData (QWidget * editor, QAbstractItemModel * model, QModelIndex const& index) const
{
model->setData (index, static_cast<FrequencyDeltaLineEdit *> (editor)->frequency_delta (), Qt::EditRole);
}

View File

@ -0,0 +1,21 @@
#ifndef FREQUENCY_DELTA_DELEGATE_HPP_
#define FREQUENCY_DELTA_DELEGATE_HPP_
#include <QStyledItemDelegate>
//
// Class FrequencyDeltaDelegate
//
// Item delegate for editing a frequency delta in Hertz but displayed in MHz
//
class FrequencyDeltaDelegate final
: public QStyledItemDelegate
{
public:
explicit FrequencyDeltaDelegate (QObject * parent = nullptr);
QWidget * createEditor (QWidget * parent, QStyleOptionViewItem const&, QModelIndex const&) const override;
void setEditorData (QWidget * editor, QModelIndex const&) const override;
void setModelData (QWidget * editor, QAbstractItemModel *, QModelIndex const&) const override;
};
#endif

View File

@ -1,11 +1,13 @@
SOURCES += \
item_delegates/ForeignKeyDelegate.cpp \
item_delegates/FrequencyItemDelegate.cpp \
item_delegates/FrequencyDelegate.cpp \
item_delegates/FrequencyDeltaDelegate.cpp \
item_delegates/CallsignDelegate.cpp \
item_delegates/MaidenheadLocatorItemDelegate.cpp
HEADERS += \
item_delegates/ForeignKeyDelegate.hpp \
item_delegates/FrequencyItemDelegate.hpp \
item_delegates/FrequencyDelegate.hpp \
item_delegates/FrequencyDeltaDelegate.hpp \
item_delegates/CallsignDelegate.hpp \
item_delegates/MaidenheadLocatorDelegate.hpp

45
logbook/Multiplier.cpp Normal file
View File

@ -0,0 +1,45 @@
#include "Multiplier.hpp"
#include <QSet>
#include <QString>
#include <QDebug>
#include "models/CabrilloLog.hpp"
#include "pimpl_impl.hpp"
class Multiplier::impl
{
public:
impl (AD1CCty const * countries)
: countries_ {countries}
{
}
AD1CCty const * countries_;
worked_set entities_worked_;
worked_set grids_worked_;
};
Multiplier::Multiplier (AD1CCty const * countries)
: m_ {countries}
{
}
Multiplier::~Multiplier ()
{
}
void Multiplier::reload (CabrilloLog const * log)
{
m_->entities_worked_ = log->unique_DXCC_entities (m_->countries_);
qDebug () << "Entities worked:" << m_->entities_worked_;
}
auto Multiplier::entities_worked () const -> worked_set const&
{
return m_->entities_worked_;
}
auto Multiplier::grids_worked () const -> worked_set const&
{
return m_->grids_worked_;
}

30
logbook/Multiplier.hpp Normal file
View File

@ -0,0 +1,30 @@
#ifndef MULTIPLIER_HPP_
#define MULTIPLIER_HPP_
#include <boost/core/noncopyable.hpp>
#include <QSet>
#include "pimpl_h.hpp"
class QString;
class AD1CCty;
class CabrilloLog;
class Multiplier final
: private boost::noncopyable
{
public:
using worked_item = QPair<QString, QString>;
using worked_set = QSet<worked_item>;
explicit Multiplier (AD1CCty const *);
~Multiplier ();
void reload (CabrilloLog const *);
worked_set const& entities_worked () const;
worked_set const& grids_worked () const;
private:
class impl;
pimpl<impl> m_;
};
#endif

View File

@ -415,9 +415,9 @@ QString const& WorkedBefore::path () const
return m_->path_;
}
AD1CCty const& WorkedBefore::countries () const
AD1CCty const * WorkedBefore::countries () const
{
return m_->prefixes_;
return &m_->prefixes_;
}
bool WorkedBefore::add (QString const& call

View File

@ -29,7 +29,7 @@ public:
, QByteArray const& ADIF_record);
QString const& path () const;
AD1CCty const& countries () const;
AD1CCty const * countries () const;
bool country_worked (QString const& call, QString const& mode, QString const& band) const;
bool grid_worked (QString const& grid, QString const& mode, QString const& band) const;
bool call_worked (QString const& call, QString const& mode, QString const& band) const;

View File

@ -3,6 +3,8 @@
#include <QDateTime>
#include "Configuration.hpp"
#include "AD1CCty.hpp"
#include "Multiplier.hpp"
#include "logbook/AD1CCty.hpp"
#include "models/CabrilloLog.hpp"
#include "models/FoxLog.hpp"
@ -16,6 +18,10 @@ LogBook::LogBook (Configuration const * configuration)
connect (&worked_before_, &WorkedBefore::finished_loading, this, &LogBook::finished_loading);
}
LogBook::~LogBook ()
{
}
void LogBook::match (QString const& call, QString const& mode, QString const& grid,
AD1CCty::Record const& looked_up,
bool& callB4,
@ -144,19 +150,36 @@ QByteArray LogBook::QSOToADIF (QString const& hisCall, QString const& hisGrid, Q
CabrilloLog * LogBook::contest_log ()
{
// lazy create of Cabrillo log object instance
if (!m_contest_log)
if (!contest_log_)
{
m_contest_log.reset (new CabrilloLog {config_});
contest_log_.reset (new CabrilloLog {config_});
if (!multiplier_)
{
multiplier_.reset (new Multiplier {countries ()});
}
connect (contest_log_.data (), &CabrilloLog::data_changed, [this] () {
multiplier_->reload (contest_log_.data ());
});
}
return m_contest_log.data ();
return contest_log_.data ();
}
Multiplier const * LogBook::multiplier () const
{
// lazy create of Multiplier object instance
if (!multiplier_)
{
multiplier_.reset (new Multiplier {countries ()});
}
return multiplier_.data ();
}
FoxLog * LogBook::fox_log ()
{
// lazy create of Fox log object instance
if (!m_fox_log)
if (!fox_log_)
{
m_fox_log.reset (new FoxLog {config_});
fox_log_.reset (new FoxLog {config_});
}
return m_fox_log.data ();
return fox_log_.data ();
}

View File

@ -16,6 +16,7 @@ class Configuration;
class QByteArray;
class QDateTime;
class CabrilloLog;
class Multiplier;
class FoxLog;
class LogBook final
@ -25,13 +26,14 @@ class LogBook final
public:
LogBook (Configuration const *);
~LogBook ();
QString const& path () const {return worked_before_.path ();}
bool add (QString const& call
, QString const& grid
, QString const& band
, QString const& mode
, QByteArray const& ADIF_record);
AD1CCty const& countries () const {return worked_before_.countries ();}
AD1CCty const * countries () const {return worked_before_.countries ();}
void rescan ();
void match (QString const& call, QString const& mode, QString const& grid,
AD1CCty::Record const&, bool& callB4, bool& countryB4,
@ -47,13 +49,15 @@ public:
Q_SIGNAL void finished_loading (int worked_before_record_count, QString const& error) const;
CabrilloLog * contest_log ();
Multiplier const * multiplier () const;
FoxLog * fox_log ();
private:
Configuration const * config_;
WorkedBefore worked_before_;
QScopedPointer<CabrilloLog> m_contest_log;
QScopedPointer<FoxLog> m_fox_log;
QScopedPointer<CabrilloLog> contest_log_;
QScopedPointer<Multiplier> mutable multiplier_;
QScopedPointer<FoxLog> fox_log_;
};
#endif

View File

@ -2,10 +2,12 @@ SOURCES += \
logbook/countriesworked.cpp \
logbook/logbook.cpp \
logbook/AD1CCty.cpp \
logbook/WorkedBefore.cpp
logbook/WorkedBefore.cpp \
logbook/Multiplier.cpp
HEADERS += \
logbook/WorkedBefore.hpp \
logbook/logbook.h \
logbook/countriesworked.h \
logbook/AD1CCty.hpp
logbook/AD1CCty.hpp \
logbook/Multiplier.hpp

View File

@ -380,10 +380,12 @@ int main(int argc, char *argv[])
}
catch (std::exception const& e)
{
MessageBox::critical_message (nullptr, QApplication::translate ("main", "Fatal error"), e.what ());
std::cerr << "Error: " << e.what () << '\n';
}
catch (...)
{
MessageBox::critical_message (nullptr, QApplication::translate ("main", "Unexpected fatal error"));
std::cerr << "Unexpected fatal error\n";
throw; // hoping the runtime might tell us more about the exception
}

View File

@ -20,59 +20,122 @@ class CabrilloLog::impl final
: public QSqlTableModel
{
public:
impl (Configuration const *);
impl (CabrilloLog *, Configuration const *);
QVariant data (QModelIndex const& index, int role) const
int columnCount (QModelIndex const& /*index */) const override
{
auto value = QSqlTableModel::data (index, role);
if (index.column () == fieldIndex ("when")
&& (Qt::DisplayRole == role || Qt::EditRole == role))
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)
{
auto t = QDateTime::fromMSecsSinceEpoch (value.toULongLong () * 1000ull, Qt::UTC);
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)
{
QLocale locale;
return locale.toString (t, locale.dateFormat (QLocale::ShortFormat) + " hh:mm:ss");
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;
}
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"))
{
create_table ();
}
setEditStrategy (QSqlTableModel::OnFieldChange);
setTable ("cabrillo_log");
if (-1 != fieldIndex ("band")) // schema out of date
{
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"
")");
"DROP TABLE IF EXISTS cabrillo_log_backup");
SQL_error_check (query, static_cast<bool (QSqlQuery::*) (QString const&)> (&QSqlQuery::exec),
"CREATE TABLE cabrillo_log_backup AS SELECT * FROM cabrillo_log");
SQL_error_check (query, static_cast<bool (QSqlQuery::*) (QString const&)> (&QSqlQuery::exec),
"DROP TABLE cabrillo_log");
create_table ();
setTable ("cabrillo_log");
}
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 "
" WHERE "
" call = :call "
" AND band = :band");
" call = :call ");
SQL_error_check (export_query_, &QSqlQuery::prepare,
"SELECT "
@ -85,29 +148,28 @@ CabrilloLog::impl::impl (Configuration const * configuration)
" cabrillo_log "
" 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 ("
" 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";
@ -125,12 +187,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);
}
@ -159,11 +224,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);
@ -175,15 +241,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;
}
@ -191,10 +258,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 ()
@ -209,6 +284,7 @@ void CabrilloLog::reset ()
transaction.submit ();
m_->select (); // to refresh views
m_->setEditStrategy (QSqlTableModel::OnFieldChange);
Q_EMIT data_changed ();
}
}
@ -217,6 +293,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");
@ -234,14 +311,16 @@ void CabrilloLog::export_qsos (QTextStream& stream) const
}
}
QSet<QString> CabrilloLog::unique_DXCC_entities (AD1CCty const& countries) const
auto CabrilloLog::unique_DXCC_entities (AD1CCty const * countries) const -> worked_set
{
QSqlQuery q {"SELECT UNIQUE CALL FROM cabrillo_log"};
QSqlQuery q {"SELECT DISTINCT BAND, CALL FROM cabrillo_log"};
auto band_index = q.record ().indexOf ("band");
auto call_index = q.record ().indexOf ("call");
QSet<QString> entities;
worked_set entities;
while (q.next ())
{
entities << countries.lookup (q.value(call_index).toString ()).primary_prefix;
entities << worked_item {q.value (band_index).toString ()
, countries->lookup (q.value (call_index).toString ()).primary_prefix};
}
return entities;
}

View File

@ -1,8 +1,9 @@
#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"
@ -14,23 +15,29 @@ 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;
QSet<QString> unique_DXCC_entities (AD1CCty const&) const;
worked_set unique_DXCC_entities (AD1CCty const *) const;
Q_SIGNAL void data_changed () const;
private:
class impl;

View File

@ -6,6 +6,7 @@
#include <QString>
#include <QSqlError>
#include <QSqlTableModel>
#include "boost/core/noncopyable.hpp"
template<typename T, typename Func, typename... Args>
void SQL_error_check (T&& object, Func func, Args&&... args)

View File

@ -1,10 +1,12 @@
#include "CabrilloLogWindow.hpp"
#include <stdexcept>
#include <QApplication>
#include <QIdentityProxyModel>
#include <QSqlTableModel>
#include "Configuration.hpp"
#include "models/Bands.hpp"
#include "item_delegates/FrequencyDelegate.hpp"
#include "item_delegates/ForeignKeyDelegate.hpp"
#include "item_delegates/CallsignDelegate.hpp"
#include "pimpl_impl.hpp"
@ -29,7 +31,7 @@ namespace
switch (index.column ())
{
case 1:
case 6:
case 7:
return Qt::AlignRight + Qt::AlignVCenter;
default:
break;
@ -63,10 +65,10 @@ CabrilloLogWindow::CabrilloLogWindow (QSettings * settings, Configuration const
m_->format_model_.setSourceModel (m_->log_model_);
m_->ui_.log_table_view->setModel (&m_->format_model_);
set_log_view (m_->ui_.log_table_view);
m_->ui_.log_table_view->setItemDelegateForColumn (3, new CallsignDelegate {this});
m_->ui_.log_table_view->setItemDelegateForColumn (6, new ForeignKeyDelegate {configuration->bands (), 0, this});
m_->ui_.log_table_view->setItemDelegateForColumn (1, new FrequencyDelegate {this});
m_->ui_.log_table_view->setItemDelegateForColumn (4, new CallsignDelegate {this});
auto h_header = m_->ui_.log_table_view->horizontalHeader ();
h_header->moveSection (6, 1); // band to first column
h_header->moveSection (7, 1); // band to first column
}
CabrilloLogWindow::~CabrilloLogWindow ()

View File

@ -0,0 +1,54 @@
#include "FrequencyDeltaLineEdit.hpp"
#include <limits>
#include <QDoubleValidator>
#include <QString>
#include <QLocale>
#include "moc_FrequencyDeltaLineEdit.cpp"
namespace
{
class MHzValidator
: public QDoubleValidator
{
public:
MHzValidator (double bottom, double top, QObject * parent = nullptr)
: QDoubleValidator {bottom, top, 6, parent}
{
}
State validate (QString& input, int& pos) const override
{
State result = QDoubleValidator::validate (input, pos);
if (Acceptable == result)
{
bool ok;
(void)QLocale {}.toDouble (input, &ok);
if (!ok)
{
result = Intermediate;
}
}
return result;
}
};
}
FrequencyDeltaLineEdit::FrequencyDeltaLineEdit (QWidget * parent)
: QLineEdit (parent)
{
setValidator (new MHzValidator {-std::numeric_limits<FrequencyDelta>::max () / 10.e6,
std::numeric_limits<FrequencyDelta>::max () / 10.e6, this});
}
auto FrequencyDeltaLineEdit::frequency_delta () const -> FrequencyDelta
{
return Radio::frequency_delta (text (), 6);
}
void FrequencyDeltaLineEdit::frequency_delta (FrequencyDelta d)
{
setText (Radio::frequency_MHz_string (d));
}

View File

@ -0,0 +1,29 @@
#ifndef FREQUENCY_DELTA_LINE_EDIT_HPP_
#define FREQUENCY_DELTA_LINE_EDIT_HPP_
#include <QLineEdit>
#include "Radio.hpp"
class QWidget;
//
// MHz frequency delta line edit with validation
//
class FrequencyDeltaLineEdit final
: public QLineEdit
{
Q_OBJECT;
Q_PROPERTY (FrequencyDelta frequency_delta READ frequency_delta WRITE frequency_delta USER true);
public:
using FrequencyDelta = Radio::FrequencyDelta;
explicit FrequencyDeltaLineEdit (QWidget * parent = nullptr);
// Property frequency_delta implementation
FrequencyDelta frequency_delta () const;
void frequency_delta (FrequencyDelta);
};
#endif

View File

@ -51,21 +51,3 @@ void FrequencyLineEdit::frequency (Frequency f)
{
setText (Radio::frequency_MHz_string (f));
}
FrequencyDeltaLineEdit::FrequencyDeltaLineEdit (QWidget * parent)
: QLineEdit (parent)
{
setValidator (new MHzValidator {-std::numeric_limits<FrequencyDelta>::max () / 10.e6,
std::numeric_limits<FrequencyDelta>::max () / 10.e6, this});
}
auto FrequencyDeltaLineEdit::frequency_delta () const -> FrequencyDelta
{
return Radio::frequency_delta (text (), 6);
}
void FrequencyDeltaLineEdit::frequency_delta (FrequencyDelta d)
{
setText (Radio::frequency_MHz_string (d));
}

View File

@ -8,7 +8,7 @@
class QWidget;
//
// MHz frequency line edits with validation
// MHz frequency line edit with validation
//
class FrequencyLineEdit final
: public QLineEdit
@ -26,20 +26,4 @@ public:
void frequency (Frequency);
};
class FrequencyDeltaLineEdit final
: public QLineEdit
{
Q_OBJECT;
Q_PROPERTY (FrequencyDelta frequency_delta READ frequency_delta WRITE frequency_delta USER true);
public:
using FrequencyDelta = Radio::FrequencyDelta;
explicit FrequencyDeltaLineEdit (QWidget * parent = nullptr);
// Property frequency_delta implementation
FrequencyDelta frequency_delta () const;
void frequency_delta (FrequencyDelta);
};
#endif

View File

@ -271,7 +271,7 @@ QString DisplayText::appendWorkedB4 (QString message, QString call, QString cons
if(call.length()<3) return message;
if(!call.contains(QRegExp("[0-9]|[A-Z]"))) return message;
auto const& looked_up = logBook.countries ().lookup (call);
auto const& looked_up = logBook.countries ()->lookup (call);
logBook.match (call, currentMode, grid, looked_up, callB4, countryB4, gridB4, continentB4, CQZoneB4, ITUZoneB4);
logBook.match (call, currentMode, grid, looked_up, callB4onBand, countryB4onBand, gridB4onBand,
continentB4onBand, CQZoneB4onBand, ITUZoneB4onBand, currentBand);

View File

@ -65,6 +65,4 @@ private:
int modified_vertical_scrollbar_max_;
};
extern QHash<QString,int> m_LoTW;
#endif // DISPLAYTEXT_H

View File

@ -157,7 +157,7 @@ void LogQSO::accept()
return; // without accepting
}
if (!m_log->contest_log ()->add_QSO (m_dialFreq, dateTimeOff, hisCall, xsent, xrcvd))
if (!m_log->contest_log ()->add_QSO (m_dialFreq, mode, dateTimeOff, hisCall, xsent, xrcvd))
{
show ();
MessageBox::warning_message (this, tr ("Invalid QSO Data"),

View File

@ -8267,7 +8267,7 @@ void MainWindow::houndCallers()
if(!ui->textBrowser4->toPlainText().contains(paddedHoundCall)) {
if(m_loggedByFox[houndCall].contains(m_lastBand)) continue; //already logged on this band
if(m_foxQSO.contains(houndCall)) continue; //still in the QSO map
auto const& entity = m_logBook.countries ().lookup (houndCall);
auto const& entity = m_logBook.countries ()->lookup (houndCall);
auto const& continent = AD1CCty::continent (entity.continent);
//If we are using a directed CQ, ignore Hound calls that do not comply.

View File

@ -8,13 +8,14 @@ SOURCES += \
widgets/fastplot.cpp widgets/MessageBox.cpp \
widgets/colorhighlighting.cpp widgets/ExportCabrillo.cpp \
widgets/AbstractLogWindow.cpp \
widgets/FrequencyLineEdit.cpp widgets/FrequencyDeltaLineEdit.cpp \
widgets/FoxLogWindow.cpp widgets/CabrilloLogWindow.cpp
HEADERS += \
widgets/mainwindow.h widgets/plotter.h \
widgets/about.h widgets/widegraph.h \
widgets/displaytext.h widgets/logqso.h widgets/LettersSpinBox.hpp \
widgets/FrequencyLineEdit.hpp widgets/signalmeter.h \
widgets/FrequencyLineEdit.hpp widgets/FrequencyDeltaLineEdit.hpp widgets/signalmeter.h \
widgets/meterwidget.h widgets/messageaveraging.h \
widgets/echoplot.h widgets/echograph.h widgets/fastgraph.h \
widgets/fastplot.h widgets/MessageBox.hpp widgets/colorhighlighting.h \