diff options
| author | Christoph Berg <myon@debian.org> | 2025-01-09 22:12:06 +0100 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2025-01-09 22:12:06 +0100 |
| commit | 992d4b4b8d3f3a630a2cf00d593ee4ce4dfa7ce8 (patch) | |
| tree | fbfdfe6bcb0a8a114be2480dac53d88c977e4869 /logbook | |
| parent | 4320ce238aae1fe87fc9f379cdd816e9317885fa (diff) | |
New upstream version 2.7.0~rc8+repackupstream/2.7.0_rc8+repack
Diffstat (limited to 'logbook')
| -rwxr-xr-x | logbook/AD1CCty.cpp | 926 | ||||
| -rwxr-xr-x | logbook/AD1CCty.hpp | 120 | ||||
| -rwxr-xr-x | logbook/Multiplier.cpp | 88 | ||||
| -rwxr-xr-x | logbook/Multiplier.hpp | 60 | ||||
| -rwxr-xr-x | logbook/WorkedBefore.cpp | 1426 | ||||
| -rwxr-xr-x | logbook/WorkedBefore.hpp | 96 | ||||
| -rwxr-xr-x | logbook/countriesworked.cpp | 48 | ||||
| -rwxr-xr-x | logbook/countriesworked.h | 48 | ||||
| -rwxr-xr-x | logbook/logbook.cpp | 430 | ||||
| -rwxr-xr-x | logbook/logbook.h | 130 | ||||
| -rwxr-xr-x | logbook/logbook.pri | 26 |
11 files changed, 1699 insertions, 1699 deletions
diff --git a/logbook/AD1CCty.cpp b/logbook/AD1CCty.cpp index 44dd1aaa..ef98b936 100755 --- a/logbook/AD1CCty.cpp +++ b/logbook/AD1CCty.cpp @@ -1,463 +1,463 @@ -#include "AD1CCty.hpp"
-
-#include <string>
-#include <stdexcept>
-#include <algorithm>
-#include <boost/multi_index_container.hpp>
-#include <boost/multi_index/hashed_index.hpp>
-#include <boost/multi_index/ordered_index.hpp>
-#include <boost/multi_index/key_extractors.hpp>
-#include <boost/lambda/lambda.hpp>
-#include <boost/lexical_cast.hpp>
-#include <QString>
-#include <QStandardPaths>
-#include <QDir>
-#include <QFile>
-#include <QTextStream>
-#include <QDebug>
-#include <QDebugStateSaver>
-#include <QRegularExpression>
-#include "Configuration.hpp"
-#include "Radio.hpp"
-#include "pimpl_impl.hpp"
-#include "Logger.hpp"
-
-#include "moc_AD1CCty.cpp"
-
-using namespace boost::multi_index;
-
-namespace
-{
- auto const file_name = "cty.dat";
-}
-
-struct entity
-{
- using Continent = AD1CCty::Continent;
-
- explicit entity (int id
- , QString const& name
- , bool WAE_only
- , int CQ_zone
- , int ITU_zone
- , Continent continent
- , float latitude
- , float longtitude
- , int UTC_offset
- , QString const& primary_prefix)
- : id_ {id}
- , name_ {name}
- , WAE_only_ {WAE_only}
- , CQ_zone_ {CQ_zone}
- , ITU_zone_ {ITU_zone}
- , continent_ {continent}
- , lat_ {latitude}
- , long_ {longtitude}
- , UTC_offset_ {UTC_offset}
- , primary_prefix_ {primary_prefix}
- {
- }
-
- int id_;
- QString name_;
- bool WAE_only_; // DARC WAE only, not valid for ARRL awards
- int CQ_zone_;
- int ITU_zone_;
- Continent continent_;
- float lat_; // degrees + is North
- float long_; // degrees + is West
- int UTC_offset_; // seconds
- QString primary_prefix_;
-};
-
-#if !defined (QT_NO_DEBUG_STREAM)
-QDebug operator << (QDebug dbg, entity const& e)
-{
- QDebugStateSaver saver {dbg};
- dbg.nospace () << "entity("
- << e.id_ << ", "
- << e.name_ << ", "
- << e.WAE_only_ << ", "
- << e.CQ_zone_ << ", "
- << e.ITU_zone_ << ", "
- << e.continent_ << ", "
- << e.lat_ << ", "
- << e.long_ << ", "
- << (e.UTC_offset_ / (60. * 60.)) << ", "
- << e.primary_prefix_ << ')';
- return dbg;
-}
-#endif
-
-// tags
-struct id {};
-struct primary_prefix {};
-
-// hash operation for QString object instances
-struct hash_QString
-{
- std::size_t operator () (QString const& qs) const
- {
- return qHash (qs);
- }
-};
-
-// set with hashed unique index that allow for efficient lookup of
-// entity by internal id
-typedef multi_index_container<
- entity,
- indexed_by<
- hashed_unique<tag<id>, member<entity, int, &entity::id_> >,
- hashed_unique<tag<primary_prefix>, member<entity, QString, &entity::primary_prefix_>, hash_QString> >
- > entities_type;
-
-struct prefix
-{
- explicit prefix (QString const& prefix, bool exact_match_only, int entity_id)
- : prefix_ {prefix}
- , exact_ {exact_match_only}
- , entity_id_ {entity_id}
- {
- }
-
- // extract key which is the prefix ignoring the trailing override
- // information
- QString prefix_key () const
- {
- auto const& prefix = prefix_.toStdString ();
- return QString::fromStdString (prefix.substr (0, prefix.find_first_of ("({[<~")));
- }
-
- QString prefix_; // call or prefix with optional
- // trailing override information
- bool exact_;
- int entity_id_;
-};
-
-#if !defined (QT_NO_DEBUG_STREAM)
-QDebug operator << (QDebug dbg, prefix const& p)
-{
- QDebugStateSaver saver {dbg};
- dbg.nospace () << "prefix("
- << p.prefix_ << ", "
- << p.exact_ << ", "
- << p.entity_id_ << ')';
- return dbg;
-}
-#endif
-
-// set with ordered unique index that allow for efficient
-// determination of entity and entity overrides for a call or call
-// prefix
-typedef multi_index_container<
- prefix,
- indexed_by<
- ordered_unique<const_mem_fun<prefix, QString, &prefix::prefix_key> > >
- > prefixes_type;
-
-class AD1CCty::impl final
-{
-public:
- using entity_by_id = entities_type::index<id>::type;
-
- explicit impl (Configuration const * configuration)
- : configuration_ {configuration}
- {
- }
-
- QString get_cty_path(const Configuration *configuration);
- void load_cty(QFile &file);
-
- entity_by_id::iterator lookup_entity (QString call, prefix const& p) const
- {
- call = call.toUpper ();
- entity_by_id::iterator e; // iterator into entity set
-
- //
- // deal with special rules that cty.dat does not cope with
- //
- if (call.startsWith ("KG4") && call.size () != 5 && call.size () != 3)
- {
- // KG4 2x1 and 2x3 calls that map to Gitmo are mainland US not Gitmo
- return entities_.project<id> (entities_.get<primary_prefix> ().find ("K"));
- }
- else
- {
- return entities_.get<id> ().find (p.entity_id_);
- }
- }
-
- Record fixup (prefix const& p, entity const& e) const
- {
- Record result;
- result.continent = e.continent_;
- result.CQ_zone = e.CQ_zone_;
- result.ITU_zone = e.ITU_zone_;
- result.entity_name = e.name_;
- result.WAE_only = e.WAE_only_;
- result.latitude = e.lat_;
- result.longtitude = e.long_;
- result.UTC_offset = e.UTC_offset_;
- result.primary_prefix = e.primary_prefix_;
-
- // check for overrides
- bool ok1 {true}, ok2 {true}, ok3 {true}, ok4 {true}, ok5 {true};
- QString value;
- if (override_value (p.prefix_, '(', ')', value)) result.CQ_zone = value.toInt (&ok1);
- if (override_value (p.prefix_, '[', ']', value)) result.ITU_zone = value.toInt (&ok2);
- if (override_value (p.prefix_, '<', '>', value))
- {
- auto const& fix = value.split ('/');
- result.latitude = fix[0].toFloat (&ok3);
- result.longtitude = fix[1].toFloat (&ok4);
- }
- if (override_value (p.prefix_, '{', '}', value)) result.continent = continent (value);
- if (override_value (p.prefix_, '~', '~', value)) result.UTC_offset = static_cast<int> (value.toFloat (&ok5) * 60 * 60);
- if (!(ok1 && ok2 && ok3 && ok4 && ok5))
- {
- throw std::domain_error {"Invalid number in cty.dat for override of " + p.prefix_.toStdString ()};
- }
- return result;
- }
-
- static bool override_value (QString const& s, QChar lb, QChar ub, QString& v)
- {
- auto pos = s.indexOf (lb);
- if (pos >= 0)
- {
- v = s.mid (pos + 1, s.indexOf (ub, pos + 1) - pos - 1);
- return true;
- }
- return false;
- }
-
- Configuration const * configuration_;
- QString path_;
- QString cty_version_;
- QString cty_version_date_;
-
- entities_type entities_;
- prefixes_type prefixes_;
-};
-
-AD1CCty::Record::Record ()
- : continent {Continent::UN}
- , CQ_zone {0}
- , ITU_zone {0}
- , WAE_only {false}
- , latitude {NAN}
- , longtitude {NAN}
- , UTC_offset {0}
-{
-}
-
-#if !defined (QT_NO_DEBUG_STREAM)
- QDebug operator << (QDebug dbg, AD1CCty::Record const& r)
- {
- QDebugStateSaver saver {dbg};
- dbg.nospace () << "AD1CCty::Record("
- << r.continent << ", "
- << r.CQ_zone << ", "
- << r.ITU_zone << ", "
- << r.entity_name << ", "
- << r.WAE_only << ", "
- << r.latitude << ", "
- << r.longtitude << ", "
- << (r.UTC_offset / (60. * 60.)) << ", "
- << r.primary_prefix << ')';
- return dbg;
- }
-#endif
-
-auto AD1CCty::continent (QString const& continent_id) -> Continent
-{
- Continent continent;
- if ("AF" == continent_id)
- {
- continent = Continent::AF;
- }
- else if ("AN" == continent_id)
- {
- continent = Continent::AN;
- }
- else if ("AS" == continent_id)
- {
- continent = Continent::AS;
- }
- else if ("EU" == continent_id)
- {
- continent = Continent::EU;
- }
- else if ("NA" == continent_id)
- {
- continent = Continent::NA;
- }
- else if ("OC" == continent_id)
- {
- continent = Continent::OC;
- }
- else if ("SA" == continent_id)
- {
- continent = Continent::SA;
- }
- else
- {
- throw std::domain_error {"Invalid continent id: " + continent_id.toStdString ()};
- }
- return continent;
-}
-
-char const * AD1CCty::continent (Continent c)
-{
- switch (c)
- {
- case Continent::AF: return "AF";
- case Continent::AN: return "AN";
- case Continent::AS: return "AS";
- case Continent::EU: return "EU";
- case Continent::NA: return "NA";
- case Continent::OC: return "OC";
- case Continent::SA: return "SA";
- default: return "UN";
- }
-}
-
-QString AD1CCty::impl::get_cty_path(Configuration const * configuration)
-{
- QDir dataPath {QStandardPaths::writableLocation (QStandardPaths::DataLocation)};
- auto path = dataPath.exists (file_name)
- ? dataPath.absoluteFilePath (file_name) // user override
- : configuration->data_dir ().absoluteFilePath (file_name); // or original
- return path;
-}
-
-void AD1CCty::impl::load_cty(QFile &file)
-{
- QRegularExpression version_pattern{R"(VER\d{8})"};
- int entity_id = 0;
- int line_number{0};
-
- entities_.clear();
- prefixes_.clear();
- cty_version_ = QString{};
- cty_version_date_ = QString{};
-
- QTextStream in{&file};
- while (!in.atEnd())
- {
- auto const &entity_line = in.readLine();
- ++line_number;
- if (!in.atEnd())
- {
- auto const &entity_parts = entity_line.split(':');
- if (entity_parts.size() >= 8)
- {
- auto primary_prefix = entity_parts[7].trimmed();
- bool WAE_only{false};
- if (primary_prefix.startsWith('*'))
- {
- primary_prefix = primary_prefix.mid(1);
- WAE_only = true;
- }
- bool ok1, ok2, ok3, ok4, ok5;
- entities_.emplace(++entity_id, entity_parts[0].trimmed(), WAE_only, entity_parts[1].trimmed().toInt(&ok1),
- entity_parts[2].trimmed().toInt(&ok2), continent(entity_parts[3].trimmed()),
- entity_parts[4].trimmed().toFloat(&ok3), entity_parts[5].trimmed().toFloat(&ok4),
- static_cast<int> (entity_parts[6].trimmed().toFloat(&ok5) * 60 * 60), primary_prefix);
- if (!(ok1 && ok2 && ok3 && ok4 && ok5))
- {
- throw std::domain_error{"Invalid number in cty.dat line " + boost::lexical_cast<std::string>(line_number)};
- }
- QString line;
- QString detail;
- do
- {
- in.readLineInto(&line);
- ++line_number;
- } while (detail += line, !detail.endsWith(';'));
- for (auto prefix: detail.left(detail.size() - 1).split(','))
- {
- prefix = prefix.trimmed();
- bool exact{false};
- if (prefix.startsWith('='))
- {
- prefix = prefix.mid(1);
- exact = true;
- // match version pattern to prefix
- if (version_pattern.match(prefix).hasMatch())
- {
- cty_version_date_ = prefix;
- }
- }
- prefixes_.emplace(prefix, exact, entity_id);
- }
- }
- }
- }
-}
-
-AD1CCty::AD1CCty (Configuration const * configuration)
- : m_ {configuration}
-{
- Q_ASSERT (configuration);
- // TODO: G4WJS - consider doing the following asynchronously to
- // speed up startup. Not urgent as it takes less than 0.5s on a Core
- // i7 reading BIG CTY.DAT.
- AD1CCty::reload (configuration);
- }
-
-void AD1CCty::reload(Configuration const * configuration)
-{
- m_->path_ = m_->impl::get_cty_path(configuration);
- QFile file {m_->path_};
-
- LOG_INFO(QString{"Loading CTY.DAT from %1"}.arg (m_->path_));
-
- if (file.open (QFile::ReadOnly))
- {
- m_->impl::load_cty(file);
- m_->cty_version_ = AD1CCty::lookup("VERSION").entity_name;
- Q_EMIT cty_loaded(m_->cty_version_);
- LOG_INFO(QString{"Loaded CTY.DAT version %1, %2"}.arg (m_->cty_version_date_).arg (m_->cty_version_));
- }
-}
-
-AD1CCty::~AD1CCty ()
-{
-}
-
-auto AD1CCty::lookup (QString const& call) const -> Record
-{
- auto const& exact_search = call.toUpper ();
- if (!(exact_search.endsWith ("/MM") || exact_search.endsWith ("/AM")))
- {
- auto search_prefix = Radio::effective_prefix (exact_search);
- if (search_prefix != exact_search)
- {
- auto p = m_->prefixes_.find (exact_search);
- if (p != m_->prefixes_.end () && p->exact_)
- {
- return m_->fixup (*p, *m_->lookup_entity (call, *p));
- }
- }
- while (search_prefix.size ())
- {
- auto p = m_->prefixes_.find (search_prefix);
- if (p != m_->prefixes_.end ())
- {
- impl::entity_by_id::iterator e = m_->lookup_entity (call, *p);
- // always lookup WAE entities, we substitute them later in displaytext.cpp if "Include extra WAE entites" is not selected
- if (!p->exact_ || call.size () == search_prefix.size ())
- {
- return m_->fixup (*p, *e);
- }
- }
- search_prefix = search_prefix.left (search_prefix.size () - 1);
- }
- }
- return Record {};
-}
-auto AD1CCty::version () const -> QString
-{
- return m_->cty_version_date_;
-}
+#include "AD1CCty.hpp" + +#include <string> +#include <stdexcept> +#include <algorithm> +#include <boost/multi_index_container.hpp> +#include <boost/multi_index/hashed_index.hpp> +#include <boost/multi_index/ordered_index.hpp> +#include <boost/multi_index/key_extractors.hpp> +#include <boost/lambda/lambda.hpp> +#include <boost/lexical_cast.hpp> +#include <QString> +#include <QStandardPaths> +#include <QDir> +#include <QFile> +#include <QTextStream> +#include <QDebug> +#include <QDebugStateSaver> +#include <QRegularExpression> +#include "Configuration.hpp" +#include "Radio.hpp" +#include "pimpl_impl.hpp" +#include "Logger.hpp" + +#include "moc_AD1CCty.cpp" + +using namespace boost::multi_index; + +namespace +{ + auto const file_name = "cty.dat"; +} + +struct entity +{ + using Continent = AD1CCty::Continent; + + explicit entity (int id + , QString const& name + , bool WAE_only + , int CQ_zone + , int ITU_zone + , Continent continent + , float latitude + , float longtitude + , int UTC_offset + , QString const& primary_prefix) + : id_ {id} + , name_ {name} + , WAE_only_ {WAE_only} + , CQ_zone_ {CQ_zone} + , ITU_zone_ {ITU_zone} + , continent_ {continent} + , lat_ {latitude} + , long_ {longtitude} + , UTC_offset_ {UTC_offset} + , primary_prefix_ {primary_prefix} + { + } + + int id_; + QString name_; + bool WAE_only_; // DARC WAE only, not valid for ARRL awards + int CQ_zone_; + int ITU_zone_; + Continent continent_; + float lat_; // degrees + is North + float long_; // degrees + is West + int UTC_offset_; // seconds + QString primary_prefix_; +}; + +#if !defined (QT_NO_DEBUG_STREAM) +QDebug operator << (QDebug dbg, entity const& e) +{ + QDebugStateSaver saver {dbg}; + dbg.nospace () << "entity(" + << e.id_ << ", " + << e.name_ << ", " + << e.WAE_only_ << ", " + << e.CQ_zone_ << ", " + << e.ITU_zone_ << ", " + << e.continent_ << ", " + << e.lat_ << ", " + << e.long_ << ", " + << (e.UTC_offset_ / (60. * 60.)) << ", " + << e.primary_prefix_ << ')'; + return dbg; +} +#endif + +// tags +struct id {}; +struct primary_prefix {}; + +// hash operation for QString object instances +struct hash_QString +{ + std::size_t operator () (QString const& qs) const + { + return qHash (qs); + } +}; + +// set with hashed unique index that allow for efficient lookup of +// entity by internal id +typedef multi_index_container< + entity, + indexed_by< + hashed_unique<tag<id>, member<entity, int, &entity::id_> >, + hashed_unique<tag<primary_prefix>, member<entity, QString, &entity::primary_prefix_>, hash_QString> > + > entities_type; + +struct prefix +{ + explicit prefix (QString const& prefix, bool exact_match_only, int entity_id) + : prefix_ {prefix} + , exact_ {exact_match_only} + , entity_id_ {entity_id} + { + } + + // extract key which is the prefix ignoring the trailing override + // information + QString prefix_key () const + { + auto const& prefix = prefix_.toStdString (); + return QString::fromStdString (prefix.substr (0, prefix.find_first_of ("({[<~"))); + } + + QString prefix_; // call or prefix with optional + // trailing override information + bool exact_; + int entity_id_; +}; + +#if !defined (QT_NO_DEBUG_STREAM) +QDebug operator << (QDebug dbg, prefix const& p) +{ + QDebugStateSaver saver {dbg}; + dbg.nospace () << "prefix(" + << p.prefix_ << ", " + << p.exact_ << ", " + << p.entity_id_ << ')'; + return dbg; +} +#endif + +// set with ordered unique index that allow for efficient +// determination of entity and entity overrides for a call or call +// prefix +typedef multi_index_container< + prefix, + indexed_by< + ordered_unique<const_mem_fun<prefix, QString, &prefix::prefix_key> > > + > prefixes_type; + +class AD1CCty::impl final +{ +public: + using entity_by_id = entities_type::index<id>::type; + + explicit impl (Configuration const * configuration) + : configuration_ {configuration} + { + } + + QString get_cty_path(const Configuration *configuration); + void load_cty(QFile &file); + + entity_by_id::iterator lookup_entity (QString call, prefix const& p) const + { + call = call.toUpper (); + entity_by_id::iterator e; // iterator into entity set + + // + // deal with special rules that cty.dat does not cope with + // + if (call.startsWith ("KG4") && call.size () != 5 && call.size () != 3) + { + // KG4 2x1 and 2x3 calls that map to Gitmo are mainland US not Gitmo + return entities_.project<id> (entities_.get<primary_prefix> ().find ("K")); + } + else + { + return entities_.get<id> ().find (p.entity_id_); + } + } + + Record fixup (prefix const& p, entity const& e) const + { + Record result; + result.continent = e.continent_; + result.CQ_zone = e.CQ_zone_; + result.ITU_zone = e.ITU_zone_; + result.entity_name = e.name_; + result.WAE_only = e.WAE_only_; + result.latitude = e.lat_; + result.longtitude = e.long_; + result.UTC_offset = e.UTC_offset_; + result.primary_prefix = e.primary_prefix_; + + // check for overrides + bool ok1 {true}, ok2 {true}, ok3 {true}, ok4 {true}, ok5 {true}; + QString value; + if (override_value (p.prefix_, '(', ')', value)) result.CQ_zone = value.toInt (&ok1); + if (override_value (p.prefix_, '[', ']', value)) result.ITU_zone = value.toInt (&ok2); + if (override_value (p.prefix_, '<', '>', value)) + { + auto const& fix = value.split ('/'); + result.latitude = fix[0].toFloat (&ok3); + result.longtitude = fix[1].toFloat (&ok4); + } + if (override_value (p.prefix_, '{', '}', value)) result.continent = continent (value); + if (override_value (p.prefix_, '~', '~', value)) result.UTC_offset = static_cast<int> (value.toFloat (&ok5) * 60 * 60); + if (!(ok1 && ok2 && ok3 && ok4 && ok5)) + { + throw std::domain_error {"Invalid number in cty.dat for override of " + p.prefix_.toStdString ()}; + } + return result; + } + + static bool override_value (QString const& s, QChar lb, QChar ub, QString& v) + { + auto pos = s.indexOf (lb); + if (pos >= 0) + { + v = s.mid (pos + 1, s.indexOf (ub, pos + 1) - pos - 1); + return true; + } + return false; + } + + Configuration const * configuration_; + QString path_; + QString cty_version_; + QString cty_version_date_; + + entities_type entities_; + prefixes_type prefixes_; +}; + +AD1CCty::Record::Record () + : continent {Continent::UN} + , CQ_zone {0} + , ITU_zone {0} + , WAE_only {false} + , latitude {NAN} + , longtitude {NAN} + , UTC_offset {0} +{ +} + +#if !defined (QT_NO_DEBUG_STREAM) + QDebug operator << (QDebug dbg, AD1CCty::Record const& r) + { + QDebugStateSaver saver {dbg}; + dbg.nospace () << "AD1CCty::Record(" + << r.continent << ", " + << r.CQ_zone << ", " + << r.ITU_zone << ", " + << r.entity_name << ", " + << r.WAE_only << ", " + << r.latitude << ", " + << r.longtitude << ", " + << (r.UTC_offset / (60. * 60.)) << ", " + << r.primary_prefix << ')'; + return dbg; + } +#endif + +auto AD1CCty::continent (QString const& continent_id) -> Continent +{ + Continent continent; + if ("AF" == continent_id) + { + continent = Continent::AF; + } + else if ("AN" == continent_id) + { + continent = Continent::AN; + } + else if ("AS" == continent_id) + { + continent = Continent::AS; + } + else if ("EU" == continent_id) + { + continent = Continent::EU; + } + else if ("NA" == continent_id) + { + continent = Continent::NA; + } + else if ("OC" == continent_id) + { + continent = Continent::OC; + } + else if ("SA" == continent_id) + { + continent = Continent::SA; + } + else + { + throw std::domain_error {"Invalid continent id: " + continent_id.toStdString ()}; + } + return continent; +} + +char const * AD1CCty::continent (Continent c) +{ + switch (c) + { + case Continent::AF: return "AF"; + case Continent::AN: return "AN"; + case Continent::AS: return "AS"; + case Continent::EU: return "EU"; + case Continent::NA: return "NA"; + case Continent::OC: return "OC"; + case Continent::SA: return "SA"; + default: return "UN"; + } +} + +QString AD1CCty::impl::get_cty_path(Configuration const * configuration) +{ + QDir dataPath {QStandardPaths::writableLocation (QStandardPaths::DataLocation)}; + auto path = dataPath.exists (file_name) + ? dataPath.absoluteFilePath (file_name) // user override + : configuration->data_dir ().absoluteFilePath (file_name); // or original + return path; +} + +void AD1CCty::impl::load_cty(QFile &file) +{ + QRegularExpression version_pattern{R"(VER\d{8})"}; + int entity_id = 0; + int line_number{0}; + + entities_.clear(); + prefixes_.clear(); + cty_version_ = QString{}; + cty_version_date_ = QString{}; + + QTextStream in{&file}; + while (!in.atEnd()) + { + auto const &entity_line = in.readLine(); + ++line_number; + if (!in.atEnd()) + { + auto const &entity_parts = entity_line.split(':'); + if (entity_parts.size() >= 8) + { + auto primary_prefix = entity_parts[7].trimmed(); + bool WAE_only{false}; + if (primary_prefix.startsWith('*')) + { + primary_prefix = primary_prefix.mid(1); + WAE_only = true; + } + bool ok1, ok2, ok3, ok4, ok5; + entities_.emplace(++entity_id, entity_parts[0].trimmed(), WAE_only, entity_parts[1].trimmed().toInt(&ok1), + entity_parts[2].trimmed().toInt(&ok2), continent(entity_parts[3].trimmed()), + entity_parts[4].trimmed().toFloat(&ok3), entity_parts[5].trimmed().toFloat(&ok4), + static_cast<int> (entity_parts[6].trimmed().toFloat(&ok5) * 60 * 60), primary_prefix); + if (!(ok1 && ok2 && ok3 && ok4 && ok5)) + { + throw std::domain_error{"Invalid number in cty.dat line " + boost::lexical_cast<std::string>(line_number)}; + } + QString line; + QString detail; + do + { + in.readLineInto(&line); + ++line_number; + } while (detail += line, !detail.endsWith(';')); + for (auto prefix: detail.left(detail.size() - 1).split(',')) + { + prefix = prefix.trimmed(); + bool exact{false}; + if (prefix.startsWith('=')) + { + prefix = prefix.mid(1); + exact = true; + // match version pattern to prefix + if (version_pattern.match(prefix).hasMatch()) + { + cty_version_date_ = prefix; + } + } + prefixes_.emplace(prefix, exact, entity_id); + } + } + } + } +} + +AD1CCty::AD1CCty (Configuration const * configuration) + : m_ {configuration} +{ + Q_ASSERT (configuration); + // TODO: G4WJS - consider doing the following asynchronously to + // speed up startup. Not urgent as it takes less than 0.5s on a Core + // i7 reading BIG CTY.DAT. + AD1CCty::reload (configuration); + } + +void AD1CCty::reload(Configuration const * configuration) +{ + m_->path_ = m_->impl::get_cty_path(configuration); + QFile file {m_->path_}; + + LOG_INFO(QString{"Loading CTY.DAT from %1"}.arg (m_->path_)); + + if (file.open (QFile::ReadOnly)) + { + m_->impl::load_cty(file); + m_->cty_version_ = AD1CCty::lookup("VERSION").entity_name; + Q_EMIT cty_loaded(m_->cty_version_); + LOG_INFO(QString{"Loaded CTY.DAT version %1, %2"}.arg (m_->cty_version_date_).arg (m_->cty_version_)); + } +} + +AD1CCty::~AD1CCty () +{ +} + +auto AD1CCty::lookup (QString const& call) const -> Record +{ + auto const& exact_search = call.toUpper (); + if (!(exact_search.endsWith ("/MM") || exact_search.endsWith ("/AM"))) + { + auto search_prefix = Radio::effective_prefix (exact_search); + if (search_prefix != exact_search) + { + auto p = m_->prefixes_.find (exact_search); + if (p != m_->prefixes_.end () && p->exact_) + { + return m_->fixup (*p, *m_->lookup_entity (call, *p)); + } + } + while (search_prefix.size ()) + { + auto p = m_->prefixes_.find (search_prefix); + if (p != m_->prefixes_.end ()) + { + impl::entity_by_id::iterator e = m_->lookup_entity (call, *p); + // always lookup WAE entities, we substitute them later in displaytext.cpp if "Include extra WAE entites" is not selected + if (!p->exact_ || call.size () == search_prefix.size ()) + { + return m_->fixup (*p, *e); + } + } + search_prefix = search_prefix.left (search_prefix.size () - 1); + } + } + return Record {}; +} +auto AD1CCty::version () const -> QString +{ + return m_->cty_version_date_; +} diff --git a/logbook/AD1CCty.hpp b/logbook/AD1CCty.hpp index 0908bb56..982ff7ce 100755 --- a/logbook/AD1CCty.hpp +++ b/logbook/AD1CCty.hpp @@ -1,60 +1,60 @@ -#ifndef AD1C_CTY_HPP_
-#define AD1C_CTY_HPP_
-
-#include <QObject>
-#include <QDebug>
-#include "pimpl_h.hpp"
-
-class QString;
-class Configuration;
-
-//
-// AD1CCty - Fast access database of Jim Reisert, AD1C's, cty.dat
-// entity and entity override information file.
-//
-class AD1CCty final
- : public QObject
-{
- Q_OBJECT
-
-public:
- //
- // Continent enumeration
- //
- enum class Continent {UN, AF, AN, AS, EU, NA, OC, SA};
- static Continent continent (QString const& continent_id);
- static char const * continent (Continent);
- Q_ENUM (Continent)
-
- struct Record
- {
- explicit Record ();
-
- Continent continent;
- int CQ_zone;
- int ITU_zone;
- QString entity_name;
- bool WAE_only;
- float latitude;
- float longtitude;
- int UTC_offset;
- QString primary_prefix;
- };
-
- explicit AD1CCty (Configuration const *);
- void reload(Configuration const * configuration);
- ~AD1CCty ();
- Record lookup (QString const& call) const;
- QString version () const;
- Q_SIGNAL void cty_loaded (QString const& version) const;
-
-private:
- class impl;
- pimpl<impl> m_;
-};
-
-#if !defined (QT_NO_DEBUG_STREAM)
-QDebug operator << (QDebug, AD1CCty::Record const&);
-#endif
-
-#endif
+#ifndef AD1C_CTY_HPP_ +#define AD1C_CTY_HPP_ + +#include <QObject> +#include <QDebug> +#include "pimpl_h.hpp" + +class QString; +class Configuration; + +// +// AD1CCty - Fast access database of Jim Reisert, AD1C's, cty.dat +// entity and entity override information file. +// +class AD1CCty final + : public QObject +{ + Q_OBJECT + +public: + // + // Continent enumeration + // + enum class Continent {UN, AF, AN, AS, EU, NA, OC, SA}; + static Continent continent (QString const& continent_id); + static char const * continent (Continent); + Q_ENUM (Continent) + + struct Record + { + explicit Record (); + + Continent continent; + int CQ_zone; + int ITU_zone; + QString entity_name; + bool WAE_only; + float latitude; + float longtitude; + int UTC_offset; + QString primary_prefix; + }; + + explicit AD1CCty (Configuration const *); + void reload(Configuration const * configuration); + ~AD1CCty (); + Record lookup (QString const& call) const; + QString version () const; + Q_SIGNAL void cty_loaded (QString const& version) const; + +private: + class impl; + pimpl<impl> m_; +}; + +#if !defined (QT_NO_DEBUG_STREAM) +QDebug operator << (QDebug, AD1CCty::Record const&); +#endif + +#endif diff --git a/logbook/Multiplier.cpp b/logbook/Multiplier.cpp index 542ba8e6..6323e4fe 100755 --- a/logbook/Multiplier.cpp +++ b/logbook/Multiplier.cpp @@ -1,44 +1,44 @@ -#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_);
-}
-
-auto Multiplier::entities_worked () const -> worked_set const&
-{
- return m_->entities_worked_;
-}
-
-auto Multiplier::grids_worked () const -> worked_set const&
-{
- return m_->grids_worked_;
-}
+#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_); +} + +auto Multiplier::entities_worked () const -> worked_set const& +{ + return m_->entities_worked_; +} + +auto Multiplier::grids_worked () const -> worked_set const& +{ + return m_->grids_worked_; +} diff --git a/logbook/Multiplier.hpp b/logbook/Multiplier.hpp index 75edd7bb..2271dd77 100755 --- a/logbook/Multiplier.hpp +++ b/logbook/Multiplier.hpp @@ -1,30 +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
+#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 diff --git a/logbook/WorkedBefore.cpp b/logbook/WorkedBefore.cpp index 0186bea5..b5dedc3d 100755 --- a/logbook/WorkedBefore.cpp +++ b/logbook/WorkedBefore.cpp @@ -1,713 +1,713 @@ -#include "WorkedBefore.hpp"
-
-#include <functional>
-#include <stdexcept>
-#include <boost/functional/hash.hpp>
-#include <boost/multi_index_container.hpp>
-#include <boost/multi_index/hashed_index.hpp>
-#include <boost/multi_index/ordered_index.hpp>
-#include <boost/multi_index/key_extractors.hpp>
-#include <boost/range/iterator_range.hpp>
-#include <QCoreApplication>
-#include <QtConcurrent/QtConcurrentRun>
-#include <QFuture>
-#include <QFutureWatcher>
-#include <QChar>
-#include <QString>
-#include <QByteArray>
-#include <QStandardPaths>
-#include <QDir>
-#include <QFileInfo>
-#include <QFile>
-#include <QTextStream>
-#include <QDateTime>
-#include "Configuration.hpp"
-#include "revision_utils.hpp"
-#include "Logger.hpp"
-#include "qt_helpers.hpp"
-#include "pimpl_impl.hpp"
-
-#include "moc_WorkedBefore.cpp"
-
-using namespace boost::multi_index;
-
-// hash function for QString members in hashed indexes
-inline
-std::size_t hash_value (QString const& s)
-{
- return std::hash<QString> {} (s);
-}
-
-//
-// worked before set element
-//
-struct worked_entry
-{
- explicit worked_entry (QString const& call, QString const& grid, QString const& band
- , QString const& mode, QString const& country, AD1CCty::Continent continent
- , int CQ_zone, int ITU_zone)
- : call_ {call}
- , grid_ {grid}
- , band_ {band}
- , mode_ {mode}
- , country_ {country}
- , continent_ {continent}
- , CQ_zone_ {CQ_zone}
- , ITU_zone_ {ITU_zone}
- {
- }
-
- QString call_;
- QString grid_;
- QString band_;
- QString mode_;
- QString country_;
- AD1CCty::Continent continent_;
- int CQ_zone_;
- int ITU_zone_;
-};
-
-bool operator == (worked_entry const& lhs, worked_entry const& rhs)
-{
- return
- lhs.continent_ == rhs.continent_ // check 1st as it is fast
- && lhs.CQ_zone_ == rhs.CQ_zone_ // ditto
- && lhs.ITU_zone_ == rhs.ITU_zone_ // ditto
- && lhs.call_ == rhs.call_ // check the rest in decreasing
- && lhs.grid_ == rhs.grid_ // domain size order to shortcut
- && lhs.country_ == rhs.country_ // differences as quickly as possible
- && lhs.band_ == rhs.band_
- && lhs.mode_ == rhs.mode_;
-}
-
-std::size_t hash_value (worked_entry const& we)
-{
- std::size_t seed {0};
- boost::hash_combine (seed, we.call_);
- boost::hash_combine (seed, we.grid_);
- boost::hash_combine (seed, we.band_);
- boost::hash_combine (seed, we.mode_);
- boost::hash_combine (seed, we.country_);
- boost::hash_combine (seed, we.continent_);
- boost::hash_combine (seed, we.CQ_zone_);
- boost::hash_combine (seed, we.ITU_zone_);
- return seed;
-}
-
-#if !defined (QT_NO_DEBUG_STREAM)
-QDebug operator << (QDebug dbg, worked_entry const& e)
-{
- QDebugStateSaver saver {dbg};
- dbg.nospace () << "worked_entry("
- << e.call_ << ", "
- << e.grid_ << ", "
- << e.band_ << ", "
- << e.mode_ << ", "
- << e.country_ << ", "
- << e.continent_ << ", "
- << e.CQ_zone_ << ", "
- << e.ITU_zone_ << ')';
- return dbg;
-}
-#endif
-
-// less then predidate for the Continent enum class, needed for
-// ordered indexes
-struct Continent_less
-{
- bool operator () (AD1CCty::Continent lhs, AD1CCty::Continent rhs) const
- {
- return static_cast<int> (lhs) < static_cast<int> (rhs);
- }
-};
-
-// index tags
-struct call_mode_band {};
-struct call_band {};
-struct grid_mode_band {};
-struct grid_band {};
-struct entity_mode_band {};
-struct entity_band {};
-struct continent_mode_band {};
-struct continent_band {};
-struct CQ_zone_mode_band {};
-struct CQ_zone_band {};
-struct ITU_zone_mode_band {};
-struct ITU_zone_band {};
-
-// set with multiple ordered unique indexes that allow for optimally
-// efficient determination of various categories of worked before
-// status
-typedef multi_index_container<
- worked_entry,
- indexed_by<
- // basic unordered set constraint - we don't need duplicate worked entries
- hashed_unique<identity<worked_entry>>,
-
- //
- // The following indexes are used to discover worked before stuff.
- //
- // They are ordered so as to support partial lookups and
- // non-unique because container inserts must be valid for all
- // indexes.
- //
-
- // call+mode+band
- ordered_non_unique<tag<call_mode_band>,
- composite_key<worked_entry,
- member<worked_entry, QString, &worked_entry::call_>,
- member<worked_entry, QString, &worked_entry::mode_>,
- member<worked_entry, QString, &worked_entry::band_> > >,
- // call+band
- ordered_non_unique<tag<call_band>,
- composite_key<worked_entry,
- member<worked_entry, QString, &worked_entry::call_>,
- member<worked_entry, QString, &worked_entry::band_> > >,
- // grid+mode+band
- ordered_non_unique<tag<grid_mode_band>,
- composite_key<worked_entry,
- member<worked_entry, QString, &worked_entry::grid_>,
- member<worked_entry, QString, &worked_entry::mode_>,
- member<worked_entry, QString, &worked_entry::band_> > >,
- // grid+band
- ordered_non_unique<tag<grid_band>,
- composite_key<worked_entry,
- member<worked_entry, QString, &worked_entry::grid_>,
- member<worked_entry, QString, &worked_entry::band_> > >,
- // country+mode+band
- ordered_non_unique<tag<entity_mode_band>,
- composite_key<worked_entry,
- member<worked_entry, QString, &worked_entry::country_>,
- member<worked_entry, QString, &worked_entry::mode_>,
- member<worked_entry, QString, &worked_entry::band_> > >,
- // country+band
- ordered_non_unique<tag<entity_band>,
- composite_key<worked_entry,
- member<worked_entry, QString, &worked_entry::country_>,
- member<worked_entry, QString, &worked_entry::band_> > >,
- // continent+mode+band
- ordered_non_unique<tag<continent_mode_band>,
- composite_key<worked_entry,
- member<worked_entry, AD1CCty::Continent, &worked_entry::continent_>,
- member<worked_entry, QString, &worked_entry::mode_>,
- member<worked_entry, QString, &worked_entry::band_> >,
- composite_key_compare<Continent_less, std::less<QString>, std::less<QString> > >,
- // continent+band
- ordered_non_unique<tag<continent_band>,
- composite_key<worked_entry,
- member<worked_entry, AD1CCty::Continent, &worked_entry::continent_>,
- member<worked_entry, QString, &worked_entry::band_> >,
- composite_key_compare<Continent_less, std::less<QString> > >,
- // CQ-zone+mode+band
- ordered_non_unique<tag<CQ_zone_mode_band>,
- composite_key<worked_entry,
- member<worked_entry, int, &worked_entry::CQ_zone_>,
- member<worked_entry, QString, &worked_entry::mode_>,
- member<worked_entry, QString, &worked_entry::band_> > >,
- // CQ-zone+band
- ordered_non_unique<tag<CQ_zone_band>,
- composite_key<worked_entry,
- member<worked_entry, int, &worked_entry::CQ_zone_>,
- member<worked_entry, QString, &worked_entry::band_> > >,
- // ITU-zone+mode+band
- ordered_non_unique<tag<ITU_zone_mode_band>,
- composite_key<worked_entry,
- member<worked_entry, int, &worked_entry::ITU_zone_>,
- member<worked_entry, QString, &worked_entry::mode_>,
- member<worked_entry, QString, &worked_entry::band_> > >,
- // ITU-zone+band
- ordered_non_unique<tag<ITU_zone_band>,
- composite_key<worked_entry,
- member<worked_entry, int, &worked_entry::ITU_zone_>,
- member<worked_entry, QString, &worked_entry::band_> > > >
- > worked_before_database_type;
-
-namespace
-{
- auto const logFileName = "wsjtx_log.adi";
-
- // Exception class suitable for using with QtConcurrent across
- // thread boundaries
- class LoaderException final
- : public QException
- {
- public:
- LoaderException (std::exception const& e) : error_ {e.what ()} {}
- QString error () const {return error_;}
- void raise () const override {throw *this;}
- LoaderException * clone () const override {return new LoaderException {*this};}
- private:
- QString error_;
- };
-
- QString extractField (QString const& record, QString const& fieldName)
- {
- int fieldNameIndex = record.indexOf ('<' + fieldName + ':', 0, Qt::CaseInsensitive);
- if (fieldNameIndex >=0)
- {
- int closingBracketIndex = record.indexOf('>',fieldNameIndex);
- int fieldLengthIndex = record.indexOf(':',fieldNameIndex); // find the size delimiter
- int dataTypeIndex = -1;
- if (fieldLengthIndex >= 0)
- {
- dataTypeIndex = record.indexOf(':',fieldLengthIndex+1); // check for a second : indicating there is a data type
- if (dataTypeIndex > closingBracketIndex)
- dataTypeIndex = -1; // second : was found but it was beyond the closing >
- }
- else
- {
- throw LoaderException (std::runtime_error {QCoreApplication::translate ("WorkedBefore", "Invalid ADIF field %0: %1").arg (fieldName).arg (record).toLocal8Bit ()});
- }
-
- if (closingBracketIndex > fieldNameIndex && fieldLengthIndex > fieldNameIndex && fieldLengthIndex < closingBracketIndex)
- {
- int fieldLengthCharCount = closingBracketIndex - fieldLengthIndex -1;
- if (dataTypeIndex >= 0)
- fieldLengthCharCount -= 2; // data type indicator is always a colon followed by a single character
- QString fieldLengthString = record.mid(fieldLengthIndex+1,fieldLengthCharCount);
- int fieldLength = fieldLengthString.toInt();
- if (fieldLength > 0)
- {
- return record.mid(closingBracketIndex+1,fieldLength);
- }
- }
- else
- {
- throw LoaderException (std::runtime_error {QCoreApplication::translate ("WorkedBefore", "Malformed ADIF field %0: %1").arg (fieldName).arg (record).toLocal8Bit ()});
- }
- }
- return QString {};
- }
-
- worked_before_database_type loader (QString const& path, AD1CCty const * prefixes)
- {
- worked_before_database_type worked;
- QFile inputFile {path};
- if (inputFile.exists ())
- {
- if (inputFile.open (QFile::ReadOnly))
- {
- QTextStream in {&inputFile};
- QString buffer;
- bool pre_read {false};
- int end_position {-1};
-
- // skip optional header record
- do
- {
- buffer += in.readLine () + '\n';
- if (buffer.startsWith (QChar {'<'})) // denotes no header
- {
- pre_read = true;
- }
- else
- {
- end_position = buffer.indexOf ("<EOH>", 0, Qt::CaseInsensitive);
- }
- }
- while (!in.atEnd () && !pre_read && end_position < 0);
- if (!pre_read) // found header
- {
- if (end_position < 0)
- {
- throw LoaderException (std::runtime_error {QCoreApplication::translate ("WorkedBefore", "Invalid ADIF header").toLocal8Bit ()});
- }
- buffer.remove (0, end_position + 5);
- }
- while (!in.atEnd ())
- {
- end_position = buffer.indexOf ("<EOR>", 0, Qt::CaseInsensitive);
- do
- {
- if (!in.atEnd () && end_position < 0)
- {
- buffer += in.readLine () + '\n';
- }
- }
- while ((end_position = buffer.indexOf ("<EOR>", 0, Qt::CaseInsensitive)) < 0 && !in.atEnd ());
- if (end_position >= 0) // require valid ADIF record
- // with terminator
- {
- auto record = buffer.left (end_position + 5).trimmed ();
- auto next_record = buffer.indexOf (QChar {'<'}, end_position + 5);
- buffer.remove (0, next_record >=0 ? next_record : buffer.size ());
- record = record.mid (record.indexOf (QChar {'<'}));
- auto call = extractField (record, "CALL");
- if (call.size ()) // require CALL field before we
- // will parse a record
- {
- auto const& entity = prefixes->lookup (call);
- auto mode = extractField (record, "MODE").toUpper ();
- if (!mode.size () || "MFSK" == mode)
- {
- mode = extractField (record, "SUBMODE").toUpper ();
- }
- worked.emplace (call.toUpper ()
- , extractField (record, "GRIDSQUARE").left (4).toUpper () // not interested in 6-digit grids
- , extractField (record, "BAND").toUpper ()
- , mode
- , entity.entity_name
- , entity.continent
- , entity.CQ_zone
- , entity.ITU_zone);
- }
- }
- }
- }
- else
- {
- throw LoaderException (std::runtime_error {QCoreApplication::translate ("WorkedBefore", "Error opening ADIF log file for read: %0").arg (inputFile.errorString ()).toLocal8Bit ()});
- }
- }
- return worked;
- }
-}
-
-class WorkedBefore::impl final
-{
-public:
- impl (Configuration const * configuration)
- : configuration_ {configuration}
- , path_ {QDir {QStandardPaths::writableLocation (QStandardPaths::DataLocation)}.absoluteFilePath (logFileName)}
- , prefixes_ {configuration}
- {
- }
-
- void reload ()
- {
- prefixes_.reload (configuration_);
- async_loader_ = QtConcurrent::run (loader, path_, &prefixes_);
- loader_watcher_.setFuture (async_loader_);
- }
-
- Configuration const * configuration_;
- QString path_;
- AD1CCty prefixes_;
- QFutureWatcher<worked_before_database_type> loader_watcher_;
- QFuture<worked_before_database_type> async_loader_;
- worked_before_database_type worked_;
-};
-
-WorkedBefore::WorkedBefore (Configuration const * configuration)
- : m_ {configuration}
-{
- Q_ASSERT (configuration);
- connect (&m_->loader_watcher_, &QFutureWatcher<worked_before_database_type>::finished, [this] () {
- QString error;
- size_t n {0};
- try
- {
- m_->worked_ = m_->loader_watcher_.result ();
- n = m_->worked_.size ();
- }
- catch (LoaderException const& e)
- {
- error = e.error ();
- }
- QString cty_ver = m_->prefixes_.version();
- LOG_DEBUG(QString{"WorkedBefore::reload: CTY.DAT version %1"}.arg (cty_ver));
- Q_EMIT finished_loading (n, cty_ver, error);
- });
- reload ();
-}
-
-QString WorkedBefore::cty_version () const
-{
- return m_->prefixes_.version ();
-}
-
-void WorkedBefore::reload ()
-{
- m_->reload ();
-}
-
-WorkedBefore::~WorkedBefore ()
-{
-}
-
-QString const& WorkedBefore::path () const
-{
- return m_->path_;
-}
-
-AD1CCty const * WorkedBefore::countries () const
-{
- return &m_->prefixes_;
-}
-
-bool WorkedBefore::add (QString const& call
- , QString const& grid
- , QString const& band
- , QString const& mode
- , QByteArray const& ADIF_record)
-{
- if (call.size ())
- {
- auto const& entity = m_->prefixes_.lookup (call);
- QFile file {m_->path_};
- if (!file.open(QIODevice::Text | QIODevice::Append))
- {
- return false;
- }
- else
- {
- QTextStream out {&file};
- if (!file.size ())
- {
- auto ts = QDateTime::currentDateTimeUtc ().toString ("yyyyMMdd HHmmss");
- auto ver = version (true);
- out << // new file
- QString {
- "ADIF Export\n"
- "<adif_ver:5>3.1.1\n"
- "<created_timestamp:15>%0\n"
- "<programid:6>WSJT-X\n"
- "<programversion:%1>%2\n"
- "<eoh>"
- }.arg (ts).arg (ver.size ()).arg (ver)
- <<
-#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
- endl
-#else
- Qt::endl
-#endif
- ;
- }
- out << ADIF_record << " <eor>" <<
-#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
- endl
-#else
- Qt::endl
-#endif
- ;
- }
- m_->worked_.emplace (call.toUpper (), grid.left (4).toUpper (), band.toUpper (), mode.toUpper ()
- , entity.entity_name, entity.continent, entity.CQ_zone, entity.ITU_zone);
- }
- return true;
-}
-
-bool WorkedBefore::country_worked (QString const& country, QString const& mode, QString const& band) const
-{
- if (mode.size ())
- {
- if (band.size ())
- {
- return
- country.size ()
- && m_->worked_.get<entity_mode_band> ().end ()
- != m_->worked_.get<entity_mode_band> ().find (std::make_tuple (country, mode.toUpper (), band.toUpper ()));
- }
- else
- {
- // partial key lookup
- return
- country.size ()
- && m_->worked_.get<entity_mode_band> ().end ()
- != m_->worked_.get<entity_mode_band> ().find (std::make_tuple (country, mode.toUpper ()));
- }
- }
- else
- {
- if (band.size ())
- {
- return
- country.size ()
- && m_->worked_.get<entity_band> ().end ()
- != m_->worked_.get<entity_band> ().find (std::make_tuple (country, band.toUpper ()));
- }
- else
- {
- // partial key lookup
- return
- country.size ()
- && m_->worked_.get<entity_band> ().end ()
- != m_->worked_.get<entity_band> ().find (country);
- }
- }
-}
-
-bool WorkedBefore::grid_worked (QString const& grid, QString const& mode, QString const& band) const
-{
- auto gridsquare = grid.left (4).toUpper ();
- if (m_->configuration_->highlight_only_fields ())
- {
- // can't use a direct set find operation or a set operation with
- // a (CompatibleKey, CompatibleCompare) concept so we must
- // partially scan the index
- auto range = boost::make_iterator_range (
- m_->worked_.get<grid_mode_band> ().lower_bound (gridsquare.left (2))
- , m_->worked_.get<grid_mode_band> ().upper_bound (gridsquare.left (2) + "99"));
- for (worked_entry const& worked : range)
- {
- if ((!mode.size () || mode.toUpper () == worked.mode_)
- && (!band.size () || worked.band_ == band.toUpper ()))
- {
- return true;
- }
- }
- }
- else
- {
- if (mode.size ())
- {
- if (band.size ())
- {
- return m_->worked_.get<grid_mode_band> ().end ()
- != m_->worked_.get<grid_mode_band> ().find (std::make_tuple (gridsquare, mode.toUpper (), band.toUpper ()));
- }
- else
- {
- // partial key lookup
- return m_->worked_.get<grid_mode_band> ().end ()
- != m_->worked_.get<grid_mode_band> ().find (std::make_tuple (gridsquare, mode.toUpper ()));
- }
- }
- else
- {
- if (band.size ())
- {
- return m_->worked_.get<grid_band> ().end ()
- != m_->worked_.get<grid_band> ().find (std::make_tuple (gridsquare, band.toUpper ()));
- }
- else
- {
- // partial key lookup
- return m_->worked_.get<grid_band> ().end ()
- != m_->worked_.get<grid_band> ().find (gridsquare);
- }
- }
- }
- return false;
-}
-
-bool WorkedBefore::call_worked (QString const& call, QString const& mode, QString const& band) const
-{
- if (mode.size ())
- {
- if (band.size ())
- {
- return m_->worked_.get<call_mode_band> ().end ()
- != m_->worked_.get<call_mode_band> ().find (std::make_tuple (call.toUpper (), mode.toUpper (), band.toUpper ()));
- }
- else
- {
- // partial key lookup
- return m_->worked_.get<call_mode_band> ().end ()
- != m_->worked_.get<call_mode_band> ().find (std::make_tuple (call.toUpper (), mode.toUpper ()));
- }
- }
- else
- {
- if (band.size ())
- {
- return m_->worked_.get<call_band> ().end ()
- != m_->worked_.get<call_band> ().find (std::make_tuple (call.toUpper (), band.toUpper ()));
- }
- else
- {
- // partial key lookup
- return m_->worked_.get<call_band> ().end ()
- != m_->worked_.get<call_band> ().find (std::make_tuple (call.toUpper ()));
- }
- }
-}
-
-bool WorkedBefore::continent_worked (Continent continent, QString const& mode, QString const& band) const
-{
- if (mode.size ())
- {
- if (band.size ())
- {
- return m_->worked_.get<continent_mode_band> ().end ()
- != m_->worked_.get<continent_mode_band> ().find (std::make_tuple (continent, mode.toUpper (), band.toUpper ()));
- }
- else
- {
- // partial key lookup
- return m_->worked_.get<continent_mode_band> ().end ()
- != m_->worked_.get<continent_mode_band> ().find (std::make_tuple (continent, mode.toUpper ()));
- }
- }
- else
- {
- if (band.size ())
- {
- return m_->worked_.get<continent_band> ().end ()
- != m_->worked_.get<continent_band> ().find (std::make_tuple (continent, band.toUpper ()));
- }
- else
- {
- // partial key lookup
- return m_->worked_.get<continent_band> ().end ()
- != m_->worked_.get<continent_band> ().find (continent);
- }
- }
-}
-
-bool WorkedBefore::CQ_zone_worked (int CQ_zone, QString const& mode, QString const& band) const
-{
- if (mode.size ())
- {
- if (band.size ())
- {
- return m_->worked_.get<CQ_zone_mode_band> ().end ()
- != m_->worked_.get<CQ_zone_mode_band> ().find (std::make_tuple (CQ_zone, mode.toUpper (), band.toUpper ()));
- }
- else
- {
- // partial key lookup
- return m_->worked_.get<CQ_zone_mode_band> ().end ()
- != m_->worked_.get<CQ_zone_mode_band> ().find (std::make_tuple (CQ_zone, mode.toUpper ()));
- }
- }
- else
- {
- if (band.size ())
- {
- return m_->worked_.get<CQ_zone_band> ().end ()
- != m_->worked_.get<CQ_zone_band> ().find (std::make_tuple (CQ_zone, band.toUpper ()));
- }
- else
- {
- // partial key lookup
- return m_->worked_.get<CQ_zone_band> ().end ()
- != m_->worked_.get<CQ_zone_band> ().find (CQ_zone);
- }
- }
-}
-
-
-bool WorkedBefore::ITU_zone_worked (int ITU_zone, QString const& mode, QString const& band) const
-{
- if (mode.size ())
- {
- if (band.size ())
- {
- return m_->worked_.get<ITU_zone_mode_band> ().end ()
- != m_->worked_.get<ITU_zone_mode_band> ().find (std::make_tuple (ITU_zone, mode.toUpper (), band.toUpper ()));
- }
- else
- {
- // partial key lookup
- return m_->worked_.get<ITU_zone_mode_band> ().end ()
- != m_->worked_.get<ITU_zone_mode_band> ().find (std::make_tuple (ITU_zone, mode.toUpper ()));
- }
- }
- else
- {
- if (band.size ())
- {
- return m_->worked_.get<ITU_zone_band> ().end ()
- != m_->worked_.get<ITU_zone_band> ().find (std::make_tuple (ITU_zone, band.toUpper ()));
- }
- else
- {
- // partial key lookup
- return m_->worked_.get<ITU_zone_band> ().end ()
- != m_->worked_.get<ITU_zone_band> ().find (ITU_zone);
- }
- }
-}
-
-
+#include "WorkedBefore.hpp" + +#include <functional> +#include <stdexcept> +#include <boost/functional/hash.hpp> +#include <boost/multi_index_container.hpp> +#include <boost/multi_index/hashed_index.hpp> +#include <boost/multi_index/ordered_index.hpp> +#include <boost/multi_index/key_extractors.hpp> +#include <boost/range/iterator_range.hpp> +#include <QCoreApplication> +#include <QtConcurrent/QtConcurrentRun> +#include <QFuture> +#include <QFutureWatcher> +#include <QChar> +#include <QString> +#include <QByteArray> +#include <QStandardPaths> +#include <QDir> +#include <QFileInfo> +#include <QFile> +#include <QTextStream> +#include <QDateTime> +#include "Configuration.hpp" +#include "revision_utils.hpp" +#include "Logger.hpp" +#include "qt_helpers.hpp" +#include "pimpl_impl.hpp" + +#include "moc_WorkedBefore.cpp" + +using namespace boost::multi_index; + +// hash function for QString members in hashed indexes +inline +std::size_t hash_value (QString const& s) +{ + return std::hash<QString> {} (s); +} + +// +// worked before set element +// +struct worked_entry +{ + explicit worked_entry (QString const& call, QString const& grid, QString const& band + , QString const& mode, QString const& country, AD1CCty::Continent continent + , int CQ_zone, int ITU_zone) + : call_ {call} + , grid_ {grid} + , band_ {band} + , mode_ {mode} + , country_ {country} + , continent_ {continent} + , CQ_zone_ {CQ_zone} + , ITU_zone_ {ITU_zone} + { + } + + QString call_; + QString grid_; + QString band_; + QString mode_; + QString country_; + AD1CCty::Continent continent_; + int CQ_zone_; + int ITU_zone_; +}; + +bool operator == (worked_entry const& lhs, worked_entry const& rhs) +{ + return + lhs.continent_ == rhs.continent_ // check 1st as it is fast + && lhs.CQ_zone_ == rhs.CQ_zone_ // ditto + && lhs.ITU_zone_ == rhs.ITU_zone_ // ditto + && lhs.call_ == rhs.call_ // check the rest in decreasing + && lhs.grid_ == rhs.grid_ // domain size order to shortcut + && lhs.country_ == rhs.country_ // differences as quickly as possible + && lhs.band_ == rhs.band_ + && lhs.mode_ == rhs.mode_; +} + +std::size_t hash_value (worked_entry const& we) +{ + std::size_t seed {0}; + boost::hash_combine (seed, we.call_); + boost::hash_combine (seed, we.grid_); + boost::hash_combine (seed, we.band_); + boost::hash_combine (seed, we.mode_); + boost::hash_combine (seed, we.country_); + boost::hash_combine (seed, we.continent_); + boost::hash_combine (seed, we.CQ_zone_); + boost::hash_combine (seed, we.ITU_zone_); + return seed; +} + +#if !defined (QT_NO_DEBUG_STREAM) +QDebug operator << (QDebug dbg, worked_entry const& e) +{ + QDebugStateSaver saver {dbg}; + dbg.nospace () << "worked_entry(" + << e.call_ << ", " + << e.grid_ << ", " + << e.band_ << ", " + << e.mode_ << ", " + << e.country_ << ", " + << e.continent_ << ", " + << e.CQ_zone_ << ", " + << e.ITU_zone_ << ')'; + return dbg; +} +#endif + +// less then predidate for the Continent enum class, needed for +// ordered indexes +struct Continent_less +{ + bool operator () (AD1CCty::Continent lhs, AD1CCty::Continent rhs) const + { + return static_cast<int> (lhs) < static_cast<int> (rhs); + } +}; + +// index tags +struct call_mode_band {}; +struct call_band {}; +struct grid_mode_band {}; +struct grid_band {}; +struct entity_mode_band {}; +struct entity_band {}; +struct continent_mode_band {}; +struct continent_band {}; +struct CQ_zone_mode_band {}; +struct CQ_zone_band {}; +struct ITU_zone_mode_band {}; +struct ITU_zone_band {}; + +// set with multiple ordered unique indexes that allow for optimally +// efficient determination of various categories of worked before +// status +typedef multi_index_container< + worked_entry, + indexed_by< + // basic unordered set constraint - we don't need duplicate worked entries + hashed_unique<identity<worked_entry>>, + + // + // The following indexes are used to discover worked before stuff. + // + // They are ordered so as to support partial lookups and + // non-unique because container inserts must be valid for all + // indexes. + // + + // call+mode+band + ordered_non_unique<tag<call_mode_band>, + composite_key<worked_entry, + member<worked_entry, QString, &worked_entry::call_>, + member<worked_entry, QString, &worked_entry::mode_>, + member<worked_entry, QString, &worked_entry::band_> > >, + // call+band + ordered_non_unique<tag<call_band>, + composite_key<worked_entry, + member<worked_entry, QString, &worked_entry::call_>, + member<worked_entry, QString, &worked_entry::band_> > >, + // grid+mode+band + ordered_non_unique<tag<grid_mode_band>, + composite_key<worked_entry, + member<worked_entry, QString, &worked_entry::grid_>, + member<worked_entry, QString, &worked_entry::mode_>, + member<worked_entry, QString, &worked_entry::band_> > >, + // grid+band + ordered_non_unique<tag<grid_band>, + composite_key<worked_entry, + member<worked_entry, QString, &worked_entry::grid_>, + member<worked_entry, QString, &worked_entry::band_> > >, + // country+mode+band + ordered_non_unique<tag<entity_mode_band>, + composite_key<worked_entry, + member<worked_entry, QString, &worked_entry::country_>, + member<worked_entry, QString, &worked_entry::mode_>, + member<worked_entry, QString, &worked_entry::band_> > >, + // country+band + ordered_non_unique<tag<entity_band>, + composite_key<worked_entry, + member<worked_entry, QString, &worked_entry::country_>, + member<worked_entry, QString, &worked_entry::band_> > >, + // continent+mode+band + ordered_non_unique<tag<continent_mode_band>, + composite_key<worked_entry, + member<worked_entry, AD1CCty::Continent, &worked_entry::continent_>, + member<worked_entry, QString, &worked_entry::mode_>, + member<worked_entry, QString, &worked_entry::band_> >, + composite_key_compare<Continent_less, std::less<QString>, std::less<QString> > >, + // continent+band + ordered_non_unique<tag<continent_band>, + composite_key<worked_entry, + member<worked_entry, AD1CCty::Continent, &worked_entry::continent_>, + member<worked_entry, QString, &worked_entry::band_> >, + composite_key_compare<Continent_less, std::less<QString> > >, + // CQ-zone+mode+band + ordered_non_unique<tag<CQ_zone_mode_band>, + composite_key<worked_entry, + member<worked_entry, int, &worked_entry::CQ_zone_>, + member<worked_entry, QString, &worked_entry::mode_>, + member<worked_entry, QString, &worked_entry::band_> > >, + // CQ-zone+band + ordered_non_unique<tag<CQ_zone_band>, + composite_key<worked_entry, + member<worked_entry, int, &worked_entry::CQ_zone_>, + member<worked_entry, QString, &worked_entry::band_> > >, + // ITU-zone+mode+band + ordered_non_unique<tag<ITU_zone_mode_band>, + composite_key<worked_entry, + member<worked_entry, int, &worked_entry::ITU_zone_>, + member<worked_entry, QString, &worked_entry::mode_>, + member<worked_entry, QString, &worked_entry::band_> > >, + // ITU-zone+band + ordered_non_unique<tag<ITU_zone_band>, + composite_key<worked_entry, + member<worked_entry, int, &worked_entry::ITU_zone_>, + member<worked_entry, QString, &worked_entry::band_> > > > + > worked_before_database_type; + +namespace +{ + auto const logFileName = "wsjtx_log.adi"; + + // Exception class suitable for using with QtConcurrent across + // thread boundaries + class LoaderException final + : public QException + { + public: + LoaderException (std::exception const& e) : error_ {e.what ()} {} + QString error () const {return error_;} + void raise () const override {throw *this;} + LoaderException * clone () const override {return new LoaderException {*this};} + private: + QString error_; + }; + + QString extractField (QString const& record, QString const& fieldName) + { + int fieldNameIndex = record.indexOf ('<' + fieldName + ':', 0, Qt::CaseInsensitive); + if (fieldNameIndex >=0) + { + int closingBracketIndex = record.indexOf('>',fieldNameIndex); + int fieldLengthIndex = record.indexOf(':',fieldNameIndex); // find the size delimiter + int dataTypeIndex = -1; + if (fieldLengthIndex >= 0) + { + dataTypeIndex = record.indexOf(':',fieldLengthIndex+1); // check for a second : indicating there is a data type + if (dataTypeIndex > closingBracketIndex) + dataTypeIndex = -1; // second : was found but it was beyond the closing > + } + else + { + throw LoaderException (std::runtime_error {QCoreApplication::translate ("WorkedBefore", "Invalid ADIF field %0: %1").arg (fieldName).arg (record).toLocal8Bit ()}); + } + + if (closingBracketIndex > fieldNameIndex && fieldLengthIndex > fieldNameIndex && fieldLengthIndex < closingBracketIndex) + { + int fieldLengthCharCount = closingBracketIndex - fieldLengthIndex -1; + if (dataTypeIndex >= 0) + fieldLengthCharCount -= 2; // data type indicator is always a colon followed by a single character + QString fieldLengthString = record.mid(fieldLengthIndex+1,fieldLengthCharCount); + int fieldLength = fieldLengthString.toInt(); + if (fieldLength > 0) + { + return record.mid(closingBracketIndex+1,fieldLength); + } + } + else + { + throw LoaderException (std::runtime_error {QCoreApplication::translate ("WorkedBefore", "Malformed ADIF field %0: %1").arg (fieldName).arg (record).toLocal8Bit ()}); + } + } + return QString {}; + } + + worked_before_database_type loader (QString const& path, AD1CCty const * prefixes) + { + worked_before_database_type worked; + QFile inputFile {path}; + if (inputFile.exists ()) + { + if (inputFile.open (QFile::ReadOnly)) + { + QTextStream in {&inputFile}; + QString buffer; + bool pre_read {false}; + int end_position {-1}; + + // skip optional header record + do + { + buffer += in.readLine () + '\n'; + if (buffer.startsWith (QChar {'<'})) // denotes no header + { + pre_read = true; + } + else + { + end_position = buffer.indexOf ("<EOH>", 0, Qt::CaseInsensitive); + } + } + while (!in.atEnd () && !pre_read && end_position < 0); + if (!pre_read) // found header + { + if (end_position < 0) + { + throw LoaderException (std::runtime_error {QCoreApplication::translate ("WorkedBefore", "Invalid ADIF header").toLocal8Bit ()}); + } + buffer.remove (0, end_position + 5); + } + while (!in.atEnd ()) + { + end_position = buffer.indexOf ("<EOR>", 0, Qt::CaseInsensitive); + do + { + if (!in.atEnd () && end_position < 0) + { + buffer += in.readLine () + '\n'; + } + } + while ((end_position = buffer.indexOf ("<EOR>", 0, Qt::CaseInsensitive)) < 0 && !in.atEnd ()); + if (end_position >= 0) // require valid ADIF record + // with terminator + { + auto record = buffer.left (end_position + 5).trimmed (); + auto next_record = buffer.indexOf (QChar {'<'}, end_position + 5); + buffer.remove (0, next_record >=0 ? next_record : buffer.size ()); + record = record.mid (record.indexOf (QChar {'<'})); + auto call = extractField (record, "CALL"); + if (call.size ()) // require CALL field before we + // will parse a record + { + auto const& entity = prefixes->lookup (call); + auto mode = extractField (record, "MODE").toUpper (); + if (!mode.size () || "MFSK" == mode) + { + mode = extractField (record, "SUBMODE").toUpper (); + } + worked.emplace (call.toUpper () + , extractField (record, "GRIDSQUARE").left (4).toUpper () // not interested in 6-digit grids + , extractField (record, "BAND").toUpper () + , mode + , entity.entity_name + , entity.continent + , entity.CQ_zone + , entity.ITU_zone); + } + } + } + } + else + { + throw LoaderException (std::runtime_error {QCoreApplication::translate ("WorkedBefore", "Error opening ADIF log file for read: %0").arg (inputFile.errorString ()).toLocal8Bit ()}); + } + } + return worked; + } +} + +class WorkedBefore::impl final +{ +public: + impl (Configuration const * configuration) + : configuration_ {configuration} + , path_ {QDir {QStandardPaths::writableLocation (QStandardPaths::DataLocation)}.absoluteFilePath (logFileName)} + , prefixes_ {configuration} + { + } + + void reload () + { + prefixes_.reload (configuration_); + async_loader_ = QtConcurrent::run (loader, path_, &prefixes_); + loader_watcher_.setFuture (async_loader_); + } + + Configuration const * configuration_; + QString path_; + AD1CCty prefixes_; + QFutureWatcher<worked_before_database_type> loader_watcher_; + QFuture<worked_before_database_type> async_loader_; + worked_before_database_type worked_; +}; + +WorkedBefore::WorkedBefore (Configuration const * configuration) + : m_ {configuration} +{ + Q_ASSERT (configuration); + connect (&m_->loader_watcher_, &QFutureWatcher<worked_before_database_type>::finished, [this] () { + QString error; + size_t n {0}; + try + { + m_->worked_ = m_->loader_watcher_.result (); + n = m_->worked_.size (); + } + catch (LoaderException const& e) + { + error = e.error (); + } + QString cty_ver = m_->prefixes_.version(); + LOG_DEBUG(QString{"WorkedBefore::reload: CTY.DAT version %1"}.arg (cty_ver)); + Q_EMIT finished_loading (n, cty_ver, error); + }); + reload (); +} + +QString WorkedBefore::cty_version () const +{ + return m_->prefixes_.version (); +} + +void WorkedBefore::reload () +{ + m_->reload (); +} + +WorkedBefore::~WorkedBefore () +{ +} + +QString const& WorkedBefore::path () const +{ + return m_->path_; +} + +AD1CCty const * WorkedBefore::countries () const +{ + return &m_->prefixes_; +} + +bool WorkedBefore::add (QString const& call + , QString const& grid + , QString const& band + , QString const& mode + , QByteArray const& ADIF_record) +{ + if (call.size ()) + { + auto const& entity = m_->prefixes_.lookup (call); + QFile file {m_->path_}; + if (!file.open(QIODevice::Text | QIODevice::Append)) + { + return false; + } + else + { + QTextStream out {&file}; + if (!file.size ()) + { + auto ts = QDateTime::currentDateTimeUtc ().toString ("yyyyMMdd HHmmss"); + auto ver = version (true); + out << // new file + QString { + "ADIF Export\n" + "<adif_ver:5>3.1.1\n" + "<created_timestamp:15>%0\n" + "<programid:6>WSJT-X\n" + "<programversion:%1>%2\n" + "<eoh>" + }.arg (ts).arg (ver.size ()).arg (ver) + << +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) + endl +#else + Qt::endl +#endif + ; + } + out << ADIF_record << " <eor>" << +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) + endl +#else + Qt::endl +#endif + ; + } + m_->worked_.emplace (call.toUpper (), grid.left (4).toUpper (), band.toUpper (), mode.toUpper () + , entity.entity_name, entity.continent, entity.CQ_zone, entity.ITU_zone); + } + return true; +} + +bool WorkedBefore::country_worked (QString const& country, QString const& mode, QString const& band) const +{ + if (mode.size ()) + { + if (band.size ()) + { + return + country.size () + && m_->worked_.get<entity_mode_band> ().end () + != m_->worked_.get<entity_mode_band> ().find (std::make_tuple (country, mode.toUpper (), band.toUpper ())); + } + else + { + // partial key lookup + return + country.size () + && m_->worked_.get<entity_mode_band> ().end () + != m_->worked_.get<entity_mode_band> ().find (std::make_tuple (country, mode.toUpper ())); + } + } + else + { + if (band.size ()) + { + return + country.size () + && m_->worked_.get<entity_band> ().end () + != m_->worked_.get<entity_band> ().find (std::make_tuple (country, band.toUpper ())); + } + else + { + // partial key lookup + return + country.size () + && m_->worked_.get<entity_band> ().end () + != m_->worked_.get<entity_band> ().find (country); + } + } +} + +bool WorkedBefore::grid_worked (QString const& grid, QString const& mode, QString const& band) const +{ + auto gridsquare = grid.left (4).toUpper (); + if (m_->configuration_->highlight_only_fields ()) + { + // can't use a direct set find operation or a set operation with + // a (CompatibleKey, CompatibleCompare) concept so we must + // partially scan the index + auto range = boost::make_iterator_range ( + m_->worked_.get<grid_mode_band> ().lower_bound (gridsquare.left (2)) + , m_->worked_.get<grid_mode_band> ().upper_bound (gridsquare.left (2) + "99")); + for (worked_entry const& worked : range) + { + if ((!mode.size () || mode.toUpper () == worked.mode_) + && (!band.size () || worked.band_ == band.toUpper ())) + { + return true; + } + } + } + else + { + if (mode.size ()) + { + if (band.size ()) + { + return m_->worked_.get<grid_mode_band> ().end () + != m_->worked_.get<grid_mode_band> ().find (std::make_tuple (gridsquare, mode.toUpper (), band.toUpper ())); + } + else + { + // partial key lookup + return m_->worked_.get<grid_mode_band> ().end () + != m_->worked_.get<grid_mode_band> ().find (std::make_tuple (gridsquare, mode.toUpper ())); + } + } + else + { + if (band.size ()) + { + return m_->worked_.get<grid_band> ().end () + != m_->worked_.get<grid_band> ().find (std::make_tuple (gridsquare, band.toUpper ())); + } + else + { + // partial key lookup + return m_->worked_.get<grid_band> ().end () + != m_->worked_.get<grid_band> ().find (gridsquare); + } + } + } + return false; +} + +bool WorkedBefore::call_worked (QString const& call, QString const& mode, QString const& band) const +{ + if (mode.size ()) + { + if (band.size ()) + { + return m_->worked_.get<call_mode_band> ().end () + != m_->worked_.get<call_mode_band> ().find (std::make_tuple (call.toUpper (), mode.toUpper (), band.toUpper ())); + } + else + { + // partial key lookup + return m_->worked_.get<call_mode_band> ().end () + != m_->worked_.get<call_mode_band> ().find (std::make_tuple (call.toUpper (), mode.toUpper ())); + } + } + else + { + if (band.size ()) + { + return m_->worked_.get<call_band> ().end () + != m_->worked_.get<call_band> ().find (std::make_tuple (call.toUpper (), band.toUpper ())); + } + else + { + // partial key lookup + return m_->worked_.get<call_band> ().end () + != m_->worked_.get<call_band> ().find (std::make_tuple (call.toUpper ())); + } + } +} + +bool WorkedBefore::continent_worked (Continent continent, QString const& mode, QString const& band) const +{ + if (mode.size ()) + { + if (band.size ()) + { + return m_->worked_.get<continent_mode_band> ().end () + != m_->worked_.get<continent_mode_band> ().find (std::make_tuple (continent, mode.toUpper (), band.toUpper ())); + } + else + { + // partial key lookup + return m_->worked_.get<continent_mode_band> ().end () + != m_->worked_.get<continent_mode_band> ().find (std::make_tuple (continent, mode.toUpper ())); + } + } + else + { + if (band.size ()) + { + return m_->worked_.get<continent_band> ().end () + != m_->worked_.get<continent_band> ().find (std::make_tuple (continent, band.toUpper ())); + } + else + { + // partial key lookup + return m_->worked_.get<continent_band> ().end () + != m_->worked_.get<continent_band> ().find (continent); + } + } +} + +bool WorkedBefore::CQ_zone_worked (int CQ_zone, QString const& mode, QString const& band) const +{ + if (mode.size ()) + { + if (band.size ()) + { + return m_->worked_.get<CQ_zone_mode_band> ().end () + != m_->worked_.get<CQ_zone_mode_band> ().find (std::make_tuple (CQ_zone, mode.toUpper (), band.toUpper ())); + } + else + { + // partial key lookup + return m_->worked_.get<CQ_zone_mode_band> ().end () + != m_->worked_.get<CQ_zone_mode_band> ().find (std::make_tuple (CQ_zone, mode.toUpper ())); + } + } + else + { + if (band.size ()) + { + return m_->worked_.get<CQ_zone_band> ().end () + != m_->worked_.get<CQ_zone_band> ().find (std::make_tuple (CQ_zone, band.toUpper ())); + } + else + { + // partial key lookup + return m_->worked_.get<CQ_zone_band> ().end () + != m_->worked_.get<CQ_zone_band> ().find (CQ_zone); + } + } +} + + +bool WorkedBefore::ITU_zone_worked (int ITU_zone, QString const& mode, QString const& band) const +{ + if (mode.size ()) + { + if (band.size ()) + { + return m_->worked_.get<ITU_zone_mode_band> ().end () + != m_->worked_.get<ITU_zone_mode_band> ().find (std::make_tuple (ITU_zone, mode.toUpper (), band.toUpper ())); + } + else + { + // partial key lookup + return m_->worked_.get<ITU_zone_mode_band> ().end () + != m_->worked_.get<ITU_zone_mode_band> ().find (std::make_tuple (ITU_zone, mode.toUpper ())); + } + } + else + { + if (band.size ()) + { + return m_->worked_.get<ITU_zone_band> ().end () + != m_->worked_.get<ITU_zone_band> ().find (std::make_tuple (ITU_zone, band.toUpper ())); + } + else + { + // partial key lookup + return m_->worked_.get<ITU_zone_band> ().end () + != m_->worked_.get<ITU_zone_band> ().find (ITU_zone); + } + } +} + + diff --git a/logbook/WorkedBefore.hpp b/logbook/WorkedBefore.hpp index c1302f06..0be9d783 100755 --- a/logbook/WorkedBefore.hpp +++ b/logbook/WorkedBefore.hpp @@ -1,48 +1,48 @@ -#ifndef WORKWED_BEFORE_HPP_
-#define WORKWED_BEFORE_HPP_
-
-#include <QObject>
-#include "AD1CCty.hpp"
-#include "pimpl_h.hpp"
-
-class Configuration;
-class CountryDat;
-class QString;
-class QByteArray;
-
-class WorkedBefore final
- : public QObject
-{
- Q_OBJECT
-
-public:
- using Continent = AD1CCty::Continent;
-
- explicit WorkedBefore (Configuration const *);
- ~WorkedBefore ();
-
- Q_SLOT void reload ();
- Q_SLOT bool add (QString const& call
- , QString const& grid
- , QString const& band
- , QString const& mode
- , QByteArray const& ADIF_record);
-
- QString const& path () 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;
- bool continent_worked (Continent continent, QString const& mode, QString const& band) const;
- bool CQ_zone_worked (int CQ_zone, QString const& mode, QString const& band) const;
- bool ITU_zone_worked (int ITU_zone, QString const& mode, QString const& band) const;
- QString cty_version () const;
-
- Q_SIGNAL void finished_loading (int worked_before_record_count, QString const, QString const& error) const;
-
-private:
- class impl;
- pimpl<impl> m_;
-};
-
-#endif
+#ifndef WORKWED_BEFORE_HPP_ +#define WORKWED_BEFORE_HPP_ + +#include <QObject> +#include "AD1CCty.hpp" +#include "pimpl_h.hpp" + +class Configuration; +class CountryDat; +class QString; +class QByteArray; + +class WorkedBefore final + : public QObject +{ + Q_OBJECT + +public: + using Continent = AD1CCty::Continent; + + explicit WorkedBefore (Configuration const *); + ~WorkedBefore (); + + Q_SLOT void reload (); + Q_SLOT bool add (QString const& call + , QString const& grid + , QString const& band + , QString const& mode + , QByteArray const& ADIF_record); + + QString const& path () 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; + bool continent_worked (Continent continent, QString const& mode, QString const& band) const; + bool CQ_zone_worked (int CQ_zone, QString const& mode, QString const& band) const; + bool ITU_zone_worked (int ITU_zone, QString const& mode, QString const& band) const; + QString cty_version () const; + + Q_SIGNAL void finished_loading (int worked_before_record_count, QString const, QString const& error) const; + +private: + class impl; + pimpl<impl> m_; +}; + +#endif diff --git a/logbook/countriesworked.cpp b/logbook/countriesworked.cpp index 0caed9df..bcd73af7 100755 --- a/logbook/countriesworked.cpp +++ b/logbook/countriesworked.cpp @@ -1,24 +1,24 @@ -#include "countriesworked.h"
-
-#include <set>
-
-#include "pimpl_impl.hpp"
-
-class CountriesWorkedimpl final
-{
-public:
- // element is country-name+band where the '+' is actual a character
- // which allows an efficient lower_bound() search for country-name+
- // to check for ATNOs
- std::set<QString> worked_;
-};
-
-void CountriesWorked::add (QString const& country, QString const& band)
-{
- m_->worked_.insert (country + '+' + band);
-}
-
-bool CountriesWorked::contains (QString const& country, QString const& band) const
-{
- return m_->worked_.end () != m_->worked_.lower_bound (country + '+' + band);
-}
+#include "countriesworked.h" + +#include <set> + +#include "pimpl_impl.hpp" + +class CountriesWorkedimpl final +{ +public: + // element is country-name+band where the '+' is actual a character + // which allows an efficient lower_bound() search for country-name+ + // to check for ATNOs + std::set<QString> worked_; +}; + +void CountriesWorked::add (QString const& country, QString const& band) +{ + m_->worked_.insert (country + '+' + band); +} + +bool CountriesWorked::contains (QString const& country, QString const& band) const +{ + return m_->worked_.end () != m_->worked_.lower_bound (country + '+' + band); +} diff --git a/logbook/countriesworked.h b/logbook/countriesworked.h index c485a164..ac8aaea6 100755 --- a/logbook/countriesworked.h +++ b/logbook/countriesworked.h @@ -1,24 +1,24 @@ -#ifndef COUNTRIES_WORKDED_H_
-#define COUNTRIES_WORKDED_H_
-
-#include <QString>
-
-#include "pimpl_h.hpp"
-
-class QStringList;
-
-class CountriesWorked final
-{
- public:
- explicit CountriesWorked (QStringList const& countryNames);
- ~CountriesWorked ();
-
- void add (QString const& country, QString const& band);
- bool contains (QString const& country, QString const& band = QString {}) const;
-
- private:
- class impl;
- pimpl<impl> m_;
-};
-
-#endif
+#ifndef COUNTRIES_WORKDED_H_ +#define COUNTRIES_WORKDED_H_ + +#include <QString> + +#include "pimpl_h.hpp" + +class QStringList; + +class CountriesWorked final +{ + public: + explicit CountriesWorked (QStringList const& countryNames); + ~CountriesWorked (); + + void add (QString const& country, QString const& band); + bool contains (QString const& country, QString const& band = QString {}) const; + + private: + class impl; + pimpl<impl> m_; +}; + +#endif diff --git a/logbook/logbook.cpp b/logbook/logbook.cpp index 3132a25a..2d434029 100755 --- a/logbook/logbook.cpp +++ b/logbook/logbook.cpp @@ -1,215 +1,215 @@ -#include "logbook.h"
-
-#include <QDateTime>
-#include "Configuration.hpp"
-#include "AD1CCty.hpp"
-#include "Multiplier.hpp"
-#include "logbook/AD1CCty.hpp"
-#include "models/CabrilloLog.hpp"
-#include "models/FoxLog.hpp"
-
-#include "moc_logbook.cpp"
-
-LogBook::LogBook (Configuration const * configuration)
- : config_ {configuration}
- , worked_before_ {configuration}
-{
- Q_ASSERT (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,
- bool& countryB4,
- bool& gridB4,
- bool& continentB4,
- bool& CQZoneB4,
- bool& ITUZoneB4,
- QString const& band) const
-{
- if (call.size() > 0)
- {
- auto const& mode_to_check = (config_ && !config_->highlight_by_mode ()) ? QString {} : mode;
- callB4 = worked_before_.call_worked (call, mode_to_check, band);
- gridB4 = worked_before_.grid_worked(grid, mode_to_check, band);
- auto const& countryName = looked_up.entity_name;
- if (countryName.size ())
- {
- countryB4 = worked_before_.country_worked (countryName, mode_to_check, band);
- continentB4 = worked_before_.continent_worked (looked_up.continent, mode_to_check, band);
- CQZoneB4 = worked_before_.CQ_zone_worked (looked_up.CQ_zone, mode_to_check, band);
- ITUZoneB4 = worked_before_.ITU_zone_worked (looked_up.ITU_zone, mode_to_check, band);
- }
- else
- {
- countryB4 = true; // we don't want to flag unknown entities
- continentB4 = true;
- CQZoneB4 = true;
- ITUZoneB4 = true;
- }
- }
-}
-
-bool LogBook::add (QString const& call
- , QString const& grid
- , QString const& band
- , QString const& mode
- , QByteArray const& ADIF_record)
-{
- return worked_before_.add (call, grid, band, mode, ADIF_record);
-}
-
-void LogBook::rescan ()
-{
- worked_before_.reload ();
-}
-
-QString const LogBook::cty_version() const
-{
- return worked_before_.cty_version();
-}
-
-QByteArray LogBook::QSOToADIF (QString const& hisCall, QString const& hisGrid, QString const& mode,
- QString const& rptSent, QString const& rptRcvd, QDateTime const& dateTimeOn,
- QDateTime const& dateTimeOff, QString const& band, QString const& comments,
- QString const& name, QString const& strDialFreq, QString const& myCall,
- QString const& myGrid, QString const& txPower, QString const& operator_call,
- QString const& xSent, QString const& xRcvd, QString const& propmode)
-{
- QString t;
- t = "<call:" + QString::number(hisCall.size()) + ">" + hisCall;
- t += " <gridsquare:" + QString::number(hisGrid.size()) + ">" + hisGrid;
- if (mode != "FT4" && mode != "FST4" && mode != "Q65")
- {
- t += " <mode:" + QString::number(mode.size()) + ">" + mode;
- }
- else
- {
- t += " <mode:4>MFSK <submode:" + QString::number(mode.size()) + ">" + mode;
- }
- t += " <rst_sent:" + QString::number(rptSent.size()) + ">" + rptSent;
- t += " <rst_rcvd:" + QString::number(rptRcvd.size()) + ">" + rptRcvd;
- t += " <qso_date:8>" + dateTimeOn.date().toString("yyyyMMdd");
- t += " <time_on:6>" + dateTimeOn.time().toString("hhmmss");
- t += " <qso_date_off:8>" + dateTimeOff.date().toString("yyyyMMdd");
- t += " <time_off:6>" + dateTimeOff.time().toString("hhmmss");
- t += " <band:" + QString::number(band.size()) + ">" + band;
- t += " <freq:" + QString::number(strDialFreq.size()) + ">" + strDialFreq;
- t += " <station_callsign:" + QString::number(myCall.size()) + ">" + myCall;
- if(myGrid!="") t += " <my_gridsquare:" + QString::number(myGrid.size()) + ">" + myGrid;
- if(txPower!="") t += " <tx_pwr:" + QString::number(txPower.size()) + ">" + txPower;
- if(comments!="") t += " <comment:" + QString::number(comments.size()) + ">" + comments;
- if(name!="") t += " <name:" + QString::number(name.size()) + ">" + name;
- if(operator_call!="") t+=" <operator:" + QString::number(operator_call.size()) + ">" + operator_call;
- if(propmode!="") t += " <prop_mode:" + QString::number(propmode.size()) + ">" + propmode;
- if (xSent.size ())
- {
- auto words = xSent.split (' '
-#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
- , QString::SkipEmptyParts
-#else
- , Qt::SkipEmptyParts
-#endif
- );
- if (words.size () > 1)
- {
- if (words.back ().toUInt ())
- {
- // assume last word is a serial if there are at least
- // two words and if it is positive numeric
- t += " <stx:" + QString::number (words.back ().size ()) + '>' + words.back ();
- }
- else
- {
- if (words.front ().toUInt () && words.front ().size () > 3) // EU VHF contest mode
- {
- auto sn_text = words.front ().mid (2);
- // assume first word is report+serial if there are
- // at least two words and if the first word less the
- // first two characters is a positive numeric
- t += " <stx:" + QString::number (sn_text.size ()) + '>' + sn_text;
- }
- }
- }
- }
- if (xRcvd.size ()) {
- auto words = xRcvd.split (' '
-#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
- , QString::SkipEmptyParts
-#else
- , Qt::SkipEmptyParts
-#endif
- );
- if (words.size () == 2)
- {
- if (words.at (1).toUInt ())
- {
- t += " <srx:" + QString::number (words.at (1).size ()) + ">" + words.at (1);
- }
- else if (words.at (0).toUInt () && words.at (0).size () > 3) // EU VHF contest exchange
- {
- // strip report and set SRX to serial
- t += " <srx:" + QString::number (words.at (0).mid (2).size ()) + ">" + words.at (0).mid (2);
- }
- else
- {
- if (Configuration::SpecialOperatingActivity::FIELD_DAY == config_->special_op_id ())
- {
- // include DX as an ARRL_SECT value even though it is
- // not in the ADIF spec ARRL_SECT enumeration, done
- // because N1MM does the same
- t += " <contest_id:14>ARRL-FIELD-DAY <SRX_STRING:" + QString::number (xRcvd.size ()) + '>' + xRcvd
- + " <class:" + QString::number (words.at (0).size ()) + '>'
- + words.at (0) + " <arrl_sect:" + QString::number (words.at (1).size ()) + '>' + words.at (1);
- }
- else if (Configuration::SpecialOperatingActivity::RTTY == config_->special_op_id ())
- {
- t += " <state:" + QString::number (words.at (1).size ()) + ">" + words.at (1);
- }
- }
- }
- }
- return t.toLatin1();
-}
-
-CabrilloLog * LogBook::contest_log ()
-{
- // lazy create of Cabrillo log object instance
- if (!contest_log_)
- {
- 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 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 (!fox_log_)
- {
- fox_log_.reset (new FoxLog {config_});
- }
- return fox_log_.data ();
-}
+#include "logbook.h" + +#include <QDateTime> +#include "Configuration.hpp" +#include "AD1CCty.hpp" +#include "Multiplier.hpp" +#include "logbook/AD1CCty.hpp" +#include "models/CabrilloLog.hpp" +#include "models/FoxLog.hpp" + +#include "moc_logbook.cpp" + +LogBook::LogBook (Configuration const * configuration) + : config_ {configuration} + , worked_before_ {configuration} +{ + Q_ASSERT (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, + bool& countryB4, + bool& gridB4, + bool& continentB4, + bool& CQZoneB4, + bool& ITUZoneB4, + QString const& band) const +{ + if (call.size() > 0) + { + auto const& mode_to_check = (config_ && !config_->highlight_by_mode ()) ? QString {} : mode; + callB4 = worked_before_.call_worked (call, mode_to_check, band); + gridB4 = worked_before_.grid_worked(grid, mode_to_check, band); + auto const& countryName = looked_up.entity_name; + if (countryName.size ()) + { + countryB4 = worked_before_.country_worked (countryName, mode_to_check, band); + continentB4 = worked_before_.continent_worked (looked_up.continent, mode_to_check, band); + CQZoneB4 = worked_before_.CQ_zone_worked (looked_up.CQ_zone, mode_to_check, band); + ITUZoneB4 = worked_before_.ITU_zone_worked (looked_up.ITU_zone, mode_to_check, band); + } + else + { + countryB4 = true; // we don't want to flag unknown entities + continentB4 = true; + CQZoneB4 = true; + ITUZoneB4 = true; + } + } +} + +bool LogBook::add (QString const& call + , QString const& grid + , QString const& band + , QString const& mode + , QByteArray const& ADIF_record) +{ + return worked_before_.add (call, grid, band, mode, ADIF_record); +} + +void LogBook::rescan () +{ + worked_before_.reload (); +} + +QString const LogBook::cty_version() const +{ + return worked_before_.cty_version(); +} + +QByteArray LogBook::QSOToADIF (QString const& hisCall, QString const& hisGrid, QString const& mode, + QString const& rptSent, QString const& rptRcvd, QDateTime const& dateTimeOn, + QDateTime const& dateTimeOff, QString const& band, QString const& comments, + QString const& name, QString const& strDialFreq, QString const& myCall, + QString const& myGrid, QString const& txPower, QString const& operator_call, + QString const& xSent, QString const& xRcvd, QString const& propmode) +{ + QString t; + t = "<call:" + QString::number(hisCall.size()) + ">" + hisCall; + t += " <gridsquare:" + QString::number(hisGrid.size()) + ">" + hisGrid; + if (mode != "FT4" && mode != "FST4" && mode != "Q65") + { + t += " <mode:" + QString::number(mode.size()) + ">" + mode; + } + else + { + t += " <mode:4>MFSK <submode:" + QString::number(mode.size()) + ">" + mode; + } + t += " <rst_sent:" + QString::number(rptSent.size()) + ">" + rptSent; + t += " <rst_rcvd:" + QString::number(rptRcvd.size()) + ">" + rptRcvd; + t += " <qso_date:8>" + dateTimeOn.date().toString("yyyyMMdd"); + t += " <time_on:6>" + dateTimeOn.time().toString("hhmmss"); + t += " <qso_date_off:8>" + dateTimeOff.date().toString("yyyyMMdd"); + t += " <time_off:6>" + dateTimeOff.time().toString("hhmmss"); + t += " <band:" + QString::number(band.size()) + ">" + band; + t += " <freq:" + QString::number(strDialFreq.size()) + ">" + strDialFreq; + t += " <station_callsign:" + QString::number(myCall.size()) + ">" + myCall; + if(myGrid!="") t += " <my_gridsquare:" + QString::number(myGrid.size()) + ">" + myGrid; + if(txPower!="") t += " <tx_pwr:" + QString::number(txPower.size()) + ">" + txPower; + if(comments!="") t += " <comment:" + QString::number(comments.size()) + ">" + comments; + if(name!="") t += " <name:" + QString::number(name.size()) + ">" + name; + if(operator_call!="") t+=" <operator:" + QString::number(operator_call.size()) + ">" + operator_call; + if(propmode!="") t += " <prop_mode:" + QString::number(propmode.size()) + ">" + propmode; + if (xSent.size ()) + { + auto words = xSent.split (' ' +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) + , QString::SkipEmptyParts +#else + , Qt::SkipEmptyParts +#endif + ); + if (words.size () > 1) + { + if (words.back ().toUInt ()) + { + // assume last word is a serial if there are at least + // two words and if it is positive numeric + t += " <stx:" + QString::number (words.back ().size ()) + '>' + words.back (); + } + else + { + if (words.front ().toUInt () && words.front ().size () > 3) // EU VHF contest mode + { + auto sn_text = words.front ().mid (2); + // assume first word is report+serial if there are + // at least two words and if the first word less the + // first two characters is a positive numeric + t += " <stx:" + QString::number (sn_text.size ()) + '>' + sn_text; + } + } + } + } + if (xRcvd.size ()) { + auto words = xRcvd.split (' ' +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) + , QString::SkipEmptyParts +#else + , Qt::SkipEmptyParts +#endif + ); + if (words.size () == 2) + { + if (words.at (1).toUInt ()) + { + t += " <srx:" + QString::number (words.at (1).size ()) + ">" + words.at (1); + } + else if (words.at (0).toUInt () && words.at (0).size () > 3) // EU VHF contest exchange + { + // strip report and set SRX to serial + t += " <srx:" + QString::number (words.at (0).mid (2).size ()) + ">" + words.at (0).mid (2); + } + else + { + if (Configuration::SpecialOperatingActivity::FIELD_DAY == config_->special_op_id ()) + { + // include DX as an ARRL_SECT value even though it is + // not in the ADIF spec ARRL_SECT enumeration, done + // because N1MM does the same + t += " <contest_id:14>ARRL-FIELD-DAY <SRX_STRING:" + QString::number (xRcvd.size ()) + '>' + xRcvd + + " <class:" + QString::number (words.at (0).size ()) + '>' + + words.at (0) + " <arrl_sect:" + QString::number (words.at (1).size ()) + '>' + words.at (1); + } + else if (Configuration::SpecialOperatingActivity::RTTY == config_->special_op_id ()) + { + t += " <state:" + QString::number (words.at (1).size ()) + ">" + words.at (1); + } + } + } + } + return t.toLatin1(); +} + +CabrilloLog * LogBook::contest_log () +{ + // lazy create of Cabrillo log object instance + if (!contest_log_) + { + 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 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 (!fox_log_) + { + fox_log_.reset (new FoxLog {config_}); + } + return fox_log_.data (); +} diff --git a/logbook/logbook.h b/logbook/logbook.h index 74931d46..96a17dd6 100755 --- a/logbook/logbook.h +++ b/logbook/logbook.h @@ -1,65 +1,65 @@ -// -*- Mode: C++ -*-
-/*
- * From an ADIF file and cty.dat, get a call's DXCC entity and its worked before status
- */
-
-#ifndef LOG_BOOK_H_
-#define LOG_BOOK_H_
-
-#include <QObject>
-#include <QString>
-#include <QScopedPointer>
-
-#include "WorkedBefore.hpp"
-
-class Configuration;
-class QByteArray;
-class QDateTime;
-class CabrilloLog;
-class Multiplier;
-class FoxLog;
-
-class LogBook final
- : public QObject
-{
- Q_OBJECT
-
-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 ();}
- void rescan ();
- void match (QString const& call, QString const& mode, QString const& grid,
- AD1CCty::Record const&, bool& callB4, bool& countryB4,
- bool &gridB4, bool &continentB4, bool& CQZoneB4, bool& ITUZoneB4,
- QString const& currentBand = QString {}) const;
- QByteArray QSOToADIF (QString const& hisCall, QString const& hisGrid, QString const& mode,
- QString const& rptSent, QString const& rptRcvd, QDateTime const& dateTimeOn,
- QDateTime const& dateTimeOff, QString const& band, QString const& comments,
- QString const& name, QString const& strDialFreq, QString const& myCall,
- QString const& m_myGrid, QString const& m_txPower, QString const& operator_call,
- QString const& xSent, QString const& xRcvd, QString const& propmode);
-
- QString const cty_version() const;
-
- Q_SIGNAL void finished_loading (int worked_before_record_count, QString const cty_version, QString const& error) const;
-
- CabrilloLog * contest_log ();
- Multiplier const * multiplier () const;
- FoxLog * fox_log ();
-
-private:
- Configuration const * config_;
- WorkedBefore worked_before_;
- QScopedPointer<CabrilloLog> contest_log_;
- QScopedPointer<Multiplier> mutable multiplier_;
- QScopedPointer<FoxLog> fox_log_;
-};
-
-#endif
+// -*- Mode: C++ -*- +/* + * From an ADIF file and cty.dat, get a call's DXCC entity and its worked before status + */ + +#ifndef LOG_BOOK_H_ +#define LOG_BOOK_H_ + +#include <QObject> +#include <QString> +#include <QScopedPointer> + +#include "WorkedBefore.hpp" + +class Configuration; +class QByteArray; +class QDateTime; +class CabrilloLog; +class Multiplier; +class FoxLog; + +class LogBook final + : public QObject +{ + Q_OBJECT + +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 ();} + void rescan (); + void match (QString const& call, QString const& mode, QString const& grid, + AD1CCty::Record const&, bool& callB4, bool& countryB4, + bool &gridB4, bool &continentB4, bool& CQZoneB4, bool& ITUZoneB4, + QString const& currentBand = QString {}) const; + QByteArray QSOToADIF (QString const& hisCall, QString const& hisGrid, QString const& mode, + QString const& rptSent, QString const& rptRcvd, QDateTime const& dateTimeOn, + QDateTime const& dateTimeOff, QString const& band, QString const& comments, + QString const& name, QString const& strDialFreq, QString const& myCall, + QString const& m_myGrid, QString const& m_txPower, QString const& operator_call, + QString const& xSent, QString const& xRcvd, QString const& propmode); + + QString const cty_version() const; + + Q_SIGNAL void finished_loading (int worked_before_record_count, QString const cty_version, QString const& error) const; + + CabrilloLog * contest_log (); + Multiplier const * multiplier () const; + FoxLog * fox_log (); + +private: + Configuration const * config_; + WorkedBefore worked_before_; + QScopedPointer<CabrilloLog> contest_log_; + QScopedPointer<Multiplier> mutable multiplier_; + QScopedPointer<FoxLog> fox_log_; +}; + +#endif diff --git a/logbook/logbook.pri b/logbook/logbook.pri index ed0bdfc6..e67cdebd 100755 --- a/logbook/logbook.pri +++ b/logbook/logbook.pri @@ -1,13 +1,13 @@ -SOURCES += \
- logbook/countriesworked.cpp \
- logbook/logbook.cpp \
- logbook/AD1CCty.cpp \
- logbook/WorkedBefore.cpp \
- logbook/Multiplier.cpp
-
-HEADERS += \
- logbook/WorkedBefore.hpp \
- logbook/logbook.h \
- logbook/countriesworked.h \
- logbook/AD1CCty.hpp \
- logbook/Multiplier.hpp
+SOURCES += \ + logbook/countriesworked.cpp \ + logbook/logbook.cpp \ + logbook/AD1CCty.cpp \ + logbook/WorkedBefore.cpp \ + logbook/Multiplier.cpp + +HEADERS += \ + logbook/WorkedBefore.hpp \ + logbook/logbook.h \ + logbook/countriesworked.h \ + logbook/AD1CCty.hpp \ + logbook/Multiplier.hpp |
