Redesign data structures, part I

This commit is contained in:
2025-12-26 15:19:33 +01:00
parent fcfa61c16c
commit 71d7350913
9 changed files with 62 additions and 84 deletions

View File

@@ -27,13 +27,13 @@ windows
SOURCES += \ SOURCES += \
bc.cpp \ bc.cpp \
bcdatamanager.cpp \ bcdatamanager.cpp \
bcdatamodel.cpp \
bcdatavalue.cpp \ bcdatavalue.cpp \
bcdevicepanel.cpp \ bcdevicepanel.cpp \
bcitemdelegate.cpp \ bcitemdelegate.cpp \
bclegacy.cpp \ bclegacy.cpp \
bctoolbutton.cpp \ bctoolbutton.cpp \
bctransmitter.cpp \ bctransmitter.cpp \
bcvaluemodel.cpp \
bcvaluetype.cpp \ bcvaluetype.cpp \
lib/can_drv_win.c \ lib/can_drv_win.c \
bccandriver.cpp \ bccandriver.cpp \
@@ -46,13 +46,13 @@ HEADERS += \
bccandriver.h \ bccandriver.h \
bccandrivertinycan.h \ bccandrivertinycan.h \
bcdatamanager.h \ bcdatamanager.h \
bcdatamodel.h \
bcdatavalue.h \ bcdatavalue.h \
bcdevicepanel.h \ bcdevicepanel.h \
bcitemdelegate.h \ bcitemdelegate.h \
bcmainwindow.h \ bcmainwindow.h \
bctoolbutton.h \ bctoolbutton.h \
bctransmitter.h \ bctransmitter.h \
bcvaluemodel.h \
bcvaluetype.h bcvaluetype.h
FORMS += \ FORMS += \

1
bc.h
View File

@@ -30,7 +30,6 @@
***************************************************************************/ ***************************************************************************/
#ifndef BC_H #ifndef BC_H
#define BC_H #define BC_H

View File

