示例#1
0
bool CurrDisplay::isZero() const
{
    if (_localControl)
        return ABS(_valueLocal) < EPSILON(_localScale);
    else
        return ABS(_valueBase) < EPSILON(_baseScale);
}
示例#2
0
void CurrDisplay::sValueLocalChanged(double newValue)
{
    if (_mapper->model() &&
            _mapper->model()->data(_mapper->model()->index(_mapper->currentIndex(),_mapper->mappedSection(this))).toDouble() != newValue)
        _mapper->model()->setData(_mapper->model()->index(_mapper->currentIndex(),_mapper->mappedSection(this)), newValue);

    double oldBase = _valueBase;
    if (ABS(newValue) < EPSILON(_localScale) || _effective.isNull())
    {
        if (ABS(_valueBase) >= EPSILON(_baseScale))
        {
            _valueBase = 0;
            _baseKnown = true;
        }
    }
    else
    {
        XSqlQuery convertVal;
        convertVal.prepare("SELECT currToBase(:curr_id, :value, :date) "
                           " AS baseValue;");
        convertVal.bindValue(":curr_id", id());
        convertVal.bindValue(":value", newValue);
        convertVal.bindValue(":date", _effective);
        convertVal.exec();
        if (convertVal.first())
        {
            _valueBase = convertVal.value("baseValue").toDouble();
            sZeroErrorCount(id(), effective());
            _baseKnown = true;
        }
        else if (convertVal.lastError().type() != QSqlError::NoError)
        {
            if (convertVal.lastError().databaseText().contains("No exchange rate"))
            {
                emit noConversionRate();
                sNoConversionRate(this, id(), effective(), "sValueLocalChanged");
            }
            else
                QMessageBox::critical(this, tr("A System Error occurred at %1::%2.")
                                      .arg(__FILE__)
                                      .arg(__LINE__),
                                      convertVal.lastError().databaseText());
            _baseKnown = false;
        }
    }

    if (ABS(oldBase - _valueBase) > EPSILON(_baseScale))
        emit valueBaseChanged(_valueBase);
}
示例#3
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();
  }
}
示例#5
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);
}
示例#6
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);
}