5#ifndef CUTELYSTVALIDATORRULE_H
6#define CUTELYSTVALIDATORRULE_H
8#include <Cutelyst/cutelyst_global.h>
9#include <Cutelyst/paramsmultimap.h>
11#include <QLoggingCategory>
12#include <QScopedPointer>
15Q_DECLARE_LOGGING_CATEGORY(C_VALIDATOR)
157 const char *customValidationError =
nullptr,
158 const char *customParsingError =
nullptr,
159 const char *customValidationDataError =
nullptr)
166 const char *label =
nullptr;
167 const char *validationError =
nullptr;
168 const char *parsingError =
nullptr;
169 const char *validationDataError =
nullptr;
172class ValidatorRulePrivate;
576 friend class Validator;
577 friend class ValidatorPrivate;
virtual QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const
Returns a generic error mesage if validation failed.
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.
bool trimBefore() const
Returns true if the field value should be trimmed before validation.
virtual QString genericValidationDataError(Context *c, const QVariant &errorData=QVariant()) const
Returns a generic error message if any validation data is missing or invalid.
QString parsingError(Context *c, const QVariant &errorData=QVariant()) const
Returns an error message if an error occurred while parsing input.
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 ...
virtual ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const =0
Starts the validation and returns the result.
ValidatorRule(const QString &field, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new ValidatorRule with the given parameters.
QString value(const ParamsMultiMap ¶ms) const
Returns the value of the field from the input params.
virtual QString genericParsingError(Context *c, const QVariant &errorData=QVariant()) const
Returns a generic error message if an error occures while parsing input.
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.
const char * parsingError
const char * validationError
const char * validationDataError
ValidatorMessages()
Constructs a default ValidatorMessages object with all custom messages disabled.
Contains the result of a single input parameter validation.
bool isValid() const
Returns true if validation succeeded.