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 "ValidatorSize: Failed to parse value of field %s into number at %s::%s.",
47 qPrintable(c->controllerName()),
48 qPrintable(c->actionName()));
50 const qlonglong size = d->extractLongLong(c, params, d->size, &ok);
51 if (Q_UNLIKELY(!ok)) {
53 qCWarning(C_VALIDATOR,
54 "ValidatorSize: Invalid comparison size for field %s in %s::%s.",
56 qPrintable(c->controllerName()),
57 qPrintable(c->actionName()));
62 QVariantMap{{QStringLiteral(
"val"), val},
63 {QStringLiteral(
"size"), size}});
65 "ValidatorSize: Validation failed for field %s in %s::%s: value is "
68 qPrintable(c->controllerName()),
69 qPrintable(c->actionName()),
77 case QMetaType::UShort:
79 case QMetaType::ULong:
80 case QMetaType::ULongLong:
82 const qulonglong val = v.toULongLong(&ok);
83 if (Q_UNLIKELY(!ok)) {
85 qCWarning(C_VALIDATOR,
86 "ValidatorSize: Failed to parse value of field %s into number at %s::%s.",
88 qPrintable(c->controllerName()),
89 qPrintable(c->actionName()));
91 const qulonglong size = d->extractULongLong(c, params, d->size, &ok);
92 if (Q_UNLIKELY(!ok)) {
96 "ValidatorSize: Invalid maximum comparison value for field %s in %s::%s.",
98 qPrintable(c->controllerName()),
99 qPrintable(c->actionName()));
104 QVariantMap{{QStringLiteral(
"val"), val},
105 {QStringLiteral(
"size"), size}});
107 "ValidatorSize: Validation failed for field %s in %s::%s: value is "
110 qPrintable(c->controllerName()),
111 qPrintable(c->actionName()),
119 case QMetaType::Float:
120 case QMetaType::Double:
122 const double val = v.toDouble(&ok);
123 if (Q_UNLIKELY(!ok)) {
125 qCWarning(C_VALIDATOR,
126 "ValidatorSize: Failed to parse value of field %s into number at %s::%s.",
128 qPrintable(c->controllerName()),
129 qPrintable(c->actionName()));
131 const double size = d->extractDouble(c, params, d->size, &ok);
132 if (Q_UNLIKELY(!ok)) {
136 "ValidatorSize: Invalid maximum comparison value for field %s in %s::%s.",
138 qPrintable(c->controllerName()),
139 qPrintable(c->actionName()));
144 QVariantMap{{QStringLiteral(
"val"), val},
145 {QStringLiteral(
"size"), size}});
147 "ValidatorSize: Validation failed for field %s in %s::%s: value is "
150 qPrintable(c->controllerName()),
151 qPrintable(c->actionName()),
159 case QMetaType::QString:
161 const qlonglong val =
static_cast<qlonglong
>(v.length());
162 const qlonglong size = d->extractLongLong(c, params, d->size, &ok);
163 if (Q_UNLIKELY(!ok)) {
165 qCWarning(C_VALIDATOR,
166 "ValidatorSize: Invalid maximum comparison value for field %s in %s::%s.",
168 qPrintable(c->controllerName()),
169 qPrintable(c->actionName()));
174 QVariantMap{{QStringLiteral(
"val"), val}, {QStringLiteral(
"size"), size}});
176 "ValidatorSize: Validation failed for field %s in %s::%s: string "
177 "length is not %lli.",
179 qPrintable(c->controllerName()),
180 qPrintable(c->actionName()),
188 qCWarning(C_VALIDATOR,
189 "ValidatorSize: The comparison type with ID %i for field %s at %s::%s is not "
191 static_cast<int>(d->type),
193 qPrintable(c->controllerName()),
194 qPrintable(c->actionName()));
200 if (d->type != QMetaType::QString) {
201 const QVariant _v = d->valueToNumber(c, v, d->type);
208 result.
value.setValue(v);
QLocale locale() const noexcept
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
ValidatorSize(const QString &field, QMetaType::Type type, const QVariant &size, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new size validator.