HomePositionManager.h 2.9 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/
pixhawk's avatar
pixhawk committed
9 10


11 12
#ifndef HomePositionManager_H
#define HomePositionManager_H
pixhawk's avatar
pixhawk committed
13

14
#include "QmlObjectListModel.h"
15
#include "QGCToolbox.h"
Don Gagne's avatar
Don Gagne committed
16

17
#include <QGeoCoordinate>
Don Gagne's avatar
Don Gagne committed
18

19 20
class HomePositionManager;

21 22 23 24 25
class HomePosition : public QObject
{
    Q_OBJECT
    
public:
26
    HomePosition(const QString& name, const QGeoCoordinate& coordinate, HomePositionManager* homePositionManager, QObject* parent = NULL);
27 28 29 30 31 32 33 34 35 36 37 38
    ~HomePosition();
    
    Q_PROPERTY(QString          name        READ name           WRITE setName       NOTIFY nameChanged)
    Q_PROPERTY(QGeoCoordinate   coordinate  READ coordinate     WRITE setCoordinate NOTIFY coordinateChanged)
    
    // Property accessors
    
    QString name(void);
    void setName(const QString& name);
    
    QGeoCoordinate coordinate(void);
    void setCoordinate(const QGeoCoordinate& coordinate);
39

40 41 42 43 44
signals:
    void nameChanged(const QString& name);
    void coordinateChanged(const QGeoCoordinate& coordinate);
    
private:
45 46
    QGeoCoordinate          _coordinate;
    HomePositionManager*    _homePositionManager;
47
};
pixhawk's avatar
pixhawk committed
48

49
class HomePositionManager : public QGCTool
pixhawk's avatar
pixhawk committed
50 51
{
    Q_OBJECT
52
    
Don Gagne's avatar
Don Gagne committed
53
public:
54 55
    HomePositionManager(QGCApplication* app);

56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
    Q_PROPERTY(QmlObjectListModel* homePositions READ homePositions CONSTANT)
    
    /// If name is not already a home position a new one will be added, otherwise the existing
    /// home position will be updated
    Q_INVOKABLE void updateHomePosition(const QString& name, const QGeoCoordinate& coordinate);
    
    Q_INVOKABLE void deleteHomePosition(const QString& name);
    
    // Property accesors
    
    QmlObjectListModel* homePositions(void) { return &_homePositions; }
    
    // Should only be called by HomePosition
    void _storeSettings(void);
    
71 72 73
    // Override from QGCTool
    virtual void setToolbox(QGCToolbox *toolbox);

74 75 76
private:
    void _loadSettings(void);
    
77
    QmlObjectListModel      _homePositions;
78 79 80 81 82 83 84 85 86 87 88
    
    static const char* _settingsGroup;
    static const char* _latitudeKey;
    static const char* _longitudeKey;
    static const char* _altitudeKey;
    
// Everything below is deprecated and will be removed once old Map code is removed
public:
    
    // Deprecated methods
    
89
    /** @brief Get home position latitude */
90 91 92
    double getHomeLatitude() const {
        return homeLat;
    }
93
    /** @brief Get home position longitude */
94 95 96
    double getHomeLongitude() const {
        return homeLon;
    }
97
    /** @brief Get home position altitude */
98 99 100
    double getHomeAltitude() const {
        return homeAlt;
    }
lm's avatar
lm committed
101

pixhawk's avatar
pixhawk committed
102
protected:
103 104 105
    double homeLat;
    double homeLon;
    double homeAlt;
pixhawk's avatar
pixhawk committed
106 107
};

108
#endif