Added model & delegate
This commit is contained in:
95
bcvaluemodel.cpp
Normal file
95
bcvaluemodel.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
/***************************************************************************
|
||||
|
||||
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 <bcvaluemodel.h>
|
||||
|
||||
|
||||
|
||||
|
||||
BCValueModel::BCValueModel(QObject *parent) : QAbstractListModel(parent) {}
|
||||
|
||||
void BCValueModel::addValue(const BCValue &val)
|
||||
{
|
||||
int row = _valueList.size();
|
||||
beginInsertRows(QModelIndex(), row, row);
|
||||
_valueList.append(val);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void BCValueModel::setValueList(const BCValueList& valueList)
|
||||
{
|
||||
beginResetModel();
|
||||
_valueList = valueList;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
int BCValueModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid()) return 0;
|
||||
return _valueList.size();
|
||||
}
|
||||
|
||||
QVariant BCValueModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() >= _valueList.size())
|
||||
return QVariant();
|
||||
|
||||
const BCValue &item = _valueList.at(index.row());
|
||||
|
||||
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
||||
return QVariant::fromValue(item);
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
Qt::ItemFlags BCValueModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid()) return Qt::NoItemFlags;
|
||||
// ItemIsEditable ist Pflicht für Persistent Editors
|
||||
return QAbstractListModel::flags(index) | Qt::ItemIsEditable;
|
||||
}
|
||||
|
||||
bool BCValueModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (index.isValid() && role == Qt::EditRole) {
|
||||
BCValue item = _valueList[index.row()];
|
||||
|
||||
// Wir erwarten hier nur den Value-Teil (vom Slider/Editor)
|
||||
// Checken ob Int oder Double
|
||||
if (value.canConvert<double>()) {
|
||||
item.value = value;
|
||||
}
|
||||
|
||||
_valueList[index.row()] = item;
|
||||
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user