5 #include "viewjson_p.h"
7 #include <Cutelyst/context.h>
8 #include <Cutelyst/response.h>
10 #include <QtCore/QJsonDocument>
11 #include <QtCore/QJsonObject>
16 :
View(new ViewJsonPrivate, parent, name)
75 d->xJsonHeader = enable;
81 return d->xJsonHeader;
90 const QVariantHash stash = c->
stash();
92 switch (d->exposeMode) {
98 auto it = stash.constFind(d->exposeKey);
99 if (it != stash.constEnd()) {
106 QVariantHash exposedStash;
108 auto it = stash.constBegin();
109 while (it != stash.constEnd()) {
111 if (d->exposeKeys.contains(key)) {
112 exposedStash.
insert(key, it.value());
121 QVariantHash exposedStash;
124 auto it = stash.constBegin();
125 while (it != stash.constEnd()) {
128 exposedStash.
insert(key, it.value());
139 res->
setHeader(
"X-Json"_qba,
"eval(\"(\"+this.transport.responseText+\")\")"_qba);
147 #include "moc_viewjson.cpp"
void stash(const QVariantHash &unite)
Response * response() const noexcept
Headers headers() const noexcept
void setContentType(const QByteArray &type)
void setHeader(const QByteArray &key, const QByteArray &value)
A view that returns stash data in JSON format.
void setOutputFormat(JsonFormat format)
void setExposeStash(const QString &key)
JsonFormat outputFormat() const
QByteArray render(Context *c) const final
ViewJson(QObject *parent, const QString &name=QString())
ExposeMode exposeStashMode() const
void setXJsonHeader(bool enable)
Abstract View component for Cutelyst.
The Cutelyst namespace holds all public Cutelyst API.
QByteArray toJson(QJsonDocument::JsonFormat format) const const
QJsonObject fromVariantHash(const QVariantHash &hash)
QJsonObject::iterator insert(QLatin1StringView key, const QJsonValue &value)
QJsonValue fromVariant(const QVariant &variant)
QRegularExpressionMatch match(QStringView subjectView, qsizetype offset, QRegularExpression::MatchType matchType, QRegularExpression::MatchOptions matchOptions) const const
bool hasMatch() const const
QString & insert(qsizetype position, QChar ch)