19 #include "validatorinteger_p.h" 24 ValidatorRule(*new ValidatorIntegerPrivate(field, type, messages, defValKey))
44 case QMetaType::Short:
47 case QMetaType::LongLong:
48 case QMetaType::UChar:
49 case QMetaType::UShort:
51 case QMetaType::ULong:
52 case QMetaType::ULongLong:
53 converted = d->valueToNumber(c, v, d->type);
57 qCWarning(C_VALIDATOR,
"ValidatorInteger: Conversion type for field %s at %s::%s is not an integer type.", qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()));
62 result.
value = converted;
64 qCDebug(C_VALIDATOR,
"ValidatorInteger: Validation failed for field %s at %s::%s: not an integer value.", qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()));
87 case QMetaType::Short:
96 min = c->
locale().
toString(static_cast<qlonglong>(std::numeric_limits<long>::min()));
97 max = c->
locale().
toString(static_cast<qlonglong>(std::numeric_limits<long>::max()));
99 case QMetaType::LongLong:
100 min = c->
locale().
toString(std::numeric_limits<qlonglong>::min());
101 max = c->
locale().
toString(std::numeric_limits<qlonglong>::max());
103 case QMetaType::UChar:
107 case QMetaType::UShort:
111 case QMetaType::UInt:
115 case QMetaType::ULong:
116 min = c->
locale().
toString(static_cast<qulonglong>(std::numeric_limits<ulong>::min()));
117 max = c->
locale().
toString(static_cast<qulonglong>(std::numeric_limits<ulong>::max()));
119 case QMetaType::ULongLong:
121 min = c->
locale().
toString(std::numeric_limits<qulonglong>::min());
122 max = c->
locale().
toString(std::numeric_limits<qulonglong>::max());
127 error = c->
translate(
"Cutelyst::ValidatorInteger",
"Not a valid integer value between %1 and %2.").
arg(min, max);
130 error = c->
translate(
"Cutelyst::ValidatorInteger",
"The value in the “%1“ field is not a valid integer between %2 and %3.").
arg(_label, min, max);
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error message if validation failed.
QString validationError(Context *c, const QVariant &errorData=QVariant()) const
Returns a descriptive error message if validation failed.
QString toString(qlonglong i) const
ValidatorInteger(const QString &field, QMetaType::Type type=QMetaType::ULongLong, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new integer validator.
Stores custom error messages and the input field label.
~ValidatorInteger() override
Deconstructs the integer validator.
Checks if the value is an integer.
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
Performs the validation and returns the result.
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
QString validationDataError(Context *c, const QVariant &errorData=QVariant()) const
Returns an error message if any validation data is missing or invalid.
The Cutelyst namespace holds all public Cutelyst API.
Base class for all validator rules.
QString label(Context *c) const
Returns the human readable field label used for generic error messages.
QString value(const ParamsMultiMap ¶ms) const
Returns the value of the field from the input params.
QString field() const
Returns the name of the field to validate.
Contains the result of a single input parameter validation.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const
void defaultValue(Context *c, ValidatorReturnType *result, const char *validatorName) const
I a defValKey has been set in the constructor, this will try to get the default value from the stash ...