6 #include "validatorsize_p.h"
15 :
ValidatorRule(*new ValidatorSizePrivate(field, type, size, messages, defValKey))
40 if (Q_UNLIKELY(!ok)) {
42 qCWarning(C_VALIDATOR).noquote().nospace()
43 <<
debugString(c) <<
"Failed to parse \"" << v <<
"\" into an integer number";
45 const qlonglong size = d->extractLongLong(c, params, d->
size, &ok);
46 if (Q_UNLIKELY(!ok)) {
48 qCWarning(C_VALIDATOR).noquote() <<
debugString(c) <<
"Invalid comparison size";
52 qCDebug(C_VALIDATOR).noquote() <<
debugString(c) << val <<
"!=" << size;
65 if (Q_UNLIKELY(!ok)) {
67 qCWarning(C_VALIDATOR).noquote().nospace()
69 <<
"\" into an unsigned integer number";
71 const qulonglong size = d->extractULongLong(c, params, d->
size, &ok);
72 if (Q_UNLIKELY(!ok)) {
74 qCWarning(C_VALIDATOR).noquote() <<
debugString(c) <<
"Invalid comparison size";
78 qCDebug(C_VALIDATOR).noquote() <<
debugString(c) << val <<
"!=" << size;
89 if (Q_UNLIKELY(!ok)) {
91 qCWarning(C_VALIDATOR).noquote().nospace()
93 <<
"\" into a floating point number";
95 const double size = d->extractDouble(c, params, d->
size, &ok);
96 if (Q_UNLIKELY(!ok)) {
98 qCWarning(C_VALIDATOR).noquote() <<
debugString(c) <<
"Invalid comparison size";
102 qCDebug(C_VALIDATOR).noquote() <<
debugString(c) << val <<
"!=" << size;
111 const auto val =
static_cast<qlonglong
>(v.
length());
112 const qlonglong size = d->extractLongLong(c, params, d->
size, &ok);
113 if (Q_UNLIKELY(!ok)) {
115 qCWarning(C_VALIDATOR).noquote() <<
debugString(c) <<
"Invalid comparison size";
119 qCDebug(C_VALIDATOR).noquote()
120 <<
debugString(c) <<
"string length" << val <<
"!=" << size;
127 qCWarning(C_VALIDATOR).noquote()
128 <<
debugString(c) <<
"The comparison type" << d->type <<
"is not supported";
135 const QVariant _v = d->valueToNumber(c, v, d->type);
184 return c->
qtTrId(
"cutelyst-valsize-genvalerr-str").
arg(size);
187 return c->
qtTrId(
"cutelyst-valsize-genvalerr-num").
arg(size);
194 return c->
qtTrId(
"cutelyst-valsize-genvalerr-str-label").
arg(_label, size);
199 return c->
qtTrId(
"cutelyst-valsize-genvalerr-num-label").
arg(_label, size);
213 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-type")
216 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-type-label")
222 return c->
qtTrId(
"cutelyst-valsize-genvaldataerr-size");
226 return c->
qtTrId(
"cutelyst-valsize-genvaldataerr-size-label").
arg(_label);
241 return c->
qtTrId(
"cutelyst-validator-genparseerr-float");
243 return c->
qtTrId(
"cutelyst-validator-genparseerr-float-label").
arg(_label);
247 return c->
qtTrId(
"cutelyst-validator-genparseerr-int");
249 return c->
qtTrId(
"cutelyst-validator-genparseerr-int-label").
arg(_label);
QLocale locale() const noexcept
QString qtTrId(const char *id, int n=-1) const
Base class for all validator rules.
QString field() const noexcept
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 field under validation must have a size matching the given value.
~ValidatorSize() override
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
ValidatorSize(const QString &field, QMetaType::Type type, const QVariant &size, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
QString genericParsingError(Context *c, const QVariant &errorData) const override
QString genericValidationDataError(Context *c, const QVariant &errorData) const override
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
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
QMultiMap::size_type size() 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.