6#include "validatormin_p.h"
15 :
ValidatorRule(*new ValidatorMinPrivate(field, type, min, messages, defValKey))
41 if (Q_UNLIKELY(!ok)) {
43 qCWarning(C_VALIDATOR).noquote().nospace()
44 <<
debugString(c) <<
" Failed to parse \"" << v <<
"\" into an integer number";
46 const qlonglong min = d->extractLongLong(c, params, d->min, &ok);
47 if (Q_UNLIKELY(!ok)) {
49 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidMin));
50 qCWarning(C_VALIDATOR).noquote()
51 <<
debugString(c) <<
"Invalid minimum comparison value";
55 qCDebug(C_VALIDATOR).noquote()
56 <<
debugString(c) << val <<
"is not greater than" << min;
70 if (Q_UNLIKELY(!ok)) {
72 qCWarning(C_VALIDATOR).noquote().nospace()
74 <<
"\" into an unsigned integer number";
76 const qulonglong min = d->extractULongLong(c, params, d->min, &ok);
77 if (Q_UNLIKELY(!ok)) {
79 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidMin));
80 qCWarning(C_VALIDATOR).noquote()
81 <<
debugString(c) <<
"Invalid minimum comparison value";
85 qCDebug(C_VALIDATOR).noquote()
86 <<
debugString(c) << val <<
"is not greater than" << min;
97 if (Q_UNLIKELY(!ok)) {
99 qCWarning(C_VALIDATOR).noquote().nospace()
101 <<
"\" into a floating point number";
103 const double min = d->extractDouble(c, params, d->min, &ok);
104 if (Q_UNLIKELY(!ok)) {
106 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidMin));
107 qCWarning(C_VALIDATOR).noquote()
108 <<
debugString(c) <<
"Invalid minimum comparison value";
112 qCDebug(C_VALIDATOR).noquote()
113 <<
debugString(c) << val <<
"is not greater than" << min;
122 const auto val =
static_cast<qlonglong
>(v.
length());
123 const qlonglong min = d->extractLongLong(c, params, d->min, &ok);
124 if (Q_UNLIKELY(!ok)) {
126 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidMin));
127 qCWarning(C_VALIDATOR).noquote()
128 <<
debugString(c) <<
"Invalid minimum comparison value";
132 qCDebug(C_VALIDATOR).noquote()
133 <<
debugString(c) <<
"String length" << val <<
"is not longer than" << min;
140 qCWarning(C_VALIDATOR).noquote()
141 <<
debugString(c) <<
"The comparison type" << d->type <<
"is not supported";
143 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidType));
149 const QVariant _v = d->valueToNumber(c, v, d->type);
193 static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidType));
201 return c->
qtTrId(
"cutelyst-valmin-genvalerr-str").
arg(min);
204 return c->
qtTrId(
"cutelyst-valmin-genvalerr-num").
arg(min);
209 return c->
qtTrId(
"cutelyst-valmin-genvalerr-str-label").
arg(_label, min);
212 return c->
qtTrId(
"cutelyst-valmin-genvalerr-num-label").
arg(_label, min);
220 const auto errorType =
static_cast<ValidatorRulePrivate::ErrorType
>(errorData.
toInt());
226 case ValidatorRulePrivate::ErrorType::InvalidType:
230 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-type")
233 case ValidatorRulePrivate::ErrorType::InvalidMin:
234 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-min");
235 case ValidatorRulePrivate::ErrorType::InvalidMax:
242 case ValidatorRulePrivate::ErrorType::InvalidType:
246 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-type-label")
249 case ValidatorRulePrivate::ErrorType::InvalidMin:
250 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-min-label").
arg(_label);
251 case ValidatorRulePrivate::ErrorType::InvalidMax:
258#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
260 Q_UNREACHABLE_RETURN({});
276 return c->
qtTrId(
"cutelyst-validator-genparseerr-float");
278 return c->
qtTrId(
"cutelyst-validator-genparseerr-float-label").
arg(_label);
282 return c->
qtTrId(
"cutelyst-validator-genparseerr-int");
284 return c->
qtTrId(
"cutelyst-validator-genparseerr-int-label").
arg(_label);
QLocale locale() const noexcept
QString qtTrId(const char *id, int n=-1) const
Checks if a value is not smaller or shorter than a maximum value.
QString genericValidationDataError(Context *c, const QVariant &errorData) const override
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
QString genericParsingError(Context *c, const QVariant &errorData) const override
ValidatorMin(const QString &field, QMetaType::Type type, const QVariant &min, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Base class for all validator rules.
QString validationError(Context *c, const QVariant &errorData={}) const
QString label(Context *c) const
QString validationDataError(Context *c, const QVariant &errorData={}) const
void defaultValue(Context *c, ValidatorReturnType *result) const
QString value(const ParamsMultiMap ¶ms) const
QString parsingError(Context *c, const QVariant &errorData={}) const
QString debugString(Context *c) const
The Cutelyst namespace holds all public Cutelyst API.
qlonglong toLongLong(QStringView s, bool *ok) const const
QString toString(QDate date, QLocale::FormatType format) const const
QString arg(Args &&... args) const const
QString fromLatin1(QByteArrayView str)
bool isEmpty() const const
qsizetype length() const const
double toDouble(bool *ok) const const
qulonglong toULongLong(bool *ok, int base) const const
bool isValid() const const
void setValue(QVariant &&value)
double toDouble(bool *ok) const const
int toInt(bool *ok) const const
qlonglong toLongLong(bool *ok) const const
qulonglong toULongLong(bool *ok) const const
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.