forked from 7h0ma5/QLog
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WSJTX: Added support to received ADIF QSO Log record
QLog can receive 2 QSO log messages. The first is a WSJTX binary log message and the second is in ADIF format. QLog tries to get as much information as possible from both and therefore merges them.
- Loading branch information
Showing
5 changed files
with
189 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#include <QSqlField> | ||
|
||
#include "UpdatableSQLRecord.h" | ||
#include "debug.h" | ||
|
||
MODULE_IDENTIFICATION("qlog.core.updatableqslrecord"); | ||
|
||
UpdatableSQLRecord::UpdatableSQLRecord(int interval, QObject *parent) | ||
: QObject{parent}, | ||
interval(interval) | ||
{ | ||
FCT_IDENTIFICATION; | ||
|
||
connect(&timer, &QTimer::timeout, this, &UpdatableSQLRecord::emitStoreRecord); | ||
} | ||
|
||
UpdatableSQLRecord::~UpdatableSQLRecord() | ||
{ | ||
FCT_IDENTIFICATION; | ||
|
||
timer.stop(); | ||
} | ||
|
||
void UpdatableSQLRecord::updateRecord(const QSqlRecord &record) | ||
{ | ||
FCT_IDENTIFICATION; | ||
|
||
if ( internalRecord.isEmpty() ) | ||
{ | ||
internalRecord = record; | ||
qCDebug(runtime) << "Record is empty, starting timer" << interval; | ||
timer.start(interval); | ||
return; | ||
} | ||
else if ( !matchQSO(QSOMatchingType, record) ) | ||
{ | ||
qCDebug(runtime) << "Records do not match"; | ||
timer.stop(); | ||
emitStoreRecord(); | ||
internalRecord = record; | ||
} | ||
else | ||
{ | ||
qCDebug(runtime) << "Records match"; | ||
|
||
timer.stop(); | ||
for ( int i = 0; i < record.count(); ++i ) | ||
{ | ||
const QString &fieldName = record.fieldName(i); | ||
|
||
if ( !internalRecord.contains(fieldName) ) | ||
internalRecord.append(record.field(i)); | ||
else if ( internalRecord.value(i).toString().isEmpty() | ||
&& !record.value(i).toString().isEmpty() ) | ||
internalRecord.setValue(fieldName, record.value(i)); | ||
} | ||
} | ||
|
||
qCDebug(runtime) << "starting timer" << interval; | ||
timer.start(interval); | ||
} | ||
|
||
void UpdatableSQLRecord::emitStoreRecord() | ||
{ | ||
FCT_IDENTIFICATION; | ||
|
||
timer.stop(); | ||
|
||
if ( internalRecord.isEmpty() ) | ||
return; | ||
|
||
qCDebug(runtime) << "emitting record"; | ||
emit recordReady(internalRecord); | ||
internalRecord.clear(); | ||
} | ||
|
||
bool UpdatableSQLRecord::matchQSO(const MatchingType matchingType, | ||
const QSqlRecord &record) | ||
{ | ||
FCT_IDENTIFICATION; | ||
|
||
const QStringList &fields = matchingFields.value(matchingType); | ||
|
||
for ( const QString &fieldName : fields ) | ||
{ | ||
qCDebug(runtime) << "compare field name " << fieldName | ||
<< "In value" << internalRecord.value(fieldName) | ||
<< "New value" << record.value(fieldName); | ||
|
||
if ( internalRecord.value(fieldName) != record.value(fieldName)) | ||
return false; | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#ifndef UPDATABLESQLRECORD_H | ||
#define UPDATABLESQLRECORD_H | ||
|
||
#include <QObject> | ||
#include <QSqlRecord> | ||
#include <QTimer> | ||
#include <QHash> | ||
|
||
class UpdatableSQLRecord : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit UpdatableSQLRecord(int interval = 500, | ||
QObject *parent = nullptr); | ||
|
||
~UpdatableSQLRecord(); | ||
void updateRecord(const QSqlRecord &record); | ||
|
||
signals: | ||
void recordReady( QSqlRecord ); | ||
|
||
private slots: | ||
void emitStoreRecord(); | ||
|
||
private: | ||
|
||
enum MatchingType{ | ||
QSOMatchingType | ||
}; | ||
|
||
QHash<MatchingType, QStringList> matchingFields | ||
{ | ||
{QSOMatchingType, {"callsign", "mode", "submode"}} | ||
}; | ||
|
||
bool matchQSO(const MatchingType, | ||
const QSqlRecord &); | ||
|
||
QSqlRecord internalRecord; | ||
QTimer timer; | ||
int interval; | ||
}; | ||
|
||
#endif // UPDATABLESQLRECORD_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters