forked from treefrogframework/treefrog-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtactioncontroller_qt5.cpp
100 lines (86 loc) · 2.52 KB
/
tactioncontroller_qt5.cpp
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
/* Copyright (c) 2012-2019, AOYAMA Kazuharu
* All rights reserved.
*
* This software may be used and distributed according to the terms of
* the New BSD License, which is incorporated herein by reference.
*/
#include <TActionController>
#include <QtCore>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
/*!
Renders the JSON document \a document as HTTP response.
This is available on Qt 5.
*/
bool TActionController::renderJson(const QJsonDocument &document)
{
return sendData(document.toJson(QJsonDocument::Compact), "application/json; charset=utf-8");
}
/*!
Renders the JSON object \a object as HTTP response.
This is available on Qt 5.
*/
bool TActionController::renderJson(const QJsonObject &object)
{
return renderJson(QJsonDocument(object));
}
/*!
Renders the JSON array \a array as HTTP response.
This is available on Qt 5.
*/
bool TActionController::renderJson(const QJsonArray &array)
{
return renderJson(QJsonDocument(array));
}
/*!
Renders the \a map as a JSON object.
This is available on Qt 5.
*/
bool TActionController::renderJson(const QVariantMap &map)
{
return renderJson(QJsonObject::fromVariantMap(map));
}
/*!
Renders the \a list as a JSON array.
This is available on Qt 5.
*/
bool TActionController::renderJson(const QVariantList &list)
{
return renderJson(QJsonArray::fromVariantList(list));
}
/*!
Renders the \a list as a JSON array.
This is available on Qt 5.
*/
bool TActionController::renderJson(const QStringList &list)
{
return renderJson(QJsonArray::fromStringList(list));
}
#if QT_VERSION >= 0x050c00 // 5.12.0
bool TActionController::renderCbor(const QVariant &variant, QCborValue::EncodingOptions opt)
{
return renderCbor(QCborValue::fromVariant(variant), opt);
}
bool TActionController::renderCbor(const QVariantMap &map, QCborValue::EncodingOptions opt)
{
return renderCbor(QCborMap::fromVariantMap(map), opt);
}
bool TActionController::renderCbor(const QVariantHash &hash, QCborValue::EncodingOptions opt)
{
return renderCbor(QCborMap::fromVariantHash(hash), opt);
}
bool TActionController::renderCbor(const QCborValue &value, QCborValue::EncodingOptions opt)
{
QCborValue val = value;
return sendData(val.toCbor(opt), "application/cbor");
}
bool TActionController::renderCbor(const QCborMap &map, QCborValue::EncodingOptions opt)
{
return renderCbor(map.toCborValue(), opt);
}
bool TActionController::renderCbor(const QCborArray &array, QCborValue::EncodingOptions opt)
{
return renderCbor(array.toCborValue(), opt);
}
#endif