6#include "validatorboolean_p.h"
12const QStringList ValidatorBooleanPrivate::trueVals{u
"1"_qs, u
"true"_qs, u
"on"_qs};
13const QStringList ValidatorBooleanPrivate::falseVals{u
"0"_qs, u
"false"_qs, u
"off"_qs};
17 const QString &defValKey)
18 :
ValidatorRule(*new ValidatorBooleanPrivate(field, messages, defValKey))
28 const QString v =
value(params);
31 if (ValidatorBooleanPrivate::trueVals.contains(v, Qt::CaseInsensitive)) {
32 result.
value.setValue<
bool>(
true);
33 }
else if (ValidatorBooleanPrivate::falseVals.contains(v, Qt::CaseInsensitive)) {
34 result.
value.setValue<
bool>(
false);
37 qCDebug(C_VALIDATOR).noquote().nospace()
38 <<
debugString(c) <<
" \"" << v <<
"\" can not be interpreted as boolean";
48 const QVariant &errorData)
const
52 const QString _label =
label(c);
53 if (_label.isEmpty()) {
55 c->
translate(
"Cutelyst::ValidatorBoolean",
"Can not be interpreted as boolean value.");
59 c->
translate(
"Cutelyst::ValidatorBoolean",
60 "The value in the “%1” field can not be interpreted as a boolean value.")
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error message if validation failed.
~ValidatorBoolean() override
Deconstructs the validator.
ValidatorBoolean(const QString &field, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new validator.
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
Performs the validation and returns the result.
Base class for all validator rules.
QString label(Context *c) const
Returns the human readable field label used for generic error messages.
void defaultValue(Context *c, ValidatorReturnType *result) const
I a defValKey has been set in the constructor, this will try to get the default value from the stash ...
QString value(const ParamsMultiMap ¶ms) const
Returns the value of the field from the input params.
QString validationError(Context *c, const QVariant &errorData=QVariant()) const
Returns a descriptive error message if validation failed.
QString debugString(Context *c) const
Returns a string that can be used for debug output if validation fails.
The Cutelyst namespace holds all public Cutelyst API.
QMultiMap< QString, QString > ParamsMultiMap
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.