#include "LineEditWidgetFactory.h"
#include "DoubleValidator.h"

LineEditWidgetFactory::LineEditWidgetFactory()
{
}

LineEditWidgetFactory::~LineEditWidgetFactory()
{
}

void LineEditWidgetFactory::create(qx::IxDataMember *dataMember, QWidget *parent)
{
	widget = new LineEditWidget(parent);
	int maxLength = dataMember->getMaxLength();
	QVariant regExpStr = dataMember->getPropertyBag("regExp");
	QString type = dataMember->getType();
	if (maxLength != -1)
	{
		widget->setMaxLength(maxLength);
	}
	else if (regExpStr.isValid())
	{
		QRegExp regExp(regExpStr.toString());
		widget->setValidator(new QRegExpValidator(regExp, widget));
	}
	else if (type == "int")
	{
		QValidator *validator = new QIntValidator(dataMember->getMinValue().toInt(), dataMember->getMaxValue().toInt(), widget);
		widget->setValidator(validator);
	}
	else if (type == "double")
	{
		QValidator *validator = new DoubleValidator(dataMember->getMinValue().toDouble(), dataMember->getMaxValue().toDouble(), dataMember->getPrecision(), widget);
		widget->setValidator(validator);
	}
}

QString LineEditWidgetFactory::type() const
{
	return LineEditWidget::type;
}

QWidget* LineEditWidgetFactory::getWidget() const
{
	return widget;
}

IxWidget* LineEditWidgetFactory::getIxWidget() const
{
	return widget;
}
