19 #include "validatormin_p.h"
24 ValidatorRule(*new ValidatorMinPrivate(field, type, min, messages, defValKey))
52 if (Q_UNLIKELY(!ok)) {
54 qCWarning(C_VALIDATOR,
"ValidatorMin: Failed to parse value of field %s into number at %s::%s.", qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()));
56 const qlonglong min = d->extractLongLong(c, params, d->min, &ok);
57 if (Q_UNLIKELY(!ok)) {
59 qCWarning(C_VALIDATOR,
"ValidatorMin: Invalid minimum comparison value for field %s in %s::%s.", qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()));
63 {QStringLiteral(
"val"), val},
64 {QStringLiteral(
"min"), min}
66 qCDebug(C_VALIDATOR,
"ValidatorMin: Validation failed for field %s in %s::%s: %lli is not greater than %lli.", qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()), val, min);
81 if (Q_UNLIKELY(!ok)) {
83 qCWarning(C_VALIDATOR,
"ValidatorMin: Failed to parse value of field %s into number at %s::%s.", qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()));
85 const qulonglong min = d->extractULongLong(c, params, d->min, &ok);
86 if (Q_UNLIKELY(!ok)) {
88 qCWarning(C_VALIDATOR,
"ValidatorMin: Invalid minimum comparison value for field %s in %s::%s.", qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()));
92 {QStringLiteral(
"val"), val},
93 {QStringLiteral(
"min"), min}
95 qCDebug(C_VALIDATOR,
"ValidatorMin: Validation failed for field %s in %s::%s: %llu is not greater than %llu.", qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()), val, min);
107 if (Q_UNLIKELY(!ok)) {
109 qCWarning(C_VALIDATOR,
"ValidatorMin: Failed to parse value of field %s into number at %s::%s.", qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()));
111 const double min = d->extractDouble(c, params, d->min, &ok);
112 if (Q_UNLIKELY(!ok)) {
114 qCWarning(C_VALIDATOR,
"ValidatorMin: Invalid minimum comparison value for field %s in %s::%s.", qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()));
118 {QStringLiteral(
"val"), val},
119 {QStringLiteral(
"min"), min}
121 qCDebug(C_VALIDATOR,
"ValidatorMin: Validation failed for field %s in %s::%s: %f is not greater than %f.", qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()), val, min);
131 const qlonglong val =
static_cast<qlonglong
>(v.
length());
132 const qlonglong min = d->extractLongLong(c, params, d->min, &ok);
133 if (Q_UNLIKELY(!ok)) {
135 qCWarning(C_VALIDATOR,
"ValidatorMin: Invalid minimum comparison value for field %s in %s::%s.", qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()));
139 {QStringLiteral(
"val"), val},
140 {QStringLiteral(
"min"), min}
142 qCDebug(C_VALIDATOR,
"ValidatorMin: Validation failed for field %s in %s::%s: string length %lli is not longer than %lli.", qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()), val, min);
150 qCWarning(C_VALIDATOR,
"ValidatorMin: The comparison type with ID %i for field %s at %s::%s is not supported.",
static_cast<int>(d->type), qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()));
157 const QVariant _v = d->valueToNumber(c, v, d->type);
180 const QVariantMap map = errorData.
toMap();
189 min = c->
locale().
toString(map.value(QStringLiteral(
"min")).toLongLong());
196 min = c->
locale().
toString(map.value(QStringLiteral(
"min")).toULongLong());
200 min = c->
locale().
toString(map.value(QStringLiteral(
"min")).toDouble());
211 error = c->
translate(
"Cutelyst::ValidatorMin",
"The text must be longer than %1 characters.").
arg(min);
213 error = c->
translate(
"Cutelyst::ValidatorMin",
"The value must be greater than %1.").
arg(min);
217 error = c->
translate(
"Cutelyst::ValidatorMin",
"The text in the “%1“ field must be longer than %2 characters.").
arg(_label, min);
219 error = c->
translate(
"Cutelyst::ValidatorMin",
"The value in the “%1” field must be greater than %2.").
arg(_label, min);
235 error = c->
translate(
"Cutelyst::ValidatorMin",
"The minimum comparison value is not valid.");
237 error = c->
translate(
"Cutelyst::ValidatorMin",
"The minimum comparison value for the “%1” field is not valid.").
arg(_label);
239 }
else if (
field == 0) {
242 error = c->
translate(
"Cutelyst::ValidatorMin",
"The comparison type with ID %1 is not supported.").
arg(
static_cast<int>(d->type));
244 error = c->
translate(
"Cutelyst::ValidatorMin",
"The comparison type with ID %1 for the “%2” field is not supported.").
arg(
QString::number(
static_cast<int>(d->type)), _label);
260 error = c->
translate(
"Cutelyst::ValidatorMin",
"Failed to parse the input value into a floating point number.");
262 error = c->
translate(
"Cutelyst::ValidatorMin",
"Failed to parse the input value for the “%1” field into a floating point number.").
arg(_label);
266 error = c->
translate(
"Cutelyst::ValidatorMin",
"Failed to parse the input value into an integer number.");
268 error = c->
translate(
"Cutelyst::ValidatorMin",
"Failed to parse the input value for the “%1” field into an integer number.").
arg(_label);
bool isValid() const const
Stores custom error messages and the input field label.
QString value(const ParamsMultiMap ¶ms) const
Returns the value of the field from the input params.
QString number(int n, int base)
QString label(Context *c) const
Returns the human readable field label used for generic error messages.
QString validationError(Context *c, const QVariant &errorData=QVariant()) const
Returns a descriptive error message if validation failed.
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.
void setValue(const T &value)
QString parsingError(Context *c, const QVariant &errorData=QVariant()) const
Returns an error message if an error occured while parsing input.
qulonglong toULongLong(bool *ok, int base) const const
QString field() const
Returns the name of the field to validate.
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
bool isEmpty() const const
Contains the result of a single input parameter validation.
QString toString(qlonglong i) const const
int toInt(bool *ok) const const
double toDouble(bool *ok) const const
QMap< QString, QVariant > toMap() const const
The Cutelyst namespace holds all public Cutelyst API.
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error message.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
qlonglong toLongLong(const QString &s, bool *ok) const const
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
Performs the validation and returns the result.
QString validationDataError(Context *c, const QVariant &errorData=QVariant()) const
Returns an error message if any validation data is missing or invalid.
QString genericParsingError(Context *c, const QVariant &errorData) const override
Returns a generic error message for input value parsing errors.
Checks if a value is not smaller or shorter than a maximum value.
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 ...
~ValidatorMin() override
Deconstructs the min validator.
QString genericValidationDataError(Context *c, const QVariant &errorData) const override
Returns a generic error message for validation data errors.