Cutelyst  1.5.0
Public Types | Public Member Functions | Protected Attributes | List of all members
Cutelyst::ViewJson Class Reference

#include <viewjson.h>

Inheritance diagram for Cutelyst::ViewJson:
Inheritance graph

Public Types

enum  ExposeMode { All, String, StringList, RegularExpression }
enum  JsonFormat { Indented, Compact }
- Public Types inherited from Cutelyst::Component
enum  Modifier {
  None, OnlyExecute, BeforeExecute, AroundExecute,

Public Member Functions

 ViewJson (QObject *parent, const QString &name=QString())
ExposeMode exposeStashMode () const
JsonFormat outputFormat () const
QByteArray render (Context *c) const final
void setExposeStashRegularExpression (const QRegularExpression &re)
void setExposeStashString (const QString &key)
void setExposeStashStringList (const QStringList &keys)
void setOutputFormat (JsonFormat format)
- Public Member Functions inherited from Cutelyst::View
 View (QObject *parent, const QString &name=QString())
virtual Modifiers modifiers () const override
QString name () const
- Public Member Functions inherited from Cutelyst::Component
 Component (QObject *parent=nullptr)
bool execute (Context *c)
virtual bool init (Application *application, const QVariantHash &args)
QString name () const
 name More...
QString reverse () const
 name More...
void setName (const QString &name)
void setReverse (const QString &reverse)

Protected Attributes

ViewJsonPrivate * d_ptr
- Protected Attributes inherited from Cutelyst::Component
ComponentPrivate * d_ptr

Additional Inherited Members

- Protected Member Functions inherited from Cutelyst::Component
virtual bool afterExecute (Context *c)
void applyRoles (const QStack< Component * > &roles)
virtual bool aroundExecute (Context *c, QStack< Component * > stack)
virtual bool beforeExecute (Context *c)
virtual bool dispatcherReady (const Dispatcher *dispatch, Controller *controller)

Detailed Description

ViewJson is a Cutelyst::View handler that renders stash data in JSON format.

Definition at line 33 of file viewjson.h.

Member Function Documentation

ExposeMode Cutelyst::ViewJson::exposeStashMode ( ) const

Returns the expose mode of the stash keys, defaults to everything (All)

JsonFormat Cutelyst::ViewJson::outputFormat ( ) const

Returns the output format of JSON, defaults to Compact

QByteArray Cutelyst::ViewJson::render ( Context c) const

All subclasses must reimplement this when doing it's rendering. If an error (c->error()) is not set c->response()->body() is defined with the returned value, this is useful if the view is not meant to be used as a body.

Implements Cutelyst::View.

void Cutelyst::ViewJson::setExposeStashRegularExpression ( const QRegularExpression &  re)

Specify which stash keys are exposed as a JSON response, this will change exposeStashMode() to ViewJson::RegularExpression

void Cutelyst::ViewJson::setExposeStashString ( const QString &  key)

Specify which stash key is exposed as a JSON response, this will change exposeStashMode() to ViewJson::String

void Cutelyst::ViewJson::setExposeStashStringList ( const QStringList &  keys)

Specify which stash keys are exposed as a JSON response, this will change exposeStashMode() to ViewJson::StringList

void Cutelyst::ViewJson::setOutputFormat ( JsonFormat  format)

Defines the output format of JSON