Files
BionxControl/bcvaluemodel.cpp

205 lines
4.6 KiB
C++
Raw Normal View History

2025-12-17 16:26:22 +01:00
/***************************************************************************
2025-12-26 14:07:55 +01:00
BionxControl
2026-01-03 23:51:14 +01:00
© 2025 -2026 christoph holzheuer
2025-12-26 14:07:55 +01:00
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>
2026-01-03 02:50:28 +01:00
2025-12-17 16:26:22 +01:00
2025-12-29 13:05:35 +01:00
/**
* @brief Konstruktor, ohne Besonderheiten
* @param parent Das Elternobject
*/
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
2025-12-29 13:05:35 +01:00
/**
* @brief Gibt die interne Werteliste als const ref zurück
* @return Die WerteListe
*/
2025-12-28 22:48:18 +01:00
const BCValueList& BCValueModel::getValueList() const
2025-12-26 23:09:53 +01:00
{
return _valueList;
}
2025-12-29 13:05:35 +01:00
/**
* @brief Nimmt eine Werteliste in Besitz.
* @param newValueList Die Wertelist. Nach dem Aufruf leer.
*/
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-28 22:48:18 +01:00
2025-12-29 13:05:35 +01:00
/**
* @brief SLOT, der aufgerufen wird, wenn sich ein Wert und/oder der Zustand eines Wertes geändert hat.
* Emitted 'dataChanged' um die zuständige View upzudaten.
*
* @param row Der Index des geänderten Wertes in der Liste
* @param state Der neue state des Wertes
* @param newValue Der neue sichtbare Zahlenwert, formatiert als QString, optionall
*/
2025-12-28 22:48:18 +01:00
2026-01-08 20:47:05 +01:00
void BCValueModel::updateValue(int row, BCValue::Flags newState, uint32_t rawValue )
2026-01-03 23:51:14 +01:00
{
2025-12-29 13:05:35 +01:00
if( row > -1 && row < _valueList.size() )
{
2026-01-06 15:59:57 +01:00
const BCValue& value = *(_valueList[row].get());
2026-01-03 23:51:14 +01:00
2026-01-08 20:47:05 +01:00
BCValue::Flags newFlags1 = BCValue::Flag::NoFlag;
BCValue::Flags newFlags2 = newState;
2026-01-09 08:39:53 +01:00
2026-01-08 14:55:47 +01:00
// Obacht hier!
//value.valueFlags = state;
2026-01-11 14:48:51 +01:00
value.setRawValue( rawValue );
2026-01-03 23:51:14 +01:00
2026-01-09 10:47:29 +01:00
QModelIndex idx = index(row,1);
2026-01-03 23:51:14 +01:00
2025-12-29 13:05:35 +01:00
// wir schicken auf jeden fall einen update request
2026-01-09 10:47:29 +01:00
emit dataChanged(idx, idx, {Qt::DisplayRole, Qt::EditRole});
2025-12-28 22:48:18 +01:00
}
}
2025-12-19 17:37:24 +01:00
2025-12-29 13:05:35 +01:00
/**
* @brief Gibt die Zeilenanzahl zurück
* @param parent Der Elternindex
* @return die Zeilenanzahl
*/
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-29 13:05:35 +01:00
/**
* @brief Gibt die Spaltenanzahl zurück
* @param parent Der Elternindex
* @return die Spaltenanzahl
*/
int BCValueModel::columnCount(const QModelIndex& parent) const
2025-12-24 14:44:54 +01:00
{
2025-12-29 13:05:35 +01:00
if (parent.isValid())
return 0;
2026-01-09 06:19:37 +01:00
return 2;
2025-12-24 14:44:54 +01:00
}
2025-12-29 13:05:35 +01:00
2025-12-24 14:44:54 +01:00
2025-12-29 15:44:06 +01:00
/**
2025-12-29 20:10:05 +01:00
* @brief Gibt die Model-Daten zurück.
2025-12-29 15:44:06 +01:00
*/
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-29 15:44:06 +01:00
Q_UNUSED(role)
2025-12-29 20:10:05 +01:00
int row = index.row();
int col = index.column();
2025-12-24 15:43:50 +01:00
2025-12-29 20:10:05 +01:00
bool wrongRole = ( role != Qt::DisplayRole && role != Qt::EditRole);
if (wrongRole || !index.isValid() || row >= _valueList.size() )
2025-12-17 16:26:22 +01:00
return QVariant();
2026-01-03 02:50:28 +01:00
const BCValue& value = *(_valueList.at( row ).get());
2025-12-29 13:05:35 +01:00
2025-12-29 20:10:05 +01:00
if( col == 0 )
2026-01-11 14:48:51 +01:00
return value.getLabel();
2025-12-29 20:10:05 +01:00
if( col == 1)
2025-12-24 15:43:50 +01:00
{
2025-12-29 20:10:05 +01:00
if( role == Qt::DisplayRole )
2026-01-11 14:48:51 +01:00
return QString("%1 %2").arg( value.formatValue(), value.getUnitLabel());
2025-12-29 20:10:05 +01:00
2026-01-07 17:13:35 +01:00
return value.formatValue();
2025-12-24 15:43:50 +01:00
}
2025-12-29 15:44:06 +01:00
2025-12-29 20:10:05 +01:00
return QVariant();
2025-12-17 16:26:22 +01:00
}
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
{
2026-01-09 00:45:26 +01:00
Qt::ItemFlags flag = Qt::NoItemFlags|Qt::ItemNeverHasChildren;
2026-01-06 16:21:59 +01:00
// die label spalte lässt sich nicht editieren
if (!index.isValid() || index.column() == 0 )
2026-01-09 00:45:26 +01:00
return flag;
int row = index.row();
if( row>-1 && row<_valueList.size() )
{
const BCValue& bcValue = *_valueList[row].get();
flag = bcValue.isReadOnly() ? flag : flag|Qt::ItemIsEditable|Qt::ItemIsEnabled;
}
return flag;
2025-12-17 16:26:22 +01:00
}
2025-12-20 01:23:57 +01:00
2026-01-07 17:13:35 +01:00
bool BCValueModel::setData(const QModelIndex& index, const QVariant& variant, int role)
2025-12-17 16:26:22 +01:00
{
2025-12-20 01:23:57 +01:00
if (index.isValid() && role == Qt::EditRole)
{
2026-01-07 17:13:35 +01:00
BCValuePtr value = _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
2026-01-07 17:13:35 +01:00
if (variant.canConvert<int>())
2025-12-20 01:23:57 +01:00
{
2026-01-10 16:38:52 +01:00
if( variant.toInt() == 42)
{
2026-01-10 22:18:54 +01:00
//emit makeSimonHappy();
2026-01-10 16:38:52 +01:00
}
2026-01-11 14:48:51 +01:00
// QUARK!
value->setRawValue( variant.toInt() );
2025-12-17 16:26:22 +01:00
}
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
return true;
}
return false;
}