Cleanups.
This commit is contained in:
41
bcvalue.cpp
41
bcvalue.cpp
@@ -39,41 +39,56 @@
|
|||||||
|
|
||||||
|
|
||||||
BCValue::BCValue( BCDevice::ID deviceID_, BC::ID registerID_)
|
BCValue::BCValue( BCDevice::ID deviceID_, BC::ID registerID_)
|
||||||
: deviceID{deviceID_}, registerID{registerID_}
|
: _deviceID{deviceID_}, _registerID{registerID_}
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString BCValue::formatValue() const
|
QString BCValue::formatValue() const
|
||||||
{
|
{
|
||||||
if( factor == 1 )
|
if( _factor == 1 )
|
||||||
return QString::number( rawValue );
|
return QString::number( _rawValue );
|
||||||
|
|
||||||
double result = rawValue * factor;
|
double result =_rawValue * _factor;
|
||||||
return QString::number(result, 'f', 2);
|
return QString::number(result, 'f', 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BCValue::isWord() const
|
bool BCValue::isWord() const
|
||||||
{
|
{
|
||||||
return valueFlags.testFlag(BCValue::Flag::IsWord);
|
return _valueFlags.testFlag(BCValue::Flag::IsWord);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BCValue::isReadOnly() const
|
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 BCValue::calcMinMaxRatio() const
|
||||||
{
|
{
|
||||||
|
|
||||||
double ratio = 0;
|
double ratio = 0;
|
||||||
|
|
||||||
if( optMin.has_value() && optMax.has_value() )
|
if( _optMin.has_value() && _optMax.has_value() )
|
||||||
{
|
{
|
||||||
|
|
||||||
double min = optMin.value();
|
double min = _optMin.value();
|
||||||
double max = optMax.value();
|
double max = _optMax.value();
|
||||||
|
|
||||||
double range = max - min;
|
double range = max - min;
|
||||||
|
|
||||||
@@ -82,7 +97,7 @@ double BCValue::calcMinMaxRatio() const
|
|||||||
return ratio;
|
return ratio;
|
||||||
|
|
||||||
// Die eigentliche Formel
|
// Die eigentliche Formel
|
||||||
ratio = ((rawValue - min) / range);
|
ratio = ((_rawValue - min) / range);
|
||||||
//ratio = (int) qBound( min,ratio, max);
|
//ratio = (int) qBound( min,ratio, max);
|
||||||
}
|
}
|
||||||
return ratio;
|
return ratio;
|
||||||
@@ -91,9 +106,9 @@ double BCValue::calcMinMaxRatio() const
|
|||||||
void BCValue::dumpValue() const
|
void BCValue::dumpValue() const
|
||||||
{
|
{
|
||||||
|
|
||||||
qDebug() << "DeviceID: " << deviceID << " Register: " << registerID << " state:" " << state << " << " label: " << label;
|
qDebug() << "DeviceID: " << _deviceID << " Register: " << _registerID << " state:" " << state << " << " label: " << _label;
|
||||||
qDebug() << "formattedValue: " << formatValue() << " min: " << optMin << " max: " << optMax << " factor: " << factor << " ValueType: " << (char)valueType << " ";
|
qDebug() << "formattedValue: " << formatValue() << " min: " << _optMin << " max: " << _optMax << " factor: " << _factor << " ValueType: " << (char)_valueType << " ";
|
||||||
qDebug() << "indexRow: " << indexRow << " isWord: " << isWord() << " isRO: " << isReadOnly();
|
qDebug() << "indexRow: " << _indexRow << " isWord: " << isWord() << " isRO: " << isReadOnly();
|
||||||
qDebug();
|
qDebug();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
78
bcvalue.h
78
bcvalue.h
@@ -98,60 +98,44 @@ public:
|
|||||||
|
|
||||||
BCValue( BCDevice::ID deviceID_, BC::ID registerID_ );
|
BCValue( BCDevice::ID deviceID_, BC::ID registerID_ );
|
||||||
|
|
||||||
QString formatValue() const;
|
QString formatValue() const;
|
||||||
double calcMinMaxRatio() const;
|
double calcMinMaxRatio() const;
|
||||||
void dumpValue() const;
|
void dumpValue() const;
|
||||||
bool isWord() const;
|
bool isWord() const;
|
||||||
bool isReadOnly() const;
|
bool isReadOnly() const;
|
||||||
|
|
||||||
Flags& getValueFlags() const noexcept { return valueFlags; }
|
Flags& getValueFlags() const noexcept { return _valueFlags; }
|
||||||
void setValueFlags(Flags newFlags) { valueFlags = newFlags; }
|
void setValueFlags(Flags newFlags) { _valueFlags = newFlags; }
|
||||||
|
|
||||||
BCDevice::ID getDeviceID() const noexcept { return deviceID; }
|
BCDevice::ID getDeviceID() const noexcept { return _deviceID; }
|
||||||
//void setDeviceID(BCDevice::ID newDeviceID) { deviceID = newDeviceID; }
|
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; }
|
ValueType getValueType() const noexcept { return _valueType; }
|
||||||
|
int getIndexRow() const noexcept { return _indexRow; }
|
||||||
int getIndexRow() const noexcept { return indexRow; }
|
void setIndexRow(int newIndexRow) { _indexRow = newIndexRow; }
|
||||||
void setIndexRow(int newIndexRow) { indexRow = newIndexRow; }
|
QString getLabel() const { return _label; }
|
||||||
|
QString getUnitLabel() const { return _unitLabel; }
|
||||||
QString getLabel() const { return label; }
|
double getFactor() const noexcept { return _factor; }
|
||||||
|
const OptDouble getOptMin() const { return _optMin; }
|
||||||
uint32_t getRawValue() const noexcept { return rawValue; }
|
const OptDouble getOptMax() const { return _optMax; }
|
||||||
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; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
mutable Flags valueFlags{BCValue::Flag::NoFlag};
|
mutable Flags _valueFlags{BCValue::Flag::NoFlag};
|
||||||
BCDevice::ID deviceID{BCDevice::ID::Invalid};
|
BCDevice::ID _deviceID{BCDevice::ID::Invalid};
|
||||||
BC::ID registerID{BC::ID::Invalid};
|
BC::ID _registerID{BC::ID::Invalid};
|
||||||
ValueType valueType{ValueType::Plain};
|
ValueType _valueType{ValueType::Plain};
|
||||||
int indexRow{-1};
|
int _indexRow{-1};
|
||||||
QString label;
|
QString _label;
|
||||||
mutable uint32_t rawValue{};
|
mutable uint32_t _rawValue{};
|
||||||
QString unitLabel;
|
QString _unitLabel;
|
||||||
double factor{1};
|
double _factor{1};
|
||||||
OptDouble optMin;
|
OptDouble _optMin;
|
||||||
OptDouble optMax;
|
OptDouble _optMax;
|
||||||
|
|
||||||
};
|
};
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(BCValue::Flags)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(BCValue::Flags)
|
||||||
|
|||||||
@@ -212,20 +212,20 @@ std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const B
|
|||||||
if( !s_valueTypes.contains( params.ValueType ) )
|
if( !s_valueTypes.contains( params.ValueType ) )
|
||||||
throw BCException( "Fehler", QString("ValueType %1 existiert nicht.").arg(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._label = params.Label;
|
||||||
newValue.unitLabel = params.UnitLabel;
|
newValue._unitLabel = params.UnitLabel;
|
||||||
|
|
||||||
setIfExists( newValue.factor, params.Factor );
|
setIfExists( newValue._factor, params.Factor );
|
||||||
setIfExists( newValue.optMin, params.Min );
|
setIfExists( newValue._optMin, params.Min );
|
||||||
setIfExists( newValue.optMax, params.Max );
|
setIfExists( newValue._optMax, params.Max );
|
||||||
|
|
||||||
if( params.IsWord == "true")
|
if( params.IsWord == "true")
|
||||||
newValue.valueFlags.setFlag( BCValue::Flag::IsWord, true );
|
newValue._valueFlags.setFlag( BCValue::Flag::IsWord, true );
|
||||||
|
|
||||||
if( params.ReadOnly == "true")
|
if( params.ReadOnly == "true")
|
||||||
newValue.valueFlags.setFlag( BCValue::Flag::ReadOnly, true );
|
newValue._valueFlags.setFlag( BCValue::Flag::ReadOnly, true );
|
||||||
|
|
||||||
//newValue.dumpValue();
|
//newValue.dumpValue();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user