Files
BionxControl/bcvaluemodel.cpp

171 lines
3.9 KiB
C++
Raw Normal View History

2025-12-17 16:26:22 +01:00
/***************************************************************************
2025-12-26 14:07:55 +01:00
BionxControl
Copyright © 2025 christoph holzheuer
christoph.holzheuer@gmail.com
2025-12-17 16:26:22 +01:00
2025-12-26 14:07:55 +01:00
Using:
2025-12-17 16:26:22 +01:00
2025-12-26 14:07:55 +01:00
mhs_can_drv.c
© 2011 - 2023 by MHS-Elektronik GmbH & Co. KG, Germany
Klaus Demlehner, klaus@mhs-elektronik.de
@see www.mhs-elektronik.de
2025-12-17 16:26:22 +01:00
2025-12-26 14:07:55 +01:00
Based on Bionx data type descriptions from:
2025-12-17 16:26:22 +01:00
2025-12-26 14:07:55 +01:00
BigXionFlasher USB V 0.2.4 rev. 97
© 2011-2013 by Thomas Koenig <info@bigxionflasher.org>
@see www.bigxionflasher.org
2025-12-17 16:26:22 +01:00
2025-12-26 14:07:55 +01:00
Bionx Bike Info
© 2018 Thorsten Schmidt (tschmidt@ts-soft.de)
@see www.ts-soft.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-17 16:26:22 +01:00
***************************************************************************/
2025-12-26 15:19:33 +01:00
#include <bcvaluemodel.h>
2025-12-17 16:26:22 +01:00
2025-12-26 15:19:33 +01:00
BCValueModel::BCValueModel(QObject *parent)
2025-12-24 14:44:54 +01:00
: QAbstractTableModel(parent)
{
}
2025-12-17 16:26:22 +01:00
2025-12-26 15:19:33 +01:00
void BCValueModel::addValue(const BCDataValue& val)
2025-12-17 16:26:22 +01:00
{
int row = _valueList.size();
beginInsertRows(QModelIndex(), row, row);
_valueList.append(val);
endInsertRows();
}
2025-12-26 15:19:33 +01:00
2025-12-26 23:09:53 +01:00
const BCValueList& BCValueModel::getValueList()
{
return _valueList;
}
2025-12-28 14:42:12 +01:00
void BCValueModel::takeValueList(BCValueList& newValueList)
2025-12-17 16:26:22 +01:00
{
beginResetModel();
2025-12-28 14:42:12 +01:00
// hier nehmen wir die valueList in Besitz.
_valueList = std::exchange(newValueList, {} );
2025-12-17 16:26:22 +01:00
endResetModel();
}
2025-12-19 17:37:24 +01:00
2025-12-26 15:19:33 +01:00
int BCValueModel::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-26 15:19:33 +01:00
int BCValueModel::columnCount(const QModelIndex &parent) const
2025-12-24 14:44:54 +01:00
{
if (parent.isValid()) return 0;
return 2;
}
2025-12-26 15:19:33 +01:00
QVariant BCValueModel::headerData(int section, Qt::Orientation orientation, int role) const
2025-12-24 14:44:54 +01:00
{
if (role != Qt::DisplayRole || orientation != Qt::Horizontal)
return QVariant();
switch (section)
{
case 0:
return QString("Bezeichnung");
case 1:
return QString("Wert");
default:
return QVariant();
}
}
2025-12-26 15:19:33 +01:00
QVariant BCValueModel::data(const QModelIndex& index, int role) const
2025-12-17 16:26:22 +01:00
{
2025-12-24 15:43:50 +01:00
/*
if (!index.isValid() || index.row() >= static_cast<int>(m_items.size()))
return QVariant();
const auto& item = m_items.at(index.row());
if (role == Qt::DisplayRole) {
switch (index.column()) {
case 0: return item.id;
case 1: return item.name;
case 2: {
// Hier nutzen wir QLocale für das Komma!
return QLocale(QLocale::German).toString(item.value, 'f', 2);
}
}
}
// Bonus: Rechtsbündig für Zahlen
if (role == Qt::TextAlignmentRole && (index.column() == 0 || index.column() == 2)) {
return Qt::AlignRight | Qt::AlignVCenter;
}
return QVariant();
*/
2025-12-19 17:37:24 +01:00
int row = index.row();
2025-12-24 15:43:50 +01:00
int col = index.column();
2025-12-19 17:37:24 +01:00
if (!index.isValid() || row >= _valueList.size())
2025-12-17 16:26:22 +01:00
return QVariant();
2025-12-24 12:11:59 +01:00
BCDataValue& entry = const_cast<BCDataValue&>(_valueList.at( row ));
2025-12-22 21:27:20 +01:00
entry.rowInModel = row;
2025-12-19 17:37:24 +01:00
if (role == Qt::DisplayRole || role == Qt::EditRole)
2025-12-24 15:43:50 +01:00
{
if( col == 0 )
return entry.label;
else if( col == 1 )
return entry.visibleValue;
}
2025-12-17 16:26:22 +01:00
return QVariant();
}
2025-12-20 01:23:57 +01:00
2025-12-26 15:19:33 +01:00
Qt::ItemFlags BCValueModel::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-24 14:44:54 +01:00
return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
2025-12-17 16:26:22 +01:00
}
2025-12-20 01:23:57 +01:00
2025-12-26 15:19:33 +01:00
bool BCValueModel::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-26 15:19:33 +01:00
BCDataValue& 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-24 12:11:59 +01:00
item.visibleValue = value.toString();
2025-12-17 16:26:22 +01:00
}
_valueList[index.row()] = item;
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
return true;
}
return false;
}