6 #include "validatorafter_p.h" 16 const char *inputFormat,
20 *new ValidatorAfterPrivate(field, comparison, timeZone, inputFormat, messages, defValKey))
38 const QTimeZone tz = d->extractTimeZone(c, params, d->timeZone);
42 ? d->extractOtherDateTime(c, params, d->comparison.toString(), tz, d->inputFormat)
48 if (Q_UNLIKELY(!odate.
isValid())) {
51 "ValidatorAfter: Invalid comparison date and time for field %s at %s::%s.",
53 qPrintable(c->controllerName()),
54 qPrintable(c->actionName()));
57 const QDate date = d->extractDate(c, v, d->inputFormat);
58 if (Q_UNLIKELY(!date.
isValid())) {
61 "ValidatorAfter: Can not parse input date \"%s\" for field %s at %s::%s.",
64 qPrintable(c->controllerName()),
65 qPrintable(c->actionName()));
68 if (Q_UNLIKELY(date <= odate)) {
70 "ValidatorAfter: Validation failed at %s::%s for field %s: Input " 71 "date \"%s\" is not after \"%s\".",
72 qPrintable(c->controllerName()),
73 qPrintable(c->actionName()),
87 if (Q_UNLIKELY(!odatetime.
isValid())) {
90 "ValidatorAfter: Invalid comparison date and time for field %s at %s::%s.",
92 qPrintable(c->controllerName()),
93 qPrintable(c->actionName()));
96 const QDateTime datetime = d->extractDateTime(c, v, d->inputFormat, tz);
97 if (Q_UNLIKELY(!datetime.
isValid())) {
98 qCWarning(C_VALIDATOR,
99 "ValidatorAfter: Can not parse input date and time \"%s\" for field " 103 qPrintable(c->controllerName()),
104 qPrintable(c->actionName()));
107 if (Q_UNLIKELY(datetime <= odatetime)) {
109 "ValidatorAfter: Validation failed at %s::%s for field %s: Input " 110 "date and time \"%s\" is not after \"%s\".",
111 qPrintable(c->controllerName()),
112 qPrintable(c->actionName()),
126 if (Q_UNLIKELY(!otime.
isValid())) {
127 qCWarning(C_VALIDATOR,
128 "ValidatorAfter: Invalid comparison time for field %s at %s::%s.",
130 qPrintable(c->controllerName()),
131 qPrintable(c->actionName()));
134 const QTime time = d->extractTime(c, v, d->inputFormat);
135 if (Q_UNLIKELY(!time.
isValid())) {
138 "ValidatorAfter: Can not parse input time \"%s\" for field %s at %s::%s.",
141 qPrintable(c->controllerName()),
142 qPrintable(c->actionName()));
145 if (Q_UNLIKELY(time <= otime)) {
147 "ValidatorAfter: Validation failed at %s::%s for field %s: Input " 148 "time \"%s\" is not after \"%s\".",
149 qPrintable(c->controllerName()),
150 qPrintable(c->actionName()),
162 qCWarning(C_VALIDATOR)
163 <<
"ValidatorAfter: Invalid validation data for field" <<
field() <<
"at" 164 << c->controllerName() <<
"::" << c->actionName() <<
":" << d->comparison;
185 QStringLiteral(
"Has to be after %1.")
189 error = QStringLiteral(
"Has to be after %1.")
195 QStringLiteral(
"Has to be after %1.")
209 "The date in the “%1” field must be after %2.")
214 error = c->
translate(
"Cutelyst::ValidatorAfter",
215 "The date and time in the “%1” field must be after %2.")
223 "The time in the “%1” field must be after %2.")
243 "The comparison value is not a valid date and/or time, or cannot be found.");
255 if (d->inputFormat) {
259 "Cutelyst::ValidatorAfter",
260 "Could not be parsed according to the following date and/or time format: %1")
261 .
arg(c->
translate(d->translationContext.data(), d->inputFormat));
263 error = c->
translate(
"Cutelyst::ValidatorAfter",
264 "The value of the “%1” field could not be parsed according to the " 265 "following date and/or time format: %2")
266 .
arg(_label, c->
translate(d->translationContext.data(), d->inputFormat));
273 error = c->
translate(
"Cutelyst::ValidatorAfter",
274 "Could not be parsed as date and time.");
277 error = c->
translate(
"Cutelyst::ValidatorAfter",
"Could not be parsed as time.");
280 error = c->
translate(
"Cutelyst::ValidatorAfter",
"Could not be parsed as date.");
291 "Cutelyst::ValidatorAfter",
292 "The value in the “%1” field could not be parsed as date and time.")
297 error = c->
translate(
"Cutelyst::ValidatorAfter",
298 "The value in the “%1” field could not be parsed as time.")
303 error = c->
translate(
"Cutelyst::ValidatorAfter",
304 "The value in the “%1” field could not be parsed as date.")
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error if validation failed.
QString toString(Qt::DateFormat format) const const
QString parsingError(Context *c, const QVariant &errorData=QVariant()) const
Returns an error message if an error occurred while parsing input.
QString validationError(Context *c, const QVariant &errorData=QVariant()) const
Returns a descriptive error message if validation failed.
QString toString(Qt::DateFormat format) const const
QString toString(Qt::DateFormat format) const const
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
Performs the validation and returns the result.
Stores custom error messages and the input field label.
QDateTime toDateTime() const const
QTime toTime() const const
bool isValid() const const
Checks if a date, time or datetime is after a comparison value.
bool isEmpty() const const
~ValidatorAfter() override
Deconstructs the after validator.
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
bool isValid() const const
QString genericParsingError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error if the input value could not be parsed.
QString validationDataError(Context *c, const QVariant &errorData=QVariant()) const
Returns an error message if any validation data is missing or invalid.
The Cutelyst namespace holds all public Cutelyst API.
Base class for all validator rules.
QLocale locale() const noexcept
QString label(Context *c) const
Returns the human readable field label used for generic error messages.
ValidatorAfter(const QString &field, const QVariant &comparison, const QString &timeZone=QString(), const char *inputFormat=nullptr, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new after validator.
int userType() const const
void setValue(const T &value)
QString value(const ParamsMultiMap ¶ms) const
Returns the value of the field from the input params.
bool isValid() const const
QDate toDate() const const
QString genericValidationDataError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error if comparison data was invalid.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString field() const
Returns the name of the field to validate.
Contains the result of a single input parameter validation.
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 ...