Debug updates.
This commit is contained in:
@@ -54,7 +54,8 @@ void BCXmlLoader::loadXmlBikeData( const QString& fileName )
|
||||
auto printAttrs = [](const QXmlStreamReader& xml)
|
||||
{
|
||||
QStringList parts;
|
||||
for (const auto &attr : xml.attributes()) {
|
||||
for (const auto &attr : xml.attributes())
|
||||
{
|
||||
parts << attr.name().toString() + "=\"" + attr.value().toString() + "\"";
|
||||
}
|
||||
qDebug().noquote() << parts.join(" ");
|
||||
@@ -64,19 +65,14 @@ void BCXmlLoader::loadXmlBikeData( const QString& fileName )
|
||||
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
// __fix throw
|
||||
QMessageBox::warning(nullptr, "Fehler", "Datei konnte nicht geöffnet werden.");
|
||||
return;
|
||||
}
|
||||
throw BCException( "Fehler", "Datei konnte nicht geöffnet werden.");
|
||||
|
||||
_xml.setDevice(&file);
|
||||
|
||||
if (_xml.readNextStartElement())
|
||||
{
|
||||
if (_xml.name() != "Bike"_L1 )
|
||||
// fix throw
|
||||
_xml.raiseError(QObject::tr("The file is not an 'Bike' file."));
|
||||
throw BCException( "Fehler", "Falsches Datenformat.");
|
||||
}
|
||||
// ??
|
||||
Q_ASSERT(_xml.isStartElement() && _xml.name() == "Bike"_L1);
|
||||
@@ -93,26 +89,22 @@ void BCXmlLoader::loadXmlBikeData( const QString& fileName )
|
||||
|
||||
// Wir wollen die Device-ID aus dem XML Tag ermitteln
|
||||
if( deviceType.isEmpty() )
|
||||
{
|
||||
printAttrs (_xml);
|
||||
continue;
|
||||
}
|
||||
QByteArray byteArray = deviceType.toUtf8();
|
||||
const char* deviceKey = byteArray.constData();
|
||||
bool ok=false;
|
||||
auto optDeviceID = bcDeviceEnum.keyToValue(deviceKey,&ok);
|
||||
//_currentDeviceID = BCDevice::ID( deviceID.value_or( BCDevice::ID::Invalid ) );
|
||||
//if( optDeviceID.has_value())
|
||||
if(ok)
|
||||
{
|
||||
qDebug() << " --- FETCH 2: Device: " << deviceType << " : " << optDeviceID;
|
||||
//BCDevice::ID currentDeviceID = BCDevice::ID( optDeviceID.value() );
|
||||
BCDevice::ID currentDeviceID = BCDevice::ID( optDeviceID );
|
||||
loadXmlBikeDeviceData(currentDeviceID);
|
||||
}
|
||||
|
||||
} // if start element
|
||||
}
|
||||
QByteArray byteArray = deviceType.toUtf8();
|
||||
const char* deviceKey = byteArray.constData();
|
||||
bool ok=false;
|
||||
auto optDeviceID = bcDeviceEnum.keyToValue(deviceKey,&ok);
|
||||
//_currentDeviceID = BCDevice::ID( deviceID.value_or( BCDevice::ID::Invalid ) );
|
||||
//if( optDeviceID.has_value())
|
||||
if(!ok)
|
||||
throw BCException( "Fehler", QString("Devicetype %1 existiert nicht.").arg(deviceType) );
|
||||
qDebug() << " --- FETCH 2: Device: " << deviceType << " : " << optDeviceID;
|
||||
//BCDevice::ID currentDeviceID = BCDevice::ID( optDeviceID.value() );
|
||||
BCDevice::ID currentDeviceID = BCDevice::ID( optDeviceID );
|
||||
loadXmlBikeDeviceData(currentDeviceID);
|
||||
} // if startElement
|
||||
} // end while
|
||||
}
|
||||
|
||||
|
||||
@@ -126,9 +118,8 @@ void BCXmlLoader::loadXmlBikeDeviceData(BCDevice::ID deviceID)
|
||||
auto printAttrs = [](const QXmlStreamReader& xml)
|
||||
{
|
||||
QStringList parts;
|
||||
for (const auto &attr : xml.attributes()) {
|
||||
for (const auto &attr : xml.attributes())
|
||||
parts << attr.name().toString() + "=\"" + attr.value().toString() + "\"";
|
||||
}
|
||||
qDebug().noquote() << parts.join(" ");
|
||||
};
|
||||
|
||||
@@ -154,6 +145,7 @@ void BCXmlLoader::loadXmlBikeDeviceData(BCDevice::ID deviceID)
|
||||
.Min = _xml.attributes().value(BCTags::Min).toString(),
|
||||
.Max = _xml.attributes().value(BCTags::Max).toString(),
|
||||
.IsWord = _xml.attributes().value(BCTags::IsWord).toString(),
|
||||
.ReadOnly = _xml.attributes().value(BCTags::ReadOnly).toString(),
|
||||
.ValueType = _xml.attributes().value(BCTags::ValueType).toString(),
|
||||
};
|
||||
|
||||
@@ -193,7 +185,7 @@ std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const B
|
||||
{ "Float", BCValue::ValueType::Float }
|
||||
};
|
||||
|
||||
auto setIfExists = [&]<typename T>( QStringView source, T& target )
|
||||
auto setIfExists = [&]<typename T>( T& target, QStringView source )
|
||||
{
|
||||
if( !source.isEmpty() )
|
||||
{
|
||||
@@ -216,29 +208,36 @@ std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const B
|
||||
int IDVal = s_bcValueEnum.keyToValue( byteArray.constData(), &ok );
|
||||
qDebug() << " --- should create: " << params.Label;
|
||||
//if( IDVal.has_value() )
|
||||
if( ok )
|
||||
{
|
||||
BCValuePtr newValuePtr = std::make_shared<BCValue>( deviceID, static_cast<BC::ID>(IDVal) );
|
||||
BCValue& newValue = *newValuePtr.get();
|
||||
if( !ok )
|
||||
throw BCException( "Fehler", QString("Devicetype %1 existiert nicht.").arg(params.ID) );
|
||||
|
||||
setIfExists( params.Factor, newValue.factor );
|
||||
setIfExists( params.Min, newValue.optMin );
|
||||
setIfExists( params.Max, newValue.optMax );
|
||||
//setIfExists( params.IsWord, newValue.isWord );
|
||||
BCValuePtr newValuePtr = std::make_shared<BCValue>( deviceID, static_cast<BC::ID>(IDVal) );
|
||||
BCValue& newValue = *newValuePtr.get();
|
||||
|
||||
newValue.label = params.Label;
|
||||
newValue.unitLabel = params.UnitLabel;
|
||||
// ValueType
|
||||
if( !s_valueTypes.contains( params.ValueType ) )
|
||||
throw BCException( "Fehler", QString("ValueType %1 existiert nicht.").arg(params.ValueType) );
|
||||
|
||||
if( s_valueTypes.contains( params.ValueType ) )
|
||||
newValue.valueType = s_valueTypes[params.ValueType];
|
||||
newValue.valueType = s_valueTypes[params.ValueType];
|
||||
|
||||
qDebug() << " --- created: " << params.Label;
|
||||
newValue.dumpValue();
|
||||
newValue.label = params.Label;
|
||||
newValue.unitLabel = params.UnitLabel;
|
||||
|
||||
return std::optional<BCValuePtr>( newValuePtr );
|
||||
}
|
||||
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 );
|
||||
|
||||
if( params.ReadOnly == "true")
|
||||
newValue.valueFlags.setFlag( BCValue::Flag::ReadOnly, true );
|
||||
|
||||
qDebug() << " --- created: " << params.Label;
|
||||
newValue.dumpValue();
|
||||
|
||||
return std::optional<BCValuePtr>( newValuePtr );
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user