AirMapRulesetsManager.h 4.71 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
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#pragma once

Gus Grubba's avatar
Gus Grubba committed
12 13
#include "LifetimeChecker.h"
#include "AirspaceRulesetsProvider.h"
Gus Grubba's avatar
Gus Grubba committed
14
#include "AirMapSharedState.h"
15
#include "QGCGeoBoundingCube.h"
Gus Grubba's avatar
Gus Grubba committed
16 17

#include <QGeoCoordinate>
18
#include <QStringList>
Gus Grubba's avatar
Gus Grubba committed
19

Gus Grubba's avatar
Gus Grubba committed
20 21
#include <airmap/rulesets.h>

22 23 24 25 26
/**
 * @file AirMapRulesetsManager.h
 * Class to download rulesets from AirMap
 */

27 28 29 30 31 32
//-----------------------------------------------------------------------------
class AirMapRuleFeature : public AirspaceRuleFeature
{
    Q_OBJECT
public:

33 34
    AirMapRuleFeature(QObject* parent = nullptr);
    AirMapRuleFeature(airmap::RuleSet::Feature feature, QObject* parent = nullptr);
35

36
    quint32         id              () override { return static_cast<quint32>(_feature.id); }
37 38 39 40 41
    Type            type            () override;
    Unit            unit            () override;
    Measurement     measurement     () override;
    QString         name            () override { return QString::fromStdString(_feature.name);  }
    QString         description     () override { return QString::fromStdString(_feature.description);  }
42
    QVariant        value           () override;
Gus Grubba's avatar
Gus Grubba committed
43
    void            setValue        (const QVariant val) override;
44 45 46 47 48
private:
    airmap::RuleSet::Feature _feature;
    QVariant _value;
};

Gus Grubba's avatar
Gus Grubba committed
49 50
//-----------------------------------------------------------------------------
class AirMapRule : public AirspaceRule
51 52
{
    Q_OBJECT
Gus Grubba's avatar
Gus Grubba committed
53
    friend class AirMapRulesetsManager;
54
    friend class AirMapFlightPlanManager;
55 56
public:

57 58 59
    AirMapRule  (QObject* parent = nullptr);
    AirMapRule  (const airmap::RuleSet::Rule& rule, QObject* parent = nullptr);
    ~AirMapRule () override;
60

61
    int                 order           () { return static_cast<int>(_rule.display_order); }
Gus Grubba's avatar
Gus Grubba committed
62 63 64 65
    Status              status          () override;
    QString             shortText       () override { return QString::fromStdString(_rule.short_text);  }
    QString             description     () override { return QString::fromStdString(_rule.description); }
    QmlObjectListModel* features        () override { return &_features; }
66 67 68

private:
    airmap::RuleSet::Rule _rule;
Gus Grubba's avatar
Gus Grubba committed
69
    QmlObjectListModel    _features;
70 71 72 73
};

//-----------------------------------------------------------------------------
class AirMapRuleSet : public AirspaceRuleSet
Gus Grubba's avatar
Gus Grubba committed
74 75 76
{
    Q_OBJECT
    friend class AirMapRulesetsManager;
Gus Grubba's avatar
Gus Grubba committed
77
    friend class AirMapFlightPlanManager;
Gus Grubba's avatar
Gus Grubba committed
78
public:
79 80
    AirMapRuleSet                   (QObject* parent = nullptr);
    ~AirMapRuleSet                  () override;
81 82 83 84
    QString         id              () override { return _id; }
    QString         description     () override { return _description; }
    bool            isDefault       () override { return _isDefault; }
    QString         name            () override { return _name; }
Gus Grubba's avatar
Gus Grubba committed
85
    QString         shortName       () override { return _shortName; }
86
    SelectionType   selectionType   () override { return _selectionType; }
Gus Grubba's avatar
Gus Grubba committed
87
    bool            selected        () override { return _selected; }
Gus Grubba's avatar
Gus Grubba committed
88
    void            setSelected     (bool sel) override;
89
    QmlObjectListModel* rules       () override { return &_rules; }
Gus Grubba's avatar
Gus Grubba committed
90
private:
91 92 93 94 95 96 97 98
    QString             _id;
    QString             _description;
    bool                _isDefault;
    bool                _selected;
    QString             _name;
    QString             _shortName;
    SelectionType       _selectionType;
    QmlObjectListModel  _rules;
Gus Grubba's avatar
Gus Grubba committed
99 100 101
};

//-----------------------------------------------------------------------------
102 103 104 105
class AirMapRulesetsManager : public AirspaceRulesetsProvider, public LifetimeChecker
{
    Q_OBJECT
public:
Gus Grubba's avatar
Gus Grubba committed
106
    AirMapRulesetsManager       (AirMapSharedState& shared);
107

108
    bool                valid       () override { return _valid; }
109
    QmlObjectListModel* ruleSets    () override { return &_ruleSets; }
110
    QString         selectedRuleSets() override;
111

112 113
    void                setROI      (const QGCGeoBoundingCube& roi, bool reset = false) override;
    void            clearAllFeatures() override;
114 115

signals:
116 117 118 119
    void        error               (const QString& what, const QString& airmapdMessage, const QString& airmapdDetails);

private slots:
    void        _selectedChanged    ();
120 121 122 123 124 125

private:
    enum class State {
        Idle,
        RetrieveItems,
    };
Gus Grubba's avatar
Gus Grubba committed
126 127 128
    bool                            _valid;
    State                           _state = State::Idle;
    AirMapSharedState&              _shared;
129
    QmlObjectListModel              _ruleSets;  //-- List of AirMapRuleSet elements
130 131 132
};