6 #include "validatorbetween_p.h"
18 :
ValidatorRule(*new ValidatorBetweenPrivate(field, type, min, max, messages, defValKey))
44 if (Q_UNLIKELY(!ok)) {
46 qCWarning(C_VALIDATOR).noquote().nospace()
48 <<
"\" into an integer number";
50 const qlonglong min = d->extractLongLong(c, params, d->min, &ok);
51 if (Q_UNLIKELY(!ok)) {
53 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidMin));
54 qCWarning(C_VALIDATOR).noquote()
55 <<
"Invalid mininum comparison value:" << d->min;
57 const qlonglong max = d->extractLongLong(c, params, d->max, &ok);
58 if (Q_UNLIKELY(!ok)) {
60 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidMax));
61 qCWarning(C_VALIDATOR).noquote()
62 <<
"Invalid maximum comparison value:" << d->max;
64 if ((val < min) || (val > max)) {
67 QVariantMap{{QStringLiteral(
"val"), val},
68 {QStringLiteral(
"min"), min},
69 {QStringLiteral(
"max"), max}});
70 qCDebug(C_VALIDATOR).noquote()
71 <<
debugString(c) << val <<
"is not between" << min <<
"and" << max;
86 if (Q_UNLIKELY(!ok)) {
88 qCWarning(C_VALIDATOR).noquote().nospace()
90 <<
"\" into an unsigned integer number";
92 const qulonglong min = d->extractULongLong(c, params, d->min, &ok);
93 if (Q_UNLIKELY(!ok)) {
95 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidMin));
96 qCWarning(C_VALIDATOR).noquote()
97 <<
debugString(c) <<
"Invalid mininum comparison value:" << d->min;
99 const qulonglong max = d->extractULongLong(c, params, d->max, &ok);
100 if (Q_UNLIKELY(!ok)) {
102 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidMax));
103 qCWarning(C_VALIDATOR).noquote()
104 <<
debugString(c) <<
"Invalid maximum comparison value:" << d->max;
106 if ((val < min) || (val > max)) {
109 QVariantMap{{QStringLiteral(
"val"), val},
110 {QStringLiteral(
"min"), min},
111 {QStringLiteral(
"max"), max}});
112 qCDebug(C_VALIDATOR).noquote()
113 <<
debugString(c) << val <<
"is not between" << min <<
"and" << max;
125 if (Q_UNLIKELY(!ok)) {
127 qCWarning(C_VALIDATOR).noquote().nospace()
128 <<
debugString(c) <<
" Can not parse input \"" << v
129 <<
"\" into a floating point number";
131 const double min = d->extractDouble(c, params, d->min, &ok);
132 if (Q_UNLIKELY(!ok)) {
134 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidMin));
135 qCWarning(C_VALIDATOR).noquote()
136 <<
debugString(c) <<
"Invalid mininum comparison value:" << d->min;
138 const double max = d->extractDouble(c, params, d->max, &ok);
139 if (Q_UNLIKELY(!ok)) {
141 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidMax));
142 qCWarning(C_VALIDATOR).noquote()
143 <<
debugString(c) <<
"Invalid maximum comparison value:" << d->max;
145 if ((val < min) || (val > max)) {
148 QVariantMap{{QStringLiteral(
"val"), val},
149 {QStringLiteral(
"min"), min},
150 {QStringLiteral(
"max"), max}});
151 qCDebug(C_VALIDATOR).noquote()
152 <<
debugString(c) << val <<
"is not between" << min <<
"and" << max;
162 const auto val =
static_cast<qlonglong
>(v.
length());
163 const qlonglong min = d->extractLongLong(c, params, d->min, &ok);
164 if (Q_UNLIKELY(!ok)) {
166 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidMin));
167 qCWarning(C_VALIDATOR).noquote()
168 <<
debugString(c) <<
"Invalid mininum comparison value:" << d->min;
170 const qlonglong max = d->extractLongLong(c, params, d->max, &ok);
171 if (Q_UNLIKELY(!ok)) {
173 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidMax));
174 qCWarning(C_VALIDATOR).noquote()
175 <<
debugString(c) <<
"Invalid maximum comparison value:" << d->max;
177 if ((val < min) || (val > max)) {
180 QVariantMap{{QStringLiteral(
"val"), val},
181 {QStringLiteral(
"min"), min},
182 {QStringLiteral(
"max"), max}});
183 qCDebug(C_VALIDATOR).noquote() <<
debugString(c) <<
"String length" << val
184 <<
"is not between" << min <<
"and" << max;
192 qCWarning(C_VALIDATOR).noquote()
193 <<
debugString(c) <<
"The comparison type" << d->type <<
"is not supported";
195 c,
static_cast<int>(ValidatorRulePrivate::ErrorType::InvalidType));
201 const QVariant _v = d->valueToNumber(c, v, d->type);
225 const QVariantMap map = errorData.
toMap();
234 min = c->
locale().
toString(map.value(QStringLiteral(
"min")).toLongLong());
235 max = c->
locale().
toString(map.value(QStringLiteral(
"max")).toLongLong());
242 min = c->
locale().
toString(map.value(QStringLiteral(
"min")).toULongLong());
243 max = c->
locale().
toString(map.value(QStringLiteral(
"max")).toULongLong());
247 min = c->
locale().
toString(map.value(QStringLiteral(
"min")).toDouble());
248 max = c->
locale().
toString(map.value(QStringLiteral(
"max")).toDouble());
260 return c->
qtTrId(
"cutelyst-valbetween-genvalerr-string").
arg(min, max);
264 return c->
qtTrId(
"cutelyst-valbetween-genvalerr-num").
arg(min, max);
271 return c->
qtTrId(
"cutelyst-valbetween-genvalerr-string-label").
arg(_label, min, max);
276 return c->
qtTrId(
"cutelyst-valbetween-genvalerr-num-label").
arg(_label, min, max);
285 const auto errorType =
static_cast<ValidatorRulePrivate::ErrorType
>(errorData.
toInt());
290 case ValidatorRulePrivate::ErrorType::InvalidMin:
292 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-min");
293 case ValidatorRulePrivate::ErrorType::InvalidType:
299 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-type")
302 case ValidatorRulePrivate::ErrorType::InvalidMax:
304 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-max");
308 case ValidatorRulePrivate::ErrorType::InvalidMin:
311 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-min-label").
arg(_label);
312 case ValidatorRulePrivate::ErrorType::InvalidType:
318 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-type-label")
321 case ValidatorRulePrivate::ErrorType::InvalidMax:
324 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-max-label").
arg(_label);
340 return c->
qtTrId(
"cutelyst-validator-genparseerr-float");
345 return c->
qtTrId(
"cutelyst-validator-genparseerr-float-label").
arg(_label);
350 return c->
qtTrId(
"cutelyst-validator-genparseerr-int");
354 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 or text length is between a minimum and maximum value.
ValidatorBetween(const QString &field, QMetaType::Type type, const QVariant &min, const QVariant &max, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
~ValidatorBetween() override
QString genericParsingError(Context *c, const QVariant &errorData) const override
QString genericValidationDataError(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)
int toInt(bool *ok) const const
QMap< QString, QVariant > toMap() const const
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.