6#include "validatorinteger_p.h"
13 const QString &defValKey)
14 :
ValidatorRule(*new ValidatorIntegerPrivate(field, type, messages, defValKey))
27 const QString v =
value(params);
35 case QMetaType::Short:
38 case QMetaType::LongLong:
39 case QMetaType::UChar:
40 case QMetaType::UShort:
42 case QMetaType::ULong:
43 case QMetaType::ULongLong:
44 converted = d->valueToNumber(c, v, d->type);
50 "ValidatorInteger: Conversion type for field %s at %s::%s is not an integer type.",
52 qPrintable(c->controllerName()),
53 qPrintable(c->actionName()));
57 if (converted.isValid()) {
58 result.
value = converted;
62 "ValidatorInteger: Validation failed for field %s at %s::%s: not an integer value.",
64 qPrintable(c->controllerName()),
65 qPrintable(c->actionName()));
80 const QString _label =
label(c);
85 min = c->
locale().toString(std::numeric_limits<char>::min());
86 max = c->
locale().toString(std::numeric_limits<char>::max());
88 case QMetaType::Short:
89 min = c->
locale().toString(std::numeric_limits<short>::min());
90 max = c->
locale().toString(std::numeric_limits<short>::max());
93 min = c->
locale().toString(std::numeric_limits<int>::min());
94 max = c->
locale().toString(std::numeric_limits<int>::max());
97 min = c->
locale().toString(
static_cast<qlonglong
>(std::numeric_limits<long>::min()));
98 max = c->
locale().toString(
static_cast<qlonglong
>(std::numeric_limits<long>::max()));
100 case QMetaType::LongLong:
101 min = c->
locale().toString(std::numeric_limits<qlonglong>::min());
102 max = c->
locale().toString(std::numeric_limits<qlonglong>::max());
104 case QMetaType::UChar:
105 min = c->
locale().toString(std::numeric_limits<uchar>::min());
106 max = c->
locale().toString(std::numeric_limits<uchar>::max());
108 case QMetaType::UShort:
109 min = c->
locale().toString(std::numeric_limits<ushort>::min());
110 max = c->
locale().toString(std::numeric_limits<ushort>::max());
112 case QMetaType::UInt:
113 min = c->
locale().toString(std::numeric_limits<uint>::min());
114 max = c->
locale().toString(std::numeric_limits<uint>::max());
116 case QMetaType::ULong:
117 min = c->
locale().toString(
static_cast<qulonglong
>(std::numeric_limits<ulong>::min()));
118 max = c->
locale().toString(
static_cast<qulonglong
>(std::numeric_limits<ulong>::max()));
120 case QMetaType::ULongLong:
122 min = c->
locale().toString(std::numeric_limits<qulonglong>::min());
123 max = c->
locale().toString(std::numeric_limits<qulonglong>::max());
126 if (_label.isEmpty()) {
128 error = c->
translate(
"Cutelyst::ValidatorInteger",
129 "Not a valid integer value between %1 and %2.")
135 c->
translate(
"Cutelyst::ValidatorInteger",
136 "The value in the “%1“ field is not a valid integer between %2 and %3.")
137 .arg(_label, min, max);
QLocale locale() const noexcept
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
Checks if the value is an integer.
~ValidatorInteger() override
Deconstructs the integer validator.
ValidatorInteger(const QString &field, QMetaType::Type type=QMetaType::ULongLong, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new integer validator.
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
Performs the validation and returns the result.
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error message if validation failed.
Base class for all validator rules.
QString label(Context *c) const
Returns the human readable field label used for generic error messages.
QString field() const
Returns the name of the field to validate.
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 ...
QString value(const ParamsMultiMap ¶ms) const
Returns the value of the field from the input params.
QString validationDataError(Context *c, const QVariant &errorData=QVariant()) const
Returns an error message if any validation data is missing or invalid.
QString validationError(Context *c, const QVariant &errorData=QVariant()) const
Returns a descriptive error message if validation failed.
The Cutelyst namespace holds all public Cutelyst API.
QMultiMap< QString, QString > ParamsMultiMap
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.