|
|
@ -27,7 +27,7 @@ FactValueSliderListModel::FactValueSliderListModel(Fact& fact, QObject* parent) |
|
|
|
, _cPrevValues (0) |
|
|
|
, _cPrevValues (0) |
|
|
|
, _cNextValues (0) |
|
|
|
, _cNextValues (0) |
|
|
|
, _initialValue (0) |
|
|
|
, _initialValue (0) |
|
|
|
, _initialValueRounded (0) |
|
|
|
, _initialValueAtPrecision (0) |
|
|
|
, _increment (0) |
|
|
|
, _increment (0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); |
|
|
|
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); |
|
|
@ -47,14 +47,14 @@ int FactValueSliderListModel::resetInitialValue(void) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_initialValue = _fact.cookedValue().toDouble(); |
|
|
|
_initialValue = _fact.cookedValue().toDouble(); |
|
|
|
_initialValueRounded = qRound(_initialValue); |
|
|
|
_initialValueAtPrecision = _valueAtPrecision(_initialValue); |
|
|
|
if (qRound(_fact.rawIncrement()) == _fact.rawIncrement()) { |
|
|
|
if (qRound(_fact.rawIncrement()) == _fact.rawIncrement()) { |
|
|
|
_increment = qRound(_fact.cookedIncrement()); |
|
|
|
_increment = qRound(_fact.cookedIncrement()); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
_increment = _fact.cookedIncrement(); |
|
|
|
_increment = _fact.cookedIncrement(); |
|
|
|
} |
|
|
|
} |
|
|
|
_cPrevValues = qMin((_initialValue - _fact.cookedMin().toDouble()), 100.0) / _increment; |
|
|
|
_cPrevValues = qMin((_initialValue - _fact.cookedMin().toDouble()) / _increment, 100.0); |
|
|
|
_cNextValues = qMin((_fact.cookedMax().toDouble() - _initialValue), 100.0) / _increment; |
|
|
|
_cNextValues = qMin((_fact.cookedMax().toDouble() - _initialValue) / _increment, 100.0); |
|
|
|
_initialValueIndex = _cPrevValues; |
|
|
|
_initialValueIndex = _cPrevValues; |
|
|
|
|
|
|
|
|
|
|
|
int totalValueCount = _cPrevValues + 1 + _cNextValues; |
|
|
|
int totalValueCount = _cPrevValues + 1 + _cNextValues; |
|
|
@ -93,12 +93,9 @@ QVariant FactValueSliderListModel::data(const QModelIndex &index, int role) cons |
|
|
|
if (cIncrementCount == 0) { |
|
|
|
if (cIncrementCount == 0) { |
|
|
|
value = _initialValue; |
|
|
|
value = _initialValue; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
value = _initialValueRounded + (cIncrementCount * _increment); |
|
|
|
value = initialValueAtPrecision() + (cIncrementCount * _increment); |
|
|
|
} |
|
|
|
} |
|
|
|
double precision = qPow(10, _fact.decimalPlaces()); |
|
|
|
return QVariant(_valueAtPrecision(value)); |
|
|
|
double atPrecision = qRound(value * precision) / precision; |
|
|
|
|
|
|
|
//qDebug() << value << precision << atPrecision << _fact.decimalPlaces() << _fact.name();
|
|
|
|
|
|
|
|
return QVariant(atPrecision); |
|
|
|
|
|
|
|
} else if (role == _valueIndexRole) { |
|
|
|
} else if (role == _valueIndexRole) { |
|
|
|
return QVariant::fromValue(valueIndex); |
|
|
|
return QVariant::fromValue(valueIndex); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -129,8 +126,8 @@ int FactValueSliderListModel::valueIndexAtModelIndex(int index) |
|
|
|
return data(createIndex(index, 0), _valueIndexRole).toInt(); |
|
|
|
return data(createIndex(index, 0), _valueIndexRole).toInt(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
double FactValueSliderListModel::initialValueAtPrecision(void) |
|
|
|
double FactValueSliderListModel::_valueAtPrecision(double value) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
double precision = qPow(10, _fact.decimalPlaces()); |
|
|
|
double precision = qPow(10, _fact.decimalPlaces()); |
|
|
|
return qRound(_initialValue * precision) / precision; |
|
|
|
return qRound(value * precision) / precision; |
|
|
|
} |
|
|
|
} |
|
|
|