6#include "validatormax_p.h"
42 if (Q_UNLIKELY(!ok)) {
44 qCWarning(C_VALIDATOR,
45 "ValidatorMax: Failed to parse value of field %s into number at %s::%s.",
47 qPrintable(c->controllerName()),
48 qPrintable(c->actionName()));
50 const qlonglong max = d->extractLongLong(c, params, d->max, &ok);
51 if (Q_UNLIKELY(!ok)) {
55 "ValidatorMax: Invalid maximum comparison value for field %s in %s::%s.",
57 qPrintable(c->controllerName()),
58 qPrintable(c->actionName()));
63 QVariantMap{{QStringLiteral(
"val"), val},
64 {QStringLiteral(
"max"), max}});
66 "ValidatorMax: Validation failed for field %s in %s::%s: %lli is "
67 "not smaller than %lli.",
69 qPrintable(c->controllerName()),
70 qPrintable(c->actionName()),
86 if (Q_UNLIKELY(!ok)) {
88 qCWarning(C_VALIDATOR,
89 "ValidatorMax: Failed to parse value of field %s into number at %s::%s.",
91 qPrintable(c->controllerName()),
92 qPrintable(c->actionName()));
94 const qulonglong max = d->extractULongLong(c, params, d->max, &ok);
95 if (Q_UNLIKELY(!ok)) {
99 "ValidatorMax: Invalid maximum comparison value for field %s in %s::%s.",
101 qPrintable(c->controllerName()),
102 qPrintable(c->actionName()));
107 QVariantMap{{QStringLiteral(
"val"), val},
108 {QStringLiteral(
"max"), max}});
110 "ValidatorMax: Validation failed for field %s in %s::%s: %llu is "
111 "not smaller than %llu.",
113 qPrintable(c->controllerName()),
114 qPrintable(c->actionName()),
127 if (Q_UNLIKELY(!ok)) {
129 qCWarning(C_VALIDATOR,
130 "ValidatorMax: Failed to parse value of field %s into number at %s::%s.",
132 qPrintable(c->controllerName()),
133 qPrintable(c->actionName()));
135 const double max = d->extractDouble(c, params, d->max, &ok);
136 if (Q_UNLIKELY(!ok)) {
140 "ValidatorMax: Invalid maximum comparison value for field %s in %s::%s.",
142 qPrintable(c->controllerName()),
143 qPrintable(c->actionName()));
148 QVariantMap{{QStringLiteral(
"val"), val},
149 {QStringLiteral(
"max"), max}});
151 "ValidatorMax: Validation failed for field %s in %s::%s: %f is not "
154 qPrintable(c->controllerName()),
155 qPrintable(c->actionName()),
166 const qlonglong val =
static_cast<qlonglong
>(v.
length());
167 const qlonglong max = d->extractLongLong(c, params, d->max, &ok);
168 if (Q_UNLIKELY(!ok)) {
170 qCWarning(C_VALIDATOR,
171 "ValidatorMax: Invalid maximum comparison value for field %s in %s::%s.",
173 qPrintable(c->controllerName()),
174 qPrintable(c->actionName()));
178 c, QVariantMap{{QStringLiteral(
"val"), val}, {QStringLiteral(
"max"), max}});
180 "ValidatorMax: Validation failed for field %s in %s::%s: string length "
181 "%lli is not smaller than %lli.",
183 qPrintable(c->controllerName()),
184 qPrintable(c->actionName()),
193 qCWarning(C_VALIDATOR,
194 "ValidatorMax: The comparison type with ID %i for field %s at %s::%s is not "
196 static_cast<int>(d->type),
198 qPrintable(c->controllerName()),
199 qPrintable(c->actionName()));
206 const QVariant _v = d->valueToNumber(c, v, d->type);
229 const QVariantMap map = errorData.
toMap();
238 max = c->
locale().
toString(map.value(QStringLiteral(
"max")).toLongLong());
245 max = c->
locale().
toString(map.value(QStringLiteral(
"max")).toULongLong());
249 max = c->
locale().
toString(map.value(QStringLiteral(
"max")).toDouble());
260 error = c->
translate(
"Cutelyst::ValidatorMax",
261 "The text must be shorter than %1 characters.")
265 c->
translate(
"Cutelyst::ValidatorMax",
"The value must be lower than %1.").
arg(max);
269 error = c->
translate(
"Cutelyst::ValidatorMax",
270 "The text in the “%1“ field must be shorter than %2 characters.")
273 error = c->
translate(
"Cutelyst::ValidatorMax",
274 "The value in the “%1” field must be lower than %2.")
292 error = c->
translate(
"Cutelyst::ValidatorMax",
293 "The comparison type with ID %1 is not supported.")
294 .
arg(
static_cast<int>(d->type));
298 "The comparison type with ID %1 for the “%2” field is not supported.")
301 }
else if (
field == 1) {
303 error = c->
translate(
"Cutelyst::ValidatorMax",
304 "The maximum comparison value is not valid.");
306 error = c->
translate(
"Cutelyst::ValidatorMax",
307 "The maximum comparison value for the “%1” field is not valid.")
324 error = c->
translate(
"Cutelyst::ValidatorMax",
325 "Failed to parse the input value into a floating point number.");
327 error = c->
translate(
"Cutelyst::ValidatorMax",
328 "Failed to parse the input value for the “%1” field into a "
329 "floating point number.")
334 error = c->
translate(
"Cutelyst::ValidatorMax",
335 "Failed to parse the input value into an integer number.");
339 "Cutelyst::ValidatorMax",
340 "Failed to parse the input value for the “%1” field into an integer number.")
QLocale locale() const noexcept
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
~ValidatorMax() override
Deconstructs the max validator.
ValidatorMax(const QString &field, QMetaType::Type type, const QVariant &max, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new max validator.
QString genericValidationDataError(Context *c, const QVariant &errorData) const override
Returns a generic error message for validation data errors.
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error message.
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
Performs the validation and returns the result.
QString genericParsingError(Context *c, const QVariant &errorData) const override
Returns a generic error message for input value parsing errors.
QString label(Context *c) const
Returns the human readable field label used for generic error messages.
QString field() const
Returns the name of the field to validate.
QString parsingError(Context *c, const QVariant &errorData=QVariant()) const
Returns an error message if an error occurred while parsing input.
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 ...
ValidatorRule(const QString &field, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new ValidatorRule with the given parameters.
QString value(const ParamsMultiMap ¶ms) const
Returns the value of the field from the input params.
QString validationDataError(Context *c, const QVariant &errorData=QVariant()) const
Returns an error message if any validation data is missing or invalid.
QString validationError(Context *c, const QVariant &errorData=QVariant()) const
Returns a descriptive error message if validation failed.
The Cutelyst namespace holds all public Cutelyst API.
QMultiMap< QString, QString > ParamsMultiMap
qlonglong toLongLong(const QString &s, bool *ok) const const
QString toString(qlonglong i) const const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
bool isEmpty() const const
QString number(int n, int base)
double toDouble(bool *ok) const const
qulonglong toULongLong(bool *ok, int base) const const
bool isValid() const const
void setValue(const T &value)
int toInt(bool *ok) const const
QMap< QString, QVariant > toMap() const const
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.