6#include "validatormin_p.h"
15 :
ValidatorRule(*new ValidatorMinPrivate(field, type, min, messages, defValKey))
43 if (Q_UNLIKELY(!ok)) {
45 qCWarning(C_VALIDATOR,
46 "ValidatorMin: Failed to parse value of field %s into number at %s::%s.",
48 qPrintable(c->controllerName()),
49 qPrintable(c->actionName()));
51 const qlonglong min = d->extractLongLong(c, params, d->min, &ok);
52 if (Q_UNLIKELY(!ok)) {
56 "ValidatorMin: Invalid minimum comparison value for field %s in %s::%s.",
58 qPrintable(c->controllerName()),
59 qPrintable(c->actionName()));
64 QVariantMap{{QStringLiteral(
"val"), val},
65 {QStringLiteral(
"min"), min}});
67 "ValidatorMin: Validation failed for field %s in %s::%s: %lli is "
68 "not greater than %lli.",
70 qPrintable(c->controllerName()),
71 qPrintable(c->actionName()),
87 if (Q_UNLIKELY(!ok)) {
89 qCWarning(C_VALIDATOR,
90 "ValidatorMin: Failed to parse value of field %s into number at %s::%s.",
92 qPrintable(c->controllerName()),
93 qPrintable(c->actionName()));
95 const qulonglong min = d->extractULongLong(c, params, d->min, &ok);
96 if (Q_UNLIKELY(!ok)) {
100 "ValidatorMin: Invalid minimum comparison value for field %s in %s::%s.",
102 qPrintable(c->controllerName()),
103 qPrintable(c->actionName()));
108 QVariantMap{{QStringLiteral(
"val"), val},
109 {QStringLiteral(
"min"), min}});
111 "ValidatorMin: Validation failed for field %s in %s::%s: %llu is "
112 "not greater than %llu.",
114 qPrintable(c->controllerName()),
115 qPrintable(c->actionName()),
128 if (Q_UNLIKELY(!ok)) {
130 qCWarning(C_VALIDATOR,
131 "ValidatorMin: Failed to parse value of field %s into number at %s::%s.",
133 qPrintable(c->controllerName()),
134 qPrintable(c->actionName()));
136 const double min = d->extractDouble(c, params, d->min, &ok);
137 if (Q_UNLIKELY(!ok)) {
141 "ValidatorMin: Invalid minimum comparison value for field %s in %s::%s.",
143 qPrintable(c->controllerName()),
144 qPrintable(c->actionName()));
149 QVariantMap{{QStringLiteral(
"val"), val},
150 {QStringLiteral(
"min"), min}});
152 "ValidatorMin: Validation failed for field %s in %s::%s: %f is not "
155 qPrintable(c->controllerName()),
156 qPrintable(c->actionName()),
167 const qlonglong val =
static_cast<qlonglong
>(v.
length());
168 const qlonglong min = d->extractLongLong(c, params, d->min, &ok);
169 if (Q_UNLIKELY(!ok)) {
171 qCWarning(C_VALIDATOR,
172 "ValidatorMin: Invalid minimum comparison value for field %s in %s::%s.",
174 qPrintable(c->controllerName()),
175 qPrintable(c->actionName()));
179 c, QVariantMap{{QStringLiteral(
"val"), val}, {QStringLiteral(
"min"), min}});
181 "ValidatorMin: Validation failed for field %s in %s::%s: string length "
182 "%lli is not longer than %lli.",
184 qPrintable(c->controllerName()),
185 qPrintable(c->actionName()),
194 qCWarning(C_VALIDATOR,
195 "ValidatorMin: The comparison type with ID %i for field %s at %s::%s is not "
197 static_cast<int>(d->type),
199 qPrintable(c->controllerName()),
200 qPrintable(c->actionName()));
207 const QVariant _v = d->valueToNumber(c, v, d->type);
230 const QVariantMap map = errorData.
toMap();
239 min = c->
locale().
toString(map.value(QStringLiteral(
"min")).toLongLong());
246 min = c->
locale().
toString(map.value(QStringLiteral(
"min")).toULongLong());
250 min = c->
locale().
toString(map.value(QStringLiteral(
"min")).toDouble());
261 error = c->
translate(
"Cutelyst::ValidatorMin",
262 "The text must be longer than %1 characters.")
265 error = c->
translate(
"Cutelyst::ValidatorMin",
"The value must be greater than %1.")
270 error = c->
translate(
"Cutelyst::ValidatorMin",
271 "The text in the “%1“ field must be longer than %2 characters.")
274 error = c->
translate(
"Cutelyst::ValidatorMin",
275 "The value in the “%1” field must be greater than %2.")
292 error = c->
translate(
"Cutelyst::ValidatorMin",
293 "The minimum comparison value is not valid.");
295 error = c->
translate(
"Cutelyst::ValidatorMin",
296 "The minimum comparison value for the “%1” field is not valid.")
299 }
else if (
field == 0) {
302 error = c->
translate(
"Cutelyst::ValidatorMin",
303 "The comparison type with ID %1 is not supported.")
304 .
arg(
static_cast<int>(d->type));
308 "The comparison type with ID %1 for the “%2” field is not supported.")
325 error = c->
translate(
"Cutelyst::ValidatorMin",
326 "Failed to parse the input value into a floating point number.");
328 error = c->
translate(
"Cutelyst::ValidatorMin",
329 "Failed to parse the input value for the “%1” field into a "
330 "floating point number.")
335 error = c->
translate(
"Cutelyst::ValidatorMin",
336 "Failed to parse the input value into an integer number.");
340 "Cutelyst::ValidatorMin",
341 "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
Checks if a value is not smaller or shorter than a maximum value.
~ValidatorMin() override
Deconstructs the min 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.
ValidatorMin(const QString &field, QMetaType::Type type, const QVariant &min, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new min validator.
Base class for all validator rules.
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 ...
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.
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.