forked from foldynl/QLog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdiFormat.h
118 lines (100 loc) · 3.77 KB
/
AdiFormat.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#ifndef QLOG_LOGFORMAT_ADIFORMAT_H
#define QLOG_LOGFORMAT_ADIFORMAT_H
#include "LogFormat.h"
class AdiFormat : public LogFormat
{
public:
explicit AdiFormat(QTextStream& stream);
virtual bool importNext(QSqlRecord& ) override;
virtual void exportContact(const QSqlRecord&,
QMap<QString, QString> *applTags = nullptr) override;
virtual void exportStart() override;
static QMap<QString, QString> fieldname2INTLNameMapping;
template<typename T>
static void preprocessINTLFields(T &contact)
{
{
const QStringList &fieldMappingList = fieldname2INTLNameMapping.keys();
for ( const QString& fieldName : fieldMappingList )
preprocessINTLField(fieldName, fieldname2INTLNameMapping.value(fieldName), contact);
}
}
protected:
virtual void writeField(const QString &name,
bool presenceCondition,
const QString &value,
const QString &type="");
virtual void writeSQLRecord(const QSqlRecord& record,
QMap<QString, QString> *applTags);
virtual bool readContact(QVariantMap &);
void mapContact2SQLRecord(QMap<QString, QVariant> &contact,
QSqlRecord &record);
void contactFields2SQLRecord(QMap<QString, QVariant> &contact,
QSqlRecord &record);
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()),
formatter(TOSTRING),
isValid(false) {};
ExportParams(const QString &inADIFName,
const OutputFieldFormatter formatter = OutputFieldFormatter::TOSTRING,
const QString &inType = QString()) :
ADIFName(inADIFName),
outputType(inType),
formatter(formatter),
isValid(true) {};
QString ADIFName;
QString outputType;
OutputFieldFormatter formatter;
bool isValid;
};
static QHash<QString, AdiFormat::ExportParams> DB2ADIFExportParams;
const QString ADIF_VERSION_STRING = "3.1.5";
const QString PROGRAMID_STRING = "QLog";
private:
void readField(QString& field,
QString& value);
QDate parseDate(const QString &date);
QTime parseTime(const QString &time);
QString parseQslRcvd(const QString &value);
QString parseQslSent(const QString &value);
QString parseUploadStatus(const QString &value);
QString parseDownloadStatus(const QString &value);
QString parseMorseKeyType(const QString &value);
enum ParserState {
START,
FIELD,
KEY,
SIZE,
DATA_TYPE,
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;
};
#endif // QLOG_LOGFORMAT_ADIFORMAT_H