cutelyst
4.3.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
validatoraccepted.cpp
1
/*
2
* SPDX-FileCopyrightText: (C) 2017-2023 Matthias Fehring <mf@huessenbergnetz.de>
3
* SPDX-License-Identifier: BSD-3-Clause
4
*/
5
6
#include "validatoraccepted_p.h"
7
8
#include <QStringList>
9
10
using namespace
Cutelyst
;
11
12
const
QStringList
ValidatorAcceptedPrivate::trueVals{u
"yes"
_qs, u
"on"
_qs, u
"1"
_qs, u
"true"
_qs};
13
14
ValidatorAccepted::ValidatorAccepted
(
const
QString
&field,
15
const
Cutelyst::ValidatorMessages
&messages)
16
:
ValidatorRule
(*new ValidatorAcceptedPrivate(field, messages))
17
{
18
}
19
20
ValidatorAccepted::~ValidatorAccepted
() =
default
;
21
22
ValidatorReturnType
ValidatorAccepted::validate
(
Cutelyst::Context
*c,
23
const
Cutelyst::ParamsMultiMap
¶ms)
const
24
{
25
ValidatorReturnType
result;
26
27
if
(Q_LIKELY(
ValidatorAccepted::validate
(
value
(params)))) {
28
result.
value
.
setValue
<
bool
>(
true
);
29
}
else
{
30
result.
errorMessage
=
validationError
(c);
31
result.
value
.
setValue
<
bool
>(
false
);
32
qCDebug(C_VALIDATOR).noquote() <<
debugString
(c);
33
}
34
35
return
result;
36
}
37
38
bool
ValidatorAccepted::validate
(
const
QString
&value)
39
{
40
return
ValidatorAcceptedPrivate::trueVals.contains(
value
,
Qt::CaseInsensitive
);
41
}
42
43
QString
ValidatorAccepted::genericValidationError
(
Cutelyst::Context
*c,
44
const
QVariant
&errorData)
const
45
{
46
Q_UNUSED(errorData)
47
const
QString
_label =
label
(c);
48
if
(_label.
isEmpty
()) {
49
//% "Has to be accepted."
50
return
c->
qtTrId
(
"cutelyst-valaccepted-genvalerr"
);
51
}
else
{
52
//: %1 will be replaced by the field label
53
//% "“%1” has to be accepted."
54
return
c->
qtTrId
(
"cutelyst-valaccepted-genvalerr-label"
).
arg
(_label);
55
}
56
}
Cutelyst::Context
The Cutelyst Context.
Definition
context.h:42
Cutelyst::Context::qtTrId
QString qtTrId(const char *id, int n=-1) const
Definition
context.h:656
Cutelyst::ValidatorAccepted::ValidatorAccepted
ValidatorAccepted(const QString &field, const ValidatorMessages &messages=ValidatorMessages())
Definition
validatoraccepted.cpp:14
Cutelyst::ValidatorAccepted::genericValidationError
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Definition
validatoraccepted.cpp:43
Cutelyst::ValidatorAccepted::~ValidatorAccepted
~ValidatorAccepted() override
Cutelyst::ValidatorRule
Base class for all validator rules.
Definition
validatorrule.h:304
Cutelyst::ValidatorRule::validationError
QString validationError(Context *c, const QVariant &errorData={}) const
Definition
validatorrule.cpp:61
Cutelyst::ValidatorRule::label
QString label(Context *c) const
Definition
validatorrule.cpp:49
Cutelyst::ValidatorRule::value
QString value(const ParamsMultiMap ¶ms) const
Definition
validatorrule.cpp:34
Cutelyst::ValidatorRule::debugString
QString debugString(Context *c) const
Definition
validatorrule.cpp:157
Cutelyst::ValidatorAccepted::validate
static bool validate(const QString &value)
Returns true if the value is equal to yes, on, 1, or true.
Definition
validatoraccepted.cpp:38
Cutelyst
The Cutelyst namespace holds all public Cutelyst API.
Definition
group-core-actions.dox:1
QMultiMap
QString
QString::arg
QString arg(Args &&... args) const const
QString::isEmpty
bool isEmpty() const const
QStringList
Qt::CaseInsensitive
CaseInsensitive
QVariant
QVariant::setValue
void setValue(QVariant &&value)
Cutelyst::ValidatorMessages
Stores custom error messages and the input field label.
Definition
validatorrule.h:142
Cutelyst::ValidatorReturnType
Contains the result of a single input parameter validation.
Definition
validatorrule.h:49
Cutelyst::ValidatorReturnType::value
QVariant value
Definition
validatorrule.h:54
Cutelyst::ValidatorReturnType::errorMessage
QString errorMessage
Definition
validatorrule.h:50
Cutelyst
Plugins
Utils
Validator
validatoraccepted.cpp
Generated by
1.9.8