5#include <QtCore/QtMath>
10 : QAbstractListModel(parent)
25 beginRemoveRows(QModelIndex(), 0, _cValues - 1);
31 _initialValueAtPrecision = _valueAtPrecision(_initialValue);
37 _cPrevValues = qMin((_initialValue - _fact.
cookedMin().toDouble()) / _increment, 100.0);
38 _cNextValues = qMin((_fact.
cookedMax().toDouble() - _initialValue) / _increment, 100.0);
39 _initialValueIndex = _cPrevValues;
41 const int totalValueCount = _cPrevValues + 1 + _cNextValues;
42 beginInsertRows(QModelIndex(), 0, totalValueCount - 1);
43 _cValues = totalValueCount;
48 return _initialValueIndex;
51QVariant FactValueSliderListModel::data(
const QModelIndex &index,
int role)
const
55 if (!index.isValid()) {
59 const int valueIndex = index.row();
60 if (valueIndex >= _cValues) {
64 if (role == _valueRole) {
66 const int cIncrementCount = valueIndex - _initialValueIndex;
67 if (cIncrementCount == 0) {
68 value = _initialValue;
72 return QVariant(_valueAtPrecision(value));
73 }
else if (role == _valueIndexRole) {
74 return QVariant::fromValue(valueIndex);
80QHash<int, QByteArray> FactValueSliderListModel::roleNames()
const
82 QHash<int, QByteArray> hash;
84 hash[_valueRole] =
"value";
85 hash[_valueIndexRole] =
"valueIndex";
92 return data(createIndex(index, 0), _valueRole).toDouble();
97 return data(createIndex(index, 0), _valueIndexRole).toInt();
100double FactValueSliderListModel::_valueAtPrecision(
double value)
const
103 return (qRound(value * precision) / precision);
#define QGC_LOGGING_CATEGORY(name, categoryStr)
Provides a list model of values for incrementing/decrementing the value of a Fact.
void initialValueAtPrecisionChanged()
Q_INVOKABLE double valueAtModelIndex(int index) const
Q_INVOKABLE int valueIndexAtModelIndex(int index) const
double initialValueAtPrecision() const
Q_INVOKABLE int resetInitialValue(void)
~FactValueSliderListModel()
A Fact is used to hold a single value within the system.
QVariant cookedValue() const
double rawIncrement() const
QVariant cookedMin() const
double cookedIncrement() const
int decimalPlaces() const
QVariant cookedMax() const