/*************************************************************************** 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) : QAbstractTableModel(parent) { } void BCDataModel::addValue(const BCDataValue& 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(); } int BCDataModel::columnCount(const QModelIndex &parent) const { if (parent.isValid()) return 0; return 2; } QVariant BCDataModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role != Qt::DisplayRole || orientation != Qt::Horizontal) return QVariant(); switch (section) { case 0: return QString("Bezeichnung"); case 1: return QString("Wert"); default: return QVariant(); } } QVariant BCDataModel::data(const QModelIndex& index, int role) const { int row = index.row(); if (!index.isValid() || row >= _valueList.size()) return QVariant(); BCDataValue& entry = const_cast(_valueList.at( row )); entry.rowInModel = row; if (role == Qt::DisplayRole || role == Qt::EditRole) return entry.visibleValue; return QVariant(); } Qt::ItemFlags BCDataModel::flags(const QModelIndex& index) const { if (!index.isValid()) return Qt::NoItemFlags; return QAbstractTableModel::flags(index) | Qt::ItemIsEditable; } bool BCDataModel::setData(const QModelIndex& index, const QVariant& value, int role) { if (index.isValid() && role == Qt::EditRole) { BCDataValue item = _valueList[index.row()]; // Wir erwarten hier nur den Value-Teil (vom Slider/Editor) // Checken ob Int oder Double if (value.canConvert()) { item.visibleValue = value.toString(); } _valueList[index.row()] = item; emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole}); return true; } return false; }