From 093b90fab6fc3ac1b44aadc5860c5fad9f23a782 Mon Sep 17 00:00:00 2001 From: "PANIK\\chris" Date: Sun, 18 Jan 2026 18:52:30 +0100 Subject: [PATCH] Changed value handling. --- bctransmitter.cpp | 2 +- bcvalue.cpp | 9 ++++++++- bcvalue.h | 1 + bcvaluedelegate.cpp | 24 ++++++++++++++++++------ bcvaluedelegate.h | 11 ++++------- bcvalueeditor.cpp | 13 ++++++------- bcvalueeditor.h | 7 ++----- 7 files changed, 40 insertions(+), 27 deletions(-) diff --git a/bctransmitter.cpp b/bctransmitter.cpp index 2ad4d82..af0d367 100644 --- a/bctransmitter.cpp +++ b/bctransmitter.cpp @@ -167,7 +167,7 @@ void BCTransmitter::onUpdateValue( BCValuePtrConst valuePtr) { newState = BCValue::Flag::InSync; newValue = result.value(); - qDebug() << " ---- " << BCTimeStamp << " DevID: " << devID << " RegID: " << regID << " Value: " << newValue; + //qDebug() << " ---- " << BCTimeStamp << " DevID: " << devID << " RegID: " << regID << " Value: " << newValue; } } diff --git a/bcvalue.cpp b/bcvalue.cpp index e4e1ff9..c9ddff5 100644 --- a/bcvalue.cpp +++ b/bcvalue.cpp @@ -173,7 +173,7 @@ void BCValue::setFromDouble( double value ) double BCValue::calcMinMaxRatio() const { - double ratio = 0; + double ratio = 1; if( _optMin.has_value() && _optMax.has_value() ) { @@ -194,6 +194,13 @@ double BCValue::calcMinMaxRatio() const return ratio; } +uint32_t BCValue::getScaledValue() const noexcept +{ + double value =_rawValue * _factor; + return (uint32_t) value * calcMinMaxRatio(); +} + + void BCValue::dumpValue() const { diff --git a/bcvalue.h b/bcvalue.h index e49db7b..f147489 100644 --- a/bcvalue.h +++ b/bcvalue.h @@ -111,6 +111,7 @@ public: BC::ID getRegisterID() const noexcept; uint32_t getRawValue() const noexcept; + uint32_t getScaledValue() const noexcept; void setRawValue(uint32_t newRawValue) const; void setFromDouble( double value ); diff --git a/bcvaluedelegate.cpp b/bcvaluedelegate.cpp index 877bd99..3a5610a 100644 --- a/bcvaluedelegate.cpp +++ b/bcvaluedelegate.cpp @@ -37,17 +37,17 @@ #include #include #include -#include #include #include #include +#include #include - #include -BCValueDelegate::BCValueDelegate(const BCValueList& valueList, QTableView* view) + +BCValueDelegate::BCValueDelegate(const BCValueList& valueList, BCDeviceView* view) : QStyledItemDelegate{view}, _valueList{valueList}, _view{view} { @@ -56,20 +56,32 @@ BCValueDelegate::BCValueDelegate(const BCValueList& valueList, QTableView* view) QWidget* BCValueDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const { - const BCValue& bcValue = *(_valueList[ index.row()].get()); Q_UNUSED(option) Q_UNUSED(index) - auto* valueEditor = new BCValueEditor(bcValue, parent); + const BCValue& bcValue = *(_valueList[ index.row()].get()); + + + qDebug() << " --- upsy: " << bcValue.getLabel() << " ratio: " << bcValue.calcMinMaxRatio() << " raw: " << bcValue.getRawValue() << " scaled: " << bcValue.getScaledValue(); + + auto* valueEditor = new BCValueEditor(bcValue.getScaledValue(), parent); // Signal für sofortige Updates - connect(valueEditor, &BCValueEditor::valueChanged, this, [this, valueEditor](int newValue) + connect(valueEditor, &BCValueEditor::valueChanged, this, [this, valueEditor]() { // Commit data sofort bei Änderung emit const_cast(this)->commitData(valueEditor); }); + // Signal für sofortige Updates + connect(valueEditor, &BCValueEditor::valueCommited, this, [this, valueEditor](int newValue) + { + qDebug() << " --- value set:" << newValue; + // Commit data sofort bei Änderung + //emit const_cast(this)->commitData(valueEditor); + }); + return valueEditor; } diff --git a/bcvaluedelegate.h b/bcvaluedelegate.h index 351d400..95a9741 100644 --- a/bcvaluedelegate.h +++ b/bcvaluedelegate.h @@ -39,7 +39,7 @@ class QPropertyAnimation; class QVariantAnimation; -class QTableView; +class BCDeviceView; class BCValueDelegate : public QStyledItemDelegate @@ -48,9 +48,7 @@ class BCValueDelegate : public QStyledItemDelegate public: - explicit BCValueDelegate(const BCValueList& valueList, QTableView* view ); - - // QString displayText(const QVariant& dataValue, const QLocale& locale) const override; + explicit BCValueDelegate(const BCValueList& valueList, BCDeviceView* view ); // Zuständig für den Edit-Modus (Doppelklick) QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const override; @@ -65,7 +63,6 @@ public slots: void onHighlightRow(int row); - protected: void updateRow(int row); @@ -77,11 +74,11 @@ protected: // Datenbeschaffung ist alleine Sache des Models. const BCValueList& _valueList; - QTableView* _view{}; + BCDeviceView* _view{}; QPropertyAnimation* _animation{}; - QHash _rowOpacities; + QHash _rowOpacities; QHash _rowAnimations; static constexpr int cTextBlockOffset = 130; diff --git a/bcvalueeditor.cpp b/bcvalueeditor.cpp index 4a01993..e1a6d2d 100644 --- a/bcvalueeditor.cpp +++ b/bcvalueeditor.cpp @@ -4,8 +4,8 @@ #include -BCValueEditor::BCValueEditor(const BCValue& bcValue, QWidget *parent ) - : QWidget(parent), _bcValue{bcValue} +BCValueEditor::BCValueEditor( int sliderValue, QWidget *parent ) + : QWidget(parent) { setupUi(this); @@ -17,9 +17,8 @@ BCValueEditor::BCValueEditor(const BCValue& bcValue, QWidget *parent ) sp.setRetainSizeWhenHidden(true); // <--- Das ist der magische Schalter _commitButton->setSizePolicy(sp); - double ratio = bcValue.calcMinMaxRatio(); - _slider->setRange(0, 100); - _slider->setValue( bcValue.getRawValue() * ratio); + _slider->setRange(0, 100); + _slider->setValue( sliderValue ); // Wenn Slider bewegt wird -> Signal nach außen senden connect(_slider, &QSlider::valueChanged, this, [this](int val) @@ -30,9 +29,9 @@ BCValueEditor::BCValueEditor(const BCValue& bcValue, QWidget *parent ) // Wenn Reset gedrückt wird -> Slider auf 0 (löst auch valueChanged aus) connect(_commitButton, &QPushButton::clicked, this, [this]() { - _slider->setValue(0); + emit valueCommited( getValue() ); }); - //_commitButton->setVisible( false); + } int BCValueEditor::getValue() const diff --git a/bcvalueeditor.h b/bcvalueeditor.h index 02f00c9..ce8b48a 100644 --- a/bcvalueeditor.h +++ b/bcvalueeditor.h @@ -15,7 +15,7 @@ class BCValueEditor : public QWidget, private Ui::BCValueEditor public: - explicit BCValueEditor(const BCValue& bcValue, QWidget *parent = nullptr); + explicit BCValueEditor(int sliderValue, QWidget *parent = nullptr); int getValue() const; void setValue(int val); @@ -23,10 +23,7 @@ public: signals: void valueChanged(int value); - -private: - - const BCValue& _bcValue; + void valueCommited(int value); }; #endif // BCValueEditor_H