@@ -93,13 +93,14 @@ void BCDataManager::onRunnerMessage(const QString &msg)
void BCDataManager::onSyncFromDevice() void BCDataManager::onSyncFromDevice()
{ {
qDebug() << " ---Syncing"; qDebug() << " ---Syncing";
/*
if( _currentDeviceID != BCDevice::ID::Invalid ) if( _currentDeviceID != BCDevice::ID::Invalid )
{ {
if( _valueModels.contains(_currentDeviceID) ) if( _valueModels.contains(_currentDeviceID) )
{ {
BCDataModel* model = _valueModels[_currentDeviceID]; BCValueModel* model = _valueModels[_currentDeviceID];
BCDataList& currentList = model->getValueList(); BCValueList& currentList = model->getValueList();
//BCDataValue& value = currentList[4]; //BCDataValue& value = currentList[4];
@@ -124,9 +125,10 @@ void BCDataManager::onSyncFromDevice()
} }
} // if contains } // if contains
} }
*/
} }
std::optional<BCDataModel*> BCDataManager::getModel(BCDevice::ID deviceID ) std::optional<BCValueModel*> BCDataManager::getModel(BCDevice::ID deviceID )
{ {
if( _valueModels.contains( deviceID) ) if( _valueModels.contains( deviceID) )
return _valueModels[deviceID]; return _valueModels[deviceID];
@@ -188,12 +190,13 @@ void BCDataManager::loadXmlBikeData()
qDebug() << " --- Device: " << _xml.name() << ": " << deviceType << " : " << deviceID; qDebug() << " --- Device: " << _xml.name() << ": " << deviceType << " : " << deviceID;
_currentDeviceID = BCDevice::ID( deviceID.value() ); _currentDeviceID = BCDevice::ID( deviceID.value() );
BCDataList parsedValues; BCValueList parsedValues;
loadXmlBikeDeviceData( parsedValues ); loadXmlBikeDeviceData( parsedValues );
if( parsedValues.count() ) if( parsedValues.count() )
{ {
BCDataModel* valueModel = new BCDataModel( this ); BCValueModel* valueModel = new BCValueModel( this );
valueModel->setValueList(parsedValues); // hier lacht der blaue HASE
//valueModel->setValueList(parsedValues);
_valueModels.insert( _currentDeviceID, valueModel ); _valueModels.insert( _currentDeviceID, valueModel );
} }
} }
@@ -218,7 +221,7 @@ void BCDataManager::loadXmlBikeData()
} }
void BCDataManager::loadXmlBikeDeviceData( BCDataList& parsedValues ) void BCDataManager::loadXmlBikeDeviceData( BCValueList& parsedValues )
{ {
auto printAttrs = [](const QXmlStreamReader& xml) auto printAttrs = [](const QXmlStreamReader& xml)
{ {

View File

@@ -1,38 +1,3 @@
/***************************************************************************
BionxControl
Copyright © 2025 christoph holzheuer
christoph.holzheuer@gmail.com
Using: mhs_can_drv.c
© 2011 - 2023 by MHS-Elektronik GmbH & Co. KG, Germany
Klaus Demlehner, klaus@mhs-elektronik.de
@see www.mhs-elektronik.de
BigXionFlasher USB V 0.2.4 rev. 97
© 2011-2013 by Thomas Koenig <info@bigxionflasher.org>
@see www.bigxionflasher.org
Bionx Bike Info
© 2018 Thorsten Schmidt (tschmidt@ts-soft.de)
@see www.ts-soft.de
mhs_can_drv.c 3.00
© 2011 - 2015 by MHS-Elektronik GmbH & Co. KG, Germany
Demlehner Klaus, info@mhs-elektronik.de
@see www.mhs-elektronik.de
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
@see https://github.com/bikemike/bionx-bikeinfo
***************************************************************************/
#ifndef BCDATAMANAGER_H
#define BCDATAMANAGER_H
/*************************************************************************** /***************************************************************************
BionxControl BionxControl
@@ -65,13 +30,16 @@ Klaus Demlehner, klaus@mhs-elektronik.de
***************************************************************************/ ***************************************************************************/
#ifndef BCDATAMANAGER_H
#define BCDATAMANAGER_H
#include <QMap> #include <QMap>
#include <QXmlStreamReader> #include <QXmlStreamReader>
#include <QXmlStreamWriter> #include <QXmlStreamWriter>
#include <QMetaEnum> #include <QMetaEnum>
#include <QThread> #include <QThread>
#include <bcdatamodel.h> #include <bcvaluemodel.h>
#include <bctransmitter.h> #include <bctransmitter.h>
@@ -85,11 +53,9 @@ public:
BCDataManager( QObject* parent = nullptr); BCDataManager( QObject* parent = nullptr);
virtual ~BCDataManager(); virtual ~BCDataManager();
std::optional<BCDataModel*> getModel(BCDevice::ID deviceID ); std::optional<BCValueModel*> getModel(BCDevice::ID deviceID );
BCTransmitter* getTransmitter(); BCTransmitter* getTransmitter();
public slots: public slots:
void loadXmlBikeData(); void loadXmlBikeData();
@@ -119,11 +85,11 @@ protected:
QString UnitType; QString UnitType;
}; };
void loadXmlBikeDeviceData( BCDataList& parsedValues ); void loadXmlBikeDeviceData( BCValueList& parsedValues );
std::optional<BCDataValue> makeDataValue( BCDevice::ID deviceID, const BCDataParams& params ); std::optional<BCDataValue> makeDataValue( BCDevice::ID deviceID, const BCDataParams& params );
using BCDeviceModels = QMap<BCDevice::ID, BCDataModel*>; using BCDeviceModels = QMap<BCDevice::ID, BCValueModel*>;
using BCValueTypeMap = QMap<QString,BCValueType*>; using BCValueTypeMap = QMap<QString,BCValueType*>;
QXmlStreamReader _xml; QXmlStreamReader _xml;

View File

@@ -101,7 +101,7 @@ public:
Q_DECLARE_METATYPE(BCDataValue*) Q_DECLARE_METATYPE(BCDataValue*)
using BCDataList = QVector<BCDataValue>; using BCValueList = QList<BCDataValue>;

View File

@@ -368,9 +368,9 @@ QString BCItemDelegate::formatDisplayString(const QModelIndex& index) const
QString displayStr; QString displayStr;
/* /*
QString label = index.data(BCDataListModel::LabelRole).toString(); QString label = index.data(BCValueListModel::LabelRole).toString();
QVariant value = index.data(BCDataListModel::ValueRole); QVariant value = index.data(BCValueListModel::ValueRole);
QString unit = index.data(BCDataListModel::UnitRole).toString(); QString unit = index.data(BCValueListModel::UnitRole).toString();
QString valueStr = value.toString(); QString valueStr = value.toString();

View File

@@ -57,8 +57,8 @@ BCMainWindow::BCMainWindow(QWidget *parent)
// Die Daten und auch die Datenmodelle für die Views werden // Die Daten und auch die Datenmodelle für die Views werden
// vom DataManager verwaltet und an die Views weitergereicht. // vom DataManager verwaltet und an die Views weitergereicht.
auto model = _dataManager.getModel( BCDevice::ID::Console ); //auto model = _dataManager.getModel( BCDevice::ID::Console );
_consolePanel->getValueView()->setModel( model.v ); //_consolePanel->getValueView()->setModel( model.v );
/* /*
if( model) if( model)

View File

@@ -30,18 +30,17 @@
***************************************************************************/ ***************************************************************************/
#include <bcdatamodel.h> #include <bcvaluemodel.h>
BCValueModel::BCValueModel(QObject *parent)
BCDataModel::BCDataModel(QObject *parent)
: QAbstractTableModel(parent) : QAbstractTableModel(parent)
{ {
} }
void BCDataModel::addValue(const BCDataValue& val)
void BCValueModel::addValue(const BCDataValue& val)
{ {
int row = _valueList.size(); int row = _valueList.size();
beginInsertRows(QModelIndex(), row, row); beginInsertRows(QModelIndex(), row, row);
@@ -49,32 +48,37 @@ void BCDataModel::addValue(const BCDataValue& val)
endInsertRows(); endInsertRows();
} }
void BCDataModel::setValueList(const BCDataList& valueList)
/*
void BCValueModel::setValueList(BCValueList* valueList)
{ {
beginResetModel(); beginResetModel();
_valueList = valueList; _valueList = valueList;
endResetModel(); endResetModel();
} }
*/
BCDataList& BCDataModel::getValueList() /*
BCValueList& BCValueModel::getValueList()
{ {
return _valueList; return _valueList;
} }
*/
int BCDataModel::rowCount(const QModelIndex& parent) const int BCValueModel::rowCount(const QModelIndex& parent) const
{ {
if (parent.isValid()) if (parent.isValid())
return 0; return 0;
return _valueList.size(); return _valueList.size();
} }
int BCDataModel::columnCount(const QModelIndex &parent) const int BCValueModel::columnCount(const QModelIndex &parent) const
{ {
if (parent.isValid()) return 0; if (parent.isValid()) return 0;
return 2; return 2;
} }
QVariant BCDataModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant BCValueModel::headerData(int section, Qt::Orientation orientation, int role) const
{ {
if (role != Qt::DisplayRole || orientation != Qt::Horizontal) if (role != Qt::DisplayRole || orientation != Qt::Horizontal)
return QVariant(); return QVariant();
@@ -90,7 +94,7 @@ QVariant BCDataModel::headerData(int section, Qt::Orientation orientation, int r
} }
} }
QVariant BCDataModel::data(const QModelIndex& index, int role) const QVariant BCValueModel::data(const QModelIndex& index, int role) const
{ {
/* /*
@@ -137,7 +141,7 @@ if (!index.isValid() || index.row() >= static_cast<int>(m_items.size()))
} }
Qt::ItemFlags BCDataModel::flags(const QModelIndex& index) const Qt::ItemFlags BCValueModel::flags(const QModelIndex& index) const
{ {
if (!index.isValid()) if (!index.isValid())
return Qt::NoItemFlags; return Qt::NoItemFlags;
@@ -146,11 +150,11 @@ Qt::ItemFlags BCDataModel::flags(const QModelIndex& index) const
} }
bool BCDataModel::setData(const QModelIndex& index, const QVariant& value, int role) bool BCValueModel::setData(const QModelIndex& index, const QVariant& value, int role)
{ {
if (index.isValid() && role == Qt::EditRole) if (index.isValid() && role == Qt::EditRole)
{ {
BCDataValue item = _valueList[index.row()]; BCDataValue& item = _valueList[index.row()];
// Wir erwarten hier nur den Value-Teil (vom Slider/Editor) // Wir erwarten hier nur den Value-Teil (vom Slider/Editor)
// Checken ob Int oder Double // Checken ob Int oder Double

View File

@@ -30,33 +30,39 @@
***************************************************************************/ ***************************************************************************/
#ifndef BCVALUEMODEL_H
#ifndef BCDATAMODEL_H #define BCVALUEMODEL_H
#define BCDATAMODEL_H
#include <QAbstractTableModel> #include <QAbstractTableModel>
#include <bcdatavalue.h> #include <bcdatavalue.h>
/**
* @brief Das BCValueModel dient als Interface zu den eigentlichen Daten,
* der BCValueList und besitzt diese.
*
* Ist das so schlau?
*
*/
class BCDataModel : public QAbstractTableModel class BCValueModel : public QAbstractTableModel
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit BCDataModel(QObject *parent = nullptr); explicit BCValueModel(QObject *parent = nullptr);
void addValue(const BCDataValue& val); void addValue(const BCDataValue& val);
void setValueList(const BCDataList& valueList);
BCDataList& getValueList(); //void setValueList(BCValueList* valueList);
//BCValueList *getValueList();
// Pure Virtual Functions von QAbstractTableModel // Pure Virtual Functions von QAbstractTableModel
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex& parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex& parent = QModelIndex()) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
// Nötig für Editierbarkeit // Nötig für Editierbarkeit
Qt::ItemFlags flags(const QModelIndex& index) const override; Qt::ItemFlags flags(const QModelIndex& index) const override;
@@ -64,8 +70,8 @@ public:
private: private:
BCDataList _valueList; BCValueList _valueList;
}; };
#endif // BCDATAMODEL_H #endif // BCVALUEMODEL_H