TreeFrogFramework  1.18
tactionview.h
Go to the documentation of this file.
1 #ifndef TACTIONVIEW_H
2 #define TACTIONVIEW_H
3 
4 #include <QObject>
5 #include <QTextStream>
6 #include <QVariant>
7 #include <TGlobal>
8 #include <TActionHelper>
9 #include <TViewHelper>
10 #include <THttpRequest>
11 #include <TPrototypeAjaxHelper>
12 #include <THttpUtility>
13 
14 class TActionController;
15 
16 
17 class T_CORE_EXPORT TActionView : public QObject, public TActionHelper, public TViewHelper, public TPrototypeAjaxHelper
18 {
19 public:
20  TActionView();
21  virtual ~TActionView() { }
22 
23  virtual QString toString() = 0;
24  QString yield() const;
25  QString renderPartial(const QString &templateName, const QVariantMap &vars = QVariantMap()) const;
26  QString authenticityToken() const;
27  QVariant variant(const QString &name) const;
28  bool hasVariant(const QString &name) const;
29  const TActionController *controller() const;
30  const THttpRequest &httpRequest() const;
31 
32 protected:
33  QString echo(const QString &str);
34  QString echo(const char *str);
35  QString echo(const QByteArray &str);
36  QString echo(int n, int base = 10);
37  QString echo(long n, int base = 10);
38  QString echo(ulong n, int base = 10);
39  QString echo(qlonglong n, int base = 10);
40  QString echo(qulonglong n, int base = 10);
41  QString echo(double d, char format = 'g', int precision = 6);
42  QString echo(const THtmlAttribute &attr);
43  QString echo(const QVariant &var);
44  QString eh(const QString &str);
45  QString eh(const char *str);
46  QString eh(const QByteArray &str);
47  QString eh(int n, int base = 10);
48  QString eh(long n, int base = 10);
49  QString eh(ulong n, int base = 10);
50  QString eh(qlonglong n, int base = 10);
51  QString eh(qulonglong n, int base = 10);
52  QString eh(double d, char format = 'g', int precision = 6);
53  QString eh(const THtmlAttribute &attr);
54  QString eh(const QVariant &var);
55  QString renderReact(const QString &component);
56  QString responsebody;
57 
58 private:
61 
62  void setVariantMap(const QVariantMap &vars);
63  void setController(TActionController *controller);
64  void setSubActionView(TActionView *actionView);
65  virtual const TActionView *actionView() const { return this; }
66 
67  TActionController *actionController;
68  TActionView *subView;
69  QVariantMap variantMap;
70 
71  friend class TActionController;
72  friend class TActionMailer;
73  friend class TDirectView;
74 };
75 
76 
77 inline void TActionView::setSubActionView(TActionView *actionView)
78 {
79  subView = actionView;
80 }
81 
83 {
84  return actionController;
85 }
86 
87 inline void TActionView::setVariantMap(const QVariantMap &vars)
88 {
89  variantMap = vars;
90 }
91 
92 inline QVariant TActionView::variant(const QString &name) const
93 {
94  return variantMap.value(name);
95 }
96 
97 inline bool TActionView::hasVariant(const QString &name) const
98 {
99  return variantMap.contains(name);
100 }
101 
102 inline QString TActionView::echo(const QString &str)
103 {
104  responsebody += str;
105  return QString();
106 }
107 
108 inline QString TActionView::echo(const char *str)
109 {
110  responsebody += QString(str); // using codecForCStrings()
111  return QString();
112 }
113 
114 inline QString TActionView::echo(const QByteArray &str)
115 {
116  responsebody += QString(str); // using codecForCStrings()
117  return QString();
118 }
119 
120 inline QString TActionView::echo(int n, int base)
121 {
122  responsebody += QString::number(n, base);
123  return QString();
124 }
125 
126 inline QString TActionView::echo(long n, int base)
127 {
128  responsebody += QString::number(n, base);
129  return QString();
130 }
131 
132 inline QString TActionView::echo(ulong n, int base)
133 {
134  responsebody += QString::number(n, base);
135  return QString();
136 }
137 
138 inline QString TActionView::echo(qlonglong n, int base)
139 {
140  responsebody += QString::number(n, base);
141  return QString();
142 }
143 
144 inline QString TActionView::echo(qulonglong n, int base)
145 {
146  responsebody += QString::number(n, base);
147  return QString();
148 }
149 
150 inline QString TActionView::echo(double d, char format, int precision)
151 {
152  responsebody += QString::number(d, format, precision);
153  return QString();
154 }
155 
156 inline QString TActionView::eh(const QString &str)
157 {
158  return echo(THttpUtility::htmlEscape(str));
159 }
160 
161 inline QString TActionView::eh(const char *str)
162 {
163  return echo(THttpUtility::htmlEscape(str));
164 }
165 
166 inline QString TActionView::eh(const QByteArray &str)
167 {
168  return echo(THttpUtility::htmlEscape(str));
169 }
170 
171 inline QString TActionView::eh(int n, int base)
172 {
173  return echo(THttpUtility::htmlEscape(QString::number(n, base)));
174 }
175 
176 inline QString TActionView::eh(long n, int base)
177 {
178  return echo(THttpUtility::htmlEscape(QString::number(n, base)));
179 }
180 
181 inline QString TActionView::eh(ulong n, int base)
182 {
183  return echo(THttpUtility::htmlEscape(QString::number(n, base)));
184 }
185 
186 inline QString TActionView::eh(qlonglong n, int base)
187 {
188  return echo(THttpUtility::htmlEscape(QString::number(n, base)));
189 }
190 
191 inline QString TActionView::eh(qulonglong n, int base)
192 {
193  return echo(THttpUtility::htmlEscape(QString::number(n, base)));
194 }
195 
196 inline QString TActionView::eh(double d, char format, int precision)
197 {
198  return echo(THttpUtility::htmlEscape(QString::number(d, format, precision)));
199 }
200 
201 inline void TActionView::setController(TActionController *controller)
202 {
203  actionController = controller;
204 }
205 
206 #endif // TACTIONVIEW_H
#define T_CORE_EXPORT
Definition: tglobal.h:81
The TViewHelper class provides some functionality for views.
Definition: tviewhelper.h:17
QString eh(const QString &str)
Outputs a escaped string of the str to a view template.
Definition: tactionview.h:156
#define T_DISABLE_COPY(Class)
Definition: tglobal.h:137
#define T_DISABLE_MOVE(Class)
Definition: tglobal.h:141
virtual const TActionController * controller() const =0
bool hasVariant(const QString &name) const
Returns true if the QVariantMap variable for a view contains an item with the name; otherwise returns...
Definition: tactionview.h:97
virtual ~TActionView()
Definition: tactionview.h:21
QVariant variant(const QString &name) const
Returns the value associated with the name in the QVariantMap variable for a view.
Definition: tactionview.h:92
The TActionView class is the abstract base class of views, providing functionality common to view...
Definition: tactionview.h:17
The THttpRequest class contains request information for HTTP.
Definition: thttprequest.h:38
virtual const TActionView * actionView() const =0
The THtmlAttribute class represents HTML attributes for customizing web elements. ...
Definition: thtmlattribute.h:9
The TPrototypeAjaxHelper provides some functionality for Ajax of Prototype JavaScript framework...
Definition: tprototypeajaxhelper.h:15
The TActionHelper class is the base class of all helpers.
Definition: tactionhelper.h:14
const TActionController * controller() const
Definition: tactionview.h:82
QString responsebody
Definition: tactionview.h:56
The TActionController class is the base class of all action controllers.
Definition: tactioncontroller.h:28
The TActionMailer class provides a mail client on action controller.
Definition: tactionmailer.h:7
static QString htmlEscape(const QString &input, Tf::EscapeFlag flag=Tf::Quotes)
Returns a converted copy of input.
Definition: thttputility.cpp:116
QString echo(const QString &str)
Outputs the string str to a view template.
Definition: tactionview.h:102