diff --git a/BionxControl.pro b/BionxControl.pro index e9fbbca..541438f 100644 --- a/BionxControl.pro +++ b/BionxControl.pro @@ -37,6 +37,7 @@ li windows { #LIBS += -L$$PWD/can_api -lmhstcan -lAdvapi32 + message("Konfiguration für Windows.") } # You can make your code fail to compile if it uses deprecated APIs. diff --git a/bcanimateddelegate.cpp b/bcanimateddelegate.cpp index c566068..6904639 100644 --- a/bcanimateddelegate.cpp +++ b/bcanimateddelegate.cpp @@ -63,11 +63,11 @@ QString BCAnimatedDelegate::displayText(const QVariant& dataValue, const QLocale // Hier bauen wir den String zusammen, den man sieht, // wenn KEIN Editor offen ist. // Format: "Label: Wert Einheit" - return QString("%1: %2 %3").arg(bc.label, bc.visibleValue, "mmX"); + return QString("%1: %2 %3").arg(bc.label, bc.formattedValue, "mmX"); } else { - qDebug() << " --- Nö!"; + //qDebug() << " --- Nö!"; } // Fallback für normale Strings/Zahlen @@ -78,10 +78,11 @@ QString BCAnimatedDelegate::displayText(const QVariant& dataValue, const QLocale QWidget *BCAnimatedDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const { +/* QVariant rawData = index.data(Qt::EditRole); //if (!rawData.canConvert()) return QStyledItemDelegate::createEditor(parent, option, index); -/* + const BCValue& bc = *rawData.value(); // Nur bei Integern den Slider-Editor bauen @@ -121,41 +122,50 @@ QWidget *BCAnimatedDelegate::createEditor(QWidget *parent, const QStyleOptionVie return container; } - +*/ return QStyledItemDelegate::createEditor(parent, option, index); - */ + } void BCAnimatedDelegate::setEditorData(QWidget *editor, const QModelIndex& index) const { + /* // Daten vom Model in den Editor laden const BCValue& bc = *index.data(Qt::EditRole).value(); QSlider *slider = editor->findChild("slider"); QLabel *lblUnit = editor->findChild("lblUnit"); - if (slider && lblUnit) { + if (slider && lblUnit) + { bool olDriverState = slider->blockSignals(true); - slider->setValue(bc.visibleValue.toInt()); + slider->setValue(bc.formattedValue.toInt()); slider->blockSignals(olDriverState); - - lblUnit->setText(QString("%1 %2").arg(bc.visibleValue.toInt()).arg( "mm3")); - } else { + lblUnit->setText(QString("%1 %2").arg(bc.formattedValue.toInt()).arg( "mm3")); + } + else + { QStyledItemDelegate::setEditorData(editor, index); } +*/ } void BCAnimatedDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const { + /* // Daten vom Editor zurück ins Model speichern (Beim Schließen) QSlider *slider = editor->findChild("slider"); - if (slider) { + if (slider) + { int value = slider->value(); model->setData(index, value, Qt::EditRole); - } else { + } + else + { QStyledItemDelegate::setModelData(editor, model, index); } + */ } void BCAnimatedDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& index) const @@ -230,38 +240,42 @@ void BCAnimatedDelegate::paintSliderIndicator(QPainter* painter, const QStyleOpt { /* -if (option.state & QStyle::State_Selected) { - // 1. Die originale Highlight-Farbe holen (z.B. das Blau aus dem CSS) - QColor highlightColor = option.palette.highlight().color(); + if (option.state & QStyle::State_Selected) + { + // 1. Die originale Highlight-Farbe holen (z.B. das Blau aus dem CSS) + QColor highlightColor = option.palette.highlight().color(); - // 2. Transparenz setzen (z.B. nur 30% Deckkraft für "Glass"-Effekt) - highlightColor.setAlphaF(0.3); // 0.0 bis 1.0 (float ist oft lesbarer) + // 2. Transparenz setzen (z.B. nur 30% Deckkraft für "Glass"-Effekt) + highlightColor.setAlphaF(0.3); // 0.0 bis 1.0 (float ist oft lesbarer) - // 3. Zeichnen (Brush setzt die Füllfarbe) - painter->fillRect(option.rect, highlightColor); - } + // 3. Zeichnen (Brush setzt die Füllfarbe) + painter->fillRect(option.rect, highlightColor); + } */ - const BCValue& valueX = *(_valueList[ index.row()].get()); - int value = 50;//index.model()->data(index, Qt::DisplayRole).toInt(); + + const BCValue& bcValue = *(_valueList[ index.row()].get()); + + qDebug() << " --- paintSLider: " << bcValue.label << ": " << (int)bcValue.valueType; + // wenn Werte readOnly sind, dann brauchen keinen EditHint + if( bcValue.flags.testFlag(BCValue::Flag::ReadOnly) ) + // || bcValue.valueType == BCValue::ValueType::Plain ) + return; // Hintergrund if (option.state & QStyle::State_Selected) { painter->fillRect(option.rect, option.palette.highlight()); } - else { QColor bcColor = option.palette.color(QPalette::Base); painter->fillRect(option.rect, bcColor); } - // Text und kleiner Slider-Indikator zeichnen + // baby-Slider-Indikator zeichnen painter->save(); painter->setRenderHint(QPainter::Antialiasing); - //QRect textRect = option.rect.adjusted(8, 0, -120, 0); - QRect barRect = option.rect.adjusted ( 8, @@ -275,10 +289,11 @@ if (option.state & QStyle::State_Selected) { painter->setBrush(QColor(0xE0E0E0)); painter->drawRoundedRect(barRect, 2, 2); - QRect fillRect = barRect; - fillRect.setWidth(barRect.width() * valueX.calcRatio() ); + // Anteil zwischen min und max berechnen + double ratio = bcValue.calcRatio(); + barRect.setWidth(barRect.width() * ratio ); painter->setBrush(QColor(0x0078D4)); - painter->drawRoundedRect(fillRect, 2, 2); + painter->drawRoundedRect(barRect, 2, 2); painter->restore(); diff --git a/bcanimateddelegate.h b/bcanimateddelegate.h index 4b81d9e..0ff9b45 100644 --- a/bcanimateddelegate.h +++ b/bcanimateddelegate.h @@ -72,7 +72,7 @@ signals: //void viewUpdateNeeded(); -private: +protected: void updateRow(int row); void paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; @@ -83,7 +83,6 @@ private: QPropertyAnimation* _animation{}; -private: QHash m_rowOpacities; QHash m_rowAnimations; diff --git a/bcdeviceview.cpp b/bcdeviceview.cpp index 19bc748..ef14c9b 100644 --- a/bcdeviceview.cpp +++ b/bcdeviceview.cpp @@ -77,7 +77,7 @@ const BCValueList& BCDeviceView::getValueListX() */ void BCDeviceView::onValueListReady( BCDevice::ID deviceID, BCValueList valueList ) { - qDebug() << " --- onValueListReady: " << deviceID << ": " << valueList.size(); + //qDebug() << " --- onValueListReady: " << deviceID << ": " << valueList.size(); if(_devideID == deviceID) _valueModel.takeValueList( valueList ); } @@ -87,9 +87,9 @@ void BCDeviceView::onValueListReady( BCDevice::ID deviceID, BCValueList valueLis * @brief SLOT, der aufgerufen wird, wenn ein Value geändert wurde. Gibt dem ItemDelegate Bescheid. */ -void BCDeviceView::onValueUpdated(int index, BCValue::State state, const QString& newVisibleValue ) +void BCDeviceView::updateValue(int index, BCValue::Flag state, uint32_t rawValue ) { - _valueModel.onValueUpdated( index, state, newVisibleValue); + _valueModel.updateValue( index, state, rawValue ); _itemDelegate->onHighlightRow( index ); } diff --git a/bcdeviceview.h b/bcdeviceview.h index c9f021a..f32aefe 100644 --- a/bcdeviceview.h +++ b/bcdeviceview.h @@ -53,14 +53,14 @@ public: BCDevice::ID getDeviceID() const; const BCValueList& getValueListX(); - //BCValueModel &getValueModel(); bool hasContent(); + void updateValue( int index, BCValue::Flag state, uint32_t rawValue ); + public slots: void onValueListReady( BCDevice::ID deviceID, BCValueList valueList ); - void onValueUpdated( int index, BCValue::State state, const QString& newVisibleValue="" ); protected: diff --git a/bcdriver.cpp b/bcdriver.cpp index c85eae9..44de6f2 100644 --- a/bcdriver.cpp +++ b/bcdriver.cpp @@ -87,7 +87,7 @@ TransmitResult BCDriverDummy::writeRawByte( uint32_t deviceID, uint8_t registerI { Q_UNUSED(deviceID) Q_UNUSED(registerID) - qDebug() << " --- BCDriverTinyCan writeRawValue: " << value; + //qDebug() << " --- BCDriverTinyCan writeRawValue: " << value; return 0; } diff --git a/bcdrivertinycan.cpp b/bcdrivertinycan.cpp index 33e4179..d08b746 100644 --- a/bcdrivertinycan.cpp +++ b/bcdrivertinycan.cpp @@ -30,7 +30,7 @@ ***************************************************************************/ -#include +#include #include #include @@ -180,22 +180,22 @@ BCDriver::DriverStateResult BCDriverTinyCan::setConsoleSlaveMode() uint32_t console = static_cast(BCDevice::ID::Console); uint8_t slaveFlag = static_cast (BC::ID::Cons_Status_Slave); - qDebug() << "XXX BCDriverTinyCan::Driver Init: putting Console in slave mode ... "; + //qDebug() << "XXX BCDriverTinyCan::Driver Init: putting Console in slave mode ... "; TransmitResult isSlave = 0; // Already slave? isSlave = readRawByte( console, slaveFlag ); if( isSlave.has_value() ) { - qDebug() << "Console responded: " << isSlave.value(); + //qDebug() << "Console responded: " << isSlave.value(); if( isSlave.value() == 1 ) { - qDebug() << "Console already in slave mode. good!"; + //qDebug() << "Console already in slave mode. good!"; return DriverState::DeviceReady; } } - qDebug() << "BCDriverTinyCan::BCDriverTinyCan::XXX Driver Init: putting Console in slave mode ... "; + //qDebug() << "BCDriverTinyCan::BCDriverTinyCan::XXX Driver Init: putting Console in slave mode ... "; unsigned int retry = cTimeOuts; @@ -237,7 +237,7 @@ void BCDriverTinyCan::resetDriver() TransmitResult BCDriverTinyCan::readRawByte( uint32_t deviceID, uint8_t registerID ) const { - qDebug() << " --- CAN Read Byte: Device: "<< deviceID << " register: " << registerID << " TRY! "; + //qDebug() << " --- CAN Read Byte: Device: "<< deviceID << " register: " << registerID << " TRY! "; struct TCanMsg msg; int err, retry = 20; @@ -258,7 +258,7 @@ TransmitResult BCDriverTinyCan::readRawByte( uint32_t deviceID, uint8_t register bc::delay_millis( cTIMEOUT_MS ); if (timeout == -1) - qDebug() << "error: could not send value to node "; + //qDebug() << "error: could not send value to node "; retry: @@ -268,34 +268,34 @@ retry: if (timeout == -1) { - qDebug() << "error: no response from node"; + //qDebug() << "error: no response from node"; return 0; } if ((err = CanReceive(0, &msg, 1)) > 0) { - qDebug() << " retry: " << retry << " BIB:" << BC::ID::ID_Bib << " msg.Id: " << msg.Id << " msg.MsgLen: " << msg.MsgLen << " msg.MsgData[1]: " << msg.MsgData[1] << " reg: " << reg; + //qDebug() << " retry: " << retry << " BIB:" << BC::ID::ID_Bib << " msg.Id: " << msg.Id << " msg.MsgLen: " << msg.MsgLen << " msg.MsgData[1]: " << msg.MsgData[1] << " reg: " << reg; if (--retry && (msg.Id != (uint32_t)BC::ID::ID_Bib|| msg.MsgLen != 4 || msg.MsgData[1] != reg)) goto retry; if (!retry) { - qDebug() << "XXX error: no response from node: " << err; + //qDebug() << "XXX error: no response from node: " << err; return 0; } - qDebug() << " --- CAN Read Byte: Device: "<< deviceID << " register: " << registerID << " BYTE: " << (uint32_t) msg.MsgData[3]; + //qDebug() << " --- CAN Read Byte: Device: "<< deviceID << " register: " << registerID << " BYTE: " << (uint32_t) msg.MsgData[3]; return (unsigned int) msg.MsgData[3]; } else { - qDebug() << "Error:" < 0 ) if( --retries && ( msg.Id != BIB || msg.MsgLen != 4 || msg.MsgData[1] != registerID ) ) @@ -354,7 +354,7 @@ retry: if( !timeOuts ) return std::unexpected(QString("CAN response errror: timeout" )); - qDebug() << " --- CAN Read Byte: " << (uint32_t) msg.MsgData[3] << " Device:: "<< deviceID << " register: " << registerID; + //qDebug() << " --- CAN Read Byte: " << (uint32_t) msg.MsgData[3] << " Device:: "<< deviceID << " register: " << registerID; return (uint32_t) msg.MsgData[3]; */ } @@ -367,7 +367,7 @@ TransmitResult BCDriverTinyCan::writeRawByte( uint32_t deviceID, uint8_t registe if( _driverState label; // wir setzen auf 'lesen' - value->state.setFlag( BCValue::State::ReadMe ); + value->flags.setFlag( BCValue::Flag::ReadMe ); _syncButton->setEnabled( false ); diff --git a/bcmainwindow.h b/bcmainwindow.h index a9d3bd6..25ba0fe 100644 --- a/bcmainwindow.h +++ b/bcmainwindow.h @@ -61,7 +61,7 @@ public slots: void onDriverStateChanged( BCDriver::DriverState state, const QString& message="" ); // Slots für Rückmeldungen vom Transmitter - void onValueUpdated( BCDevice::ID deviceID, int index, BCValue::State state, const QString& newValue="" ); + void onValueUpdated( BCDevice::ID deviceID, int index, BCValue::Flag state, uint32_t rawValue ); void onValueQueueEmpty(); void onSyncDeviceView(); diff --git a/bctransmitter.cpp b/bctransmitter.cpp index 21a9ecb..5ffae1c 100644 --- a/bctransmitter.cpp +++ b/bctransmitter.cpp @@ -31,7 +31,7 @@ #include -#include +#include #include #include @@ -56,7 +56,7 @@ BCTransmitter::BCTransmitter(QObject *parent) void BCTransmitter::onToggleDriverConnection( bool connect ) { - qDebug() << " --- onToggleDriverConnection: " << connect; + //qDebug() << " --- onToggleDriverConnection: " << connect; emit driverStateChanged(BCDriver::DriverState::Initialized, "BUSY!"); bc::delay_millis(350); // kill all pending stuff @@ -103,13 +103,13 @@ void BCTransmitter::connectCanDriver() if( hwVersion.has_value() ) { message = " ---- HAIL to the king!"; - qDebug() << message; + //qDebug() << message; // swap driver _canDriver = &_tinyCanDriver; } else { - qDebug() << "Console not responding"; + //qDebug() << "Console not responding"; } } else @@ -144,7 +144,7 @@ void BCTransmitter::onUpdateValue( BCValuePtrConst valuePtr) // der aktuelle Auftragsblock abgearbeit wurde. _valueQueue.enqueue( valuePtr ); - qDebug() << " # #### ENQ: " <<_valueQueue.size(); + //qDebug() << " # #### ENQ: " <<_valueQueue.size(); // Wir schicken den event gleich wieder weiter ... QMetaObject::invokeMethod(this, "onProcessValue", Qt::QueuedConnection); @@ -160,12 +160,12 @@ void BCTransmitter::onProcessValue() if (_valueQueue.isEmpty()) { //_isBusy = false; - qDebug() << " --- XXXXXXXXXX Warum so oft?"; + //qDebug() << " --- XXXXXXXXXX Warum so oft?"; emit valueQueueEmpty(); break; // Schleife verlassen, warten auf neue Events } valuePtr =_valueQueue.dequeue(); - qDebug() << " # #### DEQ: " <<_valueQueue.size(); + //qDebug() << " # #### DEQ: " <<_valueQueue.size(); } // Mutex wird hier freigegeben! WICHTIG: Execute ohne Lock! // Kosmetik @@ -174,19 +174,20 @@ void BCTransmitter::onProcessValue() // Kosmetik //const BCValue& value = *(valuePtr.get()); - qDebug() << "------- DE.-.QUEUE: " << QThread::currentThreadId() << ": " << value.label; + //qDebug() << "------- DE.-.QUEUE: " << QThread::currentThreadId() << ": " << value.label; // Value ist 'under construction' - //emit valueUpdated( value.deviceID, value.indexRow, BCValue::State::Locked ); + //emit valueUpdated( value.deviceID, value.indexRow, BCValue::Flag::Locked ); uint32_t devID = static_cast(value.deviceID); uint8_t regID = static_cast (value.registerID); - QString newVisibleValue; - BCValue::State newState = BCValue::State::NoState; + // Für den Fehlerfall: Wir senden den alten Wert einfach zurück + uint32_t newValue = value.rawUIntValue; + BCValue::Flag newState = BCValue::Flag::Failed;; - if(value.state.testFlag( BCValue::State::WriteMe ) ) + if(value.flags.testFlag( BCValue::Flag::WriteMe ) ) { @@ -194,23 +195,18 @@ void BCTransmitter::onProcessValue() // oder sollen wir hier beides erlauben ? readFlag & writeFlag ? // Was kommt dann zuerst? Schreiben und lesen als verify ? - else if( value.state.testFlag( BCValue::State::ReadMe ) ) + else if( value.flags.testFlag( BCValue::Flag::ReadMe ) ) { // wir sind hier im anderen thread! nicht einfach so reinschreiben, nur lesen - TransmitResult result = value.isWord ? readWordValue( devID, regID ) : readByteValue( devID, regID ); + TransmitResult result = value.isWord() ? readWordValue( devID, regID ) : readByteValue( devID, regID ); if( result.has_value() ) { - // quark! das gehört hier nicht hin! - newVisibleValue = value.formatValues( result.value() ); - newState = BCValue::State::InSync; - } - else - { - newState = BCValue::State::Failed; + newState = BCValue::Flag::InSync; + newValue = result.value(); } } - emit valueUpdated( value.deviceID, value.indexRow, newState, newVisibleValue ); + emit valueUpdated( value.deviceID, value.indexRow, newState, newValue ); // __fix //bc::processEventsFor(150); @@ -223,7 +219,7 @@ void BCTransmitter::onProcessValue() TransmitResult BCTransmitter::readByteValue( uint32_t deviceID, uint8_t registerID ) { - //qDebug() << " --- YES: Read ByteValue: " << registerID; + ////qDebug() << " --- YES: Read ByteValue: " << registerID; // Wir lesen nur ein Byte und gut. return _canDriver->readRawByte( deviceID, registerID ); } @@ -231,7 +227,7 @@ TransmitResult BCTransmitter::readByteValue( uint32_t deviceID, uint8_t register TransmitResult BCTransmitter::readWordValue( uint32_t deviceID, uint8_t registerID ) { - //qDebug() << " --- YES: Read WordValue: " << registerID; + ////qDebug() << " --- YES: Read WordValue: " << registerID; uint32_t result{}; // hi byte Leseversuch. diff --git a/bctransmitter.h b/bctransmitter.h index d66ab61..e3bfad5 100644 --- a/bctransmitter.h +++ b/bctransmitter.h @@ -70,7 +70,7 @@ public slots: signals: void valueQueueEmpty(); - void valueUpdated(BCDevice::ID deviceID, int index, BCValue::State state, const QString& newValue="" ); + void valueUpdated(BCDevice::ID deviceID, int index, BCValue::Flag state, uint32_t rawValue ); void driverStateChanged( BCDriver::DriverState state, const QString& message="" ); private: diff --git a/bcvalue.cpp b/bcvalue.cpp index 13c36a4..7016d27 100644 --- a/bcvalue.cpp +++ b/bcvalue.cpp @@ -41,18 +41,22 @@ BCValue::BCValue( BCDevice::ID deviceID_, BC::ID registerID_) : deviceID{deviceID_}, registerID{registerID_} { - visibleValue = "--"; + } -QString BCValue::formatValues( uint32_t value ) const +QString BCValue::formatValue() const { if( factor == 1 ) - return QString::number( value ); + return QString::number( rawUIntValue ); - double result = value * factor; + double result = rawUIntValue * factor; return QString::number(result, 'f', 2); } +bool BCValue::isWord() const +{ + return flags.testFlag(BCValue::Flag::IsWord); +} double BCValue::calcRatio() const { @@ -73,7 +77,7 @@ double BCValue::calcRatio() const return ratio; // Die eigentliche Formel - ratio = ((rawValue - min) / range); + ratio = ((rawDoubleValue - min) / range); //ratio = (int) qBound( min,ratio, max); } return ratio; @@ -83,8 +87,8 @@ void BCValue::dumpValue() const { qDebug() << "DeviceID: " << deviceID << " Register: " << registerID << " state:" " << state << " << " label: " << label; - qDebug() << "visibleValue: " << visibleValue << " min: " << optMin << " max: " << optMax << " factor: " << factor << " ValueType: " << (char)valueType << " "; - qDebug() << "indexRow: " << indexRow << " isWord: " << isWord; + qDebug() << "formattedValue: " << formatValue() << " min: " << optMin << " max: " << optMax << " factor: " << factor << " ValueType: " << (char)valueType << " "; + qDebug() << "indexRow: " << indexRow << " isWord: " << isWord(); qDebug(); } diff --git a/bcvalue.h b/bcvalue.h index 2223238..76a914d 100644 --- a/bcvalue.h +++ b/bcvalue.h @@ -72,46 +72,47 @@ public: // später der Editor enum class ValueType : uint8_t { - Plain, + Plain, // nur lesen, sowas wie SerialNo Bool, Number, Float }; - enum class State : uint8_t + enum class Flag : uint8_t { - NoState = 0x00, + NoFlag = 0x00, ReadMe = 0x01, WriteMe = 0x02, ReadOnly = 0x04, Locked = 0x08, Failed = 0x10, InSync = 0x20, - OK = 0x40 + OK = 0x40, + IsWord = 0x80 }; - Q_DECLARE_FLAGS(States, State ) + Q_DECLARE_FLAGS(Flags, Flag ) BCValue( BCDevice::ID deviceID_, BC::ID registerID_ ); - QString formatValues( uint32_t value ) const; + QString formatValue() const; double calcRatio() const; void dumpValue() const; + bool isWord() const; - mutable States state{BCValue::State::ReadOnly}; - BCDevice::ID deviceID{BCDevice::ID::Invalid}; - BC::ID registerID{BC::ID::Invalid}; - ValueType valueType{ValueType::Plain}; - int indexRow{-1}; - QString label; - mutable QString visibleValue; - mutable double rawValue; - bool isWord{false}; - QString unitLabel; - double factor{1}; - OptDouble optMin; - OptDouble optMax; + mutable Flags flags{BCValue::Flag::ReadOnly}; + BCDevice::ID deviceID{BCDevice::ID::Invalid}; + BC::ID registerID{BC::ID::Invalid}; + ValueType valueType{ValueType::Plain}; + int indexRow{-1}; + QString label; + mutable double rawDoubleValue; + mutable uint32_t rawUIntValue; + QString unitLabel; + double factor{1}; + OptDouble optMin; + OptDouble optMax; }; -Q_DECLARE_OPERATORS_FOR_FLAGS(BCValue::States) +Q_DECLARE_OPERATORS_FOR_FLAGS(BCValue::Flags) diff --git a/bcvaluemodel.cpp b/bcvaluemodel.cpp index 2d9b78e..1533b17 100644 --- a/bcvaluemodel.cpp +++ b/bcvaluemodel.cpp @@ -81,29 +81,20 @@ void BCValueModel::takeValueList(BCValueList& newValueList) * @param newValue Der neue sichtbare Zahlenwert, formatiert als QString, optionall */ -void BCValueModel::onValueUpdated( int row, BCValue::State state, const QString& newVisisbleValue ) +void BCValueModel::updateValue(int row, BCValue::Flag state, uint32_t rawValue ) { if( row > -1 && row < _valueList.size() ) { const BCValue& value = *(_valueList[row].get()); - QModelIndex idx = index(row,1); - //qDebug(); - //qDebug() << " --- OLD:"<< newVisisbleValue; - //value.dumpValue(); + value.flags = state; + value.rawUIntValue = rawValue; - value.state = state; - - if( !newVisisbleValue.isEmpty() && newVisisbleValue != value.visibleValue ) - { - value.visibleValue = newVisisbleValue; - } - - //qDebug() << " --- NEW: " << newVisisbleValue; - //value.dumpValue(); + QModelIndex idx1 = index(row,1); + QModelIndex idx2 = index(row,2); // wir schicken auf jeden fall einen update request - emit dataChanged(idx, idx, {Qt::DisplayRole, Qt::EditRole}); + emit dataChanged(idx1, idx2, {Qt::DisplayRole, Qt::EditRole}); } } @@ -161,9 +152,9 @@ QVariant BCValueModel::data(const QModelIndex& index, int role) const if( col == 1) { if( role == Qt::DisplayRole ) - return QString("%1 %2").arg( value.visibleValue, value.unitLabel); + return QString("%1 %2").arg( value.formatValue(), value.unitLabel); - return value.visibleValue; + return value.formatValue(); } return QVariant(); @@ -199,23 +190,19 @@ Qt::ItemFlags BCValueModel::flags(const QModelIndex& index) const } -bool BCValueModel::setData(const QModelIndex& index, const QVariant& value, int role) +bool BCValueModel::setData(const QModelIndex& index, const QVariant& variant, int role) { - - // __fix! - if (index.isValid() && role == Qt::EditRole) { - BCValuePtr item = _valueList[index.row()]; + BCValuePtr value = _valueList[index.row()]; // Wir erwarten hier nur den Value-Teil (vom Slider/Editor) // Checken ob Int oder Double - if (value.canConvert()) + if (variant.canConvert()) { - item->visibleValue = value.toString(); + value->rawUIntValue = variant.toInt(); } - _valueList[index.row()] = item; emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole}); return true; } diff --git a/bcvaluemodel.h b/bcvaluemodel.h index 4a03625..25fc1bb 100644 --- a/bcvaluemodel.h +++ b/bcvaluemodel.h @@ -66,9 +66,7 @@ public: Qt::ItemFlags flags(const QModelIndex& index) const override; bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; -public slots: - - void onValueUpdated(int index, BCValue::State state, const QString& newVisisbleValue="" ); + void updateValue(int row, BCValue::Flag state, uint32_t rawValue ); protected: diff --git a/bcxmlloader.cpp b/bcxmlloader.cpp index 25d6667..3b064e5 100644 --- a/bcxmlloader.cpp +++ b/bcxmlloader.cpp @@ -183,12 +183,12 @@ std::optional BCXmlLoader::makeValue( BCDevice::ID deviceID, const B auto setIfExists = [&]( QStringView source, T& target ) { if( !source.isEmpty() ) - { - bool ok; - double testVal = source.toDouble(&ok); - if (ok) - target = testVal; - } + { + bool ok; + double testVal = source.toDouble(&ok); + if (ok) + target = testVal; + } }; @@ -214,7 +214,9 @@ std::optional BCXmlLoader::makeValue( BCDevice::ID deviceID, const B setIfExists( params.Factor, newValue.factor ); setIfExists( params.Min, newValue.optMin ); setIfExists( params.Max, newValue.optMax ); - setIfExists( params.IsWord, newValue.isWord ); + //setIfExists( params.IsWord, newValue.isWord ); + + newValue.label = params.Label; newValue.unitLabel = params.UnitLabel;