-
-
Notifications
You must be signed in to change notification settings - Fork 226
/
Copy pathtabstractcontroller.cpp
184 lines (145 loc) · 4.75 KB
/
tabstractcontroller.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/* Copyright (c) 2011-2019, AOYAMA Kazuharu
* All rights reserved.
*
* This software may be used and distributed according to the terms of
* the New BSD License, which is incorporated herein by reference.
*/
#include "tsystemglobal.h"
#include <TAbstractController>
#include <TFormValidator>
/*!
\class TAbstractController
\brief The TAbstractController class is the abstract base class
of controllers, providing functionality common to controllers.
*/
/*!
Constructor.
*/
TAbstractController::TAbstractController() :
QObject()
{
}
/*!
Exports a new variable with the name \a name and a value of \a value for views.
Internal use only.
*/
void TAbstractController::exportVariant(const QString &name, const QVariant &value, bool overwrite)
{
if (!value.isValid()) {
tSystemWarn("An invalid QVariant object for exportVariant(), name:{}", qUtf8Printable(name));
return;
}
if (overwrite || !_exportVars.contains(name)) {
_exportVars.insert(name, value);
}
}
/*!
Exports the \a map.
Internal use only.
*/
void TAbstractController::exportVariants(const QVariantMap &map)
{
if (_exportVars.isEmpty()) {
_exportVars = map;
} else {
auto tmp = _exportVars;
_exportVars = map;
_exportVars.insert(tmp);
}
}
/*!
Exports validation error messages with the prefix \a prefix each.
*/
void TAbstractController::exportValidationErrors(const TFormValidator &v, const QString &prefix)
{
for (auto &key : (const QStringList &)v.validationErrorKeys()) {
QString msg = v.errorMessage(key);
exportVariant(prefix + key, QVariant(msg));
}
}
/*!
Returns a class name of a view for the action \a action of the
active controller. Internal use only.
*/
QString TAbstractController::viewClassName(const QString &action) const
{
return viewClassName("", action);
}
/*!
Returns a class name of a view for the action \a action of the
controller \a controller. Internal use only.
*/
QString TAbstractController::viewClassName(const QString &contoller, const QString &action) const
{
// If action string is empty, active action name.
// If controller string is empty, active contoller name.
return (contoller.isEmpty() ? name().toLower() : contoller.toLower()) + '_' + (action.isEmpty() ? activeAction() : action) + QLatin1String("View");
}
void TAbstractController::setFlash(const QString &, const QVariant &)
{
throw StandardException("Not implemented error", __FILE__, __LINE__);
}
QString TAbstractController::getRenderingData(const QString &, const QVariantMap &)
{
throw StandardException("Not implemented error", __FILE__, __LINE__);
}
const THttpRequest &TAbstractController::httpRequest() const
{
throw StandardException("Not implemented error", __FILE__, __LINE__);
}
const THttpRequest &TAbstractController::request() const
{
throw StandardException("Not implemented error", __FILE__, __LINE__);
}
const TSession &TAbstractController::session() const
{
throw StandardException("Not implemented error", __FILE__, __LINE__);
}
TSession &TAbstractController::session()
{
throw StandardException("Not implemented error", __FILE__, __LINE__);
}
bool TAbstractController::addCookie(const TCookie &)
{
throw StandardException("Not implemented error", __FILE__, __LINE__);
}
bool TAbstractController::addCookie(const QByteArray &, const QByteArray &, const QDateTime &, const QString &, const QString &, bool, bool, const QByteArray &)
{
throw StandardException("Not implemented error", __FILE__, __LINE__);
}
bool TAbstractController::addCookie(const QByteArray &, const QByteArray &, int64_t , const QString &, const QString &, bool, bool, const QByteArray &)
{
throw StandardException("Not implemented error", __FILE__, __LINE__);
}
/*!
Returns true if a user is logged in to the system; otherwise returns false.
This is a virtual function.
\sa userLogin()
*/
bool TAbstractController::isUserLoggedIn() const
{
throw StandardException("Not implemented error", __FILE__, __LINE__);
}
/*!
\fn const QVariantMap &TAbstractController::allVariants() const
Returns all the exported variables. Internal use only.
*/
/*!
\fn virtual QString TAbstractController::name() const
This function is reimplemented in subclasses to return a
controller name.
*/
/*!
\fn virtual QString TAbstractController::activeAction() const
This function is reimplemented in subclasses to return a active
action name.
*/
/*!
\fn QVariant TAbstractController::variant(const QString &name) const
Returns the exported variable with the value associated with the \a name.
*/
/*!
\fn bool TAbstractController::hasVariant(const QString &name) const
Returns true if a variable with the \a name is exported for views; otherwise returns false.
Internal use only.
*/