Reworked value handling.

This commit is contained in:
Christoph Holzheuer
2026-01-19 16:44:52 +01:00
parent 4309d2231e
commit 8639529bbe
12 changed files with 95 additions and 80 deletions

View File

@@ -75,17 +75,17 @@ void BCValue::setFlag( BCValue::Flag flag, bool state) const
}
BCDevice::ID BCValue::getDeviceID() const noexcept
BCDevice::ID BCValue::deviceID() const noexcept
{
return _deviceID;
}
BC::ID BCValue::getRegisterID() const noexcept
BC::ID BCValue::registerID() const noexcept
{
return _registerID;
}
uint32_t BCValue::getRawValue() const noexcept
uint32_t BCValue::rawValue() const noexcept
{
return _rawValue;
}
@@ -101,6 +101,12 @@ void BCValue::setRawValue(uint32_t newRawValue) const
// können beliebigen Unsinn enthalten, also müssen wir sie
// auch skalieren.
if( _valueType == ValueType::Bool )
{
_rawValue = newRawValue > 0 ? 1 : 0;
return;
}
double value = newRawValue * _factor;
if( _optMin.has_value() && _optMax.has_value() )
@@ -116,13 +122,13 @@ void BCValue::setRawValue(uint32_t newRawValue) const
}
BCValue::ValueType BCValue::getValueType() const noexcept
BCValue::ValueType BCValue::valueType() const noexcept
{
return _valueType;
}
int BCValue::getIndexRow() const noexcept
int BCValue::indexRow() const noexcept
{
return _indexRow;
}
@@ -132,31 +138,16 @@ void BCValue::setIndexRow(int newIndexRow)
_indexRow = newIndexRow;
}
QString BCValue::getLabel() const
QString BCValue::label() const
{
return _label;
}
QString BCValue::getUnitLabel() const
QString BCValue::unitLabel() const
{
return _unitLabel;
}
double BCValue::getFactor() const noexcept
{
return _factor;
}
const OptDouble BCValue::getOptMin() const
{
return _optMin;
}
const OptDouble BCValue::getOptMax() const
{
return _optMax;
}
void BCValue::setFromDouble( double value )
{
//if( _isReadOnly)
@@ -166,7 +157,7 @@ void BCValue::setFromDouble( double value )
// wir betrachten plain
case ValueType::Bool :
_rawValue = value >0 ? 1 : 0;
_rawValue = value > 0 ? 1 : 0;
break;
case ValueType::Plain :
@@ -207,19 +198,32 @@ double BCValue::calcMinMaxRatio() const
if (std::abs(range) < 1e-9)
return ratio;
double value = _rawValue * _factor;
// Die eigentliche Formel
ratio = ((_rawValue - min) / range);
//ratio = (int) qBound( min,ratio, max);
ratio = ((value - min) / range);
}
return ratio;
}
uint32_t BCValue::getScaledValue() const noexcept
{
double value =_rawValue * _factor;
return (uint32_t) value * calcMinMaxRatio();
}
bool BCValue::valuesForSlider( int& value, int& min, int& max ) const
{
// min & max sind vorraussetzung für den slider
if( !_optMin.has_value() || !_optMax.has_value() )
return false;
// wir erwarten hier, das value zwischen min
// und max liegt weil wir das schon bei setRawValue
// überprüft haben.
value = _rawValue * _factor;
min = _optMin.value();
max = _optMax.value();
return true;
}
void BCValue::dumpValue() const
{