This commit is contained in:
Christoph Holzheuer
2025-09-09 16:22:59 +02:00
parent 809ef10c0d
commit cbe8b92582
9 changed files with 107 additions and 44 deletions

View File

@@ -64,7 +64,7 @@ XQItem::XQRenderStyleMap XQItem::s_RenderStyleMap
{ "CustomRenderStyle", CustomRenderStyle },
{ "PickerStyle", PickerStyle },
{ "SpinBoxStyle", SpinBoxStyle },
{ "ProgressBarStyle", ProgressBarStyle},
{ "ColorBarStyle", ColorBarStyle},
{ "FormattedStyle", FormattedStyle},
};
@@ -74,7 +74,7 @@ XQItem::XQEditorTypeMap XQItem::s_EditorTypeMap
{ "LineEditType", LineEditType },
{ "ComboBoxType", ComboBoxType },
{ "PickerType", PickerType },
{ "ProgressBarType", ProgressBarType },
{ "ColorBarType", ColorBarType },
{ "SpinBoxType", SpinBoxType},
{ "CustomEditorType", CustomEditorType}
};
@@ -501,7 +501,8 @@ QVariant XQItem::data(int role ) const
case Qt::DisplayRole :
{
QString plainText = contentFallBackText();
if( renderStyle() == XQItem::FormattedStyle)
//if( renderStyle() == XQItem::FormattedStyle)
if( unitType() != XQItem::NoUnitType)
return XQItemType::formatToSI( plainText, unitType() );
return plainText;
}
@@ -614,7 +615,9 @@ void XQItem::setData(const QVariant& value, int role )
case XQItem::ContentRole:
{
QVariant newValue;
if( itemType().renderStyle() == XQItem::FormattedStyle)
//if( itemType().renderStyle() == XQItem::FormattedStyle)
if( unitType() != XQItem::NoUnitType)
newValue = XQItemType::unFormatFromSI( value.toString() );
else
newValue = value;

View File

@@ -84,7 +84,7 @@ public:
ComboBoxStyle,
PickerStyle,
SpinBoxStyle,
ProgressBarStyle,
ColorBarStyle,
FormattedStyle,
TreeHeaderStyle,
CustomRenderStyle,
@@ -99,7 +99,7 @@ public:
LineEditType,
ComboBoxType,
PickerType,
ProgressBarType,
ColorBarType,
SpinBoxType,
CustomEditorType,
EditorTypeEnd

View File

@@ -28,6 +28,51 @@
#include <xqitemtype.h>
#include <xqviewmodel.h>
/*
#include <QStyledItemDelegate>
#include <QPainter>
#include <QApplication>
class BarDelegate : public QStyledItemDelegate {
public:
BarDelegate(QObject *parent = nullptr) : QStyledItemDelegate(parent) {}
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const override {
// Standard-Zellenhintergrund zeichnen
QStyledItemDelegate::paint(painter, option, index);
// Wert aus dem Modell holen
bool ok;
int value = index.data().toInt(&ok);
if (!ok || value < 0 || value > 100)
return;
// Balkenbereich berechnen
QRect rect = option.rect.adjusted(4, 4, -4, -4); // etwas Padding
int barWidth = static_cast<int>(rect.width() * (value / 100.0));
// Balken zeichnen
painter->save();
painter->setRenderHint(QPainter::Antialiasing);
QRect barRect(rect.left(), rect.top(), barWidth, rect.height());
QColor barColor = QColor(100, 180, 255); // z.B. hellblau
painter->setBrush(barColor);
painter->setPen(Qt::NoPen);
painter->drawRect(barRect);
// Text (Zahl) zentriert zeichnen
painter->setPen(Qt::black);
painter->drawText(rect, Qt::AlignCenter, QString::number(value));
painter->restore();
}
};
*/
//! erzeugt eine editorfactory mit den hauseigenen editortypen.
@@ -40,8 +85,8 @@ public:
registerEditor(XQItem::LineEditType, new QStandardItemEditorCreator<QLineEdit>());
registerEditor(XQItem::ComboBoxType, new QStandardItemEditorCreator<QComboBox>());
registerEditor(XQItem::PickerType, new QStandardItemEditorCreator<QLineEdit>());
//registerEditor(XQItem::ProgressBarType, new QStandardItemEditorCreator<QProgressBar>());
registerEditor(XQItem::ProgressBarType, new QStandardItemEditorCreator<QSlider>());
//registerEditor(XQItem::ColorBarType, new QStandardItemEditorCreator<QProgressBar>());
registerEditor(XQItem::ColorBarType, new QStandardItemEditorCreator<QSlider>());
registerEditor(XQItem::SpinBoxType, new QStandardItemEditorCreator<QSpinBox>());
registerEditor(XQItem::CustomEditorType, new QStandardItemEditorCreator<QLineEdit>());
}
@@ -96,7 +141,7 @@ void XQItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option
case XQItem::SpinBoxStyle :
return drawSpinBoxStyle( painter, option, index );
case XQItem::ProgressBarStyle :
case XQItem::ColorBarStyle :
return drawProgressBarStyle( painter, option, index );
*/
case XQItem::HiddenStyle :
@@ -289,6 +334,7 @@ void XQItemDelegate::setEditorData(QWidget* editor, const QModelIndex& index) co
case XQItemType::ComboBoxType :
{
QComboBox* comboBox = qobject_cast<QComboBox*>(editor);
// wir erwarten hier ein gültiges model?
comboBox->setModel( item.fixedChoices());
comboBox->setCurrentText( item.data().toString() );
comboBox->showPopup();