Reworking value editro, part I
This commit is contained in:
@@ -59,7 +59,6 @@ SOURCES += \
|
||||
bcvaluedelegate.cpp \
|
||||
bcvalueeditor.cpp \
|
||||
bcvaluemodel.cpp \
|
||||
bcvaluewidget.cpp \
|
||||
bcxmlloader.cpp \
|
||||
libwin/can_drv_win.c \
|
||||
libwin/mhs_can_drv.c \
|
||||
@@ -82,12 +81,11 @@ HEADERS += \
|
||||
bcvaluedelegate.h \
|
||||
bcvalueeditor.h \
|
||||
bcvaluemodel.h \
|
||||
bcvaluewidget.h \
|
||||
bcxmlloader.h
|
||||
|
||||
FORMS += \
|
||||
bcmainwindow.ui \
|
||||
bcvaluewidget.ui
|
||||
bcvalueeditor.ui
|
||||
|
||||
# Default rules for deployment.
|
||||
qnx: target.path = /tmp/$${TARGET}/bin
|
||||
|
||||
@@ -92,6 +92,7 @@ void BCDeviceView::onValueListReady( BCDevice::ID deviceID, BCValueList valueLis
|
||||
if(_devideID == deviceID)
|
||||
{
|
||||
_valueModel.takeValueList( valueList );
|
||||
/*
|
||||
const BCValueList& list = _valueModel.getValueList();
|
||||
int rows = _valueModel.rowCount();
|
||||
for (int r = 0; r < rows; ++r)
|
||||
@@ -103,6 +104,7 @@ void BCDeviceView::onValueListReady( BCDevice::ID deviceID, BCValueList valueLis
|
||||
openPersistentEditor(index);
|
||||
}
|
||||
}
|
||||
*/
|
||||
} // if id
|
||||
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::EditTrigger::AnyKeyPressed|QAbstractItemView::EditTrigger::DoubleClicked|QAbstractItemView::EditTrigger::EditKeyPressed|QAbstractItemView::EditTrigger::SelectedClicked</set>
|
||||
<set>QAbstractItemView::EditTrigger::DoubleClicked</set>
|
||||
</property>
|
||||
<property name="showGrid">
|
||||
<bool>false</bool>
|
||||
@@ -287,7 +287,7 @@
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::EditTrigger::AnyKeyPressed|QAbstractItemView::EditTrigger::DoubleClicked|QAbstractItemView::EditTrigger::EditKeyPressed|QAbstractItemView::EditTrigger::SelectedClicked</set>
|
||||
<set>QAbstractItemView::EditTrigger::DoubleClicked</set>
|
||||
</property>
|
||||
<property name="showGrid">
|
||||
<bool>false</bool>
|
||||
@@ -319,7 +319,7 @@
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::EditTrigger::AnyKeyPressed|QAbstractItemView::EditTrigger::DoubleClicked|QAbstractItemView::EditTrigger::EditKeyPressed|QAbstractItemView::EditTrigger::SelectedClicked</set>
|
||||
<set>QAbstractItemView::EditTrigger::DoubleClicked</set>
|
||||
</property>
|
||||
<property name="showGrid">
|
||||
<bool>false</bool>
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
|
||||
#include <bcvaluedelegate.h>
|
||||
|
||||
#include <bcvaluewidget.h>
|
||||
#include <bcvalueeditor.h>
|
||||
|
||||
BCValueDelegate::BCValueDelegate(const BCValueList& valueList, QTableView* view)
|
||||
: QStyledItemDelegate{view}, _valueList{valueList}, _view{view}
|
||||
@@ -64,11 +64,12 @@ QWidget* BCValueDelegate::createEditor(QWidget *parent, const QStyleOptionViewIt
|
||||
Q_UNUSED(option)
|
||||
Q_UNUSED(index)
|
||||
|
||||
auto* valueEditor = new BCValueWidget(bcValue, parent);
|
||||
auto* valueEditor = new BCValueEditor(bcValue, parent);
|
||||
|
||||
// Signal für sofortige Updates
|
||||
connect(valueEditor, &BCValueWidget::valueChanged, this, [this, valueEditor]()
|
||||
connect(valueEditor, &BCValueEditor::valueChanged, this, [this, valueEditor](int newValue)
|
||||
{
|
||||
qDebug() << "---val changed: " << newValue;
|
||||
// Commit data sofort bei Änderung
|
||||
emit const_cast<BCValueDelegate*>(this)->commitData(valueEditor);
|
||||
});
|
||||
@@ -78,6 +79,7 @@ QWidget* BCValueDelegate::createEditor(QWidget *parent, const QStyleOptionViewIt
|
||||
|
||||
void BCValueDelegate::setEditorData(QWidget *editor, const QModelIndex& index) const
|
||||
{
|
||||
qDebug() << " setEditorData, warum?";
|
||||
/*
|
||||
// Daten vom Model in den Editor laden
|
||||
const BCValue& bc = *index.data(Qt::EditRole).value<BCValue*>();
|
||||
@@ -97,33 +99,33 @@ void BCValueDelegate::setEditorData(QWidget *editor, const QModelIndex& index) c
|
||||
QStyledItemDelegate::setEditorData(editor, index);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
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<QSlider*>("slider");
|
||||
if (slider)
|
||||
qDebug() << " hier 2!";
|
||||
if( index.column() == 1)
|
||||
{
|
||||
int value = slider->value();
|
||||
model->setData(index, value, Qt::EditRole);
|
||||
}
|
||||
else
|
||||
{
|
||||
QStyledItemDelegate::setModelData(editor, model, index);
|
||||
// Daten vom Editor zurück ins Model speichern (Beim Schließen)
|
||||
BCValueEditor* slider = qobject_cast<BCValueEditor*>(editor);
|
||||
if (slider)
|
||||
{
|
||||
qDebug() << " --- ok";
|
||||
int value = slider->getValue();
|
||||
model->setData(index, value, Qt::EditRole);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
QStyledItemDelegate::setModelData(editor, model, index);
|
||||
}
|
||||
|
||||
void BCValueDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& index) const
|
||||
{
|
||||
|
||||
Q_UNUSED(index)
|
||||
/*
|
||||
QRect barRect = option.rect.adjusted(option.rect.width() - 55,
|
||||
option.rect.height() / 2 - 2,
|
||||
-8,
|
||||
-option.rect.height() / 2 + 2);
|
||||
*/
|
||||
|
||||
QRect sliderRect = option.rect.adjusted(
|
||||
option.rect.width() - 125, // Von rechts: 115px (Breite der Progress Bar)
|
||||
0, // Oben: kein Offset
|
||||
@@ -150,6 +152,7 @@ QSize BCValueDelegate::sizeHint(const QStyleOptionViewItem &option, const QModel
|
||||
|
||||
void BCValueDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
qDebug() << " ---paint:" << index.row();
|
||||
|
||||
// Standard-Zeichnen (Text, Hintergrund, Selection) durchführen
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
@@ -158,14 +161,12 @@ void BCValueDelegate::paint(QPainter *painter, const QStyleOptionViewItem& optio
|
||||
|
||||
if( index.column() == 1 )
|
||||
{
|
||||
/*
|
||||
if( row>-1 && row <= _valueList.size() )
|
||||
{
|
||||
const BCValue& bcValue = *(_valueList[ index.row()].get());
|
||||
if( !bcValue.isReadOnly())
|
||||
paintSliderIndicator(painter,option,bcValue);
|
||||
}
|
||||
*/
|
||||
|
||||
if(_rowOpacities.contains(row))
|
||||
paintHighlightRow(painter,option,index.row());
|
||||
@@ -182,8 +183,9 @@ void BCValueDelegate::paintHighlightRow(QPainter* painter, const QStyleOptionVie
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
qreal opacity =_rowOpacities.value(row);
|
||||
painter->setOpacity(opacity);
|
||||
// Margin von 4px
|
||||
QRect itemRect = option.rect.adjusted(3, 3, -3, -3);
|
||||
// Margin von 2px
|
||||
const int m = 3;
|
||||
QRect itemRect = option.rect.adjusted(m,m,-m,-m);
|
||||
|
||||
// Border (2px solid #2196F3)
|
||||
// oranger rahmen
|
||||
@@ -205,23 +207,13 @@ void BCValueDelegate::paintHighlightRow(QPainter* painter, const QStyleOptionVie
|
||||
|
||||
/**
|
||||
* @brief Zeichnet eine passiven Slider, um den Wertebereich des übergebenen BCValue anzuzeigen.
|
||||
* @param painter
|
||||
* @param option
|
||||
* @param bcValue
|
||||
*/
|
||||
|
||||
void BCValueDelegate::paintSliderIndicator(QPainter* painter, const QStyleOptionViewItem& option, const BCValue& bcValue) const
|
||||
{
|
||||
|
||||
// Text und kleiner Slider-Indikator zeichnen
|
||||
painter->save();
|
||||
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
/*
|
||||
QRect barRect = option.rect.adjusted(option.rect.width() - 130,
|
||||
option.rect.height() / 2 - 2,
|
||||
-8,
|
||||
-option.rect.height() / 2 + 2);
|
||||
*/
|
||||
|
||||
QRect barRect = option.rect.adjusted(option.rect.width() - 130,
|
||||
option.rect.height() / 2 + 1,
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
|
||||
//#include <QApplication>
|
||||
#include <QVBoxLayout>
|
||||
//#include <QStyledItemDelegate>
|
||||
#include <QSlider>
|
||||
#include <QPushButton>
|
||||
|
||||
#include <bcvalueeditor.h>
|
||||
#include <bcsliderstyle.h>
|
||||
#include <bcvalueeditor.h>
|
||||
|
||||
|
||||
|
||||
BCValueEditor::BCValueEditor(const BCValue& bcValue, QWidget *parent )
|
||||
: QWidget(parent), _bcValue{bcValue}
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
_slider->setStyle(new BCSliderStyle());
|
||||
setAutoFillBackground(true);
|
||||
QSizePolicy sp = _commitButton->sizePolicy();
|
||||
sp.setRetainSizeWhenHidden(true); // <--- Das ist der magische Schalter
|
||||
_commitButton->setSizePolicy(sp);
|
||||
|
||||
/*
|
||||
_slider = new QSlider(Qt::Horizontal, this);
|
||||
_slider->setRange(0, 100);
|
||||
_slider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
@@ -34,7 +36,7 @@ BCValueEditor::BCValueEditor(const BCValue& bcValue, QWidget *parent )
|
||||
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)
|
||||
{
|
||||
@@ -42,13 +44,16 @@ 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](){
|
||||
connect(_commitButton, &QPushButton::clicked, this, [this]()
|
||||
{
|
||||
_slider->setValue(0);
|
||||
});
|
||||
//_commitButton->setVisible( false);
|
||||
}
|
||||
|
||||
int BCValueEditor::getValue() const
|
||||
{
|
||||
qDebug() << " -- jajaja: "<< size();
|
||||
return _slider->value();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
#ifndef BCVALUEEDITOR_H
|
||||
#define BCVALUEEDITOR_H
|
||||
#ifndef BCValueEditor_H
|
||||
#define BCValueEditor_H
|
||||
|
||||
|
||||
#include <QWidget>
|
||||
#include <ui_bcvalueeditor.h>
|
||||
|
||||
class QSlider;
|
||||
class QPushButton;
|
||||
class BCValue;
|
||||
|
||||
class BCValueEditor : public QWidget
|
||||
class BCValueEditor : public QWidget, private Ui::BCValueEditor
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -25,9 +27,6 @@ signals:
|
||||
private:
|
||||
|
||||
const BCValue& _bcValue;
|
||||
QSlider* _slider;
|
||||
QPushButton* _commitButton;
|
||||
|
||||
};
|
||||
|
||||
#endif // BCVALUEEDITOR_H
|
||||
#endif // BCValueEditor_H
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>BCValueWidget</class>
|
||||
<widget class="QWidget" name="BCValueWidget">
|
||||
<class>BCValueEditor</class>
|
||||
<widget class="QWidget" name="BCValueEditor">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
@@ -181,7 +181,6 @@ Qt::ItemFlags BCValueModel::flags(const QModelIndex& index) const
|
||||
|
||||
bool BCValueModel::setData(const QModelIndex& index, const QVariant& variant, int role)
|
||||
{
|
||||
|
||||
if (index.isValid() && role == Qt::EditRole)
|
||||
{
|
||||
BCValuePtr value = _valueList[index.row()];
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
|
||||
#include <bcsliderstyle.h>
|
||||
#include <bcvaluewidget.h>
|
||||
|
||||
|
||||
|
||||
BCValueWidget::BCValueWidget(const BCValue& bcValue, QWidget *parent )
|
||||
: QWidget(parent), _bcValue{bcValue}
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
_slider->setStyle(new BCSliderStyle());
|
||||
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);
|
||||
});
|
||||
_commitButton->setVisible( false);
|
||||
}
|
||||
|
||||
int BCValueWidget::getValue() const
|
||||
{
|
||||
return _slider->value();
|
||||
}
|
||||
|
||||
void BCValueWidget::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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
#ifndef BCVALUEWIDGET_H
|
||||
#define BCVALUEWIDGET_H
|
||||
|
||||
|
||||
#include <QWidget>
|
||||
#include <ui_bcvaluewidget.h>
|
||||
|
||||
class QSlider;
|
||||
class QPushButton;
|
||||
class BCValue;
|
||||
|
||||
class BCValueWidget : public QWidget, private Ui::BCValueWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
explicit BCValueWidget(const BCValue& bcValue, QWidget *parent = nullptr);
|
||||
|
||||
int getValue() const;
|
||||
void setValue(int val);
|
||||
|
||||
signals:
|
||||
|
||||
void valueChanged(int value);
|
||||
|
||||
private:
|
||||
|
||||
const BCValue& _bcValue;
|
||||
|
||||
};
|
||||
#endif // BCVALUEWIDGET_H
|
||||
Reference in New Issue
Block a user