Skip to content

Commit

Permalink
Reviewed usage of QVariant isNull
Browse files Browse the repository at this point in the history
Based on QT6 spec, all isNull calls had to be reviewed.

https://doc.qt.io/qt-6/qtcore-changes-qt6.html

QT6 spec:
QVariant has been rewritten to use QMetaType for all of its
operations. This implies behavior changes in a few methods:

QVariant::isNull() now only returns true if the QVariant
is empty or contains a nullptr. In Qt 5, it also returned
true for classes in qtbase which had an isNull method
themselves if that one returned true. Code relying on the old behavior
needs to check whether the contained value returns isNull – however such
code is unlikely to occur in practice, as isNull() is rarely the property
one is interested in (compare QString::isEmpty() / isNull()
and QTime::isValid / isNull).
  • Loading branch information
foldynl committed Dec 17, 2023
1 parent ed7a371 commit 5128ce7
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 44 deletions.
3 changes: 2 additions & 1 deletion data/Data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ DxccStatus Data::dxccStatus(int dxcc, const QString &band, const QString &mode)

QSettings settings;
QVariant start = settings.value("dxcc/start");
if (!start.isNull()) {
if ( start.toDate().isValid() )
{
filter = QString("AND start_time >= '%1'").arg(start.toDate().toString("yyyy-MM-dd"));
}

Expand Down
14 changes: 7 additions & 7 deletions logformat/AdiFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void AdiFormat::mapContact2SQLRecord(QMap<QString, QVariant> &contact,

for ( const QString &key : qAsConst(keys) )
{
if ( contact.value(key).isNull() )
if ( contact.value(key).toString().isEmpty() )
{
contact.insert(key, defaults->value(key));
}
Expand Down Expand Up @@ -518,17 +518,17 @@ void AdiFormat::preprocessINTLField(const QString &fieldName,
* therefore it is needed to implement a logic how to convert INTL fields
* to standard
*/
if ( !fld.isNull() && !fldIntl.isNull() )
if ( !fld.toString().isEmpty() && !fldIntl.toString().isEmpty() )
{
/* ascii and intl are present */
//no action
}
else if ( !fld.isNull() && fldIntl.isNull() )
else if ( !fld.toString().isEmpty() && fldIntl.toString().isEmpty() )
{
/* ascii is present but Intl is not present */
contact[fieldIntlName] = fld;
}
else if ( fld.isNull() && !fldIntl.isNull() )
else if ( fld.toString().isEmpty() && !fldIntl.toString().isEmpty() )
{
/* ascii is empty but Intl is present */
contact[fieldName] = Data::removeAccents(fldIntl.toString());
Expand All @@ -555,17 +555,17 @@ void AdiFormat::preprocessINTLField(const QString &fieldName,
* therefore it is needed to implement a logic how to convert INTL fields
* to standard
*/
if ( !fld.isNull() && !fldIntl.isNull() )
if ( !fld.toString().isEmpty() && !fldIntl.toString().isEmpty() )
{
/* ascii and intl are present */
//no action
}
else if ( !fld.isNull() && fldIntl.isNull() )
else if ( !fld.toString().isEmpty() && fldIntl.toString().isEmpty() )
{
/* ascii is present but Intl is not present */
contact.setValue(fieldIntlName, fld);
}
else if ( fld.isNull() && !fldIntl.isNull() )
else if ( fld.toString().isEmpty() && !fldIntl.toString().isEmpty() )
{
/* ascii is empty but Intl is present */
contact.setValue(fieldName, Data::removeAccents(fldIntl.toString()));
Expand Down
58 changes: 29 additions & 29 deletions logformat/LogFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ unsigned long LogFormat::runImport(QTextStream& importLogStream,

processedRec++;

if ( record.value(RECORDIDX(LogbookModel::COLUMN_BAND)).isNull()
&& !record.value(RECORDIDX(LogbookModel::COLUMN_FREQUENCY)).isNull() )
if ( record.value(RECORDIDX(LogbookModel::COLUMN_BAND)).toString().isEmpty()
&& !record.value(RECORDIDX(LogbookModel::COLUMN_FREQUENCY)).toString().isEmpty() )
{
double freq = record.value(RECORDIDX(LogbookModel::COLUMN_FREQUENCY)).toDouble();
record.setValue(RECORDIDX(LogbookModel::COLUMN_BAND), BandPlan::freq2Band(freq).name);
Expand All @@ -302,17 +302,17 @@ unsigned long LogFormat::runImport(QTextStream& importLogStream,
const QVariant &mycall = record.value(RECORDIDX(LogbookModel::COLUMN_STATION_CALLSIGN));
const QVariant &band = record.value(RECORDIDX(LogbookModel::COLUMN_BAND));
const QVariant &mode = record.value(RECORDIDX(LogbookModel::COLUMN_MODE));
const QVariant &start_time = record.value(RECORDIDX(LogbookModel::COLUMN_TIME_ON));
const QDateTime &start_time = record.value(RECORDIDX(LogbookModel::COLUMN_TIME_ON)).toDateTime();
const QVariant &sota = record.value(RECORDIDX(LogbookModel::COLUMN_SOTA_REF));
const QVariant &mysota = record.value(RECORDIDX(LogbookModel::COLUMN_MY_SOTA_REF));


/* checking matching fields if they are not empty */
if ( start_time.isNull()
|| call.isNull()
|| band.isNull()
|| mode.isNull()
|| mycall.isNull() )
if ( !start_time.isValid()
|| call.toString().isEmpty()
|| band.toString().isEmpty()
|| mode.toString().isEmpty()
|| mycall.toString().isEmpty() )
{
writeImportLog(importLogStream,
ERROR_SEVERITY,
Expand All @@ -332,7 +332,7 @@ unsigned long LogFormat::runImport(QTextStream& importLogStream,

if ( isDateRange() )
{
if (!inDateRange(start_time.toDateTime().date()))
if (!inDateRange(start_time.date()))
{
writeImportLog(importLogStream,
WARNING_SEVERITY,
Expand All @@ -349,7 +349,7 @@ unsigned long LogFormat::runImport(QTextStream& importLogStream,
dupQuery.bindValue(":callsign", call);
dupQuery.bindValue(":mode", mode);
dupQuery.bindValue(":band", band);
dupQuery.bindValue(":startdate", start_time.toDateTime().toTimeSpec(Qt::UTC).toString("yyyy-MM-dd hh:mm:ss"));
dupQuery.bindValue(":startdate", start_time.toTimeSpec(Qt::UTC).toString("yyyy-MM-dd hh:mm:ss"));

if ( !dupQuery.exec() )
{
Expand Down Expand Up @@ -411,33 +411,33 @@ unsigned long LogFormat::runImport(QTextStream& importLogStream,
continue;
}

if ( record.value(RECORDIDX(LogbookModel::COLUMN_DXCC)).isNull()
if ( record.value(RECORDIDX(LogbookModel::COLUMN_DXCC)).toString().isEmpty()
|| updateDxcc )
{
record.setValue(RECORDIDX(LogbookModel::COLUMN_DXCC), entity.dxcc);
record.setValue(RECORDIDX(LogbookModel::COLUMN_COUNTRY), Data::removeAccents(entity.country));
record.setValue(RECORDIDX(LogbookModel::COLUMN_COUNTRY_INTL), entity.country);
}

if ( record.value(RECORDIDX(LogbookModel::COLUMN_CONTINENT)).isNull()
if ( record.value(RECORDIDX(LogbookModel::COLUMN_CONTINENT)).toString().isEmpty()
|| updateDxcc )
{
record.setValue(RECORDIDX(LogbookModel::COLUMN_CONTINENT), entity.cont);
}

if ( record.value(RECORDIDX(LogbookModel::COLUMN_ITUZ)).isNull()
if ( record.value(RECORDIDX(LogbookModel::COLUMN_ITUZ)).toString().isEmpty()
|| updateDxcc )
{
record.setValue(RECORDIDX(LogbookModel::COLUMN_ITUZ), QString::number(entity.ituz));
}

if ( record.value(RECORDIDX(LogbookModel::COLUMN_CQZ)).isNull()
if ( record.value(RECORDIDX(LogbookModel::COLUMN_CQZ)).toString().isEmpty()
|| updateDxcc )
{
record.setValue(RECORDIDX(LogbookModel::COLUMN_CQZ), QString::number(entity.cqz));
}

if ( record.value(RECORDIDX(LogbookModel::COLUMN_PREFIX)).isNull() )
if ( record.value(RECORDIDX(LogbookModel::COLUMN_PREFIX)).toString().isEmpty() )
{
const QString &pfxRef = Callsign(call.toString()).getWPXPrefix();

Expand All @@ -452,7 +452,7 @@ unsigned long LogFormat::runImport(QTextStream& importLogStream,

if ( !gridsquare.isEmpty()
&& !my_gridsquare.isEmpty()
&& record.value(RECORDIDX(LogbookModel::COLUMN_DISTANCE)).isNull() )
&& record.value(RECORDIDX(LogbookModel::COLUMN_DISTANCE)).toString().isEmpty() )
{
Gridsquare grid(gridsquare);
Gridsquare my_grid(my_gridsquare);
Expand All @@ -465,8 +465,8 @@ unsigned long LogFormat::runImport(QTextStream& importLogStream,
}


if ( record.value(RECORDIDX(LogbookModel::COLUMN_ALTITUDE)).isNull()
&& !sota.isNull() )
if ( record.value(RECORDIDX(LogbookModel::COLUMN_ALTITUDE)).toString().isEmpty()
&& !sota.toString().isEmpty() )
{
const SOTAEntity &sotaInfo = Data::instance()->lookupSOTA(sota.toString());
if ( sotaInfo.summitCode.compare(sota.toString(), Qt::CaseInsensitive)
Expand All @@ -476,8 +476,8 @@ unsigned long LogFormat::runImport(QTextStream& importLogStream,
}
}

if ( record.value(RECORDIDX(LogbookModel::COLUMN_MY_ALTITUDE)).isNull()
&& !mysota.isNull() )
if ( record.value(RECORDIDX(LogbookModel::COLUMN_MY_ALTITUDE)).toString().isEmpty()
&& !mysota.toString().isEmpty() )
{
const SOTAEntity &sotaInfo = Data::instance()->lookupSOTA(mysota.toString());
if ( sotaInfo.summitCode.compare(sota.toString(), Qt::CaseInsensitive)
Expand All @@ -500,27 +500,27 @@ unsigned long LogFormat::runImport(QTextStream& importLogStream,
continue;
}

if ( record.value(RECORDIDX(LogbookModel::COLUMN_MY_DXCC)).isNull() )
if ( record.value(RECORDIDX(LogbookModel::COLUMN_MY_DXCC)).toString().isEmpty() )
{
record.setValue(RECORDIDX(LogbookModel::COLUMN_MY_DXCC), dxccEntity.dxcc);
}

if ( record.value(RECORDIDX(LogbookModel::COLUMN_MY_ITU_ZONE)).isNull() )
if ( record.value(RECORDIDX(LogbookModel::COLUMN_MY_ITU_ZONE)).toString().isEmpty() )
{
record.setValue(RECORDIDX(LogbookModel::COLUMN_MY_ITU_ZONE), dxccEntity.ituz);
}

if ( record.value(RECORDIDX(LogbookModel::COLUMN_MY_CQ_ZONE)).isNull() )
if ( record.value(RECORDIDX(LogbookModel::COLUMN_MY_CQ_ZONE)).toString().isEmpty() )
{
record.setValue(RECORDIDX(LogbookModel::COLUMN_MY_CQ_ZONE), dxccEntity.cqz);
}

if ( record.value(RECORDIDX(LogbookModel::COLUMN_MY_COUNTRY_INTL)).isNull() )
if ( record.value(RECORDIDX(LogbookModel::COLUMN_MY_COUNTRY_INTL)).toString().isEmpty() )
{
record.setValue(RECORDIDX(LogbookModel::COLUMN_MY_COUNTRY_INTL), dxccEntity.country);
}

if ( record.value(RECORDIDX(LogbookModel::COLUMN_MY_COUNTRY)).isNull() )
if ( record.value(RECORDIDX(LogbookModel::COLUMN_MY_COUNTRY)).toString().isEmpty() )
{
record.setValue(RECORDIDX(LogbookModel::COLUMN_MY_COUNTRY), Data::removeAccents(dxccEntity.country));
}
Expand Down Expand Up @@ -597,10 +597,10 @@ void LogFormat::runQSLImport(QSLFrom fromService)
const QVariant &start_time = QSLRecord.value("start_time");

/* checking matching fields if they are not empty */
if ( start_time.isNull()
|| call.isNull()
|| band.isNull()
|| mode.isNull() )
if ( !start_time.toDateTime().isValid()
|| call.toString().isEmpty()
|| band.toString().isEmpty()
|| mode.toString().isEmpty() )
{
qWarning() << "Import does not contain field start_time or callsign or band or mode ";
qCDebug(runtime) << QSLRecord;
Expand Down
2 changes: 1 addition & 1 deletion ui/DxccTableWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void DxccTableWidget::setDxcc(int dxcc, Band highlightedBand)
}
}

if ( !start.isNull() )
if ( start.toDate().isValid() )
{
filter.append(QString(" AND c.start_time >= '%1'").arg(start.toDate().toString("yyyy-MM-dd")));
}
Expand Down
10 changes: 5 additions & 5 deletions ui/NewContactWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1063,33 +1063,33 @@ void NewContactWidget::addAddlFields(QSqlRecord &record, const StationProfile &p

if ( prop_cond )
{
if ( record.value("sfi").isNull()
if ( record.value("sfi").toString().isEmpty()
&& prop_cond->isFluxValid() )
{
record.setValue("sfi", prop_cond->getFlux());
}

if ( record.value("k_index").isNull()
if ( record.value("k_index").toString().isEmpty()
&& prop_cond->isKIndexValid() )
{
record.setValue("k_index", prop_cond->getKIndex());
}

if ( record.value("a_index").isNull()
if ( record.value("a_index").toString().isEmpty()
&& prop_cond->isAIndexValid() )
{
record.setValue("a_index", prop_cond->getAIndex());
}
}

if ( (record.value("tx_pwr").isNull() || record.value("tx_pwr") == 0.0 )
if ( (record.value("tx_pwr").toString().isEmpty() || record.value("tx_pwr") == 0.0 )
&& ui->powerEdit->value() != 0.0)
{
record.setValue("tx_pwr", ui->powerEdit->value());
}

if ( record.value("band").toString().isEmpty()
&& ! record.value("freq").isNull() )
&& ! record.value("freq").toString().isEmpty() )
{
record.setValue("band", BandPlan::freq2Band(record.value("freq").toDouble()).name);
}
Expand Down
2 changes: 1 addition & 1 deletion ui/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,7 @@ void SettingsDialog::readSettings() {
/********/
/* DXCC */
/********/
if (!settings.value("dxcc/start").isNull()) {
if (settings.value("dxcc/start").toDate().isValid()) {
ui->dxccStartDateCheckBox->setCheckState(Qt::Checked);
ui->dxccStartDate->setDate(settings.value("dxcc/start").toDate());
}
Expand Down

0 comments on commit 5128ce7

Please sign in to comment.