Herunterladen als
root/src/validators/datevalidator.cpp @ 827458ed
ec6a9500 | Christian Ehringfeld | #include "datevalidator.h"
|
|
93bf6dcb | Christian Ehringfeld | #include <QDate>
|
|
#include <QLocale>
|
|||
ec6a9500 | Christian Ehringfeld | using namespace CuteEntityManager;
|
|
DateValidator::DateValidator() : Validator() {
|
|||
}
|
|||
ErrorMsg DateValidator::validateParam(QVariant value, Param param) const {
|
|||
93bf6dcb | Christian Ehringfeld | QDate date = value.toDate();
|
|
if (date.isValid()) {
|
|||
if (param.getName() == "future") {
|
|||
if (date < QDate::currentDate()) {
|
|||
3f097a32 | Christian Ehringfeld | return ErrorMsg(param.getName(), "<property> is not in the future.");
|
|
93bf6dcb | Christian Ehringfeld | }
|
|
} else if (param.getName() == "past") {
|
|||
if (date > QDate::currentDate()) {
|
|||
3f097a32 | Christian Ehringfeld | return ErrorMsg(param.getName(), "<property> is not in the past.");
|
|
93bf6dcb | Christian Ehringfeld | }
|
|
} else if (param.getName() == "min" && date < param.getValue().toDate()) {
|
|||
3f097a32 | Christian Ehringfeld | return ErrorMsg(param.getName(),
|
|
"<property> must be no less than " + param.getValue().toString() + ".");
|
|||
93bf6dcb | Christian Ehringfeld | } else if (param.getName() == "max" && date > param.getValue().toDate()) {
|
|
3f097a32 | Christian Ehringfeld | return ErrorMsg(param.getName(),
|
|
"<property> must be no greater than " + param.getValue().toString() + ".");
|
|||
93bf6dcb | Christian Ehringfeld | }
|
|
}
|
|||
//cause we don't want to replace functionality of RequiredValidator
|
|||
return ErrorMsg();
|
|||
ec6a9500 | Christian Ehringfeld | }
|