Try BCValue as smartptr

This commit is contained in:
2026-01-02 01:43:49 +01:00
parent 43f72d1be6
commit fc5ab611bd
11 changed files with 60 additions and 69 deletions

View File

@@ -45,18 +45,6 @@ BCValueModel::BCValueModel(QObject *parent)
}
/**
* @brief Einen Einzelwert hinzufügen
* @param val der neue Wert
*/
void BCValueModel::addValue(const BCValue& val)
{
int row = _valueList.size();
beginInsertRows(QModelIndex(), row, row);
_valueList.append(val);
endInsertRows();
}
/**
@@ -98,12 +86,12 @@ void BCValueModel::onValueUpdated( int row, BCValue::State state, const QString&
qDebug() << " BCValueModel::onValueUpdated update: " << newVisisbleValue;
if( row > -1 && row < _valueList.size() )
{
const BCValue& value = _valueList[row];
BCValuePtr value = _valueList[row];
QModelIndex idx = index(row,1);
value.state = state;
if( !newVisisbleValue.isEmpty() && newVisisbleValue != value.visibleValue )
value->state = state;
if( !newVisisbleValue.isEmpty() && newVisisbleValue != value->visibleValue )
{
value.visibleValue = newVisisbleValue;
value->visibleValue = newVisisbleValue;
}
// wir schicken auf jeden fall einen update request
emit dataChanged(idx, idx, {Qt::DisplayRole, Qt::EditRole});
@@ -156,17 +144,17 @@ QVariant BCValueModel::data(const QModelIndex& index, int role) const
if (wrongRole || !index.isValid() || row >= _valueList.size() )
return QVariant();
const BCValue& value = _valueList.at( row );
BCValuePtr value = _valueList.at( row );
if( col == 0 )
return value.label;
return value->label;
if( col == 1)
{
if( role == Qt::DisplayRole )
return QString("%1 %2").arg( value.visibleValue, value.valueType->unitLabel);
return QString("%1 %2").arg( value->visibleValue, value->valueType->unitLabel);
return value.visibleValue;
return value->visibleValue;
}
return QVariant();
@@ -208,13 +196,13 @@ bool BCValueModel::setData(const QModelIndex& index, const QVariant& value, int
if (index.isValid() && role == Qt::EditRole)
{
BCValue& item = _valueList[index.row()];
BCValuePtr item = _valueList[index.row()];
// Wir erwarten hier nur den Value-Teil (vom Slider/Editor)
// Checken ob Int oder Double
if (value.canConvert<double>())
{
item.visibleValue = value.toString();
item->visibleValue = value.toString();
}
_valueList[index.row()] = item;