Reworking value editro, part I

This commit is contained in:
2026-01-11 11:37:52 +01:00
parent 6232b560b5
commit 9c35c9ea42
10 changed files with 53 additions and 157 deletions

View File

@@ -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,