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);
qlonglong toLongLong(bool *ok) const const
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
qlonglong toLongLong(QStringView s, bool *ok) const const
Stores custom error messages and the input field label.
size_type size() const const
double toDouble(bool *ok) const const
qulonglong toULongLong(bool *ok) const const
QString toString(QDate date, FormatType format) const const
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
The field under validation must have a size matching the given value.
void defaultValue(Context *c, ValidatorReturnType *result) const
int toInt(bool *ok) const const
~ValidatorSize() override
bool isEmpty() const const
QString genericValidationDataError(Context *c, const QVariant &errorData) const override
QString parsingError(Context *c, const QVariant &errorData={}) const
The Cutelyst namespace holds all public Cutelyst API.
Base class for all validator rules.
qulonglong toULongLong(bool *ok, int base) const const
QLocale locale() const noexcept
QString label(Context *c) const
QString field() const noexcept
QString value(const ParamsMultiMap ¶ms) const
QString fromLatin1(QByteArrayView str)
QString validationError(Context *c, const QVariant &errorData={}) const
QString validationDataError(Context *c, const QVariant &errorData={}) const
QString qtTrId(const char *id, int n=-1) const
qsizetype length() const const
bool isValid() const const
Contains the result of a single input parameter validation.
double toDouble(bool *ok) const const
ValidatorSize(const QString &field, QMetaType::Type type, const QVariant &size, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
QString arg(Args &&... args) const const
QString genericParsingError(Context *c, const QVariant &errorData) const override
QString debugString(Context *c) const
void setValue(QVariant &&value)