forked from treefrogframework/treefrog-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtabstractcontroller.cpp
More file actions
116 lines (97 loc) · 3 KB
/
Copy pathtabstractcontroller.cpp
File metadata and controls
116 lines (97 loc) · 3 KB
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
/* 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()
{
}
/*!
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:%s", qPrintable(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 {
exportVars.unite(map);
}
}
/*!
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");
}
/*!
\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.
*/