Skip to content

Commit

Permalink
Fix element sizing
Browse files Browse the repository at this point in the history
  • Loading branch information
DonLakeFlyer committed Jul 7, 2018
1 parent a5b8891 commit e494ad4
Showing 3 changed files with 21 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/FactSystem/FactControls/FactValueSlider.qml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 10 additions & 2 deletions src/FactSystem/FactValueSliderListModel.cc
Original file line number Diff line number Diff line change
@@ -53,15 +53,17 @@ 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;
beginInsertRows(QModelIndex(), 0, totalValueCount - 1);
_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;
}
8 changes: 8 additions & 0 deletions src/FactSystem/FactValueSliderListModel.h
Original file line number Diff line number Diff line change
@@ -22,10 +22,18 @@ class FactValueSliderListModel : public QAbstractListModel
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;

0 comments on commit e494ad4

Please sign in to comment.