Skip to content

Commit

Permalink
ADI: Reworked the Output Field Format method - method virtualization
Browse files Browse the repository at this point in the history
  • Loading branch information
foldynl committed Jan 15, 2025
1 parent 67aa3ed commit bb6c5a5
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 55 deletions.
124 changes: 79 additions & 45 deletions logformat/AdiFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void AdiFormat::writeSQLRecord(const QSqlRecord &record,
if ( ExportParams.isValid )
writeField(ExportParams.ADIFName,
tmpField.isValid(),
ExportParams.formatFct(tmpField.value()),
formatOuput(ExportParams.formatter, tmpField.value()),
ExportParams.outputType );
}

Expand All @@ -82,9 +82,9 @@ void AdiFormat::writeSQLRecord(const QSqlRecord &record,
{
const QDateTime &time_start = startVariant.toDateTime().toTimeZone(QTimeZone::utc());
writeField("qso_date", startVariant.isValid(),
time_start.toString("yyyyMMdd"));
formatOuput(OutputFieldFormatter::TODATE, time_start));
writeField("time_on", startVariant.isValid(),
time_start.toString("hhmmss"));
formatOuput(OutputFieldFormatter::TOTIME, time_start));
}

const QVariant &endVariant = record.value("end_time");
Expand All @@ -93,9 +93,9 @@ void AdiFormat::writeSQLRecord(const QSqlRecord &record,
{
const QDateTime &time_end = record.value("end_time").toDateTime().toTimeZone(QTimeZone::utc());
writeField("qso_date_off", endVariant.isValid(),
time_end.toString("yyyyMMdd"));
formatOuput(OutputFieldFormatter::TODATE, time_end));
writeField("time_off", endVariant.isValid(),
time_end.toString("hhmmss"));
formatOuput(OutputFieldFormatter::TOTIME, time_end));
}

const QJsonObject &fields = QJsonDocument::fromJson(record.value("fields").toByteArray()).object();
Expand Down Expand Up @@ -495,6 +495,35 @@ void AdiFormat::contactFields2SQLRecord(QMap<QString, QVariant> &contact, QSqlRe
record.setValue("end_time", end_time);
}

const QString AdiFormat::formatOuput(OutputFieldFormatter formatter, const QVariant &in)
{
QString ret;

switch (formatter)
{
case TOLOWER:
ret = toLower(in);
break;
case TOUPPER:
ret = toUpper(in);
break;
case TODATE:
ret = toDate(in);
break;
case TOTIME:
ret = toTime(in);
break;
case REMOVEDEFAULTVALUEN:
ret = removeDefaulValueN(in);
break;
case TOSTRING:
default:
ret = toString(in);
}

return ret;
}

const QString AdiFormat::toString(const QVariant &var)
{
return var.toString();
Expand All @@ -510,11 +539,16 @@ const QString AdiFormat::toUpper(const QVariant &var)
return var.toString().toUpper();
}

const QString AdiFormat::toYYYYMMDD(const QVariant &var)
const QString AdiFormat::toDate(const QVariant &var)
{
return var.toDate().toString("yyyyMMdd");
}

const QString AdiFormat::toTime(const QVariant &var)
{
return var.toTime().toString("hhmmss");
}

