From 7780657d8221afcd2d444def35d5051e3dfbaef3 Mon Sep 17 00:00:00 2001 From: "PANIK\\chris" Date: Sat, 10 Jan 2026 22:18:54 +0100 Subject: [PATCH] Backups. --- BionxControl.pro | 6 +- bcdeviceview.cpp | 4 +- bcdeviceview.h | 4 +- bcdriver.cpp | 3 +- bcmainwindow.cpp | 2 +- bcmainwindow.ui | 11 ++- bcsliderstyle.h | 4 +- bcanimateddelegate.cpp => bcvaluedelegate.cpp | 67 +++++++++---------- bcanimateddelegate.h => bcvaluedelegate.h | 10 +-- bcvalueeditor.cpp | 66 ++++++++++++++++++ bcvalueeditor.h | 33 +++++++++ bcvaluemodel.cpp | 2 +- 12 files changed, 160 insertions(+), 52 deletions(-) rename bcanimateddelegate.cpp => bcvaluedelegate.cpp (84%) rename bcanimateddelegate.h => bcvaluedelegate.h (92%) create mode 100644 bcvalueeditor.cpp create mode 100644 bcvalueeditor.h diff --git a/BionxControl.pro b/BionxControl.pro index 87f4e0b..de45e5e 100644 --- a/BionxControl.pro +++ b/BionxControl.pro @@ -46,7 +46,6 @@ windows SOURCES += \ bc.cpp \ - bcanimateddelegate.cpp \ bcdelightpmwidget.cpp \ bcdeviceview.cpp \ bcdriver.cpp \ @@ -57,6 +56,8 @@ SOURCES += \ bctoggleswitch.cpp \ bctransmitter.cpp \ bcvalue.cpp \ + bcvaluedelegate.cpp \ + bcvalueeditor.cpp \ bcvaluemodel.cpp \ bcxmlloader.cpp \ libwin/can_drv_win.c \ @@ -66,7 +67,6 @@ SOURCES += \ HEADERS += \ bc.h \ - bcanimateddelegate.h \ bcdelightpmwidget.h \ bcdeviceview.h \ bcdriver.h \ @@ -78,6 +78,8 @@ HEADERS += \ bctoggleswitch.h \ bctransmitter.h \ bcvalue.h \ + bcvaluedelegate.h \ + bcvalueeditor.h \ bcvaluemodel.h \ bcxmlloader.h diff --git a/bcdeviceview.cpp b/bcdeviceview.cpp index cc3b460..8b8b317 100644 --- a/bcdeviceview.cpp +++ b/bcdeviceview.cpp @@ -33,7 +33,7 @@ #include #include -#include +#include BCDeviceView::BCDeviceView(QWidget *parent) : QTableView(parent) @@ -44,7 +44,7 @@ BCDeviceView::BCDeviceView(QWidget *parent) //horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); // __fix! ziemlich wildes ge-pointere, hier - _itemDelegate = new BCAnimatedDelegate( _valueModel.getValueList(), this); + _itemDelegate = new BCValueDelegate( _valueModel.getValueList(), this); setItemDelegateForColumn( 1, _itemDelegate ); } diff --git a/bcdeviceview.h b/bcdeviceview.h index da49569..ff2fbb8 100644 --- a/bcdeviceview.h +++ b/bcdeviceview.h @@ -38,7 +38,7 @@ #include -class BCAnimatedDelegate; +class BCValueDelegate; class BCDeviceView : public QTableView { @@ -67,7 +67,7 @@ protected: bool _firstExpose{true}; BCDevice::ID _devideID{BCDevice::ID::Invalid}; BCValueModel _valueModel; - BCAnimatedDelegate* _itemDelegate{}; + BCValueDelegate* _itemDelegate{}; }; diff --git a/bcdriver.cpp b/bcdriver.cpp index fff2b48..94930fd 100644 --- a/bcdriver.cpp +++ b/bcdriver.cpp @@ -75,7 +75,8 @@ TransmitResult BCDriverDummy::readRawByte( uint32_t deviceID, uint8_t registerID Q_UNUSED(deviceID) Q_UNUSED(registerID) // Tätigkeit simulieren - bc::delay_millis(200); + //bc::delay_millis(200); + bc::delay_millis(50); uint8_t myRandomByte = static_cast(QRandomGenerator::global()->bounded(256)); return myRandomByte; } diff --git a/bcmainwindow.cpp b/bcmainwindow.cpp index 52fb3d8..5834c87 100644 --- a/bcmainwindow.cpp +++ b/bcmainwindow.cpp @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include /** diff --git a/bcmainwindow.ui b/bcmainwindow.ui index 1bcdcc4..ac0097e 100644 --- a/bcmainwindow.ui +++ b/bcmainwindow.ui @@ -242,7 +242,7 @@ 0 - 2 + 1 @@ -254,6 +254,9 @@ 0 + + QAbstractItemView::EditTrigger::AnyKeyPressed|QAbstractItemView::EditTrigger::DoubleClicked|QAbstractItemView::EditTrigger::EditKeyPressed|QAbstractItemView::EditTrigger::SelectedClicked + false @@ -283,6 +286,9 @@ 0 + + QAbstractItemView::EditTrigger::AnyKeyPressed|QAbstractItemView::EditTrigger::DoubleClicked|QAbstractItemView::EditTrigger::EditKeyPressed|QAbstractItemView::EditTrigger::SelectedClicked + false @@ -312,6 +318,9 @@ 0 + + QAbstractItemView::EditTrigger::AnyKeyPressed|QAbstractItemView::EditTrigger::DoubleClicked|QAbstractItemView::EditTrigger::EditKeyPressed|QAbstractItemView::EditTrigger::SelectedClicked + false diff --git a/bcsliderstyle.h b/bcsliderstyle.h index 05792f8..3e99077 100644 --- a/bcsliderstyle.h +++ b/bcsliderstyle.h @@ -59,11 +59,11 @@ #include // Fluent Design Slider Style -class FluentSliderStyle : public QProxyStyle +class BCSliderStyle : public QProxyStyle { public: - FluentSliderStyle() + BCSliderStyle() : QProxyStyle() {} diff --git a/bcanimateddelegate.cpp b/bcvaluedelegate.cpp similarity index 84% rename from bcanimateddelegate.cpp rename to bcvaluedelegate.cpp index 482ce71..83f4fa0 100644 --- a/bcanimateddelegate.cpp +++ b/bcvaluedelegate.cpp @@ -43,11 +43,10 @@ #include #include -#include "bcanimateddelegate.h" -#include "bcsliderstyle.h" +#include +#include - -BCAnimatedDelegate::BCAnimatedDelegate(const BCValueList& valueList, QTableView* view) +BCValueDelegate::BCValueDelegate(const BCValueList& valueList, QTableView* view) : QStyledItemDelegate{view}, _valueList{valueList}, _view{view} { @@ -55,7 +54,26 @@ BCAnimatedDelegate::BCAnimatedDelegate(const BCValueList& valueList, QTableView* -void BCAnimatedDelegate::setEditorData(QWidget *editor, 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(index) + + auto* valueEditor = new BCValueEditor(bcValue, parent); + + // Signal für sofortige Updates + connect(valueEditor, &BCValueEditor::valueChanged, this, [this, valueEditor]() + { + // Commit data sofort bei Änderung + emit const_cast(this)->commitData(valueEditor); + }); + + return valueEditor; +} + +void BCValueDelegate::setEditorData(QWidget *editor, const QModelIndex& index) const { /* // Daten vom Model in den Editor laden @@ -78,7 +96,7 @@ void BCAnimatedDelegate::setEditorData(QWidget *editor, const QModelIndex& index */ } -void BCAnimatedDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const +void BCValueDelegate::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"); @@ -93,7 +111,7 @@ void BCAnimatedDelegate::setModelData(QWidget *editor, QAbstractItemModel *model } } -void BCAnimatedDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& index) const +void BCValueDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& index) const { Q_UNUSED(index) @@ -113,7 +131,7 @@ void BCAnimatedDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptio } -QSize BCAnimatedDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex& index) const +QSize BCValueDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex& index) const { return QStyledItemDelegate::sizeHint(option,index); /* @@ -127,7 +145,7 @@ QSize BCAnimatedDelegate::sizeHint(const QStyleOptionViewItem &option, const QMo } -void BCAnimatedDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const +void BCValueDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { // Standard-Zeichnen (Text, Hintergrund, Selection) durchführen @@ -151,30 +169,9 @@ void BCAnimatedDelegate::paint(QPainter *painter, const QStyleOptionViewItem& op -QWidget* BCAnimatedDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const -{ - const BCValue& bcValue = *(_valueList[ index.row()].get()); - - Q_UNUSED(option) - Q_UNUSED(index) - - auto* slider = new QSlider(Qt::Horizontal, parent); - slider->setRange(0, 100); - slider->setSingleStep(1); - slider->setPageStep(10); - slider->setStyle(new FluentSliderStyle()); - // Signal für sofortige Updates - connect(slider, &QSlider::valueChanged, this, [this, slider]() - { - // Commit data sofort bei Änderung - emit const_cast(this)->commitData(slider); - }); - - return slider; -} -void BCAnimatedDelegate::paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, int row) const +void BCValueDelegate::paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, int row) const { painter->save(); painter->setRenderHint(QPainter::Antialiasing); @@ -207,7 +204,7 @@ void BCAnimatedDelegate::paintHighlightRow(QPainter* painter, const QStyleOption * @param option * @param bcValue */ -void BCAnimatedDelegate::paintSliderIndicator(QPainter* painter, const QStyleOptionViewItem& option, const BCValue& bcValue) const +void BCValueDelegate::paintSliderIndicator(QPainter* painter, const QStyleOptionViewItem& option, const BCValue& bcValue) const { // Text und kleiner Slider-Indikator zeichnen @@ -300,7 +297,7 @@ void BCAnimatedDelegate::paintSliderIndicator(QPainter* painter, const QStyleOpt * @param row */ -void BCAnimatedDelegate::onHighlightRow(int row) +void BCValueDelegate::onHighlightRow(int row) { // Alte Animation für diese Zeile stoppen falls vorhanden if (_rowAnimations.contains(row)) @@ -351,7 +348,7 @@ void BCAnimatedDelegate::onHighlightRow(int row) * @brief Sopt alle gerade laufenden Animationen */ -void BCAnimatedDelegate::clearAllHighlights() +void BCValueDelegate::clearAllHighlights() { for(auto* anim : std::as_const(_rowAnimations)) { @@ -373,7 +370,7 @@ void BCAnimatedDelegate::clearAllHighlights() * @param row */ -void BCAnimatedDelegate::updateRow(int row) +void BCValueDelegate::updateRow(int row) { if (_view && _view->model() && row >= 0) { diff --git a/bcanimateddelegate.h b/bcvaluedelegate.h similarity index 92% rename from bcanimateddelegate.h rename to bcvaluedelegate.h index abea958..4f8b45e 100644 --- a/bcanimateddelegate.h +++ b/bcvaluedelegate.h @@ -30,8 +30,8 @@ ***************************************************************************/ -#ifndef BCANIMATEDDELEGATE_H -#define BCANIMATEDDELEGATE_H +#ifndef BCVALUEDELEGATE_H +#define BCVALUEDELEGATE_H #include @@ -42,13 +42,13 @@ class QVariantAnimation; class QTableView; -class BCAnimatedDelegate : public QStyledItemDelegate +class BCValueDelegate : public QStyledItemDelegate { Q_OBJECT public: - explicit BCAnimatedDelegate(const BCValueList& valueList, QTableView* view ); + explicit BCValueDelegate(const BCValueList& valueList, QTableView* view ); // QString displayText(const QVariant& dataValue, const QLocale& locale) const override; @@ -94,4 +94,4 @@ protected: }; -#endif // BCANIMATEDDELEGATE_H +#endif // BCVALUEDELEGATE_H diff --git a/bcvalueeditor.cpp b/bcvalueeditor.cpp new file mode 100644 index 0000000..62ec5cf --- /dev/null +++ b/bcvalueeditor.cpp @@ -0,0 +1,66 @@ + +//#include +#include +//#include +#include +#include + +#include +#include + +BCValueEditor::BCValueEditor(const BCValue& bcValue, QWidget *parent ) + : QWidget(parent), _bcValue{bcValue} +{ + + setAutoFillBackground(true); + + _slider = new QSlider(Qt::Horizontal, this); + _slider->setRange(0, 100); + _slider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + + _slider->setSingleStep(1); + _slider->setPageStep(10); + _slider->setStyle(new BCSliderStyle()); + + _commitButton = new QPushButton(this); + _commitButton->setIcon(style()->standardIcon(QStyle::SP_DialogResetButton)); + _commitButton->setFixedSize(32, 32); + + auto *layout = new QHBoxLayout(this); + // Deine gewünschten Margins für 36px Zeilenhöhe + layout->setContentsMargins(2, 2, 2, 2); + layout->setSpacing(4); + + layout->addWidget(_slider); + layout->addWidget(_commitButton); + setLayout(layout); + + // Wenn Slider bewegt wird -> Signal nach außen senden + connect(_slider, &QSlider::valueChanged, this, [this](int val) + { + emit valueChanged(val); + }); + + // Wenn Reset gedrückt wird -> Slider auf 0 (löst auch valueChanged aus) + connect(_commitButton, &QPushButton::clicked, this, [this](){ + _slider->setValue(0); + }); +} + +int BCValueEditor::getValue() const +{ + return _slider->value(); +} + +void BCValueEditor::setValue(int val) +{ + // WICHTIG: Block Signals verhindern Endlosschleifen, falls das Model + // das Widget während des Updates neu setzt (passiert manchmal bei Live-Updates). + if (val != _slider->value()) + { + bool blocked = _slider->blockSignals(true); + _slider->setValue(val); + _slider->blockSignals(blocked); + } +} + diff --git a/bcvalueeditor.h b/bcvalueeditor.h new file mode 100644 index 0000000..d1fc570 --- /dev/null +++ b/bcvalueeditor.h @@ -0,0 +1,33 @@ +#ifndef BCVALUEEDITOR_H +#define BCVALUEEDITOR_H + +#include + +class QSlider; +class QPushButton; +class BCValue; + +class BCValueEditor : public QWidget +{ + Q_OBJECT + +public: + + explicit BCValueEditor(const BCValue& bcValue, QWidget *parent = nullptr); + + int getValue() const; + void setValue(int val); + +signals: + + void valueChanged(int value); + +private: + + const BCValue& _bcValue; + QSlider* _slider; + QPushButton* _commitButton; + +}; + +#endif // BCVALUEEDITOR_H diff --git a/bcvaluemodel.cpp b/bcvaluemodel.cpp index dd62ca6..f9667e8 100644 --- a/bcvaluemodel.cpp +++ b/bcvaluemodel.cpp @@ -194,7 +194,7 @@ bool BCValueModel::setData(const QModelIndex& index, const QVariant& variant, in if( variant.toInt() == 42) { qDebug() << "--- YES! " << variant.toInt(); - emit makeSimonHappy(); + //emit makeSimonHappy(); } value->rawValue = variant.toInt(); }