Sending BCValueList to ViewPanels.

This commit is contained in:
2025-12-27 18:43:15 +01:00
parent a12fde26ef
commit 139397f045
9 changed files with 129 additions and 71 deletions

View File

@@ -83,11 +83,6 @@ BCTransmitter* BCDataManager::getTransmitter()
return &_transmitter;
};
const BCValueList& BCDataManager::getCurrentValueList()
{
return _currentValues;
}
void BCDataManager::onCommandFinished(int id, bool success)
{
@@ -224,8 +219,8 @@ void BCDataManager::loadXmlBikeDeviceData(BCDevice::ID deviceID)
Q_ASSERT(_xml.isStartElement() && _xml.name() == "Device"_L1);
qDebug() << " XXX ---------------";
// Wertliste für neues Device leeren
_currentValues.clear();
// temporäre Wertliste für neues Device
BCValueList currentValues;
while( _xml.readNextStartElement() )
{
@@ -245,15 +240,15 @@ void BCDataManager::loadXmlBikeDeviceData(BCDevice::ID deviceID)
// nur gültige Werte sind vorhanden und können gespeichert werden
std::optional<BCDataValue> newValue = makeDataValue( deviceID, params );
if(newValue)
_currentValues.push_back( *newValue );
currentValues.push_back( *newValue );
}
// weiter zum nächsten Element
_xml.skipCurrentElement();
}
// Wenn dieses Device fertig geladen wurde, soll das MainWindow es abholen
if( !_currentValues.isEmpty() )
emit valueListReady( deviceID );
if( !currentValues.isEmpty() )
emit valueListReady( deviceID, currentValues );
}

View File

@@ -55,7 +55,7 @@ public:
std::optional<BCValueModel*> getModel(BCDevice::ID deviceID );
BCTransmitter* getTransmitter();
const BCValueList& getCurrentValueList();
public slots:
@@ -65,7 +65,7 @@ public slots:
signals:
void valueListReady( BCDevice::ID deviceID );
void valueListReady( BCDevice::ID deviceID, BCValueList valueList );
// Internes Signal, um Daten an den Worker Thread zu senden
void sendValueCommand( BC::OpID, const BCDataValue* cmd);
@@ -95,11 +95,10 @@ protected:
using BCValueTypeMap = QMap<QString,BCValueType*>;
QXmlStreamReader _xml;
BCValueList _currentValues;
QMetaEnum _bcDeviceEnum{QMetaEnum::fromType<BCDevice::ID>()};
QThread _worker;
BCTransmitter _transmitter;
QThread _worker;
BCTransmitter _transmitter;
};

View File

@@ -100,12 +100,55 @@ public:
//mutable std::optional<uint32_t> rawValue;
};
// ?? ist das nötig?
Q_DECLARE_METATYPE(BCDataValue*)
using BCValueList = QList<BCDataValue>;
//using BCValueList = QList<BCDataValue>;
class BCValueList : public QList<BCDataValue>
{
public:
BCValueList()
{
qDebug() << "BC Construct: " << this;
}
BCValueList(const BCValueList& other)
: QList<BCDataValue>(other)
{
qDebug() << "BC: Copy from: " << &other << "to" << this;
}
BCValueList(BCValueList&& other) noexcept
: QList<BCDataValue>( other )
{
qDebug() << "Move from: " << &other << "to" << this;
}
// Copy Assignment Operator
BCValueList& operator=(const BCValueList& other)
{
QList<BCDataValue>::operator=( other );
return *this;
}
// Move Assignment Operator
BCValueList& operator=(BCValueList&& other) noexcept
{
QList<BCDataValue>::operator=( other );
return *this;
}
~BCValueList()
{
qDebug() << "Destruct: " << this;
}
};
Q_DECLARE_METATYPE(BCValueList)
// abbreviations:

View File