// There are fields with a default value of 'N'.
// Therefore, it is not necessary to explicitly export them when
// the local database also has the value 'N'. This approach can be
Expand Down Expand Up @@ -811,8 +845,8 @@ QHash<QString, AdiFormat::ExportParams> AdiFormat::DB2ADIFExportParams =
{ "gridsquare", ExportParams("gridsquare")},
{ "cqz", ExportParams("cqz")},
{ "ituz", ExportParams("ituz")},
{ "freq", ExportParams("freq", &AdiFormat::toString)},
{ "band", ExportParams("band", &AdiFormat::toLower)},
{ "freq", ExportParams("freq", OutputFieldFormatter::TOSTRING)},
{ "band", ExportParams("band", OutputFieldFormatter::TOLOWER)},
{ "mode", ExportParams("mode")},
{ "submode", ExportParams("submode")},
{ "cont", ExportParams("cont")},
Expand All @@ -822,15 +856,15 @@ QHash<QString, AdiFormat::ExportParams> AdiFormat::DB2ADIFExportParams =
{ "state", ExportParams("state")},
{ "cnty", ExportParams("cnty")},
{ "cnty_alt", ExportParams("cnty_alt")},
{ "iota", ExportParams("iota", &AdiFormat::toUpper)},
{ "qsl_rcvd", ExportParams("qsl_rcvd", &AdiFormat::removeDefaulValueN)},
{ "qsl_rdate", ExportParams("qslrdate", &AdiFormat::toYYYYMMDD)},
{ "qsl_sent", ExportParams("qsl_sent", &AdiFormat::removeDefaulValueN)},
{ "qsl_sdate", ExportParams("qslsdate", &AdiFormat::toYYYYMMDD)},
{ "lotw_qsl_rcvd", ExportParams("lotw_qsl_rcvd", &AdiFormat::removeDefaulValueN)},
{ "lotw_qslrdate", ExportParams("lotw_qslrdate", &AdiFormat::toYYYYMMDD)},
{ "lotw_qsl_sent", ExportParams("lotw_qsl_sent", &AdiFormat::removeDefaulValueN)},
{ "lotw_qslsdate", ExportParams("lotw_qslsdate", &AdiFormat::toYYYYMMDD)},
{ "iota", ExportParams("iota", OutputFieldFormatter::TOUPPER)},
{ "qsl_rcvd", ExportParams("qsl_rcvd", OutputFieldFormatter::REMOVEDEFAULTVALUEN)},
{ "qsl_rdate", ExportParams("qslrdate", OutputFieldFormatter::TODATE)},
{ "qsl_sent", ExportParams("qsl_sent", OutputFieldFormatter::REMOVEDEFAULTVALUEN)},
{ "qsl_sdate", ExportParams("qslsdate", OutputFieldFormatter::TODATE)},
{ "lotw_qsl_rcvd", ExportParams("lotw_qsl_rcvd", OutputFieldFormatter::REMOVEDEFAULTVALUEN)},
{ "lotw_qslrdate", ExportParams("lotw_qslrdate", OutputFieldFormatter::TODATE)},
{ "lotw_qsl_sent", ExportParams("lotw_qsl_sent", OutputFieldFormatter::REMOVEDEFAULTVALUEN)},
{ "lotw_qslsdate", ExportParams("lotw_qslsdate", OutputFieldFormatter::TODATE)},
{ "tx_pwr", ExportParams("tx_pwr")},
{ "address", ExportParams("address")},
{ "age", ExportParams("age")},
Expand All @@ -842,47 +876,47 @@ QHash<QString, AdiFormat::ExportParams> AdiFormat::DB2ADIFExportParams =
{ "arrl_sect", ExportParams("arrl_sect")},
{ "award_submitted", ExportParams("award_submitted")},
{ "award_granted", ExportParams("award_granted")},
{ "band_rx", ExportParams("band_rx", &AdiFormat::toLower)},
{ "band_rx", ExportParams("band_rx", OutputFieldFormatter::TOLOWER)},
{ "check", ExportParams("check")},
{ "class", ExportParams("class")},
{ "clublog_qso_upload_date", ExportParams("clublog_qso_upload_date", &AdiFormat::toYYYYMMDD)},
{ "clublog_qso_upload_date", ExportParams("clublog_qso_upload_date", OutputFieldFormatter::TODATE)},
{ "clublog_qso_upload_status", ExportParams("clublog_qso_upload_status")},
{ "comment", ExportParams("comment")},
{ "contacted_op", ExportParams("contacted_op")},
{ "contest_id", ExportParams("contest_id")},
{ "credit_submitted", ExportParams("credit_submitted")},
{ "credit_granted", ExportParams("credit_granted")},
{ "darc_dok", ExportParams("darc_dok")},
{ "dcl_qslrdate", ExportParams("dcl_qslrdate", &AdiFormat::toYYYYMMDD)},
{ "dcl_qslsdate", ExportParams("dcl_qslsdate", &AdiFormat::toYYYYMMDD)},
{ "dcl_qsl_rcvd", ExportParams("dcl_qsl_rcvd", &AdiFormat::removeDefaulValueN)},
{ "dcl_qsl_sent", ExportParams("dcl_qsl_sent", &AdiFormat::removeDefaulValueN)},
{ "dcl_qslrdate", ExportParams("dcl_qslrdate", OutputFieldFormatter::TODATE)},
{ "dcl_qslsdate", ExportParams("dcl_qslsdate", OutputFieldFormatter::TODATE)},
{ "dcl_qsl_rcvd", ExportParams("dcl_qsl_rcvd", OutputFieldFormatter::REMOVEDEFAULTVALUEN)},
{ "dcl_qsl_sent", ExportParams("dcl_qsl_sent", OutputFieldFormatter::REMOVEDEFAULTVALUEN)},
{ "distance", ExportParams("distance")},
{ "email", ExportParams("email")},
{ "eq_call", ExportParams("eq_call")},
{ "eqsl_qslrdate", ExportParams("eqsl_qslrdate", &AdiFormat::toYYYYMMDD)},
{ "eqsl_qslsdate", ExportParams("eqsl_qslsdate", &AdiFormat::toYYYYMMDD)},
{ "eqsl_qsl_rcvd", ExportParams("eqsl_qsl_rcvd", &AdiFormat::removeDefaulValueN)},
{ "eqsl_qsl_sent", ExportParams("eqsl_qsl_sent", &AdiFormat::removeDefaulValueN)},
{ "eqsl_qslrdate", ExportParams("eqsl_qslrdate", OutputFieldFormatter::TODATE)},
{ "eqsl_qslsdate", ExportParams("eqsl_qslsdate", OutputFieldFormatter::TODATE)},
{ "eqsl_qsl_rcvd", ExportParams("eqsl_qsl_rcvd", OutputFieldFormatter::REMOVEDEFAULTVALUEN)},
{ "eqsl_qsl_sent", ExportParams("eqsl_qsl_sent", OutputFieldFormatter::REMOVEDEFAULTVALUEN)},
{ "fists", ExportParams("fists")},
{ "fists_cc", ExportParams("fists_cc")},
{ "force_init", ExportParams("force_init")},
{ "freq_rx", ExportParams("freq_rx")},
{ "gridsquare_ext", ExportParams("gridsquare_ext")},
{ "guest_op", ExportParams("guest_op")},
{ "hamlogeu_qso_upload_date", ExportParams("hamlogeu_qso_upload_date", &AdiFormat::toYYYYMMDD)},
{ "hamlogeu_qso_upload_date", ExportParams("hamlogeu_qso_upload_date", OutputFieldFormatter::TODATE)},
{ "hamlogeu_qso_upload_status", ExportParams("hamlogeu_qso_upload_status")},
{ "hamqth_qso_upload_date", ExportParams("hamqth_qso_upload_date", &AdiFormat::toYYYYMMDD)},
{ "hamqth_qso_upload_date", ExportParams("hamqth_qso_upload_date", OutputFieldFormatter::TODATE)},
{ "hamqth_qso_upload_status", ExportParams("hamqth_qso_upload_status")},
{ "hrdlog_qso_upload_date", ExportParams("hrdlog_qso_upload_date", &AdiFormat::toYYYYMMDD)},
{ "hrdlog_qso_upload_date", ExportParams("hrdlog_qso_upload_date", OutputFieldFormatter::TODATE)},
{ "hrdlog_qso_upload_status", ExportParams("hrdlog_qso_upload_status")},
{ "iota_island_id", ExportParams("iota_island_id", &AdiFormat::toUpper)},
{ "iota_island_id", ExportParams("iota_island_id", OutputFieldFormatter::TOUPPER)},
{ "k_index", ExportParams("k_index")},
{ "lat", ExportParams("lat")},
{ "lon", ExportParams("lon")},
{ "max_bursts", ExportParams("max_bursts")},
{ "morse_key_info", ExportParams("morse_key_info")},
{ "morse_key_type", ExportParams("morse_key_type", &AdiFormat::toUpper)},
{ "morse_key_type", ExportParams("morse_key_type", OutputFieldFormatter::TOUPPER)},
{ "ms_shower", ExportParams("ms_shower")},
{ "my_altitude", ExportParams("my_altitude")},
{ "my_arrl_sect", ExportParams("my_arrl_sect")},
Expand All @@ -897,37 +931,37 @@ QHash<QString, AdiFormat::ExportParams> AdiFormat::DB2ADIFExportParams =
{ "my_fists", ExportParams("my_fists")},
{ "my_gridsquare", ExportParams("my_gridsquare")},
{ "my_gridsquare_ext", ExportParams("my_gridsquare_ext")},
{ "my_iota", ExportParams("my_iota", &AdiFormat::toUpper)},
{ "my_iota_island_id", ExportParams("my_iota_island_id", &AdiFormat::toUpper)},
{ "my_iota", ExportParams("my_iota", OutputFieldFormatter::TOUPPER)},
{ "my_iota_island_id", ExportParams("my_iota_island_id", OutputFieldFormatter::TOUPPER)},
{ "my_itu_zone", ExportParams("my_itu_zone")},
{ "my_lat", ExportParams("my_lat")},
{ "my_lon", ExportParams("my_lon")},
{ "my_morse_key_info", ExportParams("my_morse_key_info")},
{ "my_morse_key_type", ExportParams("my_morse_key_type", &AdiFormat::toUpper)},
{ "my_morse_key_type", ExportParams("my_morse_key_type", OutputFieldFormatter::TOUPPER)},
{ "my_name", ExportParams("my_name")},
{ "my_postal_code", ExportParams("my_postal_code")},
{ "my_pota_ref", ExportParams("my_pota_ref", &AdiFormat::toUpper)},
{ "my_pota_ref", ExportParams("my_pota_ref", OutputFieldFormatter::TOUPPER)},
{ "my_rig", ExportParams("my_rig")},
{ "my_sig", ExportParams("my_sig")},
{ "my_sig_info", ExportParams("my_sig_info")},
{ "my_sota_ref", ExportParams("my_sota_ref", &AdiFormat::toUpper)},
{ "my_sota_ref", ExportParams("my_sota_ref", OutputFieldFormatter::TOUPPER)},
{ "my_state", ExportParams("my_state")},
{ "my_street", ExportParams("my_street")},
{ "my_usaca_counties", ExportParams("my_usaca_counties")},
{ "my_vucc_grids", ExportParams("my_vucc_grids", &AdiFormat::toUpper)},
{ "my_wwff_ref", ExportParams("my_wwff_ref", &AdiFormat::toUpper)},
{ "my_vucc_grids", ExportParams("my_vucc_grids", OutputFieldFormatter::TOUPPER)},
{ "my_wwff_ref", ExportParams("my_wwff_ref", OutputFieldFormatter::TOUPPER)},
{ "notes", ExportParams("notes")},
{ "nr_bursts", ExportParams("nr_bursts")},
{ "nr_pings", ExportParams("nr_pings")},
{ "operator", ExportParams("operator")},
{ "owner_callsign", ExportParams("owner_callsign")},
{ "pota_ref", ExportParams("pota_ref", &AdiFormat::toUpper)},
{ "pota_ref", ExportParams("pota_ref", OutputFieldFormatter::TOUPPER)},
{ "precedence", ExportParams("precedence")},
{ "prop_mode", ExportParams("prop_mode")},
{ "public_key", ExportParams("public_key")},
{ "qrzcom_qso_download_date", ExportParams("qrzcom_qso_download_date", &AdiFormat::toYYYYMMDD)},
{ "qrzcom_qso_download_date", ExportParams("qrzcom_qso_download_date", OutputFieldFormatter::TODATE)},
{ "qrzcom_qso_download_status", ExportParams("qrzcom_qso_download_status")},
{ "qrzcom_qso_upload_date", ExportParams("qrzcom_qso_upload_date", &AdiFormat::toYYYYMMDD)},
{ "qrzcom_qso_upload_date", ExportParams("qrzcom_qso_upload_date", OutputFieldFormatter::TODATE)},
{ "qrzcom_qso_upload_status", ExportParams("qrzcom_qso_upload_status")},
{ "qslmsg", ExportParams("qslmsg")},
{ "qslmsg_rcvd", ExportParams("qslmsg_rcvd")},
Expand All @@ -946,7 +980,7 @@ QHash<QString, AdiFormat::ExportParams> AdiFormat::DB2ADIFExportParams =
{ "sig_info", ExportParams("sig_info")},
{ "silent_key", ExportParams("silent_key")},
{ "skcc", ExportParams("skcc")},
{ "sota_ref", ExportParams("sota_ref", &AdiFormat::toUpper)},
{ "sota_ref", ExportParams("sota_ref", OutputFieldFormatter::TOUPPER)},
{ "srx", ExportParams("srx")},
{ "srx_string", ExportParams("srx_string")},
{ "station_callsign", ExportParams("station_callsign")},
Expand All @@ -957,9 +991,9 @@ QHash<QString, AdiFormat::ExportParams> AdiFormat::DB2ADIFExportParams =
{ "uksmg", ExportParams("uksmg")},
{ "usaca_counties", ExportParams("usaca_counties")},
{ "ve_prov", ExportParams("ve_prov")},
{ "vucc_grids", ExportParams("vucc_grids", &AdiFormat::toUpper)},
{ "vucc_grids", ExportParams("vucc_grids", OutputFieldFormatter::TOUPPER)},
{ "web", ExportParams("web")},
{ "wwff_ref", ExportParams("wwff_ref", &AdiFormat::toUpper)}
{ "wwff_ref", ExportParams("wwff_ref", OutputFieldFormatter::TOUPPER)}
};

