cutelyst 5.0.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
Cutelyst::StatusMessage Class Reference

Manage status messages over multiple requests stored in the Session. More...

#include <Cutelyst/Plugins/StatusMessage>

Inheritance diagram for Cutelyst::StatusMessage:

Public Member Functions

 StatusMessage (Application *parent)
virtual ~StatusMessage () override
QString errorMgStashKey () const noexcept
QString sessionPrefix () const noexcept
void setErrorMgStashKey (const QString &errorMgStashKey)
void setSessionPrefix (const QString &sessionPrefix)
void setStatusMsgStashKey (const QString &statusMsgStashKey)
void setTokenParam (const QString &tokenParam)
QString statusMsgStashKey () const noexcept
QString tokenParam () const noexcept
Public Member Functions inherited from Cutelyst::Plugin
 Plugin (Application *parent)
Public Member Functions inherited from QObject
 QObject (QObject *parent)
QBindable< QStringbindableObjectName ()
bool blockSignals (bool block)
const QObjectListchildren () const const
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
void deleteLater ()
void destroyed (QObject *obj)
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
bool disconnect (const QObject *receiver, const char *method) const const
void dumpObjectInfo () const const
void dumpObjectTree () const const
QList< QByteArraydynamicPropertyNames () const const
virtual bool event (QEvent *e)
virtual bool eventFilter (QObject *watched, QEvent *event)
findChild (QAnyStringView name, Qt::FindChildOptions options) const const
findChild (Qt::FindChildOptions options) const const
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
QList< T > findChildren (QAnyStringView name, Qt::FindChildOptions options) const const
QList< T > findChildren (Qt::FindChildOptions options) const const
bool inherits (const char *className) const const
void installEventFilter (QObject *filterObj)
bool isQmlExposed () const const
bool isQuickItemType () const const
bool isWidgetType () const const
bool isWindowType () const const
void killTimer (int id)
void killTimer (Qt::TimerId id)
virtual const QMetaObjectmetaObject () const const
bool moveToThread (QThread *targetThread)
QString objectName () const const
void objectNameChanged (const QString &objectName)
QObjectparent () const const
QVariant property (const char *name) const const
 Q_CLASSINFO (Name, Value)
 Q_EMIT Q_EMIT
 Q_ENUM (...)
 Q_ENUM_NS (...)
 Q_ENUMS (...)
 Q_FLAG (...)
 Q_FLAG_NS (...)
 Q_FLAGS (...)
 Q_GADGET Q_GADGET
 Q_GADGET_EXPORT (EXPORT_MACRO)
 Q_INTERFACES (...)
 Q_INVOKABLE Q_INVOKABLE
 Q_MOC_INCLUDE Q_MOC_INCLUDE
 Q_NAMESPACE Q_NAMESPACE
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 Q_OBJECT Q_OBJECT
 Q_PROPERTY (...)
 Q_REVISION Q_REVISION
 Q_SET_OBJECT_NAME (Object)
 Q_SIGNAL Q_SIGNAL
 Q_SIGNALS Q_SIGNALS
 Q_SLOT Q_SLOT
 Q_SLOTS Q_SLOTS
qobject_cast (const QObject *object)
qobject_cast (QObject *object)
 QT_NO_CONTEXTLESS_CONNECT QT_NO_CONTEXTLESS_CONNECT
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
void removeEventFilter (QObject *obj)
void setObjectName (const QString &name)
void setObjectName (QAnyStringView name)
void setParent (QObject *parent)
bool setProperty (const char *name, const QVariant &value)
bool setProperty (const char *name, QVariant &&value)
bool signalsBlocked () const const
int startTimer (int interval, Qt::TimerType timerType)
int startTimer (std::chrono::nanoseconds interval, Qt::TimerType timerType)
QThreadthread () const const

Static Public Member Functions

static QString error (Context *c, const QString &msg)
static ParamsMultiMap errorQuery (Context *c, const QString &msg, ParamsMultiMap query={})
static void load (Context *c)
static QString status (Context *c, const QString &msg)
static ParamsMultiMap statusQuery (Context *c, const QString &msg, ParamsMultiMap query={})
Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect (const QMetaObject::Connection &connection)
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
QString tr (const char *sourceText, const char *disambiguation, int n)

Protected Member Functions

virtual bool setup (Application *app) override
Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
virtual void connectNotify (const QMetaMethod &signal)
virtual void customEvent (QEvent *event)
virtual void disconnectNotify (const QMetaMethod &signal)
bool isSignalConnected (const QMetaMethod &signal) const const
int receivers (const char *signal) const const
QObjectsender () const const
int senderSignalIndex () const const
virtual void timerEvent (QTimerEvent *event)

Additional Inherited Members

Public Types inherited from QObject
enum  TimerId
Public Attributes inherited from QObject
 Invalid
typedef QObjectList
Properties inherited from QObject
 objectName

Detailed Description

The StatusMessage plugin can be used to generate status messages that are saved to the user’s session that will be available over multiple requests. It distinguishes between normal status messages set via status() or statusQuery() and error messages set via error() or errorQuery(). The static load() method loads the status messages into the Context::stash() at appropriate places like the Auto() method of the root controller. The status messages will be identified by a message id put into the URL query of the request URL using the "mid" query key by default.

Usage example

Load the plugin in your applications’s init method:

#include <Cutelyst/Plugins/StatusMessage/StatusMessage>
bool MyCutelystApp::init()
{
// other initialization stuff
// ...
new StatusMessage(this);
// maybe more initialization stuff
// ...
}
StatusMessage(Application *parent)

Then use for example your root controller’s Auto method to load the messages into the stash:

#include <Cutelyst/Plugins/StatusMessage/StatusMessage>
bool Root::Auto(Context *c)
{
// other stuff
// ...
}
The Cutelyst Context.
Definition context.h:42
static void load(Context *c)

In another controller we can now generate a status and/or error message:

#include <Cutelyst/Plugins/StatusMessage/StatusMessage>
void MyOtherController::dostuff(Context *c)
{
// do some stuff like creating something
if (ok) {
// this will redirect to a new URL that has a query set with mid=messagetoken
// that will be used to load the message in the Auto method of the root controller
// into the stash
c->response()->redirect("/stuffdone",
{},
StatusMessage::statusQuery(c, "Successfully done your stuff."));
return;
}
// handle errors
// ...
}
Response * response() const noexcept
Definition context.cpp:98
void redirect(const QUrl &url, quint16 status=Found)
Definition response.cpp:222
static ParamsMultiMap statusQuery(Context *c, const QString &msg, ParamsMultiMap query={})
Logging category
cutelyst.plugins.statusmessage
Logging with Cutelyst

Definition at line 84 of file statusmessage.h.

Constructor & Destructor Documentation

◆ StatusMessage()

StatusMessage::StatusMessage ( Application * parent)
explicit

Constructs a new StatusMessage object with the given Application parent.

Definition at line 43 of file statusmessage.cpp.

References Cutelyst::Plugin::Plugin(), and QObject::parent().

Referenced by errorMgStashKey(), sessionPrefix(), setErrorMgStashKey(), setSessionPrefix(), setStatusMsgStashKey(), setTokenParam(), statusMsgStashKey(), and tokenParam().

◆ ~StatusMessage()

StatusMessage::~StatusMessage ( )
overridevirtual

Destroys the StatusMessage object.

Definition at line 50 of file statusmessage.cpp.

Member Function Documentation

◆ error()

QString StatusMessage::error ( Context * c,
const QString & msg )
staticnodiscard

Saves an error message msg and returns the generated message id (mid).

Definition at line 142 of file statusmessage.cpp.

References Cutelyst::Session::setValue().

◆ errorMgStashKey()

