Reworked value reading.
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
#include <QPainter>
|
||||
|
||||
#include "bcitemdelegate.h"
|
||||
#include "bcdataitem.h"
|
||||
#include "bcdatavalue.h"
|
||||
#include "qapplication.h"
|
||||
|
||||
|
||||
@@ -27,14 +27,14 @@ BCItemDelegate::BCItemDelegate(QListView *view)
|
||||
QString BCItemDelegate::displayText(const QVariant& dataValue, const QLocale& locale) const
|
||||
{
|
||||
// Wir prüfen, ob im Variant unser Struct steckt
|
||||
if (dataValue.canConvert<BCDataItem*>())
|
||||
if (dataValue.canConvert<BCDataValue*>())
|
||||
{
|
||||
BCDataItem& bc = *dataValue.value<BCDataItem*>();
|
||||
BCDataValue& bc = *dataValue.value<BCDataValue*>();
|
||||
qDebug() << " --- YES: " << bc.label;
|
||||
// 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.value.toString(), "mmX");
|
||||
return QString("%1: %2 %3").arg(bc.label, bc.visibleValue, "mmX");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -49,10 +49,10 @@ QString BCItemDelegate::displayText(const QVariant& dataValue, const QLocale& lo
|
||||
QWidget *BCItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const
|
||||
{
|
||||
QVariant rawData = index.data(Qt::EditRole);
|
||||
if (!rawData.canConvert<BCDataItem*>())
|
||||
//if (!rawData.canConvert<BCDataValue*>())
|
||||
return QStyledItemDelegate::createEditor(parent, option, index);
|
||||
|
||||
const BCDataItem& bc = *rawData.value<BCDataItem*>();
|
||||
/*
|
||||
const BCDataValue& bc = *rawData.value<BCDataValue*>();
|
||||
|
||||
// Nur bei Integern den Slider-Editor bauen
|
||||
if (bc.value.typeId() == QMetaType::Int)
|
||||
@@ -89,25 +89,27 @@ QWidget *BCItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewIte
|
||||
});
|
||||
|
||||
return container;
|
||||
|
||||
}
|
||||
|
||||
return QStyledItemDelegate::createEditor(parent, option, index);
|
||||
*/
|
||||
}
|
||||
|
||||
void BCItemDelegate::setEditorData(QWidget *editor, const QModelIndex& index) const
|
||||
{
|
||||
// Daten vom Model in den Editor laden
|
||||
const BCDataItem& bc = *index.data(Qt::EditRole).value<BCDataItem*>();
|
||||
const BCDataValue& bc = *index.data(Qt::EditRole).value<BCDataValue*>();
|
||||
|
||||
QSlider *slider = editor->findChild<QSlider*>("slider");
|
||||
QLabel *lblUnit = editor->findChild<QLabel*>("lblUnit");
|
||||
|
||||
if (slider && lblUnit) {
|
||||
bool olDriverState = slider->blockSignals(true);
|
||||
slider->setValue(bc.value.toInt());
|
||||
slider->setValue(bc.visibleValue.toInt());
|
||||
slider->blockSignals(olDriverState);
|
||||
|
||||
lblUnit->setText(QString("%1 %2").arg(bc.value.toInt()).arg( "mm3"));
|
||||
lblUnit->setText(QString("%1 %2").arg(bc.visibleValue.toInt()).arg( "mm3"));
|
||||
} else {
|
||||
QStyledItemDelegate::setEditorData(editor, index);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user