27 const QString v =
value(params);
36 case QMetaType::Short:
39 case QMetaType::LongLong:
41 const qlonglong val = c->
locale().toLongLong(v, &ok);
42 if (Q_UNLIKELY(!ok)) {
44 qCWarning(C_VALIDATOR,
45 "ValidatorMax: Failed to parse value of field %s into number at %s::%s.",
47 qPrintable(c->controllerName()),
48 qPrintable(c->actionName()));
50 const qlonglong max = d->extractLongLong(c, params, d->max, &ok);
51 if (Q_UNLIKELY(!ok)) {
55 "ValidatorMax: Invalid maximum comparison value for field %s in %s::%s.",
57 qPrintable(c->controllerName()),
58 qPrintable(c->actionName()));
63 QVariantMap{{QStringLiteral(
"val"), val},
64 {QStringLiteral(
"max"), max}});
66 "ValidatorMax: Validation failed for field %s in %s::%s: %lli is "
67 "not smaller than %lli.",
69 qPrintable(c->controllerName()),
70 qPrintable(c->actionName()),
79 case QMetaType::UChar:
80 case QMetaType::UShort:
82 case QMetaType::ULong:
83 case QMetaType::ULongLong:
85 const qulonglong val = v.toULongLong(&ok);
86 if (Q_UNLIKELY(!ok)) {
88 qCWarning(C_VALIDATOR,
89 "ValidatorMax: Failed to parse value of field %s into number at %s::%s.",
91 qPrintable(c->controllerName()),
92 qPrintable(c->actionName()));
94 const qulonglong max = d->extractULongLong(c, params, d->max, &ok);
95 if (Q_UNLIKELY(!ok)) {
99 "ValidatorMax: Invalid maximum comparison value for field %s in %s::%s.",
101 qPrintable(c->controllerName()),
102 qPrintable(c->actionName()));
107 QVariantMap{{QStringLiteral(
"val"), val},
108 {QStringLiteral(
"max"), max}});
110 "ValidatorMax: Validation failed for field %s in %s::%s: %llu is "
111 "not smaller than %llu.",
113 qPrintable(c->controllerName()),
114 qPrintable(c->actionName()),
123 case QMetaType::Float:
124 case QMetaType::Double:
126 const double val = v.toDouble(&ok);
127 if (Q_UNLIKELY(!ok)) {
129 qCWarning(C_VALIDATOR,
130 "ValidatorMax: Failed to parse value of field %s into number at %s::%s.",
132 qPrintable(c->controllerName()),
133 qPrintable(c->actionName()));
135 const double max = d->extractDouble(c, params, d->max, &ok);
136 if (Q_UNLIKELY(!ok)) {
140 "ValidatorMax: Invalid maximum comparison value for field %s in %s::%s.",
142 qPrintable(c->controllerName()),
143 qPrintable(c->actionName()));
148 QVariantMap{{QStringLiteral(
"val"), val},
149 {QStringLiteral(
"max"), max}});
151 "ValidatorMax: Validation failed for field %s in %s::%s: %f is not "
154 qPrintable(c->controllerName()),
155 qPrintable(c->actionName()),
164 case QMetaType::QString:
166 const qlonglong val =
static_cast<qlonglong
>(v.length());
167 const qlonglong max = d->extractLongLong(c, params, d->max, &ok);
168 if (Q_UNLIKELY(!ok)) {
170 qCWarning(C_VALIDATOR,
171 "ValidatorMax: Invalid maximum comparison value for field %s in %s::%s.",
173 qPrintable(c->controllerName()),
174 qPrintable(c->actionName()));
178 c, QVariantMap{{QStringLiteral(
"val"), val}, {QStringLiteral(
"max"), max}});
180 "ValidatorMax: Validation failed for field %s in %s::%s: string length "
181 "%lli is not smaller than %lli.",
183 qPrintable(c->controllerName()),
184 qPrintable(c->actionName()),
193 qCWarning(C_VALIDATOR,
194 "ValidatorMax: The comparison type with ID %i for field %s at %s::%s is not "
196 static_cast<int>(d->type),
198 qPrintable(c->controllerName()),
199 qPrintable(c->actionName()));
205 if (d->type != QMetaType::QString) {
206 const QVariant _v = d->valueToNumber(c, v, d->type);
213 result.
value.setValue(v);
QLocale locale() const noexcept
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
ValidatorMax(const QString &field, QMetaType::Type type, const QVariant &max, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new max validator.