
#include "QULongValidator.h"

QULongValidator::QULongValidator(QObject *parent) : QValidator(parent), m_Minimum(0), m_Maximum(0) {
}

QULongValidator::QULongValidator(QULongValidator::value_type minimum, QULongValidator::value_type maximum, QObject *parent) : QValidator(parent), m_Minimum(minimum), m_Maximum(maximum) {
}

QULongValidator::~QULongValidator() {
}

QULongValidator::value_type QULongValidator::bottom() const {
	return m_Minimum;
}

void QULongValidator::setBottom(QULongValidator::value_type bottom) {
	m_Minimum = bottom;
}

void QULongValidator::setRange(QULongValidator::value_type bottom, QULongValidator::value_type top) {
	setBottom(bottom);
	setTop(top);
}

void QULongValidator::setTop(QULongValidator::value_type top) {
	m_Maximum = top;
}

QULongValidator::value_type QULongValidator::top() const {
	return m_Maximum;
}

QValidator::State QULongValidator::validate(QString &input, int &pos) const {
	Q_UNUSED(pos);

	if(input.isEmpty()) {
		return QValidator::Acceptable;
	}

	bool ok;
	const value_type temp = input.toULong(&ok);
	if(!ok) {
		return QValidator::Invalid;
	}

	return (temp >= bottom() && temp <= top()) ? QValidator::Acceptable : QValidator::Intermediate;
}
