HomePositionManager.h 3.94 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 28
#include "QGCSingleton.h"
#include "QmlObjectListModel.h"
Don Gagne's avatar
Don Gagne committed
29

30
#include <QGeoCoordinate>
Don Gagne's avatar
Don Gagne committed
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
class HomePosition : public QObject
{
    Q_OBJECT
    
public:
    HomePosition(const QString& name, const QGeoCoordinate& coordinate, QObject* parent = NULL);
    ~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);
    
signals:
    void nameChanged(const QString& name);
    void coordinateChanged(const QGeoCoordinate& coordinate);
    
private:
    QGeoCoordinate  _coordinate;
};
pixhawk's avatar
pixhawk committed
58

59
class HomePositionManager : public QObject
pixhawk's avatar
pixhawk committed
60 61
{
    Q_OBJECT
62
    
63
    DECLARE_QGC_SINGLETON(HomePositionManager, HomePositionManager)
pixhawk's avatar
pixhawk committed
64

Don Gagne's avatar
Don Gagne committed
65
public:
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    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);
    
private:
    /// @brief All access to HomePositionManager singleton is through HomePositionManager::instance
    HomePositionManager(QObject* parent = NULL);
    ~HomePositionManager();
    
    void _loadSettings(void);
    
    QmlObjectListModel  _homePositions;
    
    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
    
100
    /** @brief Get home position latitude */
101 102 103
    double getHomeLatitude() const {
        return homeLat;
    }
104
    /** @brief Get home position longitude */
105 106 107
    double getHomeLongitude() const {
        return homeLon;
    }
108
    /** @brief Get home position altitude */
109 110 111
    double getHomeAltitude() const {
        return homeAlt;
    }
lm's avatar
lm committed
112

pixhawk's avatar
pixhawk committed
113
public slots:
114 115 116
    
    // Deprecated methods
    
117
    /** @brief Set the current home position, but do not change it on the UAVs */
118
    bool setHomePosition(double lat, double lon, double alt);
119

120 121 122
    /** @brief Set the current home position on all UAVs*/
    bool setHomePositionAndNotify(double lat, double lon, double alt);

123

124 125 126 127
signals:
    /** @brief Current home position changed */
    void homePositionChanged(double lat, double lon, double alt);
    
pixhawk's avatar
pixhawk committed
128
protected:
129 130 131
    double homeLat;
    double homeLon;
    double homeAlt;
pixhawk's avatar
pixhawk committed
132 133
};

134
#endif