diff --git a/bcdevicepanel.cpp b/bcdevicepanel.cpp index b969cf9..7c86df0 100644 --- a/bcdevicepanel.cpp +++ b/bcdevicepanel.cpp @@ -83,11 +83,16 @@ QTableView* BCDevicePanel::getValueView() } +const BCValueList& BCDevicePanel::getValueList() +{ + return _valueModel.getValueList(); +} + void BCDevicePanel::onValueListReady( BCDevice::ID deviceID, BCValueList valueList ) { qDebug() << " --- onValueListReady: " << getHeaderText() <<" : " << deviceID << ": " << valueList.size(); if(_devideID == deviceID) - _valueModel.setValueList( valueList ); + _valueModel.takeValueList( valueList ); } /* diff --git a/bcdevicepanel.h b/bcdevicepanel.h index 7ddfb97..4b185b1 100644 --- a/bcdevicepanel.h +++ b/bcdevicepanel.h @@ -50,10 +50,8 @@ public: void setDeviceID( BCDevice::ID deviceID ); BCDevice::ID getDeviceID() const; - - BCValueList& exposeValueList(); - QTableView* getValueView(); + const BCValueList& getValueList(); public slots: diff --git a/bcmainwindow.cpp b/bcmainwindow.cpp index 9d83f00..01e5b35 100644 --- a/bcmainwindow.cpp +++ b/bcmainwindow.cpp @@ -162,9 +162,10 @@ void BCMainWindow::initMainWindow() // C) Aufräumen: Wenn Thread endet, lösche den Runner connect(&_worker, &QThread::finished, &_transmitter, &QObject::deleteLater); - // 5. Thread starten _worker.start(); + + _consoleAction->trigger(); } @@ -179,7 +180,7 @@ void BCMainWindow::onValueListReady( BCDevice::ID deviceID ) BCValueList& newValueList = _dataManager.getCurrentValueList(); qDebug() << " --- Before: " << victim.size() << " orig:" << newValueList.size(); victim = std::exchange(newValueList, BCValueList()); - //_devicePanels[deviceID]->setValueList( newValueList ); + //_devicePanels[deviceID]->exchangeValueList( newValueList ); qDebug() << " ---After: " << victim.size() << " orig:" << newValueList.size(); } } @@ -230,40 +231,35 @@ void BCMainWindow::onRunnerMessage(const QString &msg) + void BCMainWindow::onSyncFromDevice() { qDebug() << " ---Syncing"; - /* - if( _currentDeviceID != BCDevice::ID::Invalid ) + + Q_ASSERT(_currentPanel && "currentpanel ist null!"); + + const BCValueList& currentList =_currentPanel->getValueList(); + + // alle einzeln? echt jetzt? + + for( const BCDataValue& value : currentList ) { - if( _valueModels.contains(_currentDeviceID) ) - { + qDebug() << " --- value: " << value.label; - BCValueModel* model = _valueModels[_currentDeviceID]; - BCValueList& currentList = model->getValueList(); + // statt '_transmitter.enqueueValueCommand( value )' entkoppeln + // wir das eleganter über emit sendValueCommand() - //BCDataValue& value = currentList[4]; + //_transmitter.enqueueValueCommand( value ); + emit sendValueCommand( BC::OpID::ReadValue, &value); - for( const BCDataValue& value : currentList ) - { - qDebug() << " --- value: " << value.label; + emit valueTouched( value.rowInModel ); - // statt '_transmitter.enqueueValueCommand( value )' entkoppeln - // wir das eleganter über emit sendValueCommand() + bc::processEventsFor(500); - //_transmitter.enqueueValueCommand( value ); - emit sendValueCommand( BC::OpID::ReadValue, &value); + //QApplication::processEvents(); + // Thread schlafen lassen (Simulation einer blockierenden Operation) + //QThread::msleep(500); - emit valueTouched( value.rowInModel ); - - bc::processEventsFor(500); - - //QApplication::processEvents(); - // Thread schlafen lassen (Simulation einer blockierenden Operation) - //QThread::msleep(500); - - } - } // if contains } -*/ + } diff --git a/bcvaluemodel.cpp b/bcvaluemodel.cpp index 4f45d00..c26a796 100644 --- a/bcvaluemodel.cpp +++ b/bcvaluemodel.cpp @@ -55,10 +55,11 @@ const BCValueList& BCValueModel::getValueList() } -void BCValueModel::setValueList(const BCValueList& valueList) +void BCValueModel::takeValueList(BCValueList& newValueList) { beginResetModel(); - _valueList = valueList; + // hier nehmen wir die valueList in Besitz. + _valueList = std::exchange(newValueList, {} ); endResetModel(); } diff --git a/bcvaluemodel.h b/bcvaluemodel.h index c01e9c9..bac8168 100644 --- a/bcvaluemodel.h +++ b/bcvaluemodel.h @@ -53,7 +53,8 @@ public: explicit BCValueModel(QObject *parent = nullptr); void addValue(const BCDataValue& val); - void setValueList(const BCValueList& valueList); + + void takeValueList(BCValueList& valueList); const BCValueList& getValueList(); // Pure Virtual Functions von QAbstractTableModel