6#include "validatorrule_p.h"
8#include <Cutelyst/Context>
9#include <Cutelyst/ParamsMultiMap>
17 : d_ptr(new ValidatorRulePrivate(field, messages, defValKey, validatorName))
38 if (!d->field.isEmpty() && !params.
empty()) {
40 return params.
value(d->field).trimmed();
42 return params.
value(d->field);
53 if (d->messages.label) {
54 return d->translationContext ? c->
translate(d->translationContext, d->messages.label)
55 : c->
qtTrId(d->messages.label);
66 if (d->messages.validationError) {
67 return d->translationContext
68 ? c->
translate(d->translationContext, d->messages.validationError)
69 : c->
qtTrId(d->messages.validationError);
81 return c->
qtTrId(
"cutelyst-valrule-genvalerr");
85 return c->
qtTrId(
"cutelyst-valrule-genvalerr-label").
arg(_label);
94 if (d->messages.parsingError) {
95 return d->translationContext ? c->
translate(d->translationContext, d->messages.parsingError)
96 : c->
qtTrId(d->messages.parsingError);
108 return c->
qtTrId(
"cutelyst-valrule-genparseerr");
112 return c->
qtTrId(
"cutelyst-valrule-genparseerr-label").
arg(_label);
121 if (d->messages.validationDataError) {
122 return d->translationContext
123 ? c->
translate(d->translationContext, d->messages.validationDataError)
124 : c->
qtTrId(d->messages.validationDataError);
136 return c->
qtTrId(
"cutelyst-valrule-genvaldataerr");
140 return c->
qtTrId(
"cutelyst-valrule-genvaldataerr-label").
arg(_label);
146 Q_ASSERT_X(c,
"getting default value",
"invalid context object");
147 Q_ASSERT_X(result,
"getting default value",
"invalid result object");
149 if (!d->defValKey.isEmpty() && c->
stash().contains(d->defValKey)) {
151 qCDebug(C_VALIDATOR).noquote().nospace()
152 << d->validatorName <<
": Using default value " << result->
value <<
" for field \""
168 return d->trimBefore;
171void ValidatorRule::setTrimBefore(
bool trimBefore)
noexcept
174 d->trimBefore = trimBefore;
177void ValidatorRule::setTranslationContext(
const char *trContext)
noexcept
180 d->translationContext = trContext;
void stash(const QVariantHash &unite)
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
QString qtTrId(const char *id, int n=-1) const
Base class for all validator rules.
QString field() const noexcept
QString validationError(Context *c, const QVariant &errorData={}) const
QString label(Context *c) const
virtual QString genericValidationDataError(Context *c, const QVariant &errorData={}) const
virtual QString genericValidationError(Context *c, const QVariant &errorData={}) const
virtual ~ValidatorRule()
Deconstructs the ValidatorRule.
bool trimBefore() const noexcept
ValidatorRule(const QString &field, const ValidatorMessages &messages={}, const QString &defValKey={}, QByteArrayView validatorName=nullptr)
QString validationDataError(Context *c, const QVariant &errorData={}) const
void defaultValue(Context *c, ValidatorReturnType *result) const
QString value(const ParamsMultiMap ¶ms) const
QString parsingError(Context *c, const QVariant &errorData={}) const
virtual QString genericParsingError(Context *c, const QVariant &errorData={}) const
QString debugString(Context *c) const
The Cutelyst namespace holds all public Cutelyst API.
T value(const Key &key, const T &defaultValue) const const
QString arg(Args &&... args) const const
QString fromLatin1(QByteArrayView str)
bool isEmpty() const const
void setValue(QVariant &&value)
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.