6#include "validatormax_p.h"
17 :
ValidatorRule(*new ValidatorMaxPrivate(field, type, max, messages, defValKey))
42 if (Q_UNLIKELY(!ok)) {
44 qCWarning(C_VALIDATOR).noquote().nospace()
45 <<
debugString(c) <<
" Failed to parse \"" << v <<
"\" into an integer number";
47 const qlonglong max = d->extractLongLong(c, params, d->max, &ok);
48 if (Q_UNLIKELY(!ok)) {
50 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidMax));
51 qCWarning(C_VALIDATOR).noquote()
52 <<
debugString(c) <<
"Invalid maximum comparison value";
56 qCDebug(C_VALIDATOR).noquote()
57 <<
debugString(c) << val <<
"is not smaller than" << max;
71 if (Q_UNLIKELY(!ok)) {
73 qCWarning(C_VALIDATOR).noquote().nospace()
75 <<
"\" into an unsigned integer number";
77 const qulonglong max = d->extractULongLong(c, params, d->max, &ok);
78 if (Q_UNLIKELY(!ok)) {
80 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidMax));
81 qCWarning(C_VALIDATOR).noquote()
82 <<
debugString(c) <<
"Invalid maximum comparison value";
86 qCDebug(C_VALIDATOR).noquote()
87 <<
debugString(c) << val <<
"is not smaller than" << max;
98 if (Q_UNLIKELY(!ok)) {
100 qCWarning(C_VALIDATOR).noquote().nospace()
102 <<
"\" into a floating point number";
104 const double max = d->extractDouble(c, params, d->max, &ok);
105 if (Q_UNLIKELY(!ok)) {
107 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidMax));
108 qCWarning(C_VALIDATOR).noquote()
109 <<
debugString(c) <<
"Invalid maximum comparison value";
113 qCDebug(C_VALIDATOR).noquote()
114 <<
debugString(c) << val <<
"is not smaller than" << max;
123 const auto val =
static_cast<qlonglong
>(v.
length());
124 const qlonglong max = d->extractLongLong(c, params, d->max, &ok);
125 if (Q_UNLIKELY(!ok)) {
127 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidMax));
128 qCWarning(C_VALIDATOR).noquote()
129 <<
debugString(c) <<
"Invalid maximum comparison value";
133 qCDebug(C_VALIDATOR).noquote()
134 <<
debugString(c) <<
"String length" << val <<
"is not shorter than" << max;
141 qCWarning(C_VALIDATOR).noquote()
142 <<
debugString(c) <<
"The comparison type" << d->type <<
"is not supported";
144 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidType));
150 const QVariant _v = d->valueToNumber(c, v, d->type);
194 static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidType));
202 return c->
qtTrId(
"cutelyst-valmax-genvalerr-str").
arg(max);
205 return c->
qtTrId(
"cutelyst-valmax-genvalerr-num").
arg(max);
210 return c->
qtTrId(
"cutelyst-valmax-genvalerr-str-label").
arg(_label, max);
213 return c->
qtTrId(
"cutelyst-valmax-genvalerr-num-label").
arg(_label, max);
221 const auto errorType =
static_cast<ValidatorRulePrivate::ErrorType
>(errorData.
toInt());
227 case ValidatorRulePrivate::ErrorType::InvalidType:
231 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-type")
234 case ValidatorRulePrivate::ErrorType::InvalidMax:
235 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-max");
236 case ValidatorRulePrivate::ErrorType::InvalidMin:
243 case ValidatorRulePrivate::ErrorType::InvalidType:
247 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-type-label")
250 case ValidatorRulePrivate::ErrorType::InvalidMax:
251 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-max-label").
arg(_label);
252 case ValidatorRulePrivate::ErrorType::InvalidMin:
259#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
261 Q_UNREACHABLE_RETURN({});
277 return c->
qtTrId(
"cutelyst-validator-genparseerr-float");
279 return c->
qtTrId(
"cutelyst-validator-genparseerr-float-label").
arg(_label);
283 return c->
qtTrId(
"cutelyst-validator-genparseerr-int");
285 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 bigger or longer than a maximum value.
ValidatorMax(const QString &field, QMetaType::Type type, const QVariant &max, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
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
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.