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 = ValidatorMaxPrivate::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 =
78 ValidatorMaxPrivate::extractULongLong(c, params, d->max, &ok);
79 if (Q_UNLIKELY(!ok)) {
81 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidMax));
82 qCWarning(C_VALIDATOR).noquote()
83 <<
debugString(c) <<
"Invalid maximum comparison value";
87 qCDebug(C_VALIDATOR).noquote()
88 <<
debugString(c) << val <<
"is not smaller than" << max;
99 if (Q_UNLIKELY(!ok)) {
101 qCWarning(C_VALIDATOR).noquote().nospace()
103 <<
"\" into a floating point number";
105 const double max = ValidatorMaxPrivate::extractDouble(c, params, d->max, &ok);
106 if (Q_UNLIKELY(!ok)) {
108 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidMax));
109 qCWarning(C_VALIDATOR).noquote()
110 <<
debugString(c) <<
"Invalid maximum comparison value";
114 qCDebug(C_VALIDATOR).noquote()
115 <<
debugString(c) << val <<
"is not smaller than" << max;
124 const auto val =
static_cast<qlonglong
>(v.
length());
125 const qlonglong max = ValidatorMaxPrivate::extractLongLong(c, params, d->max, &ok);
126 if (Q_UNLIKELY(!ok)) {
128 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidMax));
129 qCWarning(C_VALIDATOR).noquote()
130 <<
debugString(c) <<
"Invalid maximum comparison value";
134 qCDebug(C_VALIDATOR).noquote()
135 <<
debugString(c) <<
"String length" << val <<
"is not shorter than" << max;
142 qCWarning(C_VALIDATOR).noquote()
143 <<
debugString(c) <<
"The comparison type" << d->type <<
"is not supported";
145 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidType));
151 const QVariant _v = ValidatorMaxPrivate::valueToNumber(c, v, d->type);
200 static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidType));
208 return c->
qtTrId(
"cutelyst-valmax-genvalerr-str").
arg(max);
211 return c->
qtTrId(
"cutelyst-valmax-genvalerr-num").
arg(max);
216 return c->
qtTrId(
"cutelyst-valmax-genvalerr-str-label").
arg(_label, max);
219 return c->
qtTrId(
"cutelyst-valmax-genvalerr-num-label").
arg(_label, max);
227 const auto errorType =
static_cast<ValidatorRulePrivate::ErrorType
>(errorData.
toInt());
233 case ValidatorRulePrivate::ErrorType::InvalidType:
237 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-type")
240 case ValidatorRulePrivate::ErrorType::InvalidMax:
241 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-max");
242 case ValidatorRulePrivate::ErrorType::InvalidMin:
249 case ValidatorRulePrivate::ErrorType::InvalidType:
253 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-type-label")
256 case ValidatorRulePrivate::ErrorType::InvalidMax:
257 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-max-label").
arg(_label);
258 case ValidatorRulePrivate::ErrorType::InvalidMin:
265#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
267 Q_UNREACHABLE_RETURN({});
283 return c->
qtTrId(
"cutelyst-validator-genparseerr-float");
285 return c->
qtTrId(
"cutelyst-validator-genparseerr-float-label").
arg(_label);
289 return c->
qtTrId(
"cutelyst-validator-genparseerr-int");
291 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.
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
ValidatorMax(const QString &field, QMetaType::Type type, const QVariant &max, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey={})
void validateCb(Context *c, const ParamsMultiMap ¶ms, ValidatorRtFn cb) 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(const Context *c) const
QString debugString(const Context *c) const
QString validationDataError(Context *c, const QVariant &errorData={}) const
std::function< void(ValidatorReturnType &&result)> ValidatorRtFn
Void callback function for validator rules that processes the ValidatorReturnType.
void defaultValue(Context *c, ValidatorReturnType *result) const
QString value(const ParamsMultiMap ¶ms) const
QString parsingError(Context *c, const QVariant &errorData={}) 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.