Cleanups.

This commit is contained in:
2026-01-12 23:06:36 +01:00
parent c0ce6a81e3
commit beae1c1b3d
3 changed files with 67 additions and 68 deletions

View File

@@ -39,41 +39,56 @@
BCValue::BCValue( BCDevice::ID deviceID_, BC::ID registerID_)
: deviceID{deviceID_}, registerID{registerID_}
: _deviceID{deviceID_}, _registerID{registerID_}
{
}
QString BCValue::formatValue() const
{
if( factor == 1 )
return QString::number( rawValue );
if( _factor == 1 )
return QString::number( _rawValue );
double result = rawValue * factor;
double result =_rawValue * _factor;
return QString::number(result, 'f', 2);
}
bool BCValue::isWord() const
{
return valueFlags.testFlag(BCValue::Flag::IsWord);
return _valueFlags.testFlag(BCValue::Flag::IsWord);
}
bool BCValue::isReadOnly() const
{
return valueFlags.testFlag(BCValue::Flag::ReadOnly);
return _valueFlags.testFlag(BCValue::Flag::ReadOnly);
}
void BCValue::setFromDouble( double value )
{
if( _optMin.has_value() && _optMax.has_value() )
{
double min = _optMin.value();
double max = _optMax.value();
value = qBound( min,value,max);
}
_rawValue = value / _factor;
}
double BCValue::calcMinMaxRatio() const
{
double ratio = 0;
if( optMin.has_value() && optMax.has_value() )
if( _optMin.has_value() && _optMax.has_value() )
{
double min = optMin.value();
double max = optMax.value();
double min = _optMin.value();
double max = _optMax.value();
double range = max - min;
@@ -82,7 +97,7 @@ double BCValue::calcMinMaxRatio() const
return ratio;
// Die eigentliche Formel
ratio = ((rawValue - min) / range);
ratio = ((_rawValue - min) / range);
//ratio = (int) qBound( min,ratio, max);
}
return ratio;
@@ -91,9 +106,9 @@ double BCValue::calcMinMaxRatio() const
void BCValue::dumpValue() const
{
qDebug() << "DeviceID: " << deviceID << " Register: " << registerID << " state:" " << state << " << " label: " << label;
qDebug() << "formattedValue: " << formatValue() << " min: " << optMin << " max: " << optMax << " factor: " << factor << " ValueType: " << (char)valueType << " ";
qDebug() << "indexRow: " << indexRow << " isWord: " << isWord() << " isRO: " << isReadOnly();
qDebug() << "DeviceID: " << _deviceID << " Register: " << _registerID << " state:" " << state << " << " label: " << _label;
qDebug() << "formattedValue: " << formatValue() << " min: " << _optMin << " max: " << _optMax << " factor: " << _factor << " ValueType: " << (char)_valueType << " ";
qDebug() << "indexRow: " << _indexRow << " isWord: " << isWord() << " isRO: " << isReadOnly();
qDebug();
}

View File

@@ -98,60 +98,44 @@ public:
BCValue( BCDevice::ID deviceID_, BC::ID registerID_ );
QString formatValue() const;
double calcMinMaxRatio() const;
void dumpValue() const;
bool isWord() const;
bool isReadOnly() const;
QString formatValue() const;
double calcMinMaxRatio() const;
void dumpValue() const;
bool isWord() const;
bool isReadOnly() const;
Flags& getValueFlags() const noexcept { return valueFlags; }
void setValueFlags(Flags newFlags) { valueFlags = newFlags; }
Flags& getValueFlags() const noexcept { return _valueFlags; }
void setValueFlags(Flags newFlags) { _valueFlags = newFlags; }
BCDevice::ID getDeviceID() const noexcept { return deviceID; }
//void setDeviceID(BCDevice::ID newDeviceID) { deviceID = newDeviceID; }
BCDevice::ID getDeviceID() const noexcept { return _deviceID; }
BC::ID getRegisterID() const noexcept { return _registerID; }
BC::ID getRegisterID() const noexcept { return registerID; }
uint32_t getRawValue() const noexcept { return _rawValue; }
void setRawValue(uint32_t newRawValue) const { _rawValue = newRawValue; }
void setFromDouble( double value );
ValueType getValueType() const noexcept { return valueType; }
int getIndexRow() const noexcept { return indexRow; }
void setIndexRow(int newIndexRow) { indexRow = newIndexRow; }
QString getLabel() const { return label; }
uint32_t getRawValue() const noexcept { return rawValue; }
void setRawValue(uint32_t newRawValue) const { rawValue = newRawValue; }
void setFromDouble( double value )
{
Q_UNUSED(value)
}
QString getUnitLabel() const { return unitLabel; }
void setUnitLabel(const QString &newUnitLabel) { unitLabel = newUnitLabel; }
double getFactor() const noexcept { return factor; }
void setFactor(double newFactor) { factor = newFactor; }
const OptDouble getOptMin() const { return optMin; }
void setOptMin(const OptDouble &newOptMin) { optMin = newOptMin; }
const OptDouble getOptMax() const { return optMax; }
void setOptMax(const OptDouble &newOptMax) { optMax = newOptMax; }
ValueType getValueType() const noexcept { return _valueType; }
int getIndexRow() const noexcept { return _indexRow; }
void setIndexRow(int newIndexRow) { _indexRow = newIndexRow; }
QString getLabel() const { return _label; }
QString getUnitLabel() const { return _unitLabel; }
double getFactor() const noexcept { return _factor; }
const OptDouble getOptMin() const { return _optMin; }
const OptDouble getOptMax() const { return _optMax; }
protected:
mutable Flags valueFlags{BCValue::Flag::NoFlag};
BCDevice::ID deviceID{BCDevice::ID::Invalid};
BC::ID registerID{BC::ID::Invalid};
ValueType valueType{ValueType::Plain};
int indexRow{-1};
QString label;
mutable uint32_t rawValue{};
QString unitLabel;
double factor{1};
OptDouble optMin;
OptDouble optMax;
mutable Flags _valueFlags{BCValue::Flag::NoFlag};
BCDevice::ID _deviceID{BCDevice::ID::Invalid};
BC::ID _registerID{BC::ID::Invalid};
ValueType _valueType{ValueType::Plain};
int _indexRow{-1};
QString _label;
mutable uint32_t _rawValue{};
QString _unitLabel;
double _factor{1};
OptDouble _optMin;
OptDouble _optMax;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(BCValue::Flags)

View File

@@ -212,20 +212,20 @@ std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const B
if( !s_valueTypes.contains( params.ValueType ) )
throw BCException( "Fehler", QString("ValueType %1 existiert nicht.").arg(params.ValueType) );
newValue.valueType = s_valueTypes[params.ValueType];
newValue._valueType = s_valueTypes[params.ValueType];
newValue.label = params.Label;
newValue.unitLabel = params.UnitLabel;
newValue._label = params.Label;
newValue._unitLabel = params.UnitLabel;
setIfExists( newValue.factor, params.Factor );
setIfExists( newValue.optMin, params.Min );
setIfExists( newValue.optMax, params.Max );
setIfExists( newValue._factor, params.Factor );
setIfExists( newValue._optMin, params.Min );
setIfExists( newValue._optMax, params.Max );
if( params.IsWord == "true")
newValue.valueFlags.setFlag( BCValue::Flag::IsWord, true );
newValue._valueFlags.setFlag( BCValue::Flag::IsWord, true );
if( params.ReadOnly == "true")
newValue.valueFlags.setFlag( BCValue::Flag::ReadOnly, true );
newValue._valueFlags.setFlag( BCValue::Flag::ReadOnly, true );
//newValue.dumpValue();