FactValueSliderListModel.h 1.74 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * 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:
    FactValueSliderListModel(Fact& fact, QObject* parent = NULL);
    ~FactValueSliderListModel();

DonLakeFlyer's avatar
DonLakeFlyer committed
25 26 27 28 29
    /// 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);

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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
private:
    // 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;
    double  _initialValueRounded;
    double  _increment;

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