diff --git a/bcdatamanager.cpp b/bcdatamanager.cpp index ea01274..423d9c5 100644 --- a/bcdatamanager.cpp +++ b/bcdatamanager.cpp @@ -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 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 ); } diff --git a/bcdatamanager.h b/bcdatamanager.h index d7c9e85..543d275 100644 --- a/bcdatamanager.h +++ b/bcdatamanager.h @@ -55,7 +55,7 @@ public: std::optional 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; QXmlStreamReader _xml; - BCValueList _currentValues; QMetaEnum _bcDeviceEnum{QMetaEnum::fromType()}; - QThread _worker; - BCTransmitter _transmitter; + QThread _worker; + BCTransmitter _transmitter; }; diff --git a/bcdatavalue.h b/bcdatavalue.h index 671c069..0d10be3 100644 --- a/bcdatavalue.h +++ b/bcdatavalue.h @@ -100,12 +100,55 @@ public: //mutable std::optional rawValue; }; +// ?? ist das nötig? Q_DECLARE_METATYPE(BCDataValue*) -using BCValueList = QList; +//using BCValueList = QList; +class BCValueList : public QList +{ +public: + + BCValueList() + { + qDebug() << "BC Construct: " << this; + } + + BCValueList(const BCValueList& other) + : QList(other) + { + qDebug() << "BC: Copy from: " << &other << "to" << this; + } + + BCValueList(BCValueList&& other) noexcept + : QList( other ) + { + qDebug() << "Move from: " << &other << "to" << this; + } + + // Copy Assignment Operator + BCValueList& operator=(const BCValueList& other) + { + QList::operator=( other ); + return *this; + } + + // Move Assignment Operator + BCValueList& operator=(BCValueList&& other) noexcept + { + QList::operator=( other ); + return *this; + } + + ~BCValueList() + { + qDebug() << "Destruct: " << this; + } + +}; +Q_DECLARE_METATYPE(BCValueList) // abbreviations: diff --git a/bcdevicepanel.cpp b/bcdevicepanel.cpp index 75f8731..55c9c4d 100644 --- a/bcdevicepanel.cpp +++ b/bcdevicepanel.cpp @@ -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 ); } /* diff --git a/bcdevicepanel.h b/bcdevicepanel.h index f216c92..78a7942 100644 --- a/bcdevicepanel.h +++ b/bcdevicepanel.h @@ -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; }; diff --git a/bcmainwindow.cpp b/bcmainwindow.cpp index 84d6c15..949639e 100644 --- a/bcmainwindow.cpp +++ b/bcmainwindow.cpp @@ -43,6 +43,10 @@ BCMainWindow::BCMainWindow(QWidget *parent) : QMainWindow(parent) { + // WICHTIG: Registriere sowohl das Struct als auch die LISTE des Structs + qRegisterMetaType("BCDataValue"); + qRegisterMetaType>("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 ) { diff --git a/bcmainwindow.h b/bcmainwindow.h index dc9196f..9ae8293 100644 --- a/bcmainwindow.h +++ b/bcmainwindow.h @@ -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); diff --git a/bcmainwindow.ui b/bcmainwindow.ui index 6d131d4..9a09512 100644 --- a/bcmainwindow.ui +++ b/bcmainwindow.ui @@ -21,25 +21,6 @@ background-color: grey; - - - - - 64 - 64 - - - - ... - - - - 64 - 64 - - - - @@ -97,6 +78,25 @@ + + + + + 64 + 64 + + + + ... + + + + 48 + 48 + + + + diff --git a/main.cpp b/main.cpp index 7fce12d..80195ca 100644 --- a/main.cpp +++ b/main.cpp @@ -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};