
#include "QLongValidator.h"

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

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

QLongValidator::~QLongValidator() {
}

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

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

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

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

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

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

	if(input.isEmpty()) {
		return QValidator::Acceptable;
	}
	
	if(input.length() == 1 && input == "-") {
		return QValidator::Intermediate;
	}

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

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