Skip to content

Commit

Permalink
Fixed #197 - Operator field is incorrectly used
Browse files Browse the repository at this point in the history
QLog used ADIF field "Operator" as a field for Operator's name.
It is incorrect. Therefore This commit map Operator Name to My_Name
field.

during the fixing the issue, it was found that the _INTL fields
were being mapped incorrectly. This issue is also fixed by this commit.
  • Loading branch information
foldynl committed Apr 24, 2023
1 parent d285223 commit 38e58da
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 60 deletions.
46 changes: 37 additions & 9 deletions logformat/AdiFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ void AdiFormat::mapContact2SQLRecord(QMap<QString, QVariant> &contact,
{
FCT_IDENTIFICATION;

preprocessINTLFields(contact);
preprocessINTLFields<QMap<QString, QVariant>>(contact);

/* Set default values if not present */
if ( defaults )
Expand All @@ -364,7 +364,7 @@ void AdiFormat::mapContact2SQLRecord(QMap<QString, QVariant> &contact,
}
}
// re-evaluate the fields
preprocessINTLFields(contact);
preprocessINTLFields<QMap<QString, QVariant>>(contact);
}

contactFields2SQLRecord(contact, record);
Expand Down Expand Up @@ -589,23 +589,51 @@ void AdiFormat::contactFields2SQLRecord(QMap<QString, QVariant> &contact, QSqlRe
record.setValue("end_time", end_time);
}

void AdiFormat::preprocessINTLFields(QMap<QString, QVariant> &contact)
void AdiFormat::preprocessINTLField(const QString &fieldName,
const QString &fieldIntlName,
QMap<QString, QVariant> &contact)
{
FCT_IDENTIFICATION;

QStringList fieldMappingList = fieldname2INTLNameMapping.keys();
for ( const QString& fieldName : qAsConst(fieldMappingList) )
// NOTE: If modify this, modify also function below!!!!

QVariant fld = contact.value(fieldName);
QVariant fldIntl = contact.value(fieldIntlName);

/* In general, it is a hack because ADI must not contain
* _INTL fields. But some applications generate _INTL fields in ADI files
* therefore it is needed to implement a logic how to convert INTL fields
* to standard
*/
if ( !fld.isNull() && !fldIntl.isNull() )
{
preprocessINTLField(fieldName, fieldname2INTLNameMapping.value(fieldName), contact);
/* ascii and intl are present */
//no action
}
else if ( !fld.isNull() && fldIntl.isNull() )
{
/* ascii is present but Intl is not present */
contact[fieldIntlName] = fld;
}
else if ( fld.isNull() && !fldIntl.isNull() )
{
/* ascii is empty but Intl is present */
contact[fieldName] = Data::removeAccents(fldIntl.toString());
}
else
{
/* both are empty */
/* do nothing */
}
}

