Changed value handling.
This commit is contained in:
@@ -167,7 +167,7 @@ void BCTransmitter::onUpdateValue( BCValuePtrConst valuePtr)
|
|||||||
{
|
{
|
||||||
newState = BCValue::Flag::InSync;
|
newState = BCValue::Flag::InSync;
|
||||||
newValue = result.value();
|
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 BCValue::calcMinMaxRatio() const
|
||||||
{
|
{
|
||||||
|
|
||||||
double ratio = 0;
|
double ratio = 1;
|
||||||
|
|
||||||
if( _optMin.has_value() && _optMax.has_value() )
|
if( _optMin.has_value() && _optMax.has_value() )
|
||||||
{
|
{
|
||||||
@@ -194,6 +194,13 @@ double BCValue::calcMinMaxRatio() const
|
|||||||
return ratio;
|
return ratio;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t BCValue::getScaledValue() const noexcept
|
||||||
|
{
|
||||||
|
double value =_rawValue * _factor;
|
||||||
|
return (uint32_t) value * calcMinMaxRatio();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void BCValue::dumpValue() const
|
void BCValue::dumpValue() const
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ public:
|
|||||||
BC::ID getRegisterID() const noexcept;
|
BC::ID getRegisterID() const noexcept;
|
||||||
|
|
||||||
uint32_t getRawValue() const noexcept;
|
uint32_t getRawValue() const noexcept;
|
||||||
|
uint32_t getScaledValue() const noexcept;
|
||||||
void setRawValue(uint32_t newRawValue) const;
|
void setRawValue(uint32_t newRawValue) const;
|
||||||
void setFromDouble( double value );
|
void setFromDouble( double value );
|
||||||
|
|
||||||
|
|||||||
@@ -37,17 +37,17 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QTableView>
|
|
||||||
|
|
||||||
#include <QVariantAnimation>
|
#include <QVariantAnimation>
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
|
#include <bcdeviceview.h>
|
||||||
#include <bcvaluedelegate.h>
|
#include <bcvaluedelegate.h>
|
||||||
|
|
||||||
#include <bcvalueeditor.h>
|
#include <bcvalueeditor.h>
|
||||||
|
|
||||||
BCValueDelegate::BCValueDelegate(const BCValueList& valueList, QTableView* view)
|
|
||||||
|
BCValueDelegate::BCValueDelegate(const BCValueList& valueList, BCDeviceView* view)
|
||||||
: QStyledItemDelegate{view}, _valueList{valueList}, _view{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
|
QWidget* BCValueDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
const BCValue& bcValue = *(_valueList[ index.row()].get());
|
|
||||||
|
|
||||||
Q_UNUSED(option)
|
Q_UNUSED(option)
|
||||||
Q_UNUSED(index)
|
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
|
// 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
|
// Commit data sofort bei Änderung
|
||||||
emit const_cast<BCValueDelegate*>(this)->commitData(valueEditor);
|
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;
|
return valueEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
class QPropertyAnimation;
|
class QPropertyAnimation;
|
||||||
class QVariantAnimation;
|
class QVariantAnimation;
|
||||||
class QTableView;
|
class BCDeviceView;
|
||||||
|
|
||||||
|
|
||||||
class BCValueDelegate : public QStyledItemDelegate
|
class BCValueDelegate : public QStyledItemDelegate
|
||||||
@@ -48,9 +48,7 @@ class BCValueDelegate : public QStyledItemDelegate
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
explicit BCValueDelegate(const BCValueList& valueList, QTableView* view );
|
explicit BCValueDelegate(const BCValueList& valueList, BCDeviceView* view );
|
||||||
|
|
||||||
// QString displayText(const QVariant& dataValue, const QLocale& locale) const override;
|
|
||||||
|
|
||||||
// Zuständig für den Edit-Modus (Doppelklick)
|
// Zuständig für den Edit-Modus (Doppelklick)
|
||||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const override;
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const override;
|
||||||
@@ -65,7 +63,6 @@ public slots:
|
|||||||
|
|
||||||
void onHighlightRow(int row);
|
void onHighlightRow(int row);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void updateRow(int row);
|
void updateRow(int row);
|
||||||
@@ -77,11 +74,11 @@ protected:
|
|||||||
// Datenbeschaffung ist alleine Sache des Models.
|
// Datenbeschaffung ist alleine Sache des Models.
|
||||||
|
|
||||||
const BCValueList& _valueList;
|
const BCValueList& _valueList;
|
||||||
QTableView* _view{};
|
BCDeviceView* _view{};
|
||||||
|
|
||||||
QPropertyAnimation* _animation{};
|
QPropertyAnimation* _animation{};
|
||||||
|
|
||||||
QHash<int, qreal> _rowOpacities;
|
QHash<int, qreal> _rowOpacities;
|
||||||
QHash<int, QVariantAnimation*> _rowAnimations;
|
QHash<int, QVariantAnimation*> _rowAnimations;
|
||||||
|
|
||||||
static constexpr int cTextBlockOffset = 130;
|
static constexpr int cTextBlockOffset = 130;
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
#include <bcvalue.h>
|
#include <bcvalue.h>
|
||||||
|
|
||||||
|
|
||||||
BCValueEditor::BCValueEditor(const BCValue& bcValue, QWidget *parent )
|
BCValueEditor::BCValueEditor( int sliderValue, QWidget *parent )
|
||||||
: QWidget(parent), _bcValue{bcValue}
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
|
||||||
@@ -17,9 +17,8 @@ BCValueEditor::BCValueEditor(const BCValue& bcValue, QWidget *parent )
|
|||||||
sp.setRetainSizeWhenHidden(true); // <--- Das ist der magische Schalter
|
sp.setRetainSizeWhenHidden(true); // <--- Das ist der magische Schalter
|
||||||
_commitButton->setSizePolicy(sp);
|
_commitButton->setSizePolicy(sp);
|
||||||
|
|
||||||
double ratio = bcValue.calcMinMaxRatio();
|
_slider->setRange(0, 100);
|
||||||
_slider->setRange(0, 100);
|
_slider->setValue( sliderValue );
|
||||||
_slider->setValue( bcValue.getRawValue() * ratio);
|
|
||||||
|
|
||||||
// Wenn Slider bewegt wird -> Signal nach außen senden
|
// Wenn Slider bewegt wird -> Signal nach außen senden
|
||||||
connect(_slider, &QSlider::valueChanged, this, [this](int val)
|
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)
|
// Wenn Reset gedrückt wird -> Slider auf 0 (löst auch valueChanged aus)
|
||||||
connect(_commitButton, &QPushButton::clicked, this, [this]()
|
connect(_commitButton, &QPushButton::clicked, this, [this]()
|
||||||
{
|
{
|
||||||
_slider->setValue(0);
|
emit valueCommited( getValue() );
|
||||||
});
|
});
|
||||||
//_commitButton->setVisible( false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int BCValueEditor::getValue() const
|
int BCValueEditor::getValue() const
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class BCValueEditor : public QWidget, private Ui::BCValueEditor
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
explicit BCValueEditor(const BCValue& bcValue, QWidget *parent = nullptr);
|
explicit BCValueEditor(int sliderValue, QWidget *parent = nullptr);
|
||||||
|
|
||||||
int getValue() const;
|
int getValue() const;
|
||||||
void setValue(int val);
|
void setValue(int val);
|
||||||
@@ -23,10 +23,7 @@ public:
|
|||||||
signals:
|
signals:
|
||||||
|
|
||||||
void valueChanged(int value);
|
void valueChanged(int value);
|
||||||
|
void valueCommited(int value);
|
||||||
private:
|
|
||||||
|
|
||||||
const BCValue& _bcValue;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif // BCValueEditor_H
|
#endif // BCValueEditor_H
|
||||||
|
|||||||
Reference in New Issue
Block a user