#undef ALWAYS_PRESENT
33 changes: 23 additions & 10 deletions logformat/AdiFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,43 @@ class AdiFormat : public LogFormat
void contactFields2SQLRecord(QMap<QString, QVariant> &contact,
QSqlRecord &record);

static const QString toString(const QVariant &);
static const QString toLower(const QVariant &);
static const QString toUpper(const QVariant &);
static const QString toYYYYMMDD(const QVariant &);
static const QString removeDefaulValueN(const QVariant &);
enum OutputFieldFormatter
{
TOSTRING,
TOLOWER,
TOUPPER,
TODATE,
TOTIME,
REMOVEDEFAULTVALUEN
};

const QString formatOuput(OutputFieldFormatter formatter, const QVariant &in);

virtual const QString toString(const QVariant &);
virtual const QString toLower(const QVariant &);
virtual const QString toUpper(const QVariant &);
virtual const QString toDate(const QVariant &);
virtual const QString toTime(const QVariant &);
virtual const QString removeDefaulValueN(const QVariant &);

class ExportParams
{
public:
ExportParams() :
ADIFName(QString()),
outputType(QString()),
formatFct(nullptr),
formatter(TOSTRING),
isValid(false) {};
ExportParams(const QString &inADIFName,
const QString (*inFct)(const QVariant &) = &AdiFormat::toString,
const QString &inType = QString()) :
const OutputFieldFormatter formatter = OutputFieldFormatter::TOSTRING,
const QString &inType = QString()) :
ADIFName(inADIFName),
outputType(inType),
formatFct(inFct),
formatter(formatter),
isValid(true) {};
QString ADIFName;
QString outputType;
const QString (*formatFct)(const QVariant &);
OutputFieldFormatter formatter;
bool isValid;
};

Expand Down

0 comments on commit bb6c5a5

Please sign in to comment.