6#include "validatordifferent_p.h"
12 const char *otherLabel,
14 :
ValidatorRule(*new ValidatorDifferentPrivate(field, other, otherLabel, messages))
26 const QString v =
value(params);
28 trimBefore() ? params.value(d->otherField).trimmed() : params.value(d->otherField);
33 qCDebug(C_VALIDATOR).noquote().nospace()
34 <<
debugString(c) <<
" The value in \"" << d->otherField
35 <<
"\" is not different: \"" << v <<
"\" == \"" << o <<
"\"";
37 result.
value.setValue(v);
50 const QString _label =
label(c);
51 const QString _otherLabel = [d, c]() -> QString {
53 return d->translationContext ? c->
translate(d->translationContext, d->otherLabel)
54 : c->
qtTrId(d->otherLabel);
60 if (_label.isEmpty()) {
63 return c->
qtTrId(
"cutelyst-valdifferent-genvalerr")
64 .arg(!_otherLabel.isEmpty() ? _otherLabel : d->otherField);
69 return c->
qtTrId(
"cutelyst-valdifferent-genvalerr-label")
70 .arg(_label, !_otherLabel.isEmpty() ? _otherLabel : d->otherField);
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
Checks if two values are different.
ValidatorDifferent(const QString &field, const QString &other, const char *otherLabel=nullptr, const ValidatorMessages &messages=ValidatorMessages())
~ValidatorDifferent() override
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Base class for all validator rules.
QString validationError(Context *c, const QVariant &errorData={}) const
QString label(Context *c) const
bool trimBefore() const noexcept
QString value(const ParamsMultiMap ¶ms) const
QString debugString(Context *c) const
QMultiMap< QString, QString > ParamsMultiMap
The Cutelyst namespace holds all public Cutelyst API.
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.