32 const QString v =
value(params);
36 const QTimeZone tz = ValidatorAfterPrivate::extractTimeZone(c, params, d->timeZone);
38 const QVariant _comp =
39 (d->comparison.userType() == QMetaType::QString)
40 ? d->extractOtherDateTime(c, params, d->comparison.toString(), tz, d->inputFormat)
43 if (_comp.userType() == QMetaType::QDate) {
45 const QDate odate = _comp.toDate();
46 if (Q_UNLIKELY(!odate.isValid())) {
47 qCWarning(C_VALIDATOR).noquote() <<
debugString(c) <<
"Invalid comparison date";
50 const QDate date = d->extractDate(c, v, d->inputFormat);
51 if (Q_UNLIKELY(!date.isValid())) {
52 qCWarning(C_VALIDATOR).noquote().nospace()
53 <<
debugString(c) <<
" Can not parse input date \"" << v <<
"\"";
56 if (Q_UNLIKELY(date <= odate)) {
57 qCDebug(C_VALIDATOR).noquote()
58 <<
debugString(c) <<
"Input" << date <<
"is not after" << odate;
61 result.
value.setValue(date);
66 }
else if (_comp.userType() == QMetaType::QDateTime) {
68 const QDateTime odatetime = _comp.toDateTime();
69 if (Q_UNLIKELY(!odatetime.isValid())) {
70 qCWarning(C_VALIDATOR).noquote() <<
debugString(c) <<
"Invalid comparison datetime";
73 const QDateTime datetime = d->extractDateTime(c, v, d->inputFormat, tz);
74 if (Q_UNLIKELY(!datetime.isValid())) {
75 qCWarning(C_VALIDATOR).noquote().nospace()
76 <<
debugString(c) <<
" Can not parse input datetime \"" << v <<
"\"";
79 if (Q_UNLIKELY(datetime <= odatetime)) {
80 qCDebug(C_VALIDATOR).noquote()
81 <<
debugString(c) <<
"Input" << datetime <<
"is not after" << odatetime;
84 result.
value.setValue(datetime);
89 }
else if (_comp.userType() == QMetaType::QTime) {
91 const QTime otime = _comp.toTime();
92 if (Q_UNLIKELY(!otime.isValid())) {
93 qCWarning(C_VALIDATOR).noquote() <<
debugString(c) <<
"Invalid comparison time";
96 const QTime time = d->extractTime(c, v, d->inputFormat);
97 if (Q_UNLIKELY(!time.isValid())) {
98 qCWarning(C_VALIDATOR).noquote().nospace()
99 <<
debugString(c) <<
" Can not parse input time \"" << v <<
"\"";
102 if (Q_UNLIKELY(time <= otime)) {
103 qCDebug(C_VALIDATOR).noquote()
104 <<
debugString(c) <<
"Input" << time <<
"is not after" << otime;
107 result.
value.setValue(time);
113 qCWarning(C_VALIDATOR).noquote()
114 <<
debugString(c) <<
"Invalid comparison data:" << d->comparison;
130 const QVariant &errorData)
const
132 const QString _label =
label(c);
133 if (_label.isEmpty()) {
135 switch (errorData.userType()) {
136 case QMetaType::QDate:
139 return c->
qtTrId(
"cutelyst-valafter-genvalerr-date")
140 .arg(c->
locale().toString(errorData.toDate(), QLocale::ShortFormat));
141 case QMetaType::QDateTime:
144 return c->
qtTrId(
"cutelyst-valafter-genvalerr-dt")
145 .arg(c->
locale().toString(errorData.toDateTime(), QLocale::ShortFormat));
146 case QMetaType::QTime:
149 return c->
qtTrId(
"cutelyst-valafter-genvalerr-time")
150 .arg(c->
locale().toString(errorData.toTime(), QLocale::ShortFormat));
157 switch (errorData.userType()) {
158 case QMetaType::QDate:
161 return c->
qtTrId(
"cutelyst-valafter-genvalerr-date-label")
162 .arg(_label, c->
locale().toString(errorData.toDate(), QLocale::ShortFormat));
163 case QMetaType::QDateTime:
167 return c->
qtTrId(
"cutelyst-valafter-genvalerr-dt-label")
168 .arg(_label, c->
locale().toString(errorData.toDateTime(), QLocale::ShortFormat));
169 case QMetaType::QTime:
172 return c->
qtTrId(
"cutelyst-valafter-genvalerr-time-label")
173 .arg(_label, c->
locale().toString(errorData.toTime(), QLocale::ShortFormat));
199 const QString _label =
label(c);
200 if (d->inputFormat) {
201 const QString _inputFormatTranslated =
202 d->translationContext ? c->
translate(d->translationContext, d->inputFormat)
203 : c->
qtTrId(d->inputFormat);
204 if (_label.isEmpty()) {
207 return c->
qtTrId(
"cutelyst-validator-genparseerr-dt-format")
208 .arg(_inputFormatTranslated);
213 return c->
qtTrId(
"cutelyst-validator-genparseerr-dt-format-label")
214 .arg(_label, _inputFormatTranslated);
218 if (_label.isEmpty()) {
219 switch (errorData.userType()) {
220 case QMetaType::QDateTime:
222 return c->
qtTrId(
"cutelyst-validator-genparseerr-dt");
223 case QMetaType::QTime:
225 return c->
qtTrId(
"cutelyst-validator-genparseerr-time");
226 case QMetaType::QDate:
228 return c->
qtTrId(
"cutelyst-validator-genparseerr-date");
233 switch (errorData.userType()) {
234 case QMetaType::QDateTime:
237 return c->
qtTrId(
"cutelyst-vaidator-genparseerr-dt-label").arg(_label);
238 case QMetaType::QTime:
241 return c->
qtTrId(
"cutelyst-validator-genparseerr-time-label").arg(_label);
242 case QMetaType::QDate:
245 return c->
qtTrId(
"cutelyst-validator-genparseerr-date-label").arg(_label);
QLocale locale() const noexcept
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
ValidatorAfter(const QString &field, const QVariant &comparison, const QString &timeZone={}, const char *inputFormat=nullptr, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey={})