Files
BionxControl/bcdatamodel.cpp
2025-12-24 12:11:59 +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 <bcdatamodel.h>
BCDataModel::BCDataModel(QObject *parent) : QAbstractListModel(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();
}
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<BCDataValue&>(_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 QAbstractListModel::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<double>())
{
item.visibleValue = value.toString();
}
_valueList[index.row()] = item;
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
return true;
}
return false;
}