ValuesWidgetController.h 4.86 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

10
#pragma once
11

12 13 14
#include "FactSystem.h"
#include "QmlObjectListModel.h"
#include "QGCApplication.h"
15 16 17

#include <QObject>

18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
class ValuesWidgetController;

class InstrumentValue : public QObject
{
    Q_OBJECT

public:
    enum FontSize {
        DefaultFontSize=0,
        SmallFontSize,
        MediumFontSize,
        LargeFontSize
    };

    InstrumentValue(Vehicle* activeVehicle, int fontSize, QmlObjectListModel* rowModel);

    Q_PROPERTY(QString  factGroupName   MEMBER  _factGroupName                      NOTIFY factGroupNameChanged)
    Q_PROPERTY(Fact*    fact            READ    fact                                NOTIFY factChanged)
    Q_PROPERTY(QString  label           READ    label           WRITE setLabel      NOTIFY labelChanged)
    Q_PROPERTY(int      fontSize        READ    fontSize        WRITE setFontSize   NOTIFY fontSizeChanged)
    Q_PROPERTY(bool     showUnits       READ    showUnits       WRITE setShowUnits  NOTIFY showUnitsChanged)

    Q_INVOKABLE void setFact(QString factGroupName, QString factName, QString label);
    Q_INVOKABLE void clearFact(void);

    Fact*   fact                    (void) { return _fact; }
    int     fontSize                (void) const { return _fontSize; }
    QString label                   (void) const { return _label; }
    bool    showUnits               (void) const { return _showUnits; }
    void    setFontSize             (int fontSize);
    void    setLabel                (const QString& label);
    void    setShowUnits            (bool showUnits);
    void    activeVehicleChanged    (Vehicle* activeVehicle);
    void    saveToSettings          (QSettings& settings) const;
    void    readFromSettings        (const QSettings& settings);

signals:
    void factChanged            (Fact* fact);
    void factGroupNameChanged   (QString factGroup);
    void labelChanged           (QString label);
    void fontSizeChanged        (int fontSize);
    void showUnitsChanged       (bool showUnits);

private slots:

private:
    void _setFontSize(int fontSize);

    Vehicle*            _activeVehicle =    nullptr;
    QmlObjectListModel* _rowModel =         nullptr;
    Fact*               _fact =             nullptr;
    QString             _factGroupName;
    QString             _label;
    bool                _showUnits =        true;
    int                 _fontSize =         DefaultFontSize;

    static const char*  _factGroupNameKey;
    static const char*  _factNameKey;
    static const char*  _labelKey;
    static const char*  _fontSizeKey;
    static const char*  _showUnitsKey;
};

81 82 83 84 85
class ValuesWidgetController : public QObject
{
    Q_OBJECT
    
public:
86
    ValuesWidgetController(bool forDefaultSettingsCreation = false);
87

88
    Q_PROPERTY(QmlObjectListModel* valuesModel READ valuesModel NOTIFY valuesModelChanged)
89

90 91 92 93 94 95 96 97
    Q_INVOKABLE InstrumentValue*    appendColumn        (int rowIndex);
    Q_INVOKABLE void                deleteLastColumn    (int rowIndex);
    Q_INVOKABLE QmlObjectListModel* appendRow           (bool addBlanksColumn = true);
    Q_INVOKABLE QmlObjectListModel* insertRow           (int atIndex, bool addBlanksColumn = true);
    Q_INVOKABLE void                deleteRow           (int rowIndex);
    Q_INVOKABLE int                 fontSizeForRow      (int rowIndex);
    Q_INVOKABLE void                setFontSizeForRow   (int rowIndex, int fontSize);
    Q_INVOKABLE void                resetToDefaults     (void);
98

99 100 101 102
    QmlObjectListModel* valuesModel(void) { return _valuesModel; }

    /// Turn on/off saving changes to QSettings
    void setPreventSaveSettings(bool preventSaveSettings);
103 104

signals:
105 106 107 108 109 110
    void valuesModelChanged(QmlObjectListModel* valuesModel);

private slots:
    void        _activeVehicleChanged(Vehicle* activeVehicle);
    Vehicle*    _currentActiveVehicle(void);
    void        _saveSettings  (void);
111 112

private:
113 114 115 116 117 118 119 120
    bool                _validRowIndex                      (int rowIndex);
    InstrumentValue*    _createNewInstrumentValueWorker     (Vehicle* activeVehicle, int fontSize, QmlObjectListModel* rowModel);
    void                _loadSettings                       (void);

    MultiVehicleManager*    _multiVehicleMgr =      nullptr;
    QmlObjectListModel*     _valuesModel =          nullptr;
    QVariantList            _rgFontSizeByRow;
    bool                    _preventSaveSettings =  false;
121 122

    static const char* _groupKey;
123 124 125 126 127 128
    static const char* _rowsKey;
    static const char* _columnsKey;

    static const char* _deprecatedGroupKey;
    static const char* _deprecatedLargeValuesKey;
    static const char* _deprecatedSmallValuesKey;
129

130
};