TreeFrogFramework  2.8
tviewhelper.h
Go to the documentation of this file.
1 #pragma once
2 #include <QFileInfo>
3 #include <QPair>
4 #include <QPoint>
5 #include <QSize>
6 #include <QStringList>
7 #include <QUrl>
8 #include <QVariant>
9 #include <TGlobal>
10 #include <THtmlAttribute>
11 
12 class TActionView;
13 
14 
16 public:
17  virtual ~TViewHelper() { }
18 
19  QString linkTo(const QString &text, const QUrl &url,
20  const THtmlAttribute &attributes = THtmlAttribute()) const;
21 
22  QString linkTo(const QString &text, const QUrl &url, Tf::HttpMethod method,
23  const THtmlAttribute &attributes = THtmlAttribute()) const;
24 
25  QString linkTo(const QString &text, const QUrl &url, Tf::HttpMethod method,
26  const QString &jsCondition, const THtmlAttribute &attributes = THtmlAttribute()) const;
27 
28  QString linkToPopup(const QString &text, const QUrl &url,
29  const QString &windowTitle = QString(),
30  const QSize &size = QSize(), const QPoint &topLeft = QPoint(),
31  const QString &windowStyle = QString(),
32  const QString &jsCondition = QString(),
33  const THtmlAttribute &attributes = THtmlAttribute()) const;
34 
35  QString linkToIf(bool condition, const QString &text, const QUrl &url,
36  Tf::HttpMethod method = Tf::Get, const QString &jsCondition = QString(),
37  const THtmlAttribute &attributes = THtmlAttribute()) const;
38 
39  QString linkToUnless(bool condition, const QString &text, const QUrl &url,
40  Tf::HttpMethod method = Tf::Get, const QString &jsCondition = QString(),
41  const THtmlAttribute &attributes = THtmlAttribute()) const;
42 
43  QString linkToFunction(const QString &text, const QString &function,
44  const THtmlAttribute &attributes = THtmlAttribute()) const;
45 
46  QString buttonToFunction(const QString &text, const QString &function,
47  const THtmlAttribute &attributes = THtmlAttribute()) const;
48 
49  QString anchor(const QString &text, const QUrl &url,
50  const THtmlAttribute &attributes = THtmlAttribute()) const;
51 
52  QString anchor(const QString &text, const QUrl &url, Tf::HttpMethod method,
53  const THtmlAttribute &attributes = THtmlAttribute()) const;
54 
55  QString anchor(const QString &text, const QUrl &url, Tf::HttpMethod method = Tf::Get,
56  const QString &jsCondition = QString(),
57  const THtmlAttribute &attributes = THtmlAttribute()) const;
58 
59  QString anchorPopup(const QString &text, const QUrl &url,
60  const QString &windowTitle = QString(),
61  const QSize &size = QSize(), const QPoint &topLeft = QPoint(),
62  const QString &windowStyle = QString(),
63  const QString &jsCondition = QString(),
64  const THtmlAttribute &attributes = THtmlAttribute()) const;
65 
66  QString anchorIf(bool condition, const QString &text, const QUrl &url,
67  Tf::HttpMethod method = Tf::Get, const QString &jsCondition = QString(),
68  const THtmlAttribute &attributes = THtmlAttribute()) const;
69 
70  QString anchorUnless(bool condition, const QString &text, const QUrl &url,
71  Tf::HttpMethod method = Tf::Get, const QString &jsCondition = QString(),
72  const THtmlAttribute &attributes = THtmlAttribute()) const;
73 
74  QString anchorFunction(const QString &text, const QString &function,
75  const THtmlAttribute &attributes = THtmlAttribute()) const;
76 
77  QString formTag(const QUrl &url, Tf::HttpMethod method = Tf::Post, bool multipart = false,
78  const THtmlAttribute &attributes = THtmlAttribute());
79 
80  QString inputTag(const QString &type, const QString &name, const QVariant &value,
81  const THtmlAttribute &attributes = THtmlAttribute()) const;
82 
83  QString inputTextTag(const QString &name, const QVariant &value,
84  const THtmlAttribute &attributes = THtmlAttribute()) const;
85 
86  QString inputFileTag(const QString &name,
87  const THtmlAttribute &attributes = THtmlAttribute()) const;
88 
89  QString inputPasswordTag(const QString &name, const QVariant &value,
90  const THtmlAttribute &attributes = THtmlAttribute()) const;
91 
92  QString inputHiddenTag(const QString &name, const QVariant &value,
93  const THtmlAttribute &attributes = THtmlAttribute()) const;
94 
95  QString checkBoxTag(const QString &name, const QVariant &value, bool checked = false,
96  const THtmlAttribute &attributes = THtmlAttribute()) const;
97 
98  QString checkBoxTag(const QString &name, const QString &value, const QStringList &checkedValues,
99  const THtmlAttribute &attributes = THtmlAttribute()) const;
100 
101  QString checkBoxTag(const QString &name, const QVariant &value, const QVariantList &checkedValues,
102  const THtmlAttribute &attributes = THtmlAttribute()) const;
103 
104  QString checkBoxTag(const QString &name, const QVariant &value, const QVariant &checkedValue,
105  const THtmlAttribute &attributes = THtmlAttribute()) const;
106 
107  QString radioButtonTag(const QString &name, const QVariant &value, bool checked = false,
108  const THtmlAttribute &attributes = THtmlAttribute()) const;
109 
110  QString radioButtonTag(const QString &name, const QVariant &value, const QVariant &checkedValue,
111  const THtmlAttribute &attributes = THtmlAttribute()) const;
112 
113  QString selectTag(const QString &name, int size = 1, bool multiple = false,
114  const THtmlAttribute &attributes = THtmlAttribute());
115 
116  QString optionTag(const QString &text, const QVariant &value, bool selected = false,
117  const THtmlAttribute &attributes = THtmlAttribute()) const;
118 
119  QString optionTags(const QStringList &valueList, const QVariant &selectedValue = QVariant(),
120  const THtmlAttribute &attributes = THtmlAttribute()) const;
121 
122  QString optionTags(const QVariantList &valueList, const QVariant &selectedValue = QVariant(),
123  const THtmlAttribute &attributes = THtmlAttribute()) const;
124 
125  QString optionTags(const QList<QPair<QString, QVariant>> &valueList, const QVariant &selectedValue = QVariant(),
126  const THtmlAttribute &attributes = THtmlAttribute()) const;
127 
128  QString inputAuthenticityTag() const;
129 
130  QString textAreaTag(const QString &name, int rows, int cols, const QString &content = QString(),
131  const THtmlAttribute &attributes = THtmlAttribute()) const;
132 
133  QString submitTag(const QString &value, const THtmlAttribute &attributes = THtmlAttribute()) const;
134 
135  QString submitImageTag(const QString &src, const THtmlAttribute &attributes = THtmlAttribute()) const;
136 
137  QString resetTag(const QString &value, const THtmlAttribute &attributes = THtmlAttribute()) const;
138 
139  QString imageTag(const QString &src, const QSize &size = QSize(),
140  const QString &alt = QString(),
141  const THtmlAttribute &attributes = THtmlAttribute()) const;
142 
143  QString imageTag(const QString &src, bool withTimestamp,
144  const QSize &size = QSize(), const QString &alt = QString(),
145  const THtmlAttribute &attributes = THtmlAttribute()) const;
146 
147  QString imageTag(const QString &src, const THtmlAttribute &attributes) const;
148 
149  QString inlineImageTag(const QFileInfo &file, const QString &mediaType,
150  const QSize &size = QSize(), const QString &alt = QString(),
151  const THtmlAttribute &attributes = THtmlAttribute()) const;
152 
153  QString inlineImageTag(const QFileInfo &file, const QString &mediaType,
154  const THtmlAttribute &attributes) const;
155 
156  QString inlineImageTag(const QByteArray &data, const QString &mediaType,
157  const QSize &size = QSize(), const QString &alt = QString(),
158  const THtmlAttribute &attributes = THtmlAttribute()) const;
159 
160  QString inlineImageTag(const QByteArray &data, const QString &mediaType,
161  const THtmlAttribute &attributes) const;
162 
163  QString imageLinkTo(const QUrl &url, const QString &src, bool withTimestamp,
164  const QString &alt = QString(), const THtmlAttribute &attributes = THtmlAttribute()) const;
165  QString imageLinkTo(const QUrl &url, const QString &src, const THtmlAttribute &attributes = THtmlAttribute()) const;
166 
167  QString styleSheetTag(const QString &src, const THtmlAttribute &attributes) const;
168 
169  QString styleSheetTag(const QString &src, bool withTimestamp = true, const THtmlAttribute &attributes = THtmlAttribute()) const;
170 
171  QString scriptTag(const QString &src, const THtmlAttribute &attributes) const;
172 
173  QString scriptTag(const QString &src, bool withTimestamp = true, const THtmlAttribute &attributes = THtmlAttribute()) const;
174 
175  QString tag(const QString &name, const THtmlAttribute &attributes);
176 
177  QString tag(const QString &name, const THtmlAttribute &attributes, bool selfClose);
178 
179  QString tag(const QString &name, const THtmlAttribute &attributes, const QString &content) const;
180 
181  QString selfClosingTag(const QString &name, const THtmlAttribute &attributes) const;
182 
183  QString endTag(const QString &name) const;
184 
185  QString endTag();
186 
187  QString allEndTags();
188 
189  QString imagePath(const QString &src, bool withTimestamp = true) const;
190 
191  QString cssPath(const QString &src, bool withTimestamp = true) const;
192 
193  QString jsPath(const QString &src, bool withTimestamp = true) const;
194 
195  QString srcPath(const QString &src, const QString &dir, bool withTimestamp = true) const;
196 
197  THtmlAttribute a(const QString &key, const QString &value) const;
198  THtmlAttribute a() const { return THtmlAttribute(); }
199 
200  void clear();
201 
202 protected:
203  virtual const TActionView *actionView() const = 0;
204 
205 private:
206  QStringList endTags;
207 };
208 
209 
214 inline QString TViewHelper::linkTo(const QString &text, const QUrl &url, const THtmlAttribute &attributes) const
215 {
216  return linkTo(text, url, Tf::Get, QString(), attributes);
217 }
218 
224 inline QString TViewHelper::linkToIf(bool condition, const QString &text, const QUrl &url, Tf::HttpMethod method,
225  const QString &jsCondition, const THtmlAttribute &attributes) const
226 {
227  return condition ? linkTo(text, url, method, jsCondition, attributes) : text;
228 }
229 
235 inline QString TViewHelper::linkToUnless(bool condition, const QString &text, const QUrl &url, Tf::HttpMethod method,
236  const QString &jsCondition, const THtmlAttribute &attributes) const
237 {
238  return linkToIf(!condition, text, url, method, jsCondition, attributes);
239 }
240 
244 inline QString TViewHelper::anchor(const QString &text, const QUrl &url, const THtmlAttribute &attributes) const
245 {
246  return linkTo(text, url, attributes);
247 }
248 
252 inline QString TViewHelper::anchor(const QString &text, const QUrl &url, Tf::HttpMethod method,
253  const THtmlAttribute &attributes) const
254 {
255  return linkTo(text, url, method, attributes);
256 }
257 
261 inline QString TViewHelper::anchor(const QString &text, const QUrl &url, Tf::HttpMethod method,
262  const QString &jsCondition, const THtmlAttribute &attributes) const
263 {
264  return linkTo(text, url, method, jsCondition, attributes);
265 }
266 
270 inline QString TViewHelper::anchorPopup(const QString &text, const QUrl &url,
271  const QString &windowTitle,
272  const QSize &size, const QPoint &topLeft,
273  const QString &windowStyle,
274  const QString &jsCondition,
275  const THtmlAttribute &attributes) const
276 {
277  return linkToPopup(text, url, windowTitle, size, topLeft, windowStyle, jsCondition, attributes);
278 }
279 
283 inline QString TViewHelper::anchorIf(bool condition, const QString &text,
284  const QUrl &url, Tf::HttpMethod method,
285  const QString &jsCondition,
286  const THtmlAttribute &attributes) const
287 {
288  return linkToIf(condition, text, url, method, jsCondition, attributes);
289 }
290 
291 
295 inline QString TViewHelper::anchorUnless(bool condition, const QString &text,
296  const QUrl &url, Tf::HttpMethod method,
297  const QString &jsCondition,
298  const THtmlAttribute &attributes) const
299 {
300  return linkToUnless(condition, text, url, method, jsCondition, attributes);
301 }
302 
306 inline QString TViewHelper::anchorFunction(const QString &text,
307  const QString &function,
308  const THtmlAttribute &attributes) const
309 {
310  return linkToFunction(text, function, attributes);
311 }
312 
317 inline QString TViewHelper::inputTextTag(const QString &name, const QVariant &value,
318  const THtmlAttribute &attributes) const
319 {
320  return inputTag("text", name, value, attributes);
321 }
322 
327 inline QString TViewHelper::inputFileTag(const QString &name,
328  const THtmlAttribute &attributes) const
329 {
330  return inputTag("file", name, QVariant(), attributes);
331 }
332 
337 inline QString TViewHelper::inputPasswordTag(const QString &name, const QVariant &value,
338  const THtmlAttribute &attributes) const
339 {
340  return inputTag("password", name, value, attributes);
341 }
342 
347 inline QString TViewHelper::inputHiddenTag(const QString &name, const QVariant &value,
348  const THtmlAttribute &attributes) const
349 {
350  return inputTag("hidden", name, value, attributes);
351 }
352 
356 inline QString TViewHelper::imageTag(const QString &src, const THtmlAttribute &attributes) const
357 {
358  return imageTag(src, QSize(), QString(), attributes);
359 }
360 
366 inline QString TViewHelper::imageLinkTo(const QUrl &url, const QString &src, bool withTimestamp,
367  const QString &alt, const THtmlAttribute &attributes) const
368 {
369  return linkTo(imageTag(src, withTimestamp, QSize(), alt, attributes), url);
370 }
371 
377 inline QString TViewHelper::imageLinkTo(const QUrl &url, const QString &src, const THtmlAttribute &attributes) const
378 {
379  return imageLinkTo(url, src, false, QString(), attributes);
380 }
381 
386 inline QString TViewHelper::inlineImageTag(const QFileInfo &file, const QString &mediaType,
387  const THtmlAttribute &attributes) const
388 {
389  return inlineImageTag(file, mediaType, QSize(), QString(), attributes);
390 }
391 
396 inline QString TViewHelper::inlineImageTag(const QByteArray &data, const QString &mediaType,
397  const THtmlAttribute &attributes) const
398 {
399  return inlineImageTag(data, mediaType, QSize(), QString(), attributes);
400 }
401 
The TActionView class is the abstract base class of views, providing functionality common to view.
Definition: tactionview.h:14
The THtmlAttribute class represents HTML attributes for customizing web elements.
Definition: thtmlattribute.h:7
The TViewHelper class provides some functionality for views.
Definition: tviewhelper.h:15
QString anchorIf(bool condition, const QString &text, const QUrl &url, Tf::HttpMethod method=Tf::Get, const QString &jsCondition=QString(), const THtmlAttribute &attributes=THtmlAttribute()) const
Creates a <a> link tag with the given arguments.
Definition: tviewhelper.h:283
virtual ~TViewHelper()
Definition: tviewhelper.h:17
QString anchorFunction(const QString &text, const QString &function, const THtmlAttribute &attributes=THtmlAttribute()) const
Creates a <a> link tag with the given arguments.
Definition: tviewhelper.h:306
QString linkToPopup(const QString &text, const QUrl &url, const QString &windowTitle=QString(), const QSize &size=QSize(), const QPoint &topLeft=QPoint(), const QString &windowStyle=QString(), const QString &jsCondition=QString(), const THtmlAttribute &attributes=THtmlAttribute()) const
Creates a <a> link tag of the given text using a given URL url in a popup window with the name window...
Definition: tviewhelper.cpp:80
QString linkToUnless(bool condition, const QString &text, const QUrl &url, Tf::HttpMethod method=Tf::Get, const QString &jsCondition=QString(), const THtmlAttribute &attributes=THtmlAttribute()) const
Creates a <a> link tag of the given text using the given url.
Definition: tviewhelper.h:235
QString inputTextTag(const QString &name, const QVariant &value, const THtmlAttribute &attributes=THtmlAttribute()) const
Creates a input tag with type="text", name="name" and value="value".
Definition: tviewhelper.h:317
QString imageLinkTo(const QUrl &url, const QString &src, bool withTimestamp, const QString &alt=QString(), const THtmlAttribute &attributes=THtmlAttribute()) const
Creates a <a> link tag of a given url with a <img> tag of src="src".
Definition: tviewhelper.h:366
QString inputPasswordTag(const QString &name, const QVariant &value, const THtmlAttribute &attributes=THtmlAttribute()) const
Creates a input tag with type="password", name="name" and value="value".
Definition: tviewhelper.h:337
QString inlineImageTag(const QFileInfo &file, const QString &mediaType, const QSize &size=QSize(), const QString &alt=QString(), const THtmlAttribute &attributes=THtmlAttribute()) const
Definition: tviewhelper.cpp:485
QString linkToIf(bool condition, const QString &text, const QUrl &url, Tf::HttpMethod method=Tf::Get, const QString &jsCondition=QString(), const THtmlAttribute &attributes=THtmlAttribute()) const
Creates a <a> link tag of the given text using the given url.
Definition: tviewhelper.h:224
QString inputHiddenTag(const QString &name, const QVariant &value, const THtmlAttribute &attributes=THtmlAttribute()) const
Creates a input tag with type="hidden", name="name" and value="value".
Definition: tviewhelper.h:347
QString inputTag(const QString &type, const QString &name, const QVariant &value, const THtmlAttribute &attributes=THtmlAttribute()) const
Creates a <input> input tag with type="type", name="name" and value="value".
Definition: tviewhelper.cpp:219
QString anchorUnless(bool condition, const QString &text, const QUrl &url, Tf::HttpMethod method=Tf::Get, const QString &jsCondition=QString(), const THtmlAttribute &attributes=THtmlAttribute()) const
Creates a <a> link tag with the given arguments.
Definition: tviewhelper.h:295
QString anchorPopup(const QString &text, const QUrl &url, const QString &windowTitle=QString(), const QSize &size=QSize(), const QPoint &topLeft=QPoint(), const QString &windowStyle=QString(), const QString &jsCondition=QString(), const THtmlAttribute &attributes=THtmlAttribute()) const
Creates a <a> link tag with the given arguments.
Definition: tviewhelper.h:270
QString linkTo(const QString &text, const QUrl &url, const THtmlAttribute &attributes=THtmlAttribute()) const
Creates a <a> link tag of the given text using the given URL url and HTML attributes attributes.
Definition: tviewhelper.h:214
QString inputFileTag(const QString &name, const THtmlAttribute &attributes=THtmlAttribute()) const
Creates a input tag with type="file", name="name".
Definition: tviewhelper.h:327
QString imageTag(const QString &src, const QSize &size=QSize(), const QString &alt=QString(), const THtmlAttribute &attributes=THtmlAttribute()) const
Creates a <img> image tag with src="src".
Definition: tviewhelper.cpp:448
QString anchor(const QString &text, const QUrl &url, const THtmlAttribute &attributes=THtmlAttribute()) const
Creates a <a> link tag with the given arguments.
Definition: tviewhelper.h:244
THtmlAttribute a() const
Returns a null THtmlAttribute object.
Definition: tviewhelper.h:198
QString linkToFunction(const QString &text, const QString &function, const THtmlAttribute &attributes=THtmlAttribute()) const
Creates a <a> link tag whose onclick handler triggers the passed JavaScript.
Definition: tviewhelper.cpp:127
virtual const TActionView * actionView() const =0
Must be overridden by subclasses to return the current action view.
HttpMethod
Definition: tfnamespace.h:21
@ Post
Definition: tfnamespace.h:25
@ Get
Definition: tfnamespace.h:23
#define T_CORE_EXPORT
Definition: tdeclexport.h:28