Files
BionxControl/bcdatamodel.cpp

109 lines
2.5 KiB
C++
Raw Normal View History

2025-12-17 16:26:22 +01:00
/***************************************************************************
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
***************************************************************************/
2025-12-22 21:27:20 +01:00
#include <bcdatamodel.h>
2025-12-17 16:26:22 +01:00
2025-12-22 21:27:20 +01:00
BCDataModel::BCDataModel(QObject *parent) : QAbstractListModel(parent) {}
2025-12-17 16:26:22 +01:00
2025-12-22 21:27:20 +01:00
void BCDataModel::addValue(const BCData &val)
2025-12-17 16:26:22 +01:00
{
int row = _valueList.size();
beginInsertRows(QModelIndex(), row, row);
_valueList.append(val);
endInsertRows();
}
2025-12-22 21:27:20 +01:00
void BCDataModel::setValueList(const BCDataList& valueList)
2025-12-17 16:26:22 +01:00
{
beginResetModel();
_valueList = valueList;
endResetModel();
}
2025-12-22 21:27:20 +01:00
BCDataList& BCDataModel::getValueList()
2025-12-19 17:37:24 +01:00
{
return _valueList;
}
2025-12-22 21:27:20 +01:00
int BCDataModel::rowCount(const QModelIndex &parent) const
2025-12-17 16:26:22 +01:00
{
2025-12-19 17:37:24 +01:00
if (parent.isValid())
return 0;
2025-12-17 16:26:22 +01:00
return _valueList.size();
}
2025-12-22 21:27:20 +01:00
QVariant BCDataModel::data(const QModelIndex& index, int role) const
2025-12-17 16:26:22 +01:00
{
2025-12-19 17:37:24 +01:00
int row = index.row();
if (!index.isValid() || row >= _valueList.size())
2025-12-17 16:26:22 +01:00
return QVariant();
2025-12-22 21:27:20 +01:00
BCData& entry = const_cast<BCData&>(_valueList.at( row ));
entry.rowInModel = row;
2025-12-19 17:37:24 +01:00
if (role == Qt::DisplayRole || role == Qt::EditRole)
2025-12-22 21:27:20 +01:00
return entry.value;
2025-12-17 16:26:22 +01:00
return QVariant();
}
2025-12-20 01:23:57 +01:00
2025-12-22 21:27:20 +01:00
Qt::ItemFlags BCDataModel::flags(const QModelIndex &index) const
2025-12-17 16:26:22 +01:00
{
2025-12-20 01:23:57 +01:00
if (!index.isValid())
return Qt::NoItemFlags;
2025-12-17 16:26:22 +01:00
return QAbstractListModel::flags(index) | Qt::ItemIsEditable;
}
2025-12-20 01:23:57 +01:00
2025-12-22 21:27:20 +01:00
bool BCDataModel::setData(const QModelIndex &index, const QVariant &value, int role)
2025-12-17 16:26:22 +01:00
{
2025-12-20 01:23:57 +01:00
if (index.isValid() && role == Qt::EditRole)
{
2025-12-22 21:27:20 +01:00
BCData item = _valueList[index.row()];
2025-12-17 16:26:22 +01:00
// Wir erwarten hier nur den Value-Teil (vom Slider/Editor)
// Checken ob Int oder Double
2025-12-20 01:23:57 +01:00
if (value.canConvert<double>())
{
2025-12-17 16:26:22 +01:00
item.value = value;
}
_valueList[index.row()] = item;
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
return true;
}
return false;
}