Cleanups.

This commit is contained in:
2026-01-09 06:19:37 +01:00
parent 95765226e9
commit 53b4d6e041
4 changed files with 111 additions and 100 deletions

View File

@@ -54,76 +54,6 @@ BCAnimatedDelegate::BCAnimatedDelegate(const BCValueList& valueList, QTableView*
}
QWidget *BCAnimatedDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const
{
if( index.column() == 1 )
return QStyledItemDelegate::createEditor(parent, option, index);
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<SliderDelegate*>(this)->commitData(slider);
});
return slider;
/*
// Nur bei Integern den Slider-Editor bauen
//if (bc.value.typeId() == QMetaType::Int)
{
QWidget *container = new QWidget(parent);
container->setAutoFillBackground(true);
QHBoxLayout *layout = new QHBoxLayout(container);
layout->setContentsMargins(4, 0, 4, 0);
layout->setSpacing(10);
// Linkes Label (Name)
//QLabel *lblName = new QLabel(bcValue.label, container);
//lblName->setFixedWidth(80);
// Slider
QSlider *slider = new QSlider(Qt::Horizontal, container);
slider->setRange(0, 100);
slider->setObjectName("slider");
// Rechtes Label (Vorschau Wert + Einheit)
QLabel *lblUnit = new QLabel(container);
lblUnit->setFixedWidth(60);
lblUnit->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
lblUnit->setObjectName("lblUnit");
//layout->addWidget(lblName);
layout->addWidget(slider);
layout->addWidget(lblUnit);
// Live-Update des Labels im Editor (aber noch kein Speichern im Model)
connect(slider, &QSlider::valueChanged, this, [=](int val)
{
lblUnit->setText(QString("%1 %2").arg(val).arg("mm2"));
});
return container;
}
//return QStyledItemDelegate::createEditor(parent, option, index);
*/
}
void BCAnimatedDelegate::setEditorData(QWidget *editor, const QModelIndex& index) const
{
@@ -150,10 +80,9 @@ void BCAnimatedDelegate::setEditorData(QWidget *editor, const QModelIndex& index
void BCAnimatedDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const
{
/*
qDebug() << "... SHUHU!";
// Daten vom Editor zurück ins Model speichern (Beim Schließen)
QSlider *slider = editor->findChild<QSlider*>("slider");
if (slider)
{
int value = slider->value();
@@ -163,13 +92,28 @@ void BCAnimatedDelegate::setModelData(QWidget *editor, QAbstractItemModel *model
{
QStyledItemDelegate::setModelData(editor, model, index);
}
*/
}
void BCAnimatedDelegate::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
-8, // Rechts: 8px Padding
0 // Unten: kein Offset
);
editor->setGeometry(sliderRect); // Slider nur über Progress Bar
//editor->setGeometry(option.rect);
// __fix!
editor->setGeometry(option.rect);
//editor->setGeometry(option.rect);
}
QSize BCAnimatedDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex& index) const
@@ -193,32 +137,47 @@ void BCAnimatedDelegate::paint(QPainter *painter, const QStyleOptionViewItem& op
QStyledItemDelegate::paint(painter, option, index);
int row = index.row();
int col = index.column();
switch (col)
if( index.column() == 1 )
{
case 1:
if( row>-1 && row <= _valueList.size() )
{
const BCValue& bcValue = *(_valueList[ index.row()].get());
//qDebug() << " --- paintSLider: " << bcValue.label << " type: " << (int)bcValue.valueType << " flags:" << bcValue.valueFlags.toInt() << " RO: " << bcValue.isReadOnly();
if( !bcValue.isReadOnly())
paintSliderIndicator(painter,option,bcValue);
}
if(_rowOpacities.contains(row))
paintHighlightRow(painter,option,index.row());
break;
case 2:
if( row>-1 && row <= _valueList.size() )
{
const BCValue& bcValue = *(_valueList[ index.row()].get());
//qDebug() << " --- paintSLider: " << bcValue.label << " type: " << (int)bcValue.valueType << " flags:" << bcValue.valueFlags.toInt() << " RO: " << bcValue.isReadOnly();
if( !bcValue.isReadOnly())
paintSliderIndicator(painter,option,bcValue);
}
default:
break;
if(_rowOpacities.contains(row))
paintHighlightRow(painter,option,index.row());
}
}
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<BCAnimatedDelegate*>(this)->commitData(slider);
});
return slider;
}
void BCAnimatedDelegate::paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, int row) const
{
painter->save();
@@ -254,6 +213,43 @@ void BCAnimatedDelegate::paintHighlightRow(QPainter* painter, const QStyleOption
*/
void BCAnimatedDelegate::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,
-8,
-option.rect.height() / 2 - 3);
double ratio = bcValue.calcRatio();
if( ratio)
{
// Mini Progress Bar
painter->setPen(Qt::NoPen);
painter->setBrush(QColor(0xE0E0E0));
painter->drawRoundedRect(barRect, 2, 2);
QRect fillRect = barRect;
fillRect.setWidth(barRect.width() * ratio);
painter->setBrush(QColor(0x0078D4));
painter->drawRoundedRect(fillRect, 2, 2);
}
painter->restore();
/// -------
/*
// Hintergrund
if (option.state & QStyle::State_Selected)
{
@@ -264,7 +260,10 @@ void BCAnimatedDelegate::paintSliderIndicator(QPainter* painter, const QStyleOpt
QColor bcColor = option.palette.color(QPalette::Base);
painter->fillRect(option.rect, bcColor);
}
*/
/*
// baby-Slider-Indikator zeichnen
// Anteil zwischen min und max berechnen
double ratio = bcValue.calcRatio();
@@ -296,7 +295,7 @@ void BCAnimatedDelegate::paintSliderIndicator(QPainter* painter, const QStyleOpt
painter->drawRoundedRect(barRect, 2, 2);
painter->restore();
*/
}

View File

@@ -45,7 +45,18 @@ BCDeviceView::BCDeviceView(QWidget *parent)
// __fix! ziemlich wildes ge-pointere, hier
_itemDelegate = new BCAnimatedDelegate( _valueModel.getValueList(), this);
setItemDelegate( _itemDelegate );
setItemDelegateForColumn( 1, _itemDelegate );
// Signal für Änderungen
connect(&_valueModel, &BCValueModel::dataChanged, this, [](const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
if (topLeft.column() ==1) {
int row = topLeft.row();
int value = topLeft.data(Qt::DisplayRole).toInt();
qDebug() << "äääZeile" << row << "wurde auf" << value << "gesetzt";
}
});
}

View File

@@ -126,7 +126,7 @@ int BCValueModel::columnCount(const QModelIndex& parent) const
{
if (parent.isValid())
return 0;
return 3;
return 2;
}
@@ -183,6 +183,8 @@ Qt::ItemFlags BCValueModel::flags(const QModelIndex& index) const
bool BCValueModel::setData(const QModelIndex& index, const QVariant& variant, int role)
{
qDebug() << " --- SET DATA: " << variant.toString();
if (index.isValid() && role == Qt::EditRole)
{
BCValuePtr value = _valueList[index.row()];

View File

@@ -59,13 +59,12 @@ public:
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
//QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
// Nötig für Editierbarkeit
Qt::ItemFlags flags(const QModelIndex& index) const override;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
void updateValue(int row, BCValue::Flags newState, uint32_t rawValue );
protected: