ValuesWidgetController.h 2.88 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
#include "InstrumentValue.h"
16 17 18 19 20 21 22 23

#include <QObject>

class ValuesWidgetController : public QObject
{
    Q_OBJECT
    
public:
24
    ValuesWidgetController(bool forDefaultSettingsCreation = false);
25

26
    Q_PROPERTY(QmlObjectListModel* valuesModel READ valuesModel NOTIFY valuesModelChanged)
27

28 29 30 31 32 33 34 35
    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);
36

37 38 39 40
    QmlObjectListModel* valuesModel(void) { return _valuesModel; }

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

42 43 44
    /// Allows the ownership of the _valuesModel to be re-parented to a different controller
    void setValuesModelParentController(ValuesWidgetController* newParentController);

45
signals:
46 47 48 49 50 51
    void valuesModelChanged(QmlObjectListModel* valuesModel);

private slots:
    void        _activeVehicleChanged(Vehicle* activeVehicle);
    Vehicle*    _currentActiveVehicle(void);
    void        _saveSettings  (void);
52 53

private:
54
    bool                _validRowIndex                      (int rowIndex);
55
    InstrumentValue*    _createNewInstrumentValueWorker     (Vehicle* activeVehicle, InstrumentValue::FontSize fontSize, QmlObjectListModel* rowModel);
56
    void                _loadSettings                       (void);
57
    void                _connectSignalsToController         (InstrumentValue* value, ValuesWidgetController* controller);
58
    QString             _pascalCase                         (const QString& text);
59 60 61 62 63

    MultiVehicleManager*    _multiVehicleMgr =      nullptr;
    QmlObjectListModel*     _valuesModel =          nullptr;
    QVariantList            _rgFontSizeByRow;
    bool                    _preventSaveSettings =  false;
64 65

    static const char* _groupKey;
66 67 68 69 70 71
    static const char* _rowsKey;
    static const char* _columnsKey;

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

73
};