5 #include "viewjson_p.h" 7 #include <Cutelyst/context.h> 8 #include <Cutelyst/response.h> 10 #include <QtCore/QJsonDocument> 11 #include <QtCore/QJsonObject> 22 :
View(new ViewJsonPrivate, parent, name)
60 d->exposeMode = ViewJson::String;
67 d->exposeMode = ViewJson::StringList;
74 d->exposeMode = ViewJson::RegularExpression;
81 d->xJsonHeader = enable;
87 return d->xJsonHeader;
96 const QVariantHash stash = c->
stash();
98 switch (d->exposeMode) {
104 auto it = stash.constFind(d->exposeKey);
105 if (it != stash.constEnd()) {
112 QVariantHash exposedStash;
114 auto it = stash.constBegin();
115 while (it != stash.constEnd()) {
117 if (d->exposeKeys.contains(key)) {
118 exposedStash.
insert(key, it.value());
125 case RegularExpression:
127 QVariantHash exposedStash;
130 auto it = stash.constBegin();
131 while (it != stash.constEnd()) {
134 exposedStash.
insert(key, it.value());
144 if (d->xJsonHeader && c->request()->
headers().
contains(QStringLiteral(
"X_PROTOTYPE_VERSION"))) {
146 QStringLiteral(
"eval(\"(\"+this.transport.responseText+\")\")"));
154 #include "moc_viewjson.cpp" void setXJsonHeader(bool enable)
void setContentType(const QString &type)
QByteArray toJson(JsonFormat format) const const
void setHeader(const QString &field, const QString &value)
QJsonObject fromVariantHash(const QVariantHash &hash)
QJsonValue fromVariant(const QVariant &variant)
void setExposeStash(const QString &key)
JsonFormat outputFormat() const
QString & insert(qsizetype position, QChar ch)
ViewJson(QObject *parent, const QString &name=QString())
void stash(const QVariantHash &unite)
Headers headers() const noexcept
iterator insert(QLatin1StringView key, const QJsonValue &value)
void setOutputFormat(JsonFormat format)
bool hasMatch() const const
The Cutelyst namespace holds all public Cutelyst API.
QRegularExpressionMatch match(QStringView subjectView, qsizetype offset, MatchType matchType, MatchOptions matchOptions) const const
QByteArray render(Context *c) const final
Cutelyst View abstract view component
ExposeMode exposeStashMode() const
Response * response() const noexcept