Added ValueModel, first run.

This commit is contained in:
2025-12-16 22:42:35 +01:00
parent afb5828a65
commit 4c5e42fcfd
8 changed files with 110 additions and 76 deletions

View File

@@ -27,6 +27,7 @@
***************************************************************************/
#include <QMetaEnum>
#include <bcvalue.h>
@@ -47,10 +48,39 @@ uint8_t BCValue::getLongValue()
}
BCValue* BCValue::makeValue(BCDevice::ID deviceI, const BCValueParams& params )
BCValue* BCValue::makeValue( BCDevice::ID deviceID, const BCValueParams& params )
{
auto setIfExists = [&]( QStringView source, optDouble& target )
{
if( !source.isEmpty() )
{
bool ok;
double testVal = source.toDouble(&ok);
if (ok)
target = testVal;
}
};
static QMetaEnum s_bcValueEnum{QMetaEnum::fromType<BC::ID>()};
return nullptr;
/*
Wir brauchen:
- eine gültige ID
*/
BCValue* newValue{};
auto IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() );
if( IDVal.has_value() )
{
newValue = new BCValue( deviceID, BC::ID( IDVal.value() ) );
setIfExists( params.Factor, newValue->factor );
setIfExists( params.Min, newValue->min );
setIfExists( params.Max, newValue->max );
newValue->defaultValue.setValue( params.Default );
newValue->value.setValue( params.Current );
}
return newValue;
}