HomePositionManager.h 3.5 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2
/*=====================================================================

3
QGroundControl Open Source Ground Control Station
pixhawk's avatar
pixhawk committed
4

5
(c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
pixhawk's avatar
pixhawk committed
6

7
This file is part of the QGROUNDCONTROL project
pixhawk's avatar
pixhawk committed
8

9
    QGROUNDCONTROL is free software: you can redistribute it and/or modify
pixhawk's avatar
pixhawk committed
10 11 12 13
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

14
    QGROUNDCONTROL is distributed in the hope that it will be useful,
pixhawk's avatar
pixhawk committed
15 16 17 18 19
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
20
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
pixhawk's avatar
pixhawk committed
21 22 23

======================================================================*/

24 25
#ifndef HomePositionManager_H
#define HomePositionManager_H
pixhawk's avatar
pixhawk committed
26

27
#include "QmlObjectListModel.h"
28
#include "QGCToolbox.h"
Don Gagne's avatar
Don Gagne committed
29

30
#include <QGeoCoordinate>
Don Gagne's avatar
Don Gagne committed
31

32 33
class HomePositionManager;

34 35 36 37 38
class HomePosition : public QObject
{
    Q_OBJECT
    
public:
39
    HomePosition(const QString& name, const QGeoCoordinate& coordinate, HomePositionManager* homePositionManager, QObject* parent = NULL);
40 41 42 43 44 45 46 47 48 49 50 51
    ~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);
52

53 54 55 56 57
signals:
    void nameChanged(const QString& name);
    void coordinateChanged(const QGeoCoordinate& coordinate);
    
private:
58 59
    QGeoCoordinate          _coordinate;
    HomePositionManager*    _homePositionManager;
60
};
pixhawk's avatar
pixhawk committed
61

62
class HomePositionManager : public QGCTool
pixhawk's avatar
pixhawk committed
63 64
{
    Q_OBJECT
65
    
Don Gagne's avatar
Don Gagne committed
66
public:
67 68
    HomePositionManager(QGCApplication* app);

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
    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);
    
84 85 86
    // Override from QGCTool
    virtual void setToolbox(QGCToolbox *toolbox);

87 88 89
private:
    void _loadSettings(void);
    
90
    QmlObjectListModel      _homePositions;
91 92 93 94 95 96 97 98 99 100 101
    
    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
    
102
    /** @brief Get home position latitude */
103 104 105
    double getHomeLatitude() const {
        return homeLat;
    }
106
    /** @brief Get home position longitude */
107 108 109
    double getHomeLongitude() const {
        return homeLon;
    }
110
    /** @brief Get home position altitude */
111 112 113
    double getHomeAltitude() const {
        return homeAlt;
    }
lm's avatar
lm committed
114

pixhawk's avatar
pixhawk committed
115
protected:
116 117 118
    double homeLat;
    double homeLon;
    double homeAlt;
pixhawk's avatar
pixhawk committed
119 120
};

121
#endif