Projekt

Allgemein

Profil

Herunterladen als
Herunterladen (2,09 KB) Statistiken
| Zweig: | Revision:
ec6a9500 Christian Ehringfeld
#include "imagevalidator.h"
519b2fe3 Christian Ehringfeld
#ifdef QT_GUI_LIB
#include <QImage>
#endif
ec6a9500 Christian Ehringfeld
using namespace CuteEntityManager;
ImageValidator::ImageValidator() : FileValidator() {
}

ErrorMsg ImageValidator::validateParam(QVariant value, Param param) const {
519b2fe3 Christian Ehringfeld
ErrorMsg msg = FileValidator::validateParam(value, param);
if (msg.getErrorMsg().isEmpty()) {
msg = this->validateImage(value, param);
}
return msg;
}
ec6a9500 Christian Ehringfeld
519b2fe3 Christian Ehringfeld
ErrorMsg ImageValidator::validateImage(QVariant value, Param param) const {
#ifdef QT_GUI_LIB
//isImage
QImage img = QImage(value.toString());
if (!img.isNull()) {
if (param.getName() == "minWidth"
&& img.width() < param.getValue().toLongLong()) {
ErrorMsg(param.getName(),
"The image " + value.toString() +
" is too smal. The width cannot be smaller than " + param.getValue().toString()
+ ".");
} else if (param.getName() == "maxWidth"
&& img.width() > param.getValue().toLongLong()) {
ErrorMsg(param.getName(),
"The image " + value.toString() +
" is too smal. The width cannot be larger than " + param.getValue().toString() +
".");
} else if (param.getName() == "minHeight"
&& img.height() < param.getValue().toLongLong()) {
ErrorMsg(param.getName(),
"The image " + value.toString() +
" is too smal. The height cannot be smaller than " + param.getValue().toString()
+ ".");
} else if (param.getName() == "maxHeight"
&& img.height() > param.getValue().toLongLong()) {
ErrorMsg(param.getName(),
"The image " + value.toString() +
" is too smal. The height cannot be larger than " + param.getValue().toString()
+ ".");
}
} else {
return ErrorMsg("", "The file " + value.toString() + " is not a valid image.");
}
#else
Q_UNUSED(value)
Q_UNUSED(param)
#endif
return ErrorMsg();
ec6a9500 Christian Ehringfeld
}