QGCMapCircle.h 3.69 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#pragma once

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

#include "QmlObjectListModel.h"
#include "FactSystem.h"

/// The QGCMapCircle represents a circular area which can be displayed on a Map control.
class QGCMapCircle : public QObject
{
    Q_OBJECT

public:
26 27
    QGCMapCircle(QObject* parent = nullptr);
    QGCMapCircle(const QGeoCoordinate& center, double radius, QObject* parent = nullptr);
28
    QGCMapCircle(const QGeoCoordinate& center, double radius, bool showRotation, bool clockwiseRotation, QObject* parent = nullptr);
29
    QGCMapCircle(const QGCMapCircle& other, QObject* parent = nullptr);
30 31 32

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

33 34 35 36 37 38
    Q_PROPERTY(bool             dirty               READ dirty              WRITE setDirty              NOTIFY dirtyChanged)
    Q_PROPERTY(QGeoCoordinate   center              READ center             WRITE setCenter             NOTIFY centerChanged)
    Q_PROPERTY(Fact*            radius              READ radius                                         CONSTANT)
    Q_PROPERTY(bool             interactive         READ interactive        WRITE setInteractive        NOTIFY interactiveChanged)
    Q_PROPERTY(bool             showRotation        READ showRotation       WRITE setShowRotation       NOTIFY showRotationChanged)
    Q_PROPERTY(bool             clockwiseRotation   READ clockwiseRotation  WRITE setClockwiseRotation  NOTIFY clockwiseRotationChanged)
39 40 41 42 43 44 45 46 47 48 49 50 51

    /// Saves the polygon to the json object.
    ///     @param json Json object to save to
    void saveToJson(QJsonObject& json);

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

    // Property methods

52 53 54 55 56 57
    bool            dirty               (void) const { return _dirty; }
    QGeoCoordinate  center              (void) const { return _center; }
    Fact*           radius              (void) { return &_radius; }
    bool            interactive         (void) const { return _interactive; }
    bool            showRotation        (void) const { return _showRotation; }
    bool            clockwiseRotation   (void) const { return _clockwiseRotation; }
58

59 60 61 62 63
    void setDirty               (bool dirty);
    void setCenter              (QGeoCoordinate newCenter);
    void setInteractive         (bool interactive);
    void setShowRotation        (bool showRotation);
    void setClockwiseRotation   (bool clockwiseRotation);
64 65 66 67

    static const char* jsonCircleKey;

signals:
68 69 70 71 72
    void dirtyChanged               (bool dirty);
    void centerChanged              (QGeoCoordinate center);
    void interactiveChanged         (bool interactive);
    void showRotationChanged        (bool showRotation);
    void clockwiseRotationChanged   (bool clockwiseRotation);
73 74 75 76 77 78 79 80 81 82 83

private slots:
    void _setDirty(void);

private:
    void _init(void);

    bool            _dirty;
    QGeoCoordinate  _center;
    Fact            _radius;
    bool            _interactive;
84 85
    bool            _showRotation;
    bool            _clockwiseRotation;
86 87 88 89 90 91 92

    QMap<QString, FactMetaData*> _nameToMetaDataMap;

    static const char* _jsonCenterKey;
    static const char* _jsonRadiusKey;
    static const char* _radiusFactName;
};