示例#1
0
void CurrDisplay::setLocalValue(double newValue)
{
    _state = (_state == NANew || _state == NAInit) ? NAInit : Initialized;

    // either the value has significantly changed or we're explicitly setting 0
    if (ABS(_valueLocal - newValue) > EPSILON(_localScale) ||
            newValue < EPSILON(_localScale))
    {
        _valueLocal = newValue;
        _localKnown = true;
        emit valueLocalChanged(_valueLocal);
        sValueLocalChanged(_valueLocal);
        sReformat();
    }
}
void CurrDisplay::setLocalValue(double newValue)
{
  _state = (_state == NANew || _state == NAInit) ? NAInit : Initialized;

  // either the value has significantly changed or we're explicitly setting 0
  if (ABS(_valueLocal - newValue) > EPSILON(_localScale) ||
      newValue < EPSILON(_localScale))
  {
    double prec = pow(10.0, qMax(0, (_decimals + _localScale)));
    // use the floor function here instead of qRound to prevent problem on windows builds
    _valueLocal = floor(newValue*prec + 0.5f)/prec;
    _localKnown = true;
    emit valueLocalChanged(_valueLocal);
    sValueLocalChanged(_valueLocal);
    sReformat();
  }
}
示例#3
0
void CurrDisplay::sValueBaseChanged(double newValue)
{
    double oldLocal = _valueLocal;
    if (ABS(newValue) < EPSILON(_baseScale) || _effective.isNull())
    {
        if (ABS(_valueLocal) >= EPSILON(_localScale))
        {
            _valueLocal = 0;
            _valueLocalWidget->clear();
        }
    }
    else
    {
        XSqlQuery convertVal;
        convertVal.prepare("SELECT currToLocal(:curr_id, :value, :date) "
                           " AS localValue;");
        convertVal.bindValue(":curr_id", id());
        convertVal.bindValue(":value", newValue);
        convertVal.bindValue(":date", _effective);
        convertVal.exec();
        if (convertVal.first())
        {
            _valueLocal = convertVal.value("localValue").toDouble();
            sZeroErrorCount(id(), effective());
            _localKnown = true;
        }
        else if (convertVal.lastError().type() != QSqlError::NoError)
        {
            if (convertVal.lastError().databaseText().contains("No exchange rate"))
            {
                emit noConversionRate();
                sNoConversionRate(this, id(), effective(), "sValueBaseChanged");
            }
            else
                QMessageBox::critical(this, tr("A System Error occurred at %1::%2.")
                                      .arg(__FILE__)
                                      .arg(__LINE__),
                                      convertVal.lastError().databaseText());
            _localKnown = false;
        }
    }
    if (ABS(oldLocal - _valueLocal) > EPSILON(_localScale))
        emit valueLocalChanged(_valueLocal);
}
示例#4
0
void CurrDisplay::setLocalValue(double newValue)
{
    _state = (_state == NANew || _state == NAInit) ? NAInit : Initialized;

    // either the value has significantly changed or we're explicitly setting 0
    if (ABS(_valueLocal - newValue) > EPSILON(_localScale) ||
            newValue < EPSILON(_localScale))
    {
        _valueLocal = newValue;
        _localKnown = true;
        emit valueLocalChanged(_valueLocal);
        sValueLocalChanged(_valueLocal);
        sReformat();
    }

    if (_mapper->model() &&
            _mapper->model()->data(_mapper->model()->index(_mapper->currentIndex(),_mapper->mappedSection(this))).toDouble() != _valueLocal)
        _mapper->model()->setData(_mapper->model()->index(_mapper->currentIndex(),_mapper->mappedSection(this)), _valueLocal);
}