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 = ValidatorMinPrivate::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 =
77 ValidatorMinPrivate::extractULongLong(c, params, d->min, &ok);
78 if (Q_UNLIKELY(!ok)) {
80 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidMin));
81 qCWarning(C_VALIDATOR).noquote()
82 <<
debugString(c) <<
"Invalid minimum comparison value";
86 qCDebug(C_VALIDATOR).noquote()
87 <<
debugString(c) << val <<
"is not greater than" << min;
98 if (Q_UNLIKELY(!ok)) {
100 qCWarning(C_VALIDATOR).noquote().nospace()
102 <<
"\" into a floating point number";
104 const double min = ValidatorMinPrivate::extractDouble(c, params, d->min, &ok);
105 if (Q_UNLIKELY(!ok)) {
107 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidMin));
108 qCWarning(C_VALIDATOR).noquote()
109 <<
debugString(c) <<
"Invalid minimum comparison value";
113 qCDebug(C_VALIDATOR).noquote()
114 <<
debugString(c) << val <<
"is not greater than" << min;
123 const auto val =
static_cast<qlonglong
>(v.
length());
124 const qlonglong min = ValidatorMinPrivate::extractLongLong(c, params, d->min, &ok);
125 if (Q_UNLIKELY(!ok)) {
127 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidMin));
128 qCWarning(C_VALIDATOR).noquote()
129 <<
debugString(c) <<
"Invalid minimum comparison value";
133 qCDebug(C_VALIDATOR).noquote()
134 <<
debugString(c) <<
"String length" << val <<
"is not longer than" << min;
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 = ValidatorMinPrivate::valueToNumber(c, v, d->type);
199 static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidType));
207 return c->
qtTrId(
"cutelyst-valmin-genvalerr-str").
arg(min);
210 return c->
qtTrId(
"cutelyst-valmin-genvalerr-num").
arg(min);
215 return c->
qtTrId(
"cutelyst-valmin-genvalerr-str-label").
arg(_label, min);
218 return c->
qtTrId(
"cutelyst-valmin-genvalerr-num-label").
arg(_label, min);
226 const auto errorType =
static_cast<ValidatorRulePrivate::ErrorType
>(errorData.
toInt());
232 case ValidatorRulePrivate::ErrorType::InvalidType:
236 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-type")
239 case ValidatorRulePrivate::ErrorType::InvalidMin:
240 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-min");
241 case ValidatorRulePrivate::ErrorType::InvalidMax:
248 case ValidatorRulePrivate::ErrorType::InvalidType:
252 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-type-label")
255 case ValidatorRulePrivate::ErrorType::InvalidMin:
256 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-min-label").
arg(_label);
257 case ValidatorRulePrivate::ErrorType::InvalidMax:
264#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
266 Q_UNREACHABLE_RETURN({});
282 return c->
qtTrId(
"cutelyst-validator-genparseerr-float");
284 return c->
qtTrId(
"cutelyst-validator-genparseerr-float-label").
arg(_label);
288 return c->
qtTrId(
"cutelyst-validator-genparseerr-int");
290 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
void validateCb(Context *c, const ParamsMultiMap ¶ms, ValidatorRtFn cb) const override
ValidatorMin(const QString &field, QMetaType::Type type, const QVariant &min, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey={})
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(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.