diff --git a/bcanimateddelegate.cpp b/bcanimateddelegate.cpp index e2bd854..82c0459 100644 --- a/bcanimateddelegate.cpp +++ b/bcanimateddelegate.cpp @@ -44,9 +44,6 @@ #include #include "bcanimateddelegate.h" -#include "bcvalue.h" - - BCAnimatedDelegate::BCAnimatedDelegate(const BCValueList& valueList, QTableView* view) @@ -59,9 +56,9 @@ BCAnimatedDelegate::BCAnimatedDelegate(const BCValueList& valueList, QTableView* QString BCAnimatedDelegate::displayText(const QVariant& dataValue, const QLocale& locale) const { // Wir prüfen, ob im Variant unser Struct steckt - if (dataValue.canConvert()) + if (dataValue.canConvert()) { - const BCValue& bc = *dataValue.value(); + const BCValue& bc = dataValue.value(); //qDebug() << " --- YES: " << bc.label; // Hier bauen wir den String zusammen, den man sieht, // wenn KEIN Editor offen ist. diff --git a/bcanimateddelegate.h b/bcanimateddelegate.h index 90e05e3..6f07c91 100644 --- a/bcanimateddelegate.h +++ b/bcanimateddelegate.h @@ -35,10 +35,12 @@ #include +#include + class QPropertyAnimation; class QVariantAnimation; class QTableView; -class BCValueList; + class BCAnimatedDelegate : public QStyledItemDelegate { diff --git a/bcmainwindow.cpp b/bcmainwindow.cpp index bb04bce..afc4604 100644 --- a/bcmainwindow.cpp +++ b/bcmainwindow.cpp @@ -250,13 +250,13 @@ void BCMainWindow::onSyncFromDevice() // alle einzeln? echt jetzt? - for( const BCValue& value : currentList ) + for( const BCValuePtr &value : currentList ) { - qDebug() << " --- value: " << value.label; - + qDebug() << " --- begin sync of value: " << value->label; + // wir setze // statt '_transmitter.enqueueValueCommand( value )' entkoppeln // wir das eleganter über emit requestValueUpdate() - emit requestValueUpdate( BCValue::OpID::ReadValue, &value); + //emit requestValueUpdate( value); } diff --git a/bcmainwindow.h b/bcmainwindow.h index 4217c94..569c40e 100644 --- a/bcmainwindow.h +++ b/bcmainwindow.h @@ -64,9 +64,7 @@ public slots: signals: // Internes Signal, um Daten an den Worker Thread zu senden - void requestValueUpdate( BCValue::OpID, const BCValue* cmd); - //void valuedTouched(const BCValue& cmd); - void valueTouched(int indexRow ); + void requestValueUpdate( const BCValue& value); protected: diff --git a/bctransmitter.cpp b/bctransmitter.cpp index 6c9276c..aff4766 100644 --- a/bctransmitter.cpp +++ b/bctransmitter.cpp @@ -67,8 +67,9 @@ void BCTransmitter::onToggleConnectionState( bool connect ) } -void BCTransmitter::enqueueValueOp(BCValue::OpID opID, const BCValue* value) +void BCTransmitter::enqueueValueOp( const BCValue& value) { + // Hier sind wir noch in GUI Thread QMutexLocker locker(&_mutex); _valueQueue.enqueue( value ); @@ -81,13 +82,13 @@ void BCTransmitter::enqueueValueOp(BCValue::OpID opID, const BCValue* value) // damit enqueueValueOp sofort zurückkehrt (non-blocking für den Aufrufer). //QMetaObject::invokeMethod(this, "processValueOp", Qt::QueuedConnection); - QMetaObject::invokeMethod(this, [this, opID]() + QMetaObject::invokeMethod(this, [this]() { - processValueOp(opID); + processValueOp(); }, Qt::QueuedConnection ); } -void BCTransmitter::processValueOp( BCValue::OpID opID ) +void BCTransmitter::processValueOp() { if (_isBusy) @@ -97,7 +98,7 @@ void BCTransmitter::processValueOp( BCValue::OpID opID ) while (true) { - const BCValue* currentValue{}; + BCValue* currentValue{}; { QMutexLocker locker(&_mutex); if (_valueQueue.isEmpty()) @@ -105,23 +106,25 @@ void BCTransmitter::processValueOp( BCValue::OpID opID ) _isBusy = false; break; // Schleife verlassen, warten auf neue Events } - currentValue =_valueQueue.dequeue(); + //currentValue =_valueQueue.dequeue(); } // Mutex wird hier freigegeben! WICHTIG: Execute ohne Lock! - + /* // Abkürzung - const BCValue& val = *currentValue; + const BCValue& value = *currentValue; // Value ist 'under construction' //emit valueUpdated( val.deviceID, val.indexRow, BCValue::State::Locked ); + if( opID == BCValue::OpID::ReadValue ) { QString result = currentValue->readRawValueX( *this ); - emit valueUpdated( val.deviceID, val.indexRow, BCValue::State::InSync, result ); + emit valueUpdated( valuel.deviceID, value.indexRow, BCValue::State::InSync, result ); } else if( opID == BCValue::OpID::WriteValue ) { currentValue->writeRawValueX( *this ); } +*/ // __fix bc::processEventsFor(50); diff --git a/bctransmitter.h b/bctransmitter.h index 757275d..34d3fb9 100644 --- a/bctransmitter.h +++ b/bctransmitter.h @@ -64,8 +64,8 @@ public: public slots: void onToggleConnectionState( bool connect ); - void enqueueValueOp(BCValue::OpID opID, const BCValue* value ); - void processValueOp(BCValue::OpID opID); + void enqueueValueOp(const BCValue& value ); + void processValueOp(); signals: @@ -74,7 +74,7 @@ signals: private: - using BCDataQueue = QQueue; + using BCDataQueue = QQueue; BCDataQueue _valueQueue; QMutex _mutex; diff --git a/bcvalue.h b/bcvalue.h index 414b483..b648d9c 100644 --- a/bcvalue.h +++ b/bcvalue.h @@ -78,20 +78,16 @@ class BCValue public: - enum class OpID : uint8_t - { - ReadValue, - WriteValue, - }; - enum class State : uint8_t { - NoState = 0x0, - ReadOnly = 0x1, - Locked = 0x2, - Failed = 0x4, - InSync = 0x8, - OK = 0x10 + NoState = 0x00, + ReadMe = 0x01, + WriteMe = 0x02, + ReadOnly = 0x04, + Locked = 0x08, + Failed = 0x10, + InSync = 0x20, + OK = 0x40 }; Q_DECLARE_FLAGS(States, State ) @@ -109,13 +105,18 @@ public: mutable QString visibleValue; }; - Q_DECLARE_OPERATORS_FOR_FLAGS(BCValue::States) -Q_DECLARE_METATYPE(const BCValue*) + + + +Q_DECLARE_METATYPE(const BCValue&) //Q_DECLARE_METATYPE(const BCValue&) +using BCValuePtr = std::shared_ptr; //using BCValueList = QList; +using BCValueList = QList; +/* class BCValueList : public QList { @@ -160,6 +161,7 @@ public: } }; +*/ Q_DECLARE_METATYPE(BCValueList) diff --git a/bcvaluemodel.cpp b/bcvaluemodel.cpp index bde18d0..2f2d0ba 100644 --- a/bcvaluemodel.cpp +++ b/bcvaluemodel.cpp @@ -45,18 +45,6 @@ BCValueModel::BCValueModel(QObject *parent) } -/** - * @brief Einen Einzelwert hinzufügen - * @param val der neue Wert - */ - -void BCValueModel::addValue(const BCValue& val) -{ - int row = _valueList.size(); - beginInsertRows(QModelIndex(), row, row); - _valueList.append(val); - endInsertRows(); -} /** @@ -98,12 +86,12 @@ void BCValueModel::onValueUpdated( int row, BCValue::State state, const QString& qDebug() << " BCValueModel::onValueUpdated update: " << newVisisbleValue; if( row > -1 && row < _valueList.size() ) { - const BCValue& value = _valueList[row]; + BCValuePtr value = _valueList[row]; QModelIndex idx = index(row,1); - value.state = state; - if( !newVisisbleValue.isEmpty() && newVisisbleValue != value.visibleValue ) + value->state = state; + if( !newVisisbleValue.isEmpty() && newVisisbleValue != value->visibleValue ) { - value.visibleValue = newVisisbleValue; + value->visibleValue = newVisisbleValue; } // wir schicken auf jeden fall einen update request emit dataChanged(idx, idx, {Qt::DisplayRole, Qt::EditRole}); @@ -156,17 +144,17 @@ QVariant BCValueModel::data(const QModelIndex& index, int role) const if (wrongRole || !index.isValid() || row >= _valueList.size() ) return QVariant(); - const BCValue& value = _valueList.at( row ); + BCValuePtr value = _valueList.at( row ); if( col == 0 ) - return value.label; + return value->label; if( col == 1) { if( role == Qt::DisplayRole ) - return QString("%1 %2").arg( value.visibleValue, value.valueType->unitLabel); + return QString("%1 %2").arg( value->visibleValue, value->valueType->unitLabel); - return value.visibleValue; + return value->visibleValue; } return QVariant(); @@ -208,13 +196,13 @@ bool BCValueModel::setData(const QModelIndex& index, const QVariant& value, int if (index.isValid() && role == Qt::EditRole) { - BCValue& item = _valueList[index.row()]; + BCValuePtr item = _valueList[index.row()]; // Wir erwarten hier nur den Value-Teil (vom Slider/Editor) // Checken ob Int oder Double if (value.canConvert()) { - item.visibleValue = value.toString(); + item->visibleValue = value.toString(); } _valueList[index.row()] = item; diff --git a/bcvaluemodel.h b/bcvaluemodel.h index d7369a3..9cfb5ae 100644 --- a/bcvaluemodel.h +++ b/bcvaluemodel.h @@ -52,7 +52,6 @@ public: explicit BCValueModel(QObject *parent = nullptr); - void addValue(const BCValue& val); void takeValueList(BCValueList& valueList); const BCValueList& getValueList() const; diff --git a/bcxmlloader.cpp b/bcxmlloader.cpp index 5933716..7e95023 100644 --- a/bcxmlloader.cpp +++ b/bcxmlloader.cpp @@ -176,11 +176,11 @@ void BCXmlLoader::loadXmlBikeDeviceData(BCDevice::ID deviceID) }; // nur gültige Werte sind vorhanden und können gespeichert werden - std::optional newValue = makeDataValue( deviceID, params ); + std::optional newValue = makeDataValue( deviceID, params ); if(newValue) { // wir merken uns gleich den index in der Werteliste - (*newValue).indexRow = currentValues.size(); + (*newValue)->indexRow = currentValues.size(); currentValues.push_back( *newValue ); } @@ -195,7 +195,7 @@ void BCXmlLoader::loadXmlBikeDeviceData(BCDevice::ID deviceID) } -std::optional BCXmlLoader::makeDataValue( BCDevice::ID deviceID, const BCDataParams& params ) +std::optional BCXmlLoader::makeDataValue( BCDevice::ID deviceID, const BCDataParams& params ) { /* @@ -221,7 +221,7 @@ std::optional BCXmlLoader::makeDataValue( BCDevice::ID deviceID, const */ - std::optional newValue; + bool ok; //std::optional IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() ); @@ -233,7 +233,7 @@ std::optional BCXmlLoader::makeDataValue( BCDevice::ID deviceID, const auto valueType = BCValueType::fetchValueType(params.UnitType); if( valueType.has_value() ) { - newValue = BCValue( *valueType, deviceID, static_cast(IDVal) ); + BCValuePtr newValue = std::make_shared( *valueType, deviceID, static_cast(IDVal) ); /* setIfExists( params.Factor, newValue.factor ); @@ -242,10 +242,12 @@ std::optional BCXmlLoader::makeDataValue( BCDevice::ID deviceID, const */ newValue->label = params.Label; qDebug() << " --- created: " << params.Label; + + return std::optional( newValue ); } } - return newValue; + return std::nullopt; } // --- NEU: Speichern mit QXmlStreamWriter --- diff --git a/bcxmlloader.h b/bcxmlloader.h index da44302..ed1f339 100644 --- a/bcxmlloader.h +++ b/bcxmlloader.h @@ -73,7 +73,7 @@ protected: void loadXmlBikeDeviceData( BCDevice::ID deviceID ); - std::optional makeDataValue( BCDevice::ID deviceID, const BCDataParams& params ); + std::optional makeDataValue( BCDevice::ID deviceID, const BCDataParams& params ); QXmlStreamReader _xml;