예제 #1
0
void BoundTextBox::finalise()
{
    QString value = text();

    while (value.endsWith(","))
        value = value.left(value.length() - 1);

    if (_integerArray != NULL)
    {
        _integerArray->setValue(QIntArrayValidator::parse(value));
    }
    else if (_integer != NULL)
    {
        _integer->setValue(value.toInt());
    }
    else if (_number != NULL)
    {
        double v = value.toDouble();
        double min = _number->min();
        double max = _number->max();

        bool pc = _number->format() == "%";

        if (pc)
        {
            v /= 100;
            min *= 100;
            max *= 100;
        }

        if (v > _number->max() || v < _number->min())
        {
            if (pc)
            {
                setIllegal(QString("%1 must be between %2% and %3%").arg(_label).arg(min).arg(max));
            }
            else
            {
                setIllegal(QString("%1 must be between %2 and %3").arg(_label).arg(min).arg(max));
            }
        }
        else
        {
            _number->setValue(v);
            setLegal();
        }
    }
}
예제 #2
0
void BoundTextBox::bindTo(Option *option)
{
	setLegal();

	_integer = dynamic_cast<OptionInteger *>(option);

	if (_integer != NULL)
	{
		int v = _integer->value();
		int min = _integer->min();
		int max = _integer->max();

		this->setValidator(new QIntValidator(min, max, this));
		this->setText(QString::number(_integer->value()));
		return;
	}

	_integerArray = dynamic_cast<OptionIntegerArray *>(option);

	if (_integerArray != NULL)
	{
		this->setValidator(new QIntArrayValidator());
		return;
	}

	_number = dynamic_cast<OptionNumber *>(option);

	if (_number != NULL)
	{
		double v = _number->value();
		double min = _number->min();
		double max = _number->max();

		if (_number->format() == "%")
		{
			v *= 100;
			min *= 100;
			max *= 100;
		}

		this->setValidator(new QDoubleValidator(min, max, 4, this));
		this->setText(QString::number(v));
		return;
	}

}
예제 #3
0
void BoundTextBox::bindTo(Option *option)
{
	setLegal();

	_string = dynamic_cast<OptionString *>(option);
	if (_string != NULL)
	{
		int max = _string->max();
		std::string regExpStr = _string->regexp();
		if (max > 0 && regExpStr.empty())
		{
			std::ostringstream strs;
			strs << "^.{0," << max << "}$";
			regExpStr = strs.str();
		}
		if (!regExpStr.empty())
			this->setValidator(new QRegExpValidator(QRegExp(QString::fromStdString(regExpStr)), this));

		this->setText(QString::fromStdString(_string->value()));
		return;
	}

	_integer = dynamic_cast<OptionInteger *>(option);

	if (_integer != NULL)
	{
		int min = _integer->minimum();
		int max = _integer->maximum();

		this->setValidator(new QIntValidator(min, max, this));
		this->setText(QString::number(_integer->value()));
		return;
	}

	_integerArray = dynamic_cast<OptionIntegerArray *>(option);

	if (_integerArray != NULL)
	{
		this->setValidator(new QIntArrayValidator());
		return;
	}

	_number = dynamic_cast<OptionNumber *>(option);

	if (_number != NULL)
	{
		double v = _number->value();
		double min = _number->minimum();
		double max = _number->maximum();

		if (_number->format() == "%")
		{
			v *= 100;
			min *= 100;
			max *= 100;
		}

		this->setValidator(new QDoubleValidator(min, max, 4, this));
		this->setText(QString::number(v));
		return;
	}

}