UASParameterDataModel.h 4.55 KB
Newer Older
1 2 3 4 5 6 7
#ifndef UASPARAMETERDATAMODEL_H
#define UASPARAMETERDATAMODEL_H

#include <QMap>
#include <QObject>
#include <QVariant>

8 9
class QTextStream;

10 11 12 13 14 15 16
class UASParameterDataModel : public QObject
{
    Q_OBJECT
public:
    explicit UASParameterDataModel(QObject *parent = 0);
    

17 18 19 20 21 22 23 24 25 26 27 28 29 30
    //Parameter meta info
    bool isParamMinKnown(const QString& param) { return paramMin.contains(param); }
    virtual bool isValueLessThanParamMin(const QString& param, double dblVal);

    bool isParamMaxKnown(const QString& param) { return paramMax.contains(param); }
    virtual bool isValueGreaterThanParamMax(const QString& param, double dblVal);

    bool isParamDefaultKnown(const QString& param) { return paramDefault.contains(param); }
    double getParamMin(const QString& param) { return paramMin.value(param, 0.0f); }
    double getParamMax(const QString& param) { return paramMax.value(param, 0.0f); }
    double getParamDefault(const QString& param) { return paramDefault.value(param, 0.0f); }
    virtual QString getParamDescription(const QString& param) { return paramDescriptions.value(param, ""); }
    virtual void setParamDescriptions(const QMap<QString,QString>& paramInfo);

tstellanova's avatar
tstellanova committed
31 32 33 34 35
    //TODO make this method protected?
     /** @brief Ensure that the data model is aware of this component
      * @param compId Id of the component
      */
    virtual void addComponent(int compId);
36

37 38

    virtual void removePendingParam(int compId, QString& key);
39
    virtual void commitAllPendingParams();///< Called by eg params comms mgr when all pending params have been sent & acked
40 41

    /** @brief Save the onboard parameter with a the type specified in the QVariant as fixed */
42
    virtual void setOnboardParamWithType(int componentId, QString& key, QVariant& value);
43 44

    /** @brief clears every parameter for every loaded component */
45
    virtual void forgetAllOnboardParams();
46 47


48
    /** @brief add this parameter to pending list iff it has changed from onboard value
49
     * @return true if the parameter is now pending
50
    */
51
    virtual bool updatePendingParamWithValue(int componentId, QString& key,  const QVariant &value);
52 53
    virtual void handleParamUpdate(int componentId, QString& key, QVariant& value);
    virtual bool getOnboardParamValue(int componentId, const QString& key, QVariant& value) const;
54

55 56
    virtual bool isParamChangePending(int componentId,const QString& key);

57
    QMap<QString , QVariant>* getPendingParamsForComponent(int componentId) {
58 59 60
        return pendingParameters.value(componentId);
    }

61
    QMap<QString , QVariant>* getOnboardParamsForComponent(int componentId) {
62 63
        return onboardParameters.value(componentId);
    }
64

65
    QMap<int, QMap<QString, QVariant>* >*  getAllPendingParams() {
66
       return &pendingParameters;
67 68
   }

69
    QMap<int, QMap<QString, QVariant>* >* getAllOnboardParams() {
70
       return &onboardParameters;
71 72 73
   }


74 75
    virtual void writeOnboardParamsToStream(QTextStream &stream, const QString& uasName);
    virtual void readUpdateParamsFromStream(QTextStream &stream);
76 77

    virtual void loadParamMetaInfoFromStream(QTextStream& stream);
78

79 80
    void setUASID(int anId) {  this->uasId = anId; }

81 82
protected:
    virtual void setOnboardParam(int componentId, QString& key, const QVariant& value);
83 84 85 86
    /** @brief Write a new pending parameter value that may be eventually sent to the UAS */
    virtual void setPendingParam(int componentId,  QString& key,  const QVariant& value);

    int countPendingParams();
87

88 89
signals:
    
tstellanova's avatar
tstellanova committed
90 91
    /** @brief We've received an update of a parameter's value */
    void parameterUpdated(int compId, QString paramName, QVariant value);
tstellanova's avatar
tstellanova committed
92

93 94 95
    /** @brief Notifies listeners that a param was added to or removed from the pending list */
    void pendingParamUpdate(int compId, const QString& paramName, QVariant value, bool isPending);

96 97
    void allPendingParamsCommitted(); ///< All pending params have been committed to the MAV

98 99 100 101 102 103 104 105
public slots:


protected:
    int     uasId; ///< The UAS / MAV to which this data model pertains
    QMap<int, QMap<QString, QVariant>* > pendingParameters; ///< Changed values that have not yet been transmitted to the UAS, by component ID
    QMap<int, QMap<QString, QVariant>* > onboardParameters; ///< All parameters confirmed to be stored onboard the UAS, by component ID

106 107 108 109 110 111 112 113
    // Tooltip data structures
    QMap<QString, QString> paramDescriptions; ///< Tooltip values

    // Min / Default / Max data structures
    QMap<QString, double> paramMin; ///< Minimum param values
    QMap<QString, double> paramDefault; ///< Default param values
    QMap<QString, double> paramMax; ///< Minimum param values

114 115 116 117
    
};

#endif // UASPARAMETERDATAMODEL_H