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

5
bc.h
View File

@@ -134,6 +134,8 @@ public:
//{%Region Console} //{%Region Console}
Invalid = 0x0, Invalid = 0x0,
ID_Pimp = 0xF1, // dummy id to identify the tuning page
ID_Console_Master = 0x08, // (Can Id In Master Mode) ID_Console_Master = 0x08, // (Can Id In Master Mode)
ID_Console_Slave = 0x48, // (Can Id In Slave Mode) ID_Console_Slave = 0x48, // (Can Id In Slave Mode)
@@ -772,7 +774,8 @@ public:
Battery = uint8_t( BC::ID::ID_Battery), Battery = uint8_t( BC::ID::ID_Battery),
Motor = uint8_t( BC::ID::ID_Motor ), Motor = uint8_t( BC::ID::ID_Motor ),
BIB = uint8_t( BC::ID::ID_Bib ), BIB = uint8_t( BC::ID::ID_Bib ),
Sensor = uint8_t( BC::ID::ID_Sensor ) Sensor = uint8_t( BC::ID::ID_Sensor ),
Pimp = uint8_t( BC::ID::ID_Pimp )
}; };
Q_ENUM(ID) Q_ENUM(ID)
}; };

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

View File

@@ -55,15 +55,18 @@ public:
std::optional<BCValueModel*> getModel(BCDevice::ID deviceID ); std::optional<BCValueModel*> getModel(BCDevice::ID deviceID );
BCTransmitter* getTransmitter(); BCTransmitter* getTransmitter();
const BCValueList& getCurrentValueList();
public slots: public slots:
void loadXmlBikeData(); void loadXmlBikeData( const QString& fileName );
void saveBikeData(); void saveBikeData();
void onSyncFromDevice(); void onSyncFromDevice();
signals: signals:
void valueListReady( BCDevice::ID deviceID );
// Internes Signal, um Daten an den Worker Thread zu senden // Internes Signal, um Daten an den Worker Thread zu senden
void sendValueCommand( BC::OpID, const BCDataValue* cmd); void sendValueCommand( BC::OpID, const BCDataValue* cmd);
//void valuedTouched(const BCDataValue& cmd); //void valuedTouched(const BCDataValue& cmd);
@@ -85,17 +88,14 @@ protected:
QString UnitType; QString UnitType;
}; };
void loadXmlBikeDeviceData( BCValueList& parsedValues ); void loadXmlBikeDeviceData( BCDevice::ID deviceID );
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, BCValueModel*>;
using BCValueTypeMap = QMap<QString,BCValueType*>; using BCValueTypeMap = QMap<QString,BCValueType*>;
QXmlStreamReader _xml; QXmlStreamReader _xml;
BCValueList _currentValues;
BCDeviceModels _valueModels;
BCDevice::ID _currentDeviceID{BCDevice::ID::Invalid};
QMetaEnum _bcDeviceEnum{QMetaEnum::fromType<BCDevice::ID>()}; QMetaEnum _bcDeviceEnum{QMetaEnum::fromType<BCDevice::ID>()};
QThread _worker; QThread _worker;

View File

@@ -80,6 +80,9 @@ public:
void writeRawValueX( const BCAbstractTransmitter& transmitter ) const; void writeRawValueX( const BCAbstractTransmitter& transmitter ) const;
// void reset() // void reset()
// später
//protected:
//const BCValueType& valueType; //const BCValueType& valueType;
//BCValueTypeCRef valueType; //BCValueTypeCRef valueType;
const BCValueType* valueType{}; const BCValueType* valueType{};
@@ -87,6 +90,7 @@ public:
BC::ID registerID{BC::ID::Invalid}; BC::ID registerID{BC::ID::Invalid};
int rowInModel{-1}; int rowInModel{-1};
QString label; QString label;
// ??
mutable QString visibleValue; mutable QString visibleValue;
QVariant defaultValue; QVariant defaultValue;
@@ -95,8 +99,6 @@ public:
//mutable std::optional<uint32_t> rawValue; //mutable std::optional<uint32_t> rawValue;
}; };
Q_DECLARE_METATYPE(BCDataValue*) Q_DECLARE_METATYPE(BCDataValue*)

