Changed value handling.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
|
||||
@@ -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 );
|
||||
|
||||
|
||||
@@ -37,17 +37,17 @@
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
#include <QTimer>
|
||||
#include <QTableView>
|
||||
|
||||
#include <QVariantAnimation>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QPainter>
|
||||
|
||||
#include <bcdeviceview.h>
|
||||
#include <bcvaluedelegate.h>
|
||||
|
||||
#include <bcvalueeditor.h>
|
||||
|
||||
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<BCValueDelegate*>(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<BCValueDelegate*>(this)->commitData(valueEditor);
|
||||
});
|
||||
|
||||
return valueEditor;
|
||||
}
|
||||
|
||||
|
||||
@@ -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,7 +74,7 @@ protected:
|
||||
// Datenbeschaffung ist alleine Sache des Models.
|
||||
|
||||
const BCValueList& _valueList;
|
||||
QTableView* _view{};
|
||||
BCDeviceView* _view{};
|
||||
|
||||
QPropertyAnimation* _animation{};
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
#include <bcvalue.h>
|
||||
|
||||
|
||||
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->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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user