19 #include "validatorboolean_p.h"
20 #include <QStringList>
22 using namespace Cutelyst;
25 ValidatorRule(*new ValidatorBooleanPrivate(field, messages, defValKey))
40 static const QStringList lt({QStringLiteral(
"1"), QStringLiteral(
"true"), QStringLiteral(
"on")});
41 static const QStringList lf({QStringLiteral(
"0"), QStringLiteral(
"false"), QStringLiteral(
"off")});
42 if (lt.contains(v, Qt::CaseInsensitive)) {
44 }
else if (lf.contains(v, Qt::CaseInsensitive)) {
48 qCDebug(C_VALIDATOR,
"ValidatorBoolean: The value %s of field %s in %s::%s can not be interpreted as boolean.", qPrintable(v), qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()));
63 error = c->
translate(
"Cutelyst::ValidatorBoolean",
"Can not be interpreted as boolean value.");
66 error = c->
translate(
"Cutelyst::ValidatorBoolean",
"The value in the “%1” field can not be interpreted as a boolean value.").
arg(_label);
QString field() const
Returns the name of the field to validate.
QString label(Context *c) const
Returns the human readable field label used for generic error messages.
Stores custom error messages and the input field label.
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error message if validation failed.
QString value(const ParamsMultiMap ¶ms) const
Returns the value of the field from the input params.
~ValidatorBoolean() override
Deconstructs the validator.
QString validationError(Context *c, const QVariant &errorData=QVariant()) const
Returns a descriptive error message if validation failed.
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
Performs the validation and returns the result.
Base class for all validator rules.
void defaultValue(Context *c, ValidatorReturnType *result, const char *validatorName) const
I a defValKey has been set in the constructor, this will try to get the default value from the stash ...
void setValue(const T &value)
ValidatorBoolean(const QString &field, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new validator.
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
Contains the result of a single input parameter validation.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const