View File

@@ -44,15 +44,59 @@ BCMainWindow::BCMainWindow(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
{ {
setupUi(this); setupUi(this);
initData();
}
BCMainWindow::~BCMainWindow()
{
}
void BCMainWindow::initData()
{
// Die Daten und auch die Datenmodelle für die Views werden
// vom DataManager verwaltet und an die Views weitergereicht.
/*
auto setDeviceModel = [&]( BCDevice::ID deviceID, BCDevicePanel* panel )
{
auto model = _dataManager.getModel( deviceID );
if( model)
{
QAbstractItemView* valueView = panel->getValueView();
valueView->setModel( *model );
//valueView->resizeColumnsToContents();
//_valueView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
}
};
*/
auto configureAction = [&]( QToolButton* button, QAction* action, BCDevice::ID deviceID )
{
button->setDefaultAction( action);
connect( action, &QAction::triggered, this, &BCMainWindow::onActionButtonTriggered );
connect( action, &QAction::toggled, this, &BCMainWindow::onActionButtonToggled );
// new way
connect( action, &QAction::triggered, this, [&]
{
onShowDevicePanel( deviceID );
});
};
// Wir wollen die Devices den Views zuordnen können
_devicePanels[BCDevice::ID::Console] = _consolePanel;
_devicePanels[BCDevice::ID::Battery] = _batteryPanel;
_devicePanels[BCDevice::ID::Motor] = _motorPanel;
// Die actions an die Buttons binden // Die actions an die Buttons binden
_motorButton->setDefaultAction( _motorAction); configureAction(_motorButton, _motorAction, BCDevice::ID::Motor );
_consoleButton->setDefaultAction( _consoleAction ); configureAction(_consoleButton, _consoleAction, BCDevice::ID::Console );
_batteryButton->setDefaultAction( _batteryAction ); configureAction(_batteryButton, _batteryAction, BCDevice::ID::Battery );
_pimpButton->setDefaultAction( _pimpAction); configureAction(_pimpButton, _pimpAction, BCDevice::ID::Pimp );
// die Daten des eBikes laden
_dataManager.loadXmlBikeData();
// 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.
@@ -92,42 +136,49 @@ BCMainWindow::BCMainWindow(QWidget *parent)
connect( _syncButton, &QPushButton::clicked, &_dataManager, &BCDataManager::onSyncFromDevice ); connect( _syncButton, &QPushButton::clicked, &_dataManager, &BCDataManager::onSyncFromDevice );
*/ */
}
BCMainWindow::~BCMainWindow()
{
// wir wollen Bescheid wissen, wenn ein Device (entspricht einem Datenmodel)
// fertig eingelesen wurde.
connect( &_dataManager, &BCDataManager::valueListReady, this, &BCMainWindow::onValueListReady );
// die Daten des eBikes laden
_dataManager.loadXmlBikeData(":/bikeinfo.xml"_L1);
} }
void BCMainWindow::initData()
{
// Die Daten und auch die Datenmodelle für die Views werden
// vom DataManager verwaltet und an die Views weitergereicht.
auto setDeviceModel = [&]( BCDevice::ID deviceID, BCDevicePanel* panel )
void BCMainWindow::onValueListReady( BCDevice::ID deviceID )
{ {
auto model = _dataManager.getModel( deviceID ); qDebug() << " --- onValueListReady!" << deviceID;
if( model) if( _devicePanels.contains( deviceID ) )
{ {
QAbstractItemView* valueView = panel->getValueView(); const BCValueList& newValueList = _dataManager.getCurrentValueList();
valueView->setModel( *model ); _devicePanels[deviceID]->setValueList( newValueList );
//valueView->resizeColumnsToContents(); }
//_valueView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
} }
void BCMainWindow::onShowDevicePanel( BCDevice::ID deviceID )
{
qDebug() << " --- onShowDevicePanel:" << deviceID;
if( _devicePanels.contains( deviceID ) )
{
//const BCValueList& newValueList = _dataManager.getCurrentValueList();
//_devicePanels[deviceID]->setValueList( newValueList );
}
}
}; void BCMainWindow::onActionButtonTriggered( bool checked)
{
qDebug() << " --- onActionButtonTriggered: " << checked;
_dataManager.loadXmlBikeData();
} }
void BCMainWindow::onActionButtonToggled( bool checked)
{
qDebug() << " --- onActionButtonToggled: " << checked;
}
void BCMainWindow::onConnectButtonToggled(bool checked ) void BCMainWindow::onConnectButtonToggled(bool checked )
{ {
//_dataManager.setDriverConnectionState( checked ); //_dataManager.setDriverConnectionState( checked );

View File

@@ -38,8 +38,7 @@
#include <ui_bcmainwindow.h> #include <ui_bcmainwindow.h>
#include <bcdatamanager.h> #include <bcdatamanager.h>
class BCDevicePanel;
class AnimatedDelegate;
class BCMainWindow : public QMainWindow, public Ui_BCMainWindow class BCMainWindow : public QMainWindow, public Ui_BCMainWindow
{ {
@@ -52,6 +51,10 @@ public:
public slots: public slots:
void onValueListReady( BCDevice::ID deviceID );
void onShowDevicePanel( BCDevice::ID deviceID );
void onActionButtonTriggered( bool checked);
void onActionButtonToggled( bool checked);
void onConnectButtonToggled(bool active ); void onConnectButtonToggled(bool active );
protected: protected:
@@ -59,8 +62,12 @@ protected:
void initData(); void initData();
BCDataManager _dataManager; BCDataManager _dataManager;
AnimatedDelegate* _delegate;
// Wir brauchen eine Verbindung zwischen den Views
// und dem Device, das sie darstellen.
using BCDevicePanels = QMap<BCDevice::ID, BCDevicePanel*>;
BCDevicePanels _devicePanels;
}; };

View File

@@ -151,6 +151,9 @@
</widget> </widget>
<widget class="QStatusBar" name="_statusbar"/> <widget class="QStatusBar" name="_statusbar"/>
<action name="_pimpAction"> <action name="_pimpAction">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon"> <property name="icon">
<iconset> <iconset>
<normaloff>:restart.png</normaloff>:restart.png</iconset> <normaloff>:restart.png</normaloff>:restart.png</iconset>

View File

@@ -49,21 +49,19 @@ void BCValueModel::addValue(const BCDataValue& val)
} }
/* const BCValueList& BCValueModel::getValueList()
void BCValueModel::setValueList(BCValueList* valueList) {
return _valueList;
}
void BCValueModel::setValueList(const BCValueList& valueList)
{ {
beginResetModel(); beginResetModel();
_valueList = valueList; _valueList = valueList;
endResetModel(); endResetModel();
} }
*/
/*
BCValueList& BCValueModel::getValueList()
{
return _valueList;
}
*/
int BCValueModel::rowCount(const QModelIndex& parent) const int BCValueModel::rowCount(const QModelIndex& parent) const
{ {

View File

@@ -53,9 +53,8 @@ public:
explicit BCValueModel(QObject *parent = nullptr); explicit BCValueModel(QObject *parent = nullptr);
void addValue(const BCDataValue& val); void addValue(const BCDataValue& val);
void setValueList(const BCValueList& valueList);
//void setValueList(BCValueList* valueList); const BCValueList& getValueList();
//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;
@@ -70,6 +69,7 @@ public:
private: private:
// Die eigentlichen Werte wohnen im tatsächlich hier, im Model.
BCValueList _valueList; BCValueList _valueList;
}; };