Updated ValueHandling.

This commit is contained in:
Christoph Holzheuer
2026-01-07 17:13:35 +01:00
parent 7d43b0a694
commit 3bdc491830
17 changed files with 152 additions and 150 deletions

View File

@@ -63,11 +63,11 @@ QString BCAnimatedDelegate::displayText(const QVariant& dataValue, const QLocale
// Hier bauen wir den String zusammen, den man sieht,
// wenn KEIN Editor offen ist.
// Format: "Label: Wert Einheit"
return QString("%1: %2 %3").arg(bc.label, bc.visibleValue, "mmX");
return QString("%1: %2 %3").arg(bc.label, bc.formattedValue, "mmX");
}
else
{
qDebug() << " --- Nö!";
//qDebug() << " --- Nö!";
}
// Fallback für normale Strings/Zahlen
@@ -78,10 +78,11 @@ QString BCAnimatedDelegate::displayText(const QVariant& dataValue, const QLocale
QWidget *BCAnimatedDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const
{
/*
QVariant rawData = index.data(Qt::EditRole);
//if (!rawData.canConvert<BCValue*>())
return QStyledItemDelegate::createEditor(parent, option, index);
/*
const BCValue& bc = *rawData.value<BCValue*>();
// Nur bei Integern den Slider-Editor bauen
@@ -121,41 +122,50 @@ QWidget *BCAnimatedDelegate::createEditor(QWidget *parent, const QStyleOptionVie
return container;
}
*/
return QStyledItemDelegate::createEditor(parent, option, index);
*/
}
void BCAnimatedDelegate::setEditorData(QWidget *editor, const QModelIndex& index) const
{
/*
// Daten vom Model in den Editor laden
const BCValue& bc = *index.data(Qt::EditRole).value<BCValue*>();
QSlider *slider = editor->findChild<QSlider*>("slider");
QLabel *lblUnit = editor->findChild<QLabel*>("lblUnit");
if (slider && lblUnit) {
if (slider && lblUnit)
{
bool olDriverState = slider->blockSignals(true);
slider->setValue(bc.visibleValue.toInt());
slider->setValue(bc.formattedValue.toInt());
slider->blockSignals(olDriverState);
lblUnit->setText(QString("%1 %2").arg(bc.visibleValue.toInt()).arg( "mm3"));
} else {
lblUnit->setText(QString("%1 %2").arg(bc.formattedValue.toInt()).arg( "mm3"));
}
else
{
QStyledItemDelegate::setEditorData(editor, index);
}
*/
}
void BCAnimatedDelegate::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) {
if (slider)
{
int value = slider->value();
model->setData(index, value, Qt::EditRole);
} else {
}
else
{
QStyledItemDelegate::setModelData(editor, model, index);
}
*/
}
void BCAnimatedDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& index) const
@@ -230,38 +240,42 @@ void BCAnimatedDelegate::paintSliderIndicator(QPainter* painter, const QStyleOpt
{
/*
if (option.state & QStyle::State_Selected) {
// 1. Die originale Highlight-Farbe holen (z.B. das Blau aus dem CSS)
QColor highlightColor = option.palette.highlight().color();
if (option.state & QStyle::State_Selected)
{
// 1. Die originale Highlight-Farbe holen (z.B. das Blau aus dem CSS)
QColor highlightColor = option.palette.highlight().color();
// 2. Transparenz setzen (z.B. nur 30% Deckkraft für "Glass"-Effekt)
highlightColor.setAlphaF(0.3); // 0.0 bis 1.0 (float ist oft lesbarer)
// 2. Transparenz setzen (z.B. nur 30% Deckkraft für "Glass"-Effekt)
highlightColor.setAlphaF(0.3); // 0.0 bis 1.0 (float ist oft lesbarer)
// 3. Zeichnen (Brush setzt die Füllfarbe)
painter->fillRect(option.rect, highlightColor);
}
// 3. Zeichnen (Brush setzt die Füllfarbe)
painter->fillRect(option.rect, highlightColor);
}
*/
const BCValue& valueX = *(_valueList[ index.row()].get());
int value = 50;//index.model()->data(index, Qt::DisplayRole).toInt();
const BCValue& bcValue = *(_valueList[ index.row()].get());
qDebug() << " --- paintSLider: " << bcValue.label << ": " << (int)bcValue.valueType;
// wenn Werte readOnly sind, dann brauchen keinen EditHint
if( bcValue.flags.testFlag(BCValue::Flag::ReadOnly) )
// || bcValue.valueType == BCValue::ValueType::Plain )
return;
// Hintergrund
if (option.state & QStyle::State_Selected)
{
painter->fillRect(option.rect, option.palette.highlight());
}
else
{
QColor bcColor = option.palette.color(QPalette::Base);
painter->fillRect(option.rect, bcColor);
}
// Text und kleiner Slider-Indikator zeichnen
// baby-Slider-Indikator zeichnen
painter->save();
painter->setRenderHint(QPainter::Antialiasing);
//QRect textRect = option.rect.adjusted(8, 0, -120, 0);
QRect barRect = option.rect.adjusted
(
8,
@@ -275,10 +289,11 @@ if (option.state & QStyle::State_Selected) {
painter->setBrush(QColor(0xE0E0E0));
painter->drawRoundedRect(barRect, 2, 2);
QRect fillRect = barRect;
fillRect.setWidth(barRect.width() * valueX.calcRatio() );
// Anteil zwischen min und max berechnen
double ratio = bcValue.calcRatio();
barRect.setWidth(barRect.width() * ratio );
painter->setBrush(QColor(0x0078D4));
painter->drawRoundedRect(fillRect, 2, 2);
painter->drawRoundedRect(barRect, 2, 2);
painter->restore();