QGCMapPolygon.h 2.11 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/

#ifndef QGCMapPolygon_H
#define QGCMapPolygon_H

#include <QObject>
#include <QGeoCoordinate>
#include <QVariantList>

class QGCMapPolygon : public QObject
{
    Q_OBJECT

public:
    QGCMapPolygon(QObject* parent = NULL);

    const QGCMapPolygon& operator=(const QGCMapPolygon& other);

    Q_PROPERTY(QVariantList path    READ path   WRITE setPath   NOTIFY pathChanged)
    Q_PROPERTY(bool         dirty   READ dirty  WRITE setDirty  NOTIFY dirtyChanged)

    Q_INVOKABLE void clear(void);
    Q_INVOKABLE void adjustCoordinate(int vertexIndex, const QGeoCoordinate coordinate);
    Q_INVOKABLE QGeoCoordinate center(void) const;
    Q_INVOKABLE int count(void) const { return _polygonPath.count(); }

34
    QVariantList path(void) const { return _polygonPath; }
35 36 37
    void setPath(const QList<QGeoCoordinate>& path);
    void setPath(const QVariantList& path);

38 39 40
    QList<QGeoCoordinate> coordinateList(void) const;

    QGeoCoordinate operator[](int index) const { return _polygonPath[index].value<QGeoCoordinate>(); }
41 42 43 44

    bool dirty(void) const { return _dirty; }
    void setDirty(bool dirty);

45 46 47 48 49 50 51 52 53 54 55
    /// Saves the polygon to the json object.
    ///     @param json Json object to save to
    void saveToJson(QJsonObject& json);

    /// Load a polygon from json
    ///     @param json Json object to load from
    ///     @param required true: no polygon in object will generate error
    ///     @param errorString Error string if return is false
    /// @return true: success, false: failure (errorString set)
    bool loadFromJson(const QJsonObject& json, bool required, QString& errorString);

56 57 58 59 60 61 62
signals:
    void pathChanged(void);
    void dirtyChanged(bool dirty);

private:
    QVariantList    _polygonPath;
    bool            _dirty;
63 64

    static const char* _jsonPolygonKey;
65 66 67
};

#endif