@@ -35,9 +35,8 @@
BCDevicePanel::BCDevicePanel(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
_valueView->setModel( &_valueModel );
}
@@ -54,18 +53,35 @@ QString BCDevicePanel::getHeaderText()
QTableView* BCDevicePanel::getValueView()
{
//valueModel;
return _valueView;
}
void BCDevicePanel::setValueList(const BCValueList& valueList)
{
// 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 );
/*
if( model)
{
_valueView->setModel( *model );
_valueView->resizeColumnsToContents();
//_valueView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
}
*/
}
const BCValueList& BCDevicePanel::getValueList()
BCValueList& BCDevicePanel::exposeValueList()
{
return _myTmpList;
}
void BCDevicePanel::onValueListReady( BCDevice::ID deviceID, BCValueList valueList )
{
qDebug() << " --- onValueListReady: " << getHeaderText() <<" : " << deviceID << ": " << valueList.size();
_valueModel.setValueList( valueList );
}
/*

View File

@@ -48,15 +48,18 @@ public:
void setHeaderText( const QString& headerText);
QString getHeaderText();
void setValueList(const BCValueList& valueList);
const BCValueList& getValueList();
BCValueList& exposeValueList();
QTableView* getValueView();
public slots:
void onValueListReady( BCDevice::ID deviceID, BCValueList valueList );
protected:
BCValueModel _valueModel;
BCValueList _myTmpList;
};

View File

@@ -43,6 +43,10 @@
BCMainWindow::BCMainWindow(QWidget *parent)
: QMainWindow(parent)
{
// WICHTIG: Registriere sowohl das Struct als auch die LISTE des Structs
qRegisterMetaType<BCDataValue>("BCDataValue");
qRegisterMetaType<QList<BCDataValue>>("BCValueList");
setupUi(this);
initData();
@@ -79,17 +83,25 @@ void BCMainWindow::initData()
// Action an den Button binden
button->setDefaultAction( action);
// old school, not used
connect( action, &QAction::triggered, this, &BCMainWindow::onActionButtonTriggered );
connect( action, &QAction::toggled, this, &BCMainWindow::onActionButtonToggled );
//connect( action, &QAction::triggered, this, &BCMainWindow::onActionButtonTriggered );
//connect( action, &QAction::toggled, this, &BCMainWindow::onActionButtonToggled );
// new way: die DeviceID muss aber explizit vom Lambda eingefanden werden.
connect( action, &QAction::triggered, this, [this,deviceID]()
{
onShowDevicePanel( deviceID );
});
// den Panels ihren title geben
if( _devicePanels.contains(deviceID) )
{
_devicePanels[deviceID]->setHeaderText( panelTitle );
BCDevicePanel* currentPanel = _devicePanels[deviceID];
// den Panels ihren title geben
currentPanel->setHeaderText( panelTitle );
// Wenn ein Device (entspricht einem Datenmodel) fertig eingelesen wurde,
// wird es weitergereicht.
// Problem: alle Panels bekommen alle Datenmodelle angeboten.
connect( &_dataManager, &BCDataManager::valueListReady, currentPanel, &BCDevicePanel::onValueListReady );
}
@@ -107,21 +119,8 @@ void BCMainWindow::initData()
configureAction(_pimpButton, _pimpAction, BCDevice::ID::Pimp, "Pimp my Ride"_L1 );
// 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 );
/*
if( model)
{
_valueView->setModel( *model );
_valueView->resizeColumnsToContents();
//_valueView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
}
/*
BCItemDelegate* _delegate = new BCItemDelegate( _valueView);
//_delegate = new AnimatedDelegate(_valueView );
_valueView->setItemDelegate( _delegate );
@@ -145,26 +144,28 @@ void BCMainWindow::initData()
connect( _syncButton, &QPushButton::clicked, &_dataManager, &BCDataManager::onSyncFromDevice );
*/
// 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::onValueListReady( BCDevice::ID deviceID )
{
qDebug() << " --- onValueListReady!" << deviceID;
if( _devicePanels.contains( deviceID ) )
{
const BCValueList& newValueList = _dataManager.getCurrentValueList();
_devicePanels[deviceID]->setValueList( newValueList );
BCDevicePanel& panel = *_devicePanels[deviceID];
BCValueList& victim = panel.exposeValueList();
BCValueList& newValueList = _dataManager.getCurrentValueList();
qDebug() << " --- Before: " << victim.size() << " orig:" << newValueList.size();
victim = std::exchange(newValueList, BCValueList());
//_devicePanels[deviceID]->setValueList( newValueList );
qDebug() << " ---After: " << victim.size() << " orig:" << newValueList.size();
}
}
*/
void BCMainWindow::onShowDevicePanel( BCDevice::ID deviceID )
{

View File

@@ -51,7 +51,7 @@ public:
public slots:
void onValueListReady( BCDevice::ID deviceID );
//void onValueListReady( BCDevice::ID deviceID );
void onShowDevicePanel( BCDevice::ID deviceID );
void onActionButtonTriggered( bool checked);
void onActionButtonToggled( bool checked);

View File

@@ -21,25 +21,6 @@
<string notr="true">background-color: grey;</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="BCToolButton" name="_pimpButton">
<property name="minimumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
<property name="iconSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="BCToolButton" name="_motorButton">
<property name="minimumSize">
@@ -97,6 +78,25 @@
</property>
</widget>
</item>
<item>
<widget class="BCToolButton" name="_pimpButton">
<property name="minimumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
<property name="iconSize">
<size>
<width>48</width>
<height>48</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">

View File

@@ -149,6 +149,7 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
//setApplicationStyleSheet( ":/bionxcontrol.qss"_L1 );
mookoo myMookoo{"",1,1.0};
mookoo myMooko2{"",1};
mookoo2* myMooko3 = new mookoo2{{"superfitze",1},8};