TreeFrogFramework  1.18
tviewhelper.h
Go to the documentation of this file.
1 #ifndef TVIEWHELPER_H
2 #define TVIEWHELPER_H
3 
4 #include <QStringList>
5 #include <QVariant>
6 #include <QUrl>
7 #include <QPoint>
8 #include <QSize>
9 #include <QPair>
10 #include <QFileInfo>
11 #include <TGlobal>
12 #include <THtmlAttribute>
13 
14 class TActionView;
15 
16 
18 {
19 public:
20  virtual ~TViewHelper() { }
21 
22  QString linkTo(const QString &text, const QUrl &url, Tf::HttpMethod method = Tf::Get,
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, Tf::HttpMethod method = Tf::Get,
50  const QString &jsCondition = QString(),
51  const THtmlAttribute &attributes = THtmlAttribute()) const;
52 
53  QString anchorPopup(const QString &text, const QUrl &url,
54  const QString &windowTitle = QString(),
55  const QSize &size = QSize(), const QPoint &topLeft = QPoint(),
56  const QString &windowStyle = QString(),
57  const QString &jsCondition = QString(),
58  const THtmlAttribute &attributes = THtmlAttribute()) const;
59 
60  QString anchorIf(bool condition, const QString &text, const QUrl &url,
61  Tf::HttpMethod method = Tf::Get, const QString &jsCondition = QString(),
62  const THtmlAttribute &attributes = THtmlAttribute()) const;
63 
64  QString anchorUnless(bool condition, const QString &text, const QUrl &url,
65  Tf::HttpMethod method = Tf::Get, const QString &jsCondition = QString(),
66  const THtmlAttribute &attributes = THtmlAttribute()) const;
67 
68  QString anchorFunction(const QString &text, const QString &function,
69  const THtmlAttribute &attributes = THtmlAttribute()) const;
70 
71  QString formTag(const QUrl &url, Tf::HttpMethod method = Tf::Post, bool multipart = false,
72  const THtmlAttribute &attributes = THtmlAttribute());
73 
74  QString inputTag(const QString &type, const QString &name, const QVariant &value,
75  const THtmlAttribute &attributes = THtmlAttribute()) const;
76 
77  QString inputTextTag(const QString &name, const QVariant &value,
78  const THtmlAttribute &attributes = THtmlAttribute()) const;
79 
80  QString inputFileTag(const QString &name, const QVariant &value, // obsolete
81  const THtmlAttribute &attributes = THtmlAttribute()) const;
82 
83  QString inputFileTag(const QString &name,
84  const THtmlAttribute &attributes = THtmlAttribute()) const;
85 
86  QString inputPasswordTag(const QString &name, const QVariant &value,
87  const THtmlAttribute &attributes = THtmlAttribute()) const;
88 
89  QString inputHiddenTag(const QString &name, const QVariant &value,
90  const THtmlAttribute &attributes = THtmlAttribute()) const;
91 
92  QString checkBoxTag(const QString &name, const QVariant &value, bool checked = false,
93  const THtmlAttribute &attributes = THtmlAttribute()) const;
94 
95  QString checkBoxTag(const QString &name, const QString &value, const QStringList &checkedValues,
96  const THtmlAttribute &attributes = THtmlAttribute()) const;
97 
98  QString checkBoxTag(const QString &name, const QVariant &value, const QVariantList &checkedValues,
99  const THtmlAttribute &attributes = THtmlAttribute()) const;
100 
101  QString checkBoxTag(const QString &name, const QVariant &value, const QVariant &checkedValue,
102  const THtmlAttribute &attributes = THtmlAttribute()) const;
103 
104  QString radioButtonTag(const QString &name, const QVariant &value, bool checked = false,
105  const THtmlAttribute &attributes = THtmlAttribute()) const;
106 
107  QString radioButtonTag(const QString &name, const QVariant &value, const QVariant &checkedValue,
108  const THtmlAttribute &attributes = THtmlAttribute()) const;
109 
110  QString selectTag(const QString &name, int size = 1, bool multiple = false,
111  const THtmlAttribute &attributes = THtmlAttribute()) const;
112 
113  QString optionTag(const QString &text, const QVariant &value, bool selected = false,
114  const THtmlAttribute &attributes = THtmlAttribute()) const;
115 
116  QString optionTags(const QStringList &valueList, const QVariant &selectedValue = QVariant(),
117  const THtmlAttribute &attributes = THtmlAttribute()) const;
118 
119  QString optionTags(const QVariantList &valueList, const QVariant &selectedValue = QVariant(),
120  const THtmlAttribute &attributes = THtmlAttribute()) const;
121 
122  QString optionTags(const QList<QPair<QString, QVariant>> &valueList, const QVariant &selectedValue = QVariant(),
123  const THtmlAttribute &attributes = THtmlAttribute()) const;
124 
125  QString inputAuthenticityTag() const;
126 
127  QString textAreaTag(const QString &name, int rows, int cols, const QString &content = QString(),
128  const THtmlAttribute &attributes = THtmlAttribute()) const;
129 
130  QString submitTag(const QString &value, const THtmlAttribute &attributes = THtmlAttribute()) const;
131 
132  QString submitImageTag(const QString &src, const THtmlAttribute &attributes = THtmlAttribute()) const;
133 
134  QString resetTag(const QString &value, const THtmlAttribute &attributes = THtmlAttribute()) const;
135 
136  QString imageTag(const QString &src, const QSize &size = QSize(),
137  const QString &alt = QString(),
138  const THtmlAttribute &attributes = THtmlAttribute()) const;
139 
140  QString imageTag(const QString &src, bool withTimestamp,
141  const QSize &size = QSize(), const QString &alt = QString(),
142  const THtmlAttribute &attributes = THtmlAttribute()) const;
143 
144  QString imageTag(const QString &src, const THtmlAttribute &attributes) const;
145 
146  QString inlineImageTag(const QFileInfo &file, const QString &mediaType,
147  const QSize &size = QSize(), const QString &alt = QString(),
148  const THtmlAttribute &attributes = THtmlAttribute()) const;
149 
150  QString inlineImageTag(const QFileInfo &file, const QString &mediaType,
151  const THtmlAttribute &attributes) const;
152 
153  QString inlineImageTag(const QByteArray &data, const QString &mediaType,
154  const QSize &size = QSize(), const QString &alt = QString(),
155  const THtmlAttribute &attributes = THtmlAttribute()) const;
156 
157  QString inlineImageTag(const QByteArray &data, const QString &mediaType,
158  const THtmlAttribute &attributes) const;
159 
160  QString imageLinkTo(const QUrl &url, const QString &src, bool withTimestamp,
161  const QString &alt = QString(), const THtmlAttribute &attributes = THtmlAttribute()) const;
162  QString imageLinkTo(const QUrl &url, const QString &src, const THtmlAttribute &attributes = THtmlAttribute()) const;
163 
164  QString styleSheetTag(const QString &src, const THtmlAttribute &attributes) const;
165 
166  QString styleSheetTag(const QString &src, bool withTimestamp = true, const THtmlAttribute &attributes = THtmlAttribute()) const;
167 
168  QString scriptTag(const QString &src, const THtmlAttribute &attributes) const;
169 
170  QString scriptTag(const QString &src, bool withTimestamp = true, const THtmlAttribute &attributes = THtmlAttribute()) const;
171 
172  QString tag(const QString &name, const THtmlAttribute &attributes);
173 
174  QString tag(const QString &name, const THtmlAttribute &attributes, bool selfClose);
175 
176  QString tag(const QString &name, const THtmlAttribute &attributes, const QString &content) const;
177 
178  QString selfClosingTag(const QString &name, const THtmlAttribute &attributes) const;
179 
180  QString endTag(const QString &name) const;
181 
182  QString endTag();
183 
184  QString allEndTags();
185 
186  QString imagePath(const QString &src, bool withTimestamp = true) const;
187 
188  QString cssPath(const QString &src, bool withTimestamp = true) const;
189 
190  QString jsPath(const QString &src, bool withTimestamp = true) const;
191 
192  QString srcPath(const QString &src, const QString &dir, bool withTimestamp = true) const;
193 
194  THtmlAttribute a(const QString &key, const QString &value) const;
195  THtmlAttribute a() const { return THtmlAttribute(); }
196 
197 protected:
198  virtual const TActionView *actionView() const = 0;
199 
200 private:
201  QStringList endTags;
202 };
203 
204 
210 inline QString TViewHelper::linkToIf(bool condition, const QString &text, const QUrl &url, Tf::HttpMethod method,
211  const QString &jsCondition, const THtmlAttribute &attributes) const
212 {
213  return condition ? linkTo(text, url, method, jsCondition, attributes) : text;
214 }
215 
221 inline QString TViewHelper::linkToUnless(bool condition, const QString &text, const QUrl &url, Tf::HttpMethod method,
222  const QString &jsCondition, const THtmlAttribute &attributes) const
223 {
224  return linkToIf(!condition, text, url, method, jsCondition, attributes);
225 }
226 
230 inline QString TViewHelper::anchor(const QString &text, const QUrl &url, Tf::HttpMethod method,
231  const QString &jsCondition, const THtmlAttribute &attributes) const
232 {
233  return linkTo(text, url, method, jsCondition, attributes);
234 }
235 
239 inline QString TViewHelper::anchorPopup(const QString &text, const QUrl &url,
240  const QString &windowTitle,
241  const QSize &size, const QPoint &topLeft,
242  const QString &windowStyle,
243  const QString &jsCondition,
244  const THtmlAttribute &attributes) const
245 {
246  return linkToPopup(text, url, windowTitle, size, topLeft, windowStyle, jsCondition, attributes);
247 }
248 
252 inline QString TViewHelper::anchorIf(bool condition, const QString &text,
253  const QUrl &url, Tf::HttpMethod method,
254  const QString &jsCondition,
255  const THtmlAttribute &attributes) const
256 {
257  return linkToIf(condition, text, url, method, jsCondition, attributes);
258 }
259 
260 
264 inline QString TViewHelper::anchorUnless(bool condition, const QString &text,
265  const QUrl &url, Tf::HttpMethod method,
266  const QString &jsCondition,
267  const THtmlAttribute &attributes) const
268 {
269  return linkToUnless(condition, text, url, method, jsCondition, attributes);
270 }
271 
275 inline QString TViewHelper::anchorFunction(const QString &text,
276  const QString &function,
277  const THtmlAttribute &attributes) const
278 {
279  return linkToFunction(text, function, attributes);
280 }
281 
286 inline QString TViewHelper::inputTextTag(const QString &name, const QVariant &value,
287  const THtmlAttribute &attributes) const
288 {
289  return inputTag("text", name, value, attributes);
290 }
291 
292 // obsolete 'value is disabled at input type=file tag.'
293 inline QString TViewHelper::inputFileTag(const QString &name, const QVariant &value,
294  const THtmlAttribute &attributes) const
295 {
296  return inputTag("file", name, value, attributes);
297 }
298 
303 inline QString TViewHelper::inputFileTag(const QString &name,
304  const THtmlAttribute &attributes) const
305 {
306  return inputTag("file", name, QVariant(), attributes);
307 }
308 
313 inline QString TViewHelper::inputPasswordTag(const QString &name, const QVariant &value,
314  const THtmlAttribute &attributes) const
315 {
316  return inputTag("password", name, value, attributes);
317 }
318 
323 inline QString TViewHelper::inputHiddenTag(const QString &name, const QVariant &value,
324  const THtmlAttribute &attributes) const
325 {
326  return inputTag("hidden", name, value, attributes);
327 }
328 
332 inline QString TViewHelper::imageTag(const QString &src, const THtmlAttribute &attributes) const
333 {
334  return imageTag(src, QSize(), QString(), attributes);
335 }
336 
342 inline QString TViewHelper::imageLinkTo(const QUrl &url, const QString &src, bool withTimestamp,
343  const QString &alt, const THtmlAttribute &attributes) const
344 {
345  return linkTo(imageTag(src, withTimestamp, QSize(), alt, attributes), url);
346 }
347 
353 inline QString TViewHelper::imageLinkTo(const QUrl &url, const QString &src, const THtmlAttribute &attributes) const
354 {
355  return imageLinkTo(url, src, false, QString(), attributes);
356 }
357 
362 inline QString TViewHelper::inlineImageTag(const QFileInfo &file, const QString &mediaType,
363  const THtmlAttribute &attributes) const
364 {
365  return inlineImageTag(file, mediaType, QSize(), QString(), attributes);
366 }
367 
372 inline QString TViewHelper::inlineImageTag(const QByteArray &data, const QString &mediaType,
373  const THtmlAttribute &attributes) const
374 {
375  return inlineImageTag(data, mediaType, QSize(), QString(), attributes);
376 }
377 
378 #endif // TVIEWHELPER_H
#define T_CORE_EXPORT
Definition: tglobal.h:81
The TViewHelper class provides some functionality for views.
Definition: tviewhelper.h:17
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:313
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:286
Definition: tfnamespace.h:27
THtmlAttribute a() const
Returns a null THtmlAttribute object.
Definition: tviewhelper.h:195
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:210
The TActionView class is the abstract base class of views, providing functionality common to view...
Definition: tactionview.h:17
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:252
The THtmlAttribute class represents HTML attributes for customizing web elements. ...
Definition: thtmlattribute.h:9
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:323
HttpMethod
Definition: tfnamespace.h:23
Definition: tfnamespace.h:25
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:239
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:264
QString inlineImageTag(const QFileInfo &file, const QString &mediaType, const QSize &size=QSize(), const QString &alt=QString(), const THtmlAttribute &attributes=THtmlAttribute()) const
Definition: tviewhelper.cpp:484
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:447
QString inputFileTag(const QString &name, const QVariant &value, const THtmlAttribute &attributes=THtmlAttribute()) const
Definition: tviewhelper.h:293
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:221
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:275
QString anchor(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:230
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:342
virtual ~TViewHelper()
Definition: tviewhelper.h:20