Unverified Commit 3a2a3584 authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #6694 from DonLakeFlyer/SliderFix

FactValueSlider: Fix element sizing
parents d264eda0 e494ad44
......@@ -13,10 +13,11 @@ Rectangle {
color: qgcPal.textField
property Fact fact: undefined
property int digitCount: 4 ///< The number of digits to show for each value
property int digitCount: 4 ///< The minimum number of digits to show for each value
property int incrementSlots: 1 ///< The number of visible slots to left/right of center value
property int _totalDigitCount: digitCount + 1 + fact.units.length
property int _adjustedDigitCount: Math.max(digitCount, _model.initialValueAtPrecision.toString().length)
property int _totalDigitCount: _adjustedDigitCount + 1 + fact.units.length
property real _margins: (ScreenTools.implicitTextFieldHeight - ScreenTools.defaultFontPixelHeight) / 2
property real _increment: fact.increment
property real _value: fact.value
......
......@@ -53,8 +53,8 @@ int FactValueSliderListModel::resetInitialValue(void)
} else {
_increment = _fact.cookedIncrement();
}
_cPrevValues = qMin((_initialValue - _fact.cookedMin().toDouble()), 1000.0) / _increment;
_cNextValues = qMin((_fact.cookedMax().toDouble() - _initialValue), 1000.0) / _increment;
_cPrevValues = qMin((_initialValue - _fact.cookedMin().toDouble()), 100.0) / _increment;
_cNextValues = qMin((_fact.cookedMax().toDouble() - _initialValue), 100.0) / _increment;
_initialValueIndex = _cPrevValues;
int totalValueCount = _cPrevValues + 1 + _cNextValues;
......@@ -62,6 +62,8 @@ int FactValueSliderListModel::resetInitialValue(void)
_cValues = totalValueCount;
endInsertRows();
emit initialValueAtPrecisionChanged();
return _initialValueIndex;
}
......@@ -126,3 +128,9 @@ int FactValueSliderListModel::valueIndexAtModelIndex(int index)
{
return data(createIndex(index, 0), _valueIndexRole).toInt();
}
double FactValueSliderListModel::initialValueAtPrecision(void)
{
double precision = qPow(10, _fact.decimalPlaces());
return qRound(_initialValue * precision) / precision;
}
......@@ -22,10 +22,18 @@ public:
FactValueSliderListModel(Fact& fact, QObject* parent = NULL);
~FactValueSliderListModel();
/// The initial value of the Fact at the meta data specified decimal place precision
Q_PROPERTY(double initialValueAtPrecision READ initialValueAtPrecision NOTIFY initialValueAtPrecisionChanged)
double initialValueAtPrecision(void);
Q_INVOKABLE int resetInitialValue(void);
Q_INVOKABLE double valueAtModelIndex(int index);
Q_INVOKABLE int valueIndexAtModelIndex(int index);
signals:
void initialValueAtPrecisionChanged(void);
private:
// Overrides from QAbstractListModel
int rowCount(const QModelIndex & parent = QModelIndex()) const override;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment