cutelyst 4.3.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
|
Cutelyst Controller base class. More...
#include <Cutelyst/Controller>
Public Member Functions | |
Controller (QObject *parent=nullptr) | |
Action * | actionFor (QStringView name) const |
ActionList | actions () const noexcept |
QString | ns () const noexcept |
bool | operator== (const char *className) |
Public Member Functions inherited from QObject | |
QObject (QObject *parent) | |
bool | blockSignals (bool block) |
const QObjectList & | children () 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< QByteArray > | dynamicPropertyNames () const const |
virtual bool | event (QEvent *e) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
T | findChild (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QString &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 | isQuickItemType () const const |
bool | isWidgetType () const const |
bool | isWindowType () const const |
void | killTimer (int id) |
virtual const QMetaObject * | metaObject () const const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const const |
void | objectNameChanged (const QString &objectName) |
QObject * | parent () const const |
QVariant | property (const char *name) const const |
Q_CLASSINFO (Name, Value) | |
Q_DISABLE_COPY (Class) | |
Q_DISABLE_COPY_MOVE (Class) | |
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 | |
T | qobject_cast (const QObject *object) |
T | qobject_cast (QObject *object) |
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 | signalsBlocked () const const |
int | startTimer (int interval, Qt::TimerType timerType) |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType) |
QThread * | thread () const const |
Protected Member Functions | |
bool | _DISPATCH (Context *c) |
virtual bool | postFork (Application *app) |
virtual bool | preFork (Application *app) |
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 |
QObject * | sender () const const |
int | senderSignalIndex () const const |
virtual void | timerEvent (QTimerEvent *event) |
Friends | |
class | Application |
class | Dispatcher |
Related Symbols | |
(Note that these are not member symbols.) | |
#define | C_ATTR(X, Y) |
#define | C_NAMESPACE(value) |
#define | CActionFor(str) |
Additional Inherited Members | |
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) |
Public Attributes inherited from QObject | |
typedef | QObjectList |
Properties inherited from QObject | |
objectName | |
Controllers are where the actions in the Cutelyst framework reside. Each action is represented by a function/method with an attribute to identify what kind of action it is. See the Cutelyst::Dispatcher for more information about how Cutelyst dispatches to actions.
If not explicitely set by C_NAMESPACE() macro, the controller namespace will be generated from the C++ class name and optional C++ namespace name the class is part of. Camel-case class and namespace names like FooBar
will be converted into a controller namespace foo/bar
, while Foo
would be only the foo
controller namespace. A class FooBar
inside C++ namespace FuBaz
would have the controller namespace /fu/baz/foo/bar
.
The controller namespace will be prepended to the public path of your controller methods unless you specify a global public path.
A root namespace can be created by setting an empty controller namespace with C_NAMESPACE("").
Public paths are the routes that you can call with your user agent like the web browser. Private paths are internally used and can for example be used to get an URI via Context::uriForAction(). The public path has not to be the same like the private path, but it can be the same.
While the public path is created with the :Path attribute prepended by the controller namespace or from multiple
:Chained actions, the private path will be the function/method name prepended by the controller namespace.
Use the C_ATTR() macro to give hints about methods build like C_ATTR(methodName, options), where options are some of the following:
Indicates the number of expected arguments on a public path. If omitted, an unlimited number of args will be accepted. Can also be set to 0
to expect no arguments.
Arguments are the request url parts behind your public route path. Like if your public path is /foo/bar
and you call /foo/bar/fu/baz and there is no other path fitting that and if your /foo/bar
path will expect two arguments, the method behind foo/bar
would be called with the two arguments 'fu'
and 'baz'
.
Methods are only exposed to the dispatcher when they have a C_ATTR() macro in front and have a pointer to a Context object as first parameter. If the method should take request arguments it should either have QStringList to take the arguments from Request::arguments() or the expected amount of QString parameters.
There are also three special methods that can be implemented that will be automatically dispatched, they are Begin(), Auto() and End().
Called on the closest namespace match. If the Controller implements Begin(), it’s that action that will be called. Otherwise it will try to match looking at the namespace. So there will be only one Begin() action dispatched.
Begin will be dispached as first action before the Auto() actions and the actual action will be dispatched.
Foo
and a FooBar
controller with 'foo' and 'foo/bar' namespaces and both implement Auto() and you call an action on the 'foo/bar' namespace, you get Foo->Auto() and FooBar->Auto() called. Definition at line 55 of file controller.h.
|
explicit |
Constructs a Controller object with the given parent
.
Definition at line 240 of file controller.cpp.
|
virtual |
Definition at line 246 of file controller.cpp.
|
protected |
This is called by the dispatch engine to do the contextual action dispatching. Transversing nearest Begin(), each namespace’s Auto(), the Action method of this controller and nearest End().
Definition at line 377 of file controller.cpp.
References Cutelyst::Context::action, and Cutelyst::Action::dispatch().
Referenced by Cutelyst::Dispatcher::dispatch().
Action * Controller::actionFor | ( | QStringView | name | ) | const |
Returns the Cutelyst::Action object (if any) for a given method name in this class namespace.
You can also use the macro CActionFor to keep the resolved action around.
Definition at line 259 of file controller.cpp.
References QStringView::toString().
Referenced by Cutelyst::RoleACL::dispatcherReady().
|
noexcept |
Returns the Cutelyst::ActionList containing all actions which belongs to this controller.
Definition at line 269 of file controller.cpp.
Referenced by Cutelyst::Dispatcher::setupActions().
|
noexcept |
This specifies the internal namespace the controller should be bound to. By default the controller is bound to the URI version of the controller name. For instance a controller named 'MyFooBar' will be bound to 'my/foo/bar'. The default Root controller is an example of setting namespace to '' (the null string).
Definition at line 253 of file controller.cpp.
bool Controller::operator== | ( | const char * | className | ) |
Return TRUE if className is equal to this Controller's name
Definition at line 275 of file controller.cpp.
References QObject::metaObject().
|
protectedvirtual |
This method is called after the application has registered all controllers.
Reimplement this method if you need to configure internal variable and you need to know for example which configuration options are enabled.
Definition at line 286 of file controller.cpp.
|
protectedvirtual |
This method is called right after Controller has been setup and before application forks and postFork() is called.
Reimplement this method if you need to configure internal variable and you need to know for example which configuration options are enabled.
Definition at line 280 of file controller.cpp.
|
friend |
Definition at line 129 of file controller.h.
|
related |
Sets method attributes Y to method X and marks the method as Q_INVOKABLE.
Definition at line 41 of file controller.h.
|
related |
Explicitely sets the controller namespace to value. Use this in the private part of your controller declaration.
Definition at line 23 of file controller.h.
|
related |
Definition at line 46 of file controller.h.
|
friend |
Definition at line 130 of file controller.h.