-
Notifications
You must be signed in to change notification settings - Fork 10
/
formfielddescriptor.cpp
102 lines (87 loc) · 2.71 KB
/
formfielddescriptor.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
/*
* Copyright 2012 Aarhus University
*
* Licensed under the GNU General Public License, Version 3 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/gpl-3.0.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <assert.h>
#include <QDebug>
#include "artemisglobals.h"
#include "formfielddescriptor.h"
namespace artemis
{
FormFieldDescriptor::FormFieldDescriptor(FormFieldTypes type, DOMElementDescriptorConstPtr element, QSet<QString> inputOptions) :
mFieldType(type),
mDomElementDescriptor(element),
mInputOptions(inputOptions)
{
}
FormFieldDescriptor::FormFieldDescriptor(FormFieldTypes type, DOMElementDescriptorConstPtr element) :
mFieldType(type),
mDomElementDescriptor(element)
{
}
QDebug operator<<(QDebug dbg, const FormFieldDescriptor& f)
{
dbg.nospace() << "{" << f.mDomElementDescriptor->toString() << "," << f.formFieldTypeTostring(f.mFieldType) << "," << f.mInputOptions << "}";
return dbg.space();
}
FormFieldTypes getTypeFromAttr(QString typeAttr)
{
if (typeAttr.isEmpty()) {
return TEXT;
} //de facto standard;
typeAttr = typeAttr.toLower();
/** Types :
button
checkbox
file
hidden
image
password
radio
reset
submit
text
*/
// Should match the list in CodeGeneratorJS.pm
if (typeAttr == "button"
|| typeAttr == "hidden"
|| typeAttr == "submit"
|| typeAttr == "reset"
|| typeAttr == "image")
{ return NO_INPUT; }
if (typeAttr == "checkbox"
|| typeAttr == "radio")
{ return BOOLEAN; }
if (typeAttr == "password"
|| typeAttr == "text"
|| typeAttr == "email" //HTML5
|| typeAttr == "file"
|| typeAttr == "search" //HTML5
|| typeAttr == "url" //HTML5
|| typeAttr == "week" //HTML5
|| typeAttr == "time" //HTML5
|| typeAttr == "tel" //HTML5
|| typeAttr == "range" //HTML5
|| typeAttr == "number" //HTML5
|| typeAttr == "month" //HTML5
|| typeAttr == "datetime-local" //HTML5
|| typeAttr == "datetime" //HTML5
|| typeAttr == "date" //HTML5
|| typeAttr == "color" //HTML5
)
{ return TEXT; }
qWarning() << "WARN: Unknown type attribute on form element: " << typeAttr;
return TEXT;
}
}