Redesign data structures, part I
This commit is contained in:
@@ -27,13 +27,13 @@ windows
|
||||
SOURCES += \
|
||||
bc.cpp \
|
||||
bcdatamanager.cpp \
|
||||
bcdatamodel.cpp \
|
||||
bcdatavalue.cpp \
|
||||
bcdevicepanel.cpp \
|
||||
bcitemdelegate.cpp \
|
||||
bclegacy.cpp \
|
||||
bctoolbutton.cpp \
|
||||
bctransmitter.cpp \
|
||||
bcvaluemodel.cpp \
|
||||
bcvaluetype.cpp \
|
||||
lib/can_drv_win.c \
|
||||
bccandriver.cpp \
|
||||
@@ -46,13 +46,13 @@ HEADERS += \
|
||||
bccandriver.h \
|
||||
bccandrivertinycan.h \
|
||||
bcdatamanager.h \
|
||||
bcdatamodel.h \
|
||||
bcdatavalue.h \
|
||||
bcdevicepanel.h \
|
||||
bcitemdelegate.h \
|
||||
bcmainwindow.h \
|
||||
bctoolbutton.h \
|
||||
bctransmitter.h \
|
||||
bcvaluemodel.h \
|
||||
bcvaluetype.h
|
||||
|
||||
FORMS += \
|
||||
|
||||
1
bc.h
1
bc.h
@@ -30,7 +30,6 @@
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
|
||||
#ifndef BC_H
|
||||
#define BC_H
|
||||
|
||||
|
||||
@@ -93,13 +93,14 @@ void BCDataManager::onRunnerMessage(const QString &msg)
|
||||
void BCDataManager::onSyncFromDevice()
|
||||
{
|
||||
qDebug() << " ---Syncing";
|
||||
/*
|
||||
if( _currentDeviceID != BCDevice::ID::Invalid )
|
||||
{
|
||||
if( _valueModels.contains(_currentDeviceID) )
|
||||
{
|
||||
|
||||
BCDataModel* model = _valueModels[_currentDeviceID];
|
||||
BCDataList& currentList = model->getValueList();
|
||||
BCValueModel* model = _valueModels[_currentDeviceID];
|
||||
BCValueList& currentList = model->getValueList();
|
||||
|
||||
//BCDataValue& value = currentList[4];
|
||||
|
||||
@@ -124,9 +125,10 @@ void BCDataManager::onSyncFromDevice()
|
||||
}
|
||||
} // if contains
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
std::optional<BCDataModel*> BCDataManager::getModel(BCDevice::ID deviceID )
|
||||
std::optional<BCValueModel*> BCDataManager::getModel(BCDevice::ID deviceID )
|
||||
{
|
||||
if( _valueModels.contains( deviceID) )
|
||||
return _valueModels[deviceID];
|
||||
@@ -188,12 +190,13 @@ void BCDataManager::loadXmlBikeData()
|
||||
qDebug() << " --- Device: " << _xml.name() << ": " << deviceType << " : " << deviceID;
|
||||
|
||||
_currentDeviceID = BCDevice::ID( deviceID.value() );
|
||||
BCDataList parsedValues;
|
||||
BCValueList parsedValues;
|
||||
loadXmlBikeDeviceData( parsedValues );
|
||||
if( parsedValues.count() )
|
||||
{
|
||||
BCDataModel* valueModel = new BCDataModel( this );
|
||||
valueModel->setValueList(parsedValues);
|
||||
BCValueModel* valueModel = new BCValueModel( this );
|
||||
// hier lacht der blaue HASE
|
||||
//valueModel->setValueList(parsedValues);
|
||||
_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)
|
||||
{
|
||||
|
||||
@@ -4,41 +4,6 @@
|
||||
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
|
||||
Copyright © 2025 christoph holzheuer
|
||||
christoph.holzheuer@gmail.com
|
||||
|
||||
Using:
|
||||
|
||||
mhs_can_drv.c
|
||||
@@ -65,13 +30,16 @@ Klaus Demlehner, klaus@mhs-elektronik.de
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef BCDATAMANAGER_H
|
||||
#define BCDATAMANAGER_H
|
||||
|
||||
#include <QMap>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QXmlStreamWriter>
|
||||
#include <QMetaEnum>
|
||||
|
||||
#include <QThread>
|
||||
#include <bcdatamodel.h>
|
||||
#include <bcvaluemodel.h>
|
||||
|
||||
#include <bctransmitter.h>
|
||||
|
||||
@@ -85,11 +53,9 @@ public:
|
||||
BCDataManager( QObject* parent = nullptr);
|
||||
virtual ~BCDataManager();
|
||||
|
||||
std::optional<BCDataModel*> getModel(BCDevice::ID deviceID );
|
||||
std::optional<BCValueModel*> getModel(BCDevice::ID deviceID );
|
||||
BCTransmitter* getTransmitter();
|
||||
|
||||
|
||||
|
||||
public slots:
|
||||
|
||||
void loadXmlBikeData();
|
||||
@@ -119,11 +85,11 @@ protected:
|
||||
QString UnitType;
|
||||
};
|
||||
|
||||
void loadXmlBikeDeviceData( BCDataList& parsedValues );
|
||||
void loadXmlBikeDeviceData( BCValueList& parsedValues );
|
||||
|
||||
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*>;
|
||||
|
||||
QXmlStreamReader _xml;
|
||||
|
||||
@@ -101,7 +101,7 @@ public:
|
||||
Q_DECLARE_METATYPE(BCDataValue*)
|
||||
|
||||
|
||||
using BCDataList = QVector<BCDataValue>;
|
||||
using BCValueList = QList<BCDataValue>;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -368,9 +368,9 @@ QString BCItemDelegate::formatDisplayString(const QModelIndex& index) const
|
||||
QString displayStr;
|
||||
|
||||
/*
|
||||
QString label = index.data(BCDataListModel::LabelRole).toString();
|
||||
QVariant value = index.data(BCDataListModel::ValueRole);
|
||||
QString unit = index.data(BCDataListModel::UnitRole).toString();
|
||||
QString label = index.data(BCValueListModel::LabelRole).toString();
|
||||
QVariant value = index.data(BCValueListModel::ValueRole);
|
||||
QString unit = index.data(BCValueListModel::UnitRole).toString();
|
||||
|
||||
QString valueStr = value.toString();
|
||||
|
||||
|
||||
@@ -57,8 +57,8 @@ BCMainWindow::BCMainWindow(QWidget *parent)
|
||||
// Die Daten und auch die Datenmodelle für die Views werden
|
||||
// vom DataManager verwaltet und an die Views weitergereicht.
|
||||
|
||||
auto model = _dataManager.getModel( BCDevice::ID::Console );
|
||||
_consolePanel->getValueView()->setModel( model.v );
|
||||
//auto model = _dataManager.getModel( BCDevice::ID::Console );
|
||||
//_consolePanel->getValueView()->setModel( model.v );
|
||||
|
||||
/*
|
||||
if( model)
|
||||
|
||||
@@ -30,18 +30,17 @@
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include <bcdatamodel.h>
|
||||
#include <bcvaluemodel.h>
|
||||
|
||||
|
||||
|
||||
|
||||
BCDataModel::BCDataModel(QObject *parent)
|
||||
BCValueModel::BCValueModel(QObject *parent)
|
||||
: QAbstractTableModel(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void BCDataModel::addValue(const BCDataValue& val)
|
||||
|
||||
void BCValueModel::addValue(const BCDataValue& val)
|
||||
{
|
||||
int row = _valueList.size();
|
||||
beginInsertRows(QModelIndex(), row, row);
|
||||
@@ -49,32 +48,37 @@ void BCDataModel::addValue(const BCDataValue& val)
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void BCDataModel::setValueList(const BCDataList& valueList)
|
||||
|
||||
/*
|
||||
void BCValueModel::setValueList(BCValueList* valueList)
|
||||
{
|
||||
beginResetModel();
|
||||
_valueList = valueList;
|
||||
endResetModel();
|
||||
}
|
||||
*/
|
||||
|
||||
BCDataList& BCDataModel::getValueList()
|
||||
/*
|
||||
BCValueList& BCValueModel::getValueList()
|
||||
{
|
||||
return _valueList;
|
||||
}
|
||||
*/
|
||||
|
||||
int BCDataModel::rowCount(const QModelIndex& parent) const
|
||||
int BCValueModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
return _valueList.size();
|
||||
}
|
||||
|
||||
int BCDataModel::columnCount(const QModelIndex &parent) const
|
||||
int BCValueModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid()) return 0;
|
||||
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)
|
||||
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())
|
||||
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)
|
||||
{
|
||||
BCDataValue item = _valueList[index.row()];
|
||||
BCDataValue& item = _valueList[index.row()];
|
||||
|
||||
// Wir erwarten hier nur den Value-Teil (vom Slider/Editor)
|
||||
// Checken ob Int oder Double
|
||||
@@ -30,33 +30,39 @@
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
|
||||
#ifndef BCDATAMODEL_H
|
||||
#define BCDATAMODEL_H
|
||||
#ifndef BCVALUEMODEL_H
|
||||
#define BCVALUEMODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
#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
|
||||
|
||||
public:
|
||||
|
||||
explicit BCDataModel(QObject *parent = nullptr);
|
||||
explicit BCValueModel(QObject *parent = nullptr);
|
||||
|
||||
void addValue(const BCDataValue& val);
|
||||
void setValueList(const BCDataList& valueList);
|
||||
BCDataList& getValueList();
|
||||
|
||||
//void setValueList(BCValueList* valueList);
|
||||
//BCValueList *getValueList();
|
||||
|
||||
// Pure Virtual Functions von QAbstractTableModel
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int rowCount(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 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
|
||||
Qt::ItemFlags flags(const QModelIndex& index) const override;
|
||||
@@ -64,8 +70,8 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
BCDataList _valueList;
|
||||
BCValueList _valueList;
|
||||
|
||||
};
|
||||
|
||||
#endif // BCDATAMODEL_H
|
||||
#endif // BCVALUEMODEL_H
|
||||
Reference in New Issue
Block a user