QString StatusMessage::errorMgStashKey ( ) const
nodiscardnoexcept

Returns the name of the stash key where error messages are loaded when load() is called. Defaults to "error_msg".

Definition at line 91 of file statusmessage.cpp.

References StatusMessage().

Referenced by setErrorMgStashKey().

◆ errorQuery()

ParamsMultiMap StatusMessage::errorQuery ( Context * c,
const QString & msg,
ParamsMultiMap query = {} )
staticnodiscard

Saves an error message msg returning query parameters with the generated message id (mid) and it's token combined with query.

Definition at line 155 of file statusmessage.cpp.

References QMultiMap::insert(), and Cutelyst::Session::setValue().

◆ load()

void StatusMessage::load ( Context * c)
static

◆ sessionPrefix()

QString StatusMessage::sessionPrefix ( ) const
nodiscardnoexcept

Returns the key prefix inside Session where messages will be stored. Defaults to "status_mg".

Definition at line 55 of file statusmessage.cpp.

References StatusMessage().

Referenced by setSessionPrefix().

◆ setErrorMgStashKey()

void StatusMessage::setErrorMgStashKey ( const QString & errorMgStashKey)

Sets the name of the stash key where error messages are loaded when load() is called. Defaults to "error_msg".

Definition at line 97 of file statusmessage.cpp.

References StatusMessage(), and errorMgStashKey().

◆ setSessionPrefix()

void StatusMessage::setSessionPrefix ( const QString & sessionPrefix)

Sets the key prefix inside Session where messages will be stored. Defaults to "status_msg".

Definition at line 61 of file statusmessage.cpp.

References StatusMessage(), and sessionPrefix().

◆ setStatusMsgStashKey()

void StatusMessage::setStatusMsgStashKey ( const QString & statusMsgStashKey)

Sets the name of the stash key where "success" status messages are loaded when load() is called. Defaults to "status_msg".

Definition at line 85 of file statusmessage.cpp.

References StatusMessage(), and statusMsgStashKey().

◆ setTokenParam()

void StatusMessage::setTokenParam ( const QString & tokenParam)

Sets the name of the URL query parameter that holds the token on the page where you want to retrieve/display the status message. Defaults to "mid".

Definition at line 73 of file statusmessage.cpp.

References StatusMessage(), and tokenParam().

◆ setup()

bool StatusMessage::setup ( Application * app)
overrideprotectedvirtual

Reimplemented from Plugin::setup().

Reimplemented from Cutelyst::Plugin.

Definition at line 198 of file statusmessage.cpp.

References QObject::connect(), and Cutelyst::Application::postForked().

◆ status()

QString StatusMessage::status ( Context * c,
const QString & msg )
staticnodiscard

Saves a status message msg and returns the generated message id (mid).

Definition at line 170 of file statusmessage.cpp.

References Cutelyst::Session::setValue().

◆ statusMsgStashKey()

QString StatusMessage::statusMsgStashKey ( ) const
nodiscardnoexcept

Returns the name of the stash key where "success" status messages are loaded when load() is called. Defaults to "status_msg".

Definition at line 79 of file statusmessage.cpp.

References StatusMessage().

Referenced by setStatusMsgStashKey().

◆ statusQuery()

ParamsMultiMap StatusMessage::statusQuery ( Context * c,
const QString & msg,
ParamsMultiMap query = {} )
staticnodiscard

Saves an status message msg returning query parameters with the generated message id (mid) and it's token combined with query.

Definition at line 183 of file statusmessage.cpp.

References QMultiMap::insert(), and Cutelyst::Session::setValue().

◆ tokenParam()

QString StatusMessage::tokenParam ( ) const
nodiscardnoexcept

Returns the name of the URL query parameter that holds the token on the page where you want to retrieve/display the status message. Defaults to "mid".

Definition at line 67 of file statusmessage.cpp.

References StatusMessage().

Referenced by setTokenParam().