/*************************************************************************** BionxControl Copyright © 2025 christoph holzheuer christoph.holzheuer@gmail.com Using: BigXionFlasher USB V 0.2.4 rev. 97 © 2011-2013 by Thomas Koenig @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 BCDataModel::BCDataModel(QObject *parent) : QAbstractListModel(parent) {} void BCDataModel::addValue(const BCDataItem& val) { int row = _valueList.size(); beginInsertRows(QModelIndex(), row, row); _valueList.append(val); endInsertRows(); } void BCDataModel::setValueList(const BCDataList& valueList) { beginResetModel(); _valueList = valueList; endResetModel(); } BCDataList& BCDataModel::getValueList() { return _valueList; } int BCDataModel::rowCount(const QModelIndex& parent) const { if (parent.isValid()) return 0; return _valueList.size(); } QVariant BCDataModel::data(const QModelIndex& index, int role) const { int row = index.row(); if (!index.isValid() || row >= _valueList.size()) return QVariant(); BCDataItem& entry = const_cast(_valueList.at( row )); entry.rowInModel = row; if (role == Qt::DisplayRole || role == Qt::EditRole) return entry.value; return QVariant(); } Qt::ItemFlags BCDataModel::flags(const QModelIndex& index) const { if (!index.isValid()) return Qt::NoItemFlags; return QAbstractListModel::flags(index) | Qt::ItemIsEditable; } bool BCDataModel::setData(const QModelIndex& index, const QVariant& value, int role) { if (index.isValid() && role == Qt::EditRole) { BCDataItem item = _valueList[index.row()]; // Wir erwarten hier nur den Value-Teil (vom Slider/Editor) // Checken ob Int oder Double if (value.canConvert()) { item.value = value; } _valueList[index.row()] = item; emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole}); return true; } return false; }