From beae1c1b3d62f3ead288c49c881ca49bf0e17275 Mon Sep 17 00:00:00 2001 From: "PANIK\\chris" Date: Mon, 12 Jan 2026 23:06:36 +0100 Subject: [PATCH] Cleanups. --- bcvalue.cpp | 41 +++++++++++++++++--------- bcvalue.h | 78 ++++++++++++++++++++----------------------------- bcxmlloader.cpp | 16 +++++----- 3 files changed, 67 insertions(+), 68 deletions(-) diff --git a/bcvalue.cpp b/bcvalue.cpp index a8ea24d..f2e5157 100644 --- a/bcvalue.cpp +++ b/bcvalue.cpp @@ -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(); } diff --git a/bcvalue.h b/bcvalue.h index 1f97c8c..be573d5 100644 --- a/bcvalue.h +++ b/bcvalue.h @@ -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) diff --git a/bcxmlloader.cpp b/bcxmlloader.cpp index 4d5c45c..ac1647a 100644 --- a/bcxmlloader.cpp +++ b/bcxmlloader.cpp @@ -212,20 +212,20 @@ std::optional 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();