18 #ifndef CUTELYST_CONTEXT_H
19 #define CUTELYST_CONTEXT_H
21 #include <QtCore/QObject>
22 #include <QtCore/QVariant>
23 #include <QtCore/QUrl>
24 #include <QtCore/QStringList>
25 #include <QtCore/QStack>
27 #include <Cutelyst/request.h>
28 #include <Cutelyst/cutelyst_global.h>
50 class CUTELYST_LIBRARY
Context :
public QObject
53 Q_PROPERTY(
Action* action READ action CONSTANT)
54 Q_PROPERTY(QString actionName READ actionName CONSTANT)
55 Q_PROPERTY(QString ns READ ns CONSTANT)
56 Q_PROPERTY(QString
namespace READ ns CONSTANT)
57 Q_PROPERTY(
Request *req READ request CONSTANT)
58 Q_PROPERTY(
Request *request READ request CONSTANT)
59 Q_PROPERTY(
Controller *controller READ controller CONSTANT)
60 Q_PROPERTY(QString controllerName READ controllerName CONSTANT)
61 Q_PROPERTY(QVariantMap config READ config CONSTANT)
62 Q_PROPERTY(
bool state READ state CONSTANT)
80 void error(
const QString &error);
85 QStringList errors()
const;
96 void setState(
bool state);
126 QString actionName()
const;
156 QString controllerName()
const;
167 Controller *controller(
const QString &name)
const;
172 View *view(
const QString &name = QString())
const;
179 View *customView()
const;
192 bool setCustomView(
const QString &name);
213 inline void stash(
const QVariantHash &unite);
226 QVariantHash &stash();
231 QVariant stash(
const QString &key)
const;
236 QVariant stash(
const QString &key,
const QVariant &defaultValue)
const;
243 QVariant stashTake(
const QString &key);
249 bool stashRemove(
const QString &key);
254 void setStash(
const QString &key,
const QVariant &value);
264 QStack<Component *> stack()
const;
277 QUrl uriFor(
const QString &path = QString(),
278 const QStringList &args = QStringList(),
291 inline QUrl uriFor(
const QString &path,
303 QUrl uriFor(
Action *action,
304 const QStringList &captures = QStringList(),
305 const QStringList &args = QStringList(),
313 inline QUrl uriFor(
Action *action,
339 QUrl uriForAction(
const QString &path,
340 const QStringList &captures = QStringList(),
341 const QStringList &args = QStringList(),
347 inline QUrl uriForAction(
const QString &path,
354 bool detached()
const;
361 void detach(
Action *action =
nullptr);
423 bool forward(
const QString &action);
428 Action *getAction(
const QString &action,
const QString &ns = QString())
const;
433 QVector<Action *> getActions(
const QString &action,
const QString &ns = QString())
const;
438 QVector<Plugin *> plugins()
const;
443 template <
typename T>
446 const auto pluginsConst = plugins();
447 for (
Plugin *plugin : pluginsConst) {
448 auto p = qobject_cast<T>(plugin);
468 QLocale locale()
const;
484 void setLocale(
const QLocale &locale);
489 QVariant config(
const QString &key,
const QVariant &defaultValue = QVariant())
const;
494 QVariantMap config()
const;
509 QString translate(
const char *context,
const char *sourceText,
const char *disambiguation =
nullptr,
int n = -1)
const;
523 Q_DECL_DEPRECATED
bool wait(uint count = 1);
536 void next(
bool force =
false);
552 ContextPrivate *d_ptr;
559 {
stash().unite(unite); }
562 {
return uriFor(path, QStringList(), queryValues); }
565 {
return uriFor(action, QStringList(), QStringList(), queryValues); }
568 {
return uriForAction(path, QStringList(), QStringList(), queryValues); }
574 #endif // CUTELYST_CONTEXT_H