void AdiFormat::preprocessINTLField(const QString &fieldName,
const QString &fieldIntlName,
QMap<QString, QVariant> &contact)
QSqlRecord &contact)
{
FCT_IDENTIFICATION;

// NOTE: If modify this, modify also function above!!!!
QVariant fld = contact.value(fieldName);
QVariant fldIntl = contact.value(fieldIntlName);

Expand All @@ -622,12 +650,12 @@ void AdiFormat::preprocessINTLField(const QString &fieldName,
else if ( !fld.isNull() && fldIntl.isNull() )
{
/* ascii is present but Intl is not present */
contact[fieldIntlName] = fld;
contact.setValue(fieldIntlName, fld);
}
else if ( fld.isNull() && !fldIntl.isNull() )
{
/* ascii is empty but Intl is present */
contact[fieldName] = Data::removeAccents(fldIntl.toString());
contact.setValue(fieldName, Data::removeAccents(fldIntl.toString()));
}
else
{
Expand Down
22 changes: 18 additions & 4 deletions logformat/AdiFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ class AdiFormat : public LogFormat
virtual void exportStart() override;

static QMap<QString, QString> fieldname2INTLNameMapping;
template<typename T>
static void preprocessINTLFields(T &contact)
{
{
QStringList fieldMappingList = fieldname2INTLNameMapping.keys();
for ( const QString& fieldName : qAsConst(fieldMappingList) )
{
preprocessINTLField(fieldName, fieldname2INTLNameMapping.value(fieldName), contact);
}
}
}

protected:
virtual void writeField(const QString &name,
Expand All @@ -36,10 +47,6 @@ class AdiFormat : public LogFormat
QString parseQslRcvd(const QString &value);
QString parseQslSent(const QString &value);
QString parseUploadStatus(const QString &value);
void preprocessINTLFields(QMap<QString, QVariant> &contact);
void preprocessINTLField(const QString &sourceField,
const QString &sourceFieldIntl,
QMap<QString, QVariant> &);
enum ParserState {
START,
FIELD,
Expand All @@ -49,6 +56,13 @@ class AdiFormat : public LogFormat
VALUE
};

static void preprocessINTLField(const QString &sourceField,
const QString &sourceFieldIntl,
QMap<QString, QVariant> &);
static void preprocessINTLField(const QString &sourceField,
const QString &sourceFieldIntl,
QSqlRecord &);

ParserState state = START;
bool inHeader = false;
};
Expand Down
63 changes: 16 additions & 47 deletions ui/NewContactWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "core/Callsign.h"
#include "core/PropConditions.h"
#include "core/MembershipQE.h"
#include "logformat/AdiFormat.h"

MODULE_IDENTIFICATION("qlog.ui.newcontactwidget");

Expand Down Expand Up @@ -1110,36 +1111,18 @@ void NewContactWidget::addAddlFields(QSqlRecord &record, const StationProfile &p
record.setValue("sat_name", Data::removeAccents(ui->satNameEdit->text().toUpper()));
}

if ( record.value("my_rig").toString().isEmpty()
&& !ui->rigEdit->currentText().isEmpty() )
{
record.setValue("my_rig", Data::removeAccents(ui->rigEdit->currentText()));
}

if ( record.value("my_rig_intl").toString().isEmpty()
&& !ui->rigEdit->currentText().isEmpty() )
{
record.setValue("my_rig_intl", ui->rigEdit->currentText());
}

if ( record.value("my_antenna").toString().isEmpty()
&& !ui->antennaEdit->currentText().isEmpty())
{
record.setValue("my_antenna", Data::removeAccents(ui->antennaEdit->currentText()));
}

if ( record.value("my_antenna_intl").toString().isEmpty()
&& !ui->antennaEdit->currentText().isEmpty())
{
record.setValue("my_antenna_intl", ui->antennaEdit->currentText());
}

if ( record.value("my_city").toString().isEmpty()
&& !profile.qthName.isEmpty())
{
record.setValue("my_city", Data::removeAccents(profile.qthName));
}

if ( record.value("my_city_intl").toString().isEmpty()
&& !profile.qthName.isEmpty())
{
Expand Down Expand Up @@ -1177,17 +1160,12 @@ void NewContactWidget::addAddlFields(QSqlRecord &record, const StationProfile &p
{
record.setValue("my_country_intl", dxccEntity.country);
}

if ( record.value("my_country").toString().isEmpty() )
{
record.setValue("my_country", Data::removeAccents(dxccEntity.country));
}
}

if ( record.value("operator").toString().isEmpty()
if ( record.value("my_name_intl").toString().isEmpty()
&& !profile.operatorName.isEmpty() )
{
record.setValue("operator", Data::removeAccents(profile.operatorName));
record.setValue("my_name_intl", profile.operatorName);
}

if ( record.value("my_iota").toString().isEmpty()
Expand Down Expand Up @@ -1218,24 +1196,12 @@ void NewContactWidget::addAddlFields(QSqlRecord &record, const StationProfile &p
record.setValue("my_pota_ref", Data::removeAccents(profile.pota.toUpper()));
}

if ( record.value("my_sig").toString().isEmpty()
&& !profile.sig.isEmpty())
{
record.setValue("my_sig", Data::removeAccents(profile.sig));
}

if ( record.value("my_sig_intl").toString().isEmpty()
&& !profile.sig.isEmpty())
{
record.setValue("my_sig_intl", profile.sig);
}

if ( record.value("my_sig_info").toString().isEmpty()
&& !profile.sigInfo.isEmpty())
{
record.setValue("my_sig_info", Data::removeAccents(profile.sigInfo));
}

if ( record.value("my_sig_info_intl").toString().isEmpty()
&& !profile.sigInfo.isEmpty())
{
Expand Down Expand Up @@ -1433,7 +1399,6 @@ void NewContactWidget::saveContact()
{
FCT_IDENTIFICATION;

QSettings settings;
StationProfile profile = StationProfilesManager::instance()->getProfile(ui->stationProfileCombo->currentText());

if ( profile.callsign.isEmpty() )
Expand Down Expand Up @@ -1481,13 +1446,11 @@ void NewContactWidget::saveContact()
if ( ! ui->nameEdit->text().isEmpty() )
{
record.setValue("name_intl", ui->nameEdit->text());
record.setValue("name", Data::removeAccents(ui->nameEdit->text()));
}

if ( ! ui->qthEdit->text().isEmpty() )
{
record.setValue("qth_intl", ui->qthEdit->text());
record.setValue("qth", Data::removeAccents(ui->qthEdit->text()));
}

if ( ! ui->gridEdit->text().isEmpty() )
Expand Down Expand Up @@ -1539,13 +1502,11 @@ void NewContactWidget::saveContact()

if ( ! ui->sigEdit->text().isEmpty() )
{
record.setValue("sig", Data::removeAccents(ui->sigEdit->text()));
record.setValue("sig_intl", ui->sigEdit->text());
}

if ( ! ui->sigInfoEdit->text().isEmpty() )
{
record.setValue("sig_info", Data::removeAccents(ui->sigInfoEdit->text()));
record.setValue("sig_info_intl", ui->sigInfoEdit->text());
}

Expand Down Expand Up @@ -1590,18 +1551,18 @@ void NewContactWidget::saveContact()
record.setValue("wwff_ref", ui->wwffEdit->text().toUpper());
}

if (!ui->commentEdit->text().isEmpty()) {
if (!ui->commentEdit->text().isEmpty())
{
record.setValue("comment_intl", ui->commentEdit->text());
record.setValue("comment", Data::removeAccents(ui->commentEdit->text()));
}

if (!ui->noteEdit->toPlainText().isEmpty())
{
record.setValue("notes_intl", ui->noteEdit->toPlainText());
record.setValue("notes", Data::removeAccents(ui->noteEdit->toPlainText()));
}

if (!ui->qslViaEdit->text().isEmpty()) {
if (!ui->qslViaEdit->text().isEmpty())
{
record.setValue("qsl_via", Data::removeAccents(ui->qslViaEdit->text().toUpper()));
}

Expand All @@ -1617,10 +1578,14 @@ void NewContactWidget::saveContact()

if (!ui->urlEdit->text().isEmpty()) {
record.setValue("web", Data::removeAccents(ui->urlEdit->text()));
}
}

AdiFormat::preprocessINTLFields<QSqlRecord>(record);

addAddlFields(record, profile);

AdiFormat::preprocessINTLFields<QSqlRecord>(record);

qCDebug(runtime) << record;

if ( !model.insertRecord(-1, record) )
Expand Down Expand Up @@ -1680,8 +1645,12 @@ void NewContactWidget::saveExternalContact(QSqlRecord record)

StationProfile profile = StationProfilesManager::instance()->getCurProfile1();

AdiFormat::preprocessINTLFields<QSqlRecord>(record);

addAddlFields(record, profile);

AdiFormat::preprocessINTLFields<QSqlRecord>(record);

qCDebug(runtime) << record;

if ( !model.insertRecord(-1, record) )
Expand Down

0 comments on commit 38e58da

Please sign in to comment.