Compiles again, without BCValueType.
This commit is contained in:
128
bcxmlloader.cpp
128
bcxmlloader.cpp
@@ -32,28 +32,20 @@
|
||||
|
||||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
#include <QTableView>
|
||||
#include <QPushButton>
|
||||
#include <QMessageBox>
|
||||
#include <QStatusBar>
|
||||
#include <QApplication>
|
||||
#include <QElapsedTimer>
|
||||
#include <QMetaEnum>
|
||||
#include <QHash>
|
||||
|
||||
#include <bcxmlloader.h>
|
||||
#include <bcvaluetype.h>
|
||||
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
|
||||
|
||||
BCXmlLoader::BCXmlLoader(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
|
||||
//qRegisterMetaType<BCValue*>("BCValue*");
|
||||
//qRegisterMetaType<BCValue*>();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -156,17 +148,22 @@ void BCXmlLoader::loadXmlBikeDeviceData(BCDevice::ID deviceID)
|
||||
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
|
||||
BCValueParams params
|
||||
{
|
||||
.ID = id,
|
||||
.Label = _xml.attributes().value(BCTags::Label).toString(),
|
||||
.UnitType = _xml.attributes().value(BCTags::UnitType).toString(),
|
||||
.ID = _xml.attributes().value(BCTags::ID).toString(),
|
||||
.Label = _xml.attributes().value(BCTags::Label).toString(),
|
||||
.UnitLabel = _xml.attributes().value(BCTags::UnitLabel).toString(),
|
||||
.Factor = _xml.attributes().value(BCTags::Factor).toString(),
|
||||
.Min = _xml.attributes().value(BCTags::Min).toString(),
|
||||
.Max = _xml.attributes().value(BCTags::Max).toString(),
|
||||
.IsWord = _xml.attributes().value(BCTags::IsWord).toString(),
|
||||
.ValueType = _xml.attributes().value(BCTags::ValueType).toString(),
|
||||
};
|
||||
|
||||
// nur gültige Werte sind vorhanden und können gespeichert werden
|
||||
std::optional<BCValuePtr> newValue = makeDataValue( deviceID, params );
|
||||
std::optional<BCValuePtr> newValue = makeValue( deviceID, params );
|
||||
if(newValue)
|
||||
{
|
||||
// wir merken uns gleich den index in der Werteliste
|
||||
@@ -185,11 +182,26 @@ void BCXmlLoader::loadXmlBikeDeviceData(BCDevice::ID deviceID)
|
||||
|
||||
}
|
||||
|
||||
std::optional<BCValuePtr> BCXmlLoader::makeDataValue( BCDevice::ID deviceID, const BCDataParams& params )
|
||||
std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const BCValueParams& params )
|
||||
{
|
||||
|
||||
/*
|
||||
auto setIfExists = [&]( QStringView source, optDouble& target )
|
||||
static QHash<QString,ReadValueFunc> s_bcReadValueFunctions
|
||||
{
|
||||
{ "Byte", readByteValue },
|
||||
{ "Word", readWordValue },
|
||||
{ "Assist", readByteValue }
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
if( !s_bcReadValueFunctions.contains( unitTypeKey ) )
|
||||
return std::nullopt;
|
||||
|
||||
return s_bcReadValueFunctions[unitTypeKey];
|
||||
*/
|
||||
auto setIfExists = [&]( QStringView source, OptDouble& target )
|
||||
{
|
||||
if( !source.isEmpty() )
|
||||
{
|
||||
@@ -199,11 +211,9 @@ std::optional<BCValuePtr> BCXmlLoader::makeDataValue( BCDevice::ID deviceID, con
|
||||
target = testVal;
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
static QMetaEnum s_bcValueEnum{QMetaEnum::fromType<BC::ID>()};
|
||||
|
||||
|
||||
/*
|
||||
Wir brauchen:
|
||||
- einen gültige ID String um die enum ID herauszufinden.
|
||||
@@ -215,69 +225,39 @@ std::optional<BCValuePtr> BCXmlLoader::makeDataValue( BCDevice::ID deviceID, con
|
||||
//std::optional<quint64> IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() );
|
||||
bool ok;
|
||||
int IDVal = s_bcValueEnum.keyToValue( params.ID.toLatin1().constData(), &ok );
|
||||
qDebug() << " --- should create: " << params.Label << ": " << params.UnitType;
|
||||
qDebug() << " --- should create: " << params.Label;
|
||||
//if( IDVal.has_value() )
|
||||
if( ok )
|
||||
{
|
||||
auto valueType = BCValueType::fetchValueType(params.UnitType);
|
||||
if( valueType.has_value() )
|
||||
{
|
||||
BCValuePtr newValue = std::make_shared<BCValue>( *valueType, deviceID, static_cast<BC::ID>(IDVal) );
|
||||
BCValuePtr newValue = std::make_shared<BCValue>( deviceID, static_cast<BC::ID>(IDVal) );
|
||||
|
||||
/*
|
||||
setIfExists( params.Factor, newValue.factor );
|
||||
setIfExists( params.Min, newValue.min );
|
||||
setIfExists( params.Max, newValue.max );
|
||||
*/
|
||||
newValue->label = params.Label;
|
||||
qDebug() << " --- created: " << params.Label;
|
||||
//setIfExists( params.Factor, newValue->factor );
|
||||
setIfExists( params.Min, newValue->min );
|
||||
setIfExists( params.Max, newValue->max );
|
||||
|
||||
return std::optional<BCValuePtr>( newValue );
|
||||
}
|
||||
newValue->label = params.Label;
|
||||
|
||||
/*
|
||||
QString ID;
|
||||
QString Label;
|
||||
QString UnitLabel;
|
||||
QString Factor;
|
||||
QString Min;
|
||||
QString Max;
|
||||
QString IsWord;
|
||||
QString ValueType;
|
||||
*/
|
||||
|
||||
|
||||
qDebug() << " --- created: " << params.Label;
|
||||
|
||||
return std::optional<BCValuePtr>( newValue );
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// --- NEU: Speichern mit QXmlStreamWriter ---
|
||||
void BCXmlLoader::saveBikeData()
|
||||
{
|
||||
/*
|
||||
QString fileName = QFileDialog::getSaveFileName(this, "XML speichern", "", "XML Files (*.xml)");
|
||||
if (fileName.isEmpty()) return;
|
||||
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
QMessageBox::warning(this, "Fehler", "Datei konnte nicht zum Schreiben geöffnet werden.");
|
||||
return;
|
||||
}
|
||||
|
||||
QXmlStreamWriter xml(&file);
|
||||
xml.setAutoFormatting(true); // Sorgt für schöne Einrückungen (Tabs/Spaces)
|
||||
xml.writeStartDocument();
|
||||
xml.writeStartElement("devices");
|
||||
|
||||
// Daten vom Model holen
|
||||
const QList<Device> &devices = m_model->getDevices();
|
||||
|
||||
for (const Device &d : devices) {
|
||||
xml.writeStartElement("device");
|
||||
xml.writeAttribute("name", d.name);
|
||||
xml.writeAttribute("ip", d.ip);
|
||||
xml.writeEndElement(); // </device>
|
||||
}
|
||||
|
||||
xml.writeEndElement(); // </devices>
|
||||
xml.writeEndDocument();
|
||||
|
||||
// Prüfen ob alles geschrieben wurde
|
||||
if (file.error() != QFile::NoError) {
|
||||
QMessageBox::critical(this, "Fehler", "Fehler beim Schreiben der Datei.");
|
||||
} else {
|
||||
statusBar()->showMessage("Datei erfolgreich gespeichert!", 3000);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user