FactValueSliderListModel.h 1.83 KB
Newer Older
1 2
/****************************************************************************
 *
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#pragma once

#include <QAbstractListModel>

#include "Fact.h"

/// Provides a list model of values for incrementing/decrementing the value of a Fact
class FactValueSliderListModel : public QAbstractListModel
{
    Q_OBJECT
    
public:
22
    FactValueSliderListModel(Fact& fact, QObject* parent = nullptr);
23 24
    ~FactValueSliderListModel();

DonLakeFlyer's avatar
DonLakeFlyer committed
25 26 27
    /// The initial value of the Fact at the meta data specified decimal place precision
    Q_PROPERTY(double initialValueAtPrecision READ initialValueAtPrecision NOTIFY initialValueAtPrecisionChanged)

28
    double initialValueAtPrecision(void) const { return _initialValueAtPrecision; }
DonLakeFlyer's avatar
DonLakeFlyer committed
29

30 31 32 33
    Q_INVOKABLE int resetInitialValue(void);
    Q_INVOKABLE double valueAtModelIndex(int index);
    Q_INVOKABLE int valueIndexAtModelIndex(int index);

DonLakeFlyer's avatar
DonLakeFlyer committed
34 35 36
signals:
    void initialValueAtPrecisionChanged(void);

37
private:
38 39
    double _valueAtPrecision(double value) const;

40 41 42 43 44 45 46 47 48 49 50 51 52
    // Overrides from QAbstractListModel
    int	rowCount(const QModelIndex & parent = QModelIndex()) const override;
    QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
    QHash<int, QByteArray> roleNames(void) const override;

    Fact&   _fact;
    int     _cValues;
    int     _firstValueIndexInWindow;
    int     _initialValueIndex;
    int     _cPrevValues;
    int     _cNextValues;
    int     _windowSize;
    double  _initialValue;
53
    double  _initialValueAtPrecision;
54 55 56 57 58
    double  _increment;

    static const int _valueRole;
    static const int _valueIndexRole;
};