Files
BionxControl/bcvaluemodel.cpp
2025-12-20 01:23:57 +01:00

109 lines
2.5 KiB
C++

/***************************************************************************
BionxControl
Copyright © 2025 christoph holzheuer
christoph.holzheuer@gmail.com
Using:
BigXionFlasher USB V 0.2.4 rev. 97
© 2011-2013 by Thomas Koenig <info@bigxionflasher.org>
@see www.bigxionflasher.org
Bionx Bike Info
© 2018 Thorsten Schmidt (tschmidt@ts-soft.de)
@see www.ts-soft.de
mhs_can_drv.c 3.00
© 2011 - 2015 by MHS-Elektronik GmbH & Co. KG, Germany
Demlehner Klaus, info@mhs-elektronik.de
@see www.mhs-elektronik.de
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
@see https://github.com/bikemike/bionx-bikeinfo
***************************************************************************/
#include <bcvaluemodel.h>
BCValueModel::BCValueModel(QObject *parent) : QAbstractListModel(parent) {}
void BCValueModel::addValue(const BCValue &val)
{
int row = _valueList.size();
beginInsertRows(QModelIndex(), row, row);
_valueList.append(val);
endInsertRows();
}
void BCValueModel::setValueList(const BCValueList& valueList)
{
beginResetModel();
_valueList = valueList;
endResetModel();
}
BCValueList& BCValueModel::getValueList()
{
return _valueList;
}
int BCValueModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid())
return 0;
return _valueList.size();
}
QVariant BCValueModel::data(const QModelIndex& index, int role) const
{
int row = index.row();
if (!index.isValid() || row >= _valueList.size())
return QVariant();
BCValue& value = const_cast<BCValue&>(_valueList.at( row ));
value.rowInModel = row;
if (role == Qt::DisplayRole || role == Qt::EditRole)
return QVariant::fromValue(value);
return QVariant();
}
Qt::ItemFlags BCValueModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return Qt::NoItemFlags;
return QAbstractListModel::flags(index) | Qt::ItemIsEditable;
}
bool BCValueModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (index.isValid() && role == Qt::EditRole)
{
BCValue item = _valueList[index.row()];
// Wir erwarten hier nur den Value-Teil (vom Slider/Editor)
// Checken ob Int oder Double
if (value.canConvert<double>())
{
item.value = value;
}
_valueList[index.row()] = item;
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
return true;
}
return false;
}