-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgftprogram.h
79 lines (61 loc) · 2.26 KB
/
gftprogram.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
/// Run SQL instructions on Google Fusion Tables
#ifndef GFTPROGRAM_H
#define GFTPROGRAM_H
#include <QObject>
#include <QString>
#include <QByteArray>
#include <QList>
#include <QMetaType>
#include <QNetworkAccessManager>
#include "otwo/o2requestor.h"
/// POST URL for SQL queries.
#define GFT_SQL_URL "https://fusiontables.googleusercontent.com/fusiontables/api/query"
class QNetworkReply;
/// List of record IDs.
typedef QList<qlonglong> GftIdList;
Q_DECLARE_METATYPE(GftIdList)
/// Operation.
enum GftOp {
GftFindTable, ///< Find table, return its ID in GftProgram::tableId. Parameter is the table name.
GftCreateTableIf, ///< Create table if doesn't exist, return its ID in GftProgram::tableId. Parameter is the table name.
GftQuery ///< Execute queries. Parameter is one or more SQL statements; $T will be replaced by the table ID.
};
/// Instruction.
struct GftInstruction {
GftInstruction(GftOp op_, const QString ¶m_, QList<qlonglong> idList_ = QList<qlonglong>()): op(op_), param(param_), idList(idList_) {}
GftOp op; ///< Operation.
QString param; ///< Table name or SQL statements.
GftIdList idList; ///< Local record IDs to be uploaded by this instruction.
};
/// Upload program
class GftProgram: public QObject {
Q_OBJECT
public:
/// Execution status.
enum Status {Idle, Running, Completed, Failed};
explicit GftProgram(QObject *parent = 0);
~GftProgram();
/// Set instructions, reset instruction counter and status.
void setInstructions(const QList<GftInstruction> instructions_);
public slots:
/// Execute next instruction.
void step();
/// Process finished request.
void stepDone(int id, QNetworkReply::NetworkError error, const QByteArray &data);
signals:
/// Emitted when an instruction step is completed.
/// @param idList Record IDs uploaded by to the step.
void stepCompleted(GftIdList idList);
/// Emitted when all instructions are completed.
/// @param failed If true, execution had an error.
void programCompleted(bool failed);
public:
QList<GftInstruction> instructions;
int ic;
Status status;
QString tableId;
int requestId;
QNetworkAccessManager *manager;
O2Requestor *requestor;
};
#endif // GFTPROGRAM_H