Added & configured actions.

This commit is contained in:
2025-12-26 23:09:53 +01:00
parent 71d7350913
commit c4714bfca2
9 changed files with 159 additions and 105 deletions

View File

@@ -78,6 +78,17 @@ BCDataManager::~BCDataManager()
}
BCTransmitter* BCDataManager::getTransmitter()
{
return &_transmitter;
};
const BCValueList& BCDataManager::getCurrentValueList()
{
return _currentValues;
}
void BCDataManager::onCommandFinished(int id, bool success)
{
qDebug() << "[Manager] Command" << id << "finished. Success:" << success;
@@ -128,19 +139,7 @@ void BCDataManager::onSyncFromDevice()
*/
}
std::optional<BCValueModel*> BCDataManager::getModel(BCDevice::ID deviceID )
{
if( _valueModels.contains( deviceID) )
return _valueModels[deviceID];
return std::nullopt;
}
BCTransmitter* BCDataManager::getTransmitter()
{
return &_transmitter;
};
void BCDataManager::loadXmlBikeData()
void BCDataManager::loadXmlBikeData( const QString& fileName )
{
auto printAttrs = [](const QXmlStreamReader& xml)
{
@@ -156,7 +155,7 @@ void BCDataManager::loadXmlBikeData()
return;
*/
QFile file(":/bikeinfo.xml");
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
// __fix throw
@@ -182,28 +181,17 @@ void BCDataManager::loadXmlBikeData()
{
QString deviceType = _xml.attributes().value("Type"_L1).toString();
printAttrs (_xml);
// Wir wollen die Device-ID aus dem XML Tag ermitteln
const char* deviceKey = _xml.attributes().value("Type"_L1).toLatin1().constData();
auto deviceID = _bcDeviceEnum.keyToValue64(deviceKey);
auto optDeviceID = _bcDeviceEnum.keyToValue64(deviceKey);
//_currentDeviceID = BCDevice::ID( deviceID.value_or( BCDevice::ID::Invalid ) );
if(deviceID.has_value())
if( optDeviceID.has_value())
{
qDebug() << " --- Device: " << _xml.name() << ": " << deviceType << " : " << deviceID;
_currentDeviceID = BCDevice::ID( deviceID.value() );
BCValueList parsedValues;
loadXmlBikeDeviceData( parsedValues );
if( parsedValues.count() )
{
BCValueModel* valueModel = new BCValueModel( this );
// hier lacht der blaue HASE
//valueModel->setValueList(parsedValues);
_valueModels.insert( _currentDeviceID, valueModel );
}
qDebug() << " --- Device: " << _xml.name() << ": " << deviceType << " : " << optDeviceID;
BCDevice::ID currentDeviceID = BCDevice::ID( optDeviceID.value() );
loadXmlBikeDeviceData(currentDeviceID);
}
}
_currentDeviceID = BCDevice::ID::Console;
}
/*
@@ -221,7 +209,7 @@ void BCDataManager::loadXmlBikeData()
}
void BCDataManager::loadXmlBikeDeviceData( BCValueList& parsedValues )
void BCDataManager::loadXmlBikeDeviceData(BCDevice::ID deviceID)
{
auto printAttrs = [](const QXmlStreamReader& xml)
{
@@ -234,17 +222,18 @@ void BCDataManager::loadXmlBikeDeviceData( BCValueList& parsedValues )
printAttrs (_xml);
Q_ASSERT(_xml.isStartElement() && _xml.name() == "Device"_L1);
qDebug() << " ---------------";
qDebug() << " XXX ---------------";
// Wertliste für neues Device leeren
_currentValues.clear();
//while (!_xml.atEnd() && !_xml.hasError())
while( _xml.readNextStartElement() )
{
if( _xml.attributes().hasAttribute(BCTags::ID) )
{
//qDebug() << " --- found: " << _xml.name() << " : " << _xml.attributes().value(BCTags::ID);
QString id = _xml.attributes().value(BCTags::ID).toString();
// füllen des Parameter packs
BCDataParams params
{
.ID = id,
@@ -253,18 +242,19 @@ void BCDataManager::loadXmlBikeDeviceData( BCValueList& parsedValues )
.UnitType = _xml.attributes().value(BCTags::UnitType).toString(),
};
// __fix! können ungültige werte erzeugt werden ?
//BCDataValue newValue = BCData::makeDataValue( _currentDeviceID, params );
//if(newValue)
// parsedValues.push_back( newValue );
std::optional<BCDataValue> newValue = makeDataValue( _currentDeviceID, params );
// nur gültige Werte sind vorhanden und können gespeichert werden
std::optional<BCDataValue> newValue = makeDataValue( deviceID, params );
if(newValue)
parsedValues.push_back( *newValue );
_currentValues.push_back( *newValue );
}
//printAttrs (_xml);
// weiter zum nächsten Element
_xml.skipCurrentElement();
}
// Wenn dieses Device fertig geladen wurde, soll das MainWindow es abholen
if( !_currentValues.isEmpty() )
emit valueListReady( deviceID );
}
std::optional<BCDataValue> BCDataManager::makeDataValue( BCDevice::ID deviceID, const BCDataParams& params )