AirMapRulesetsManager.h 4.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/****************************************************************************
 *
 *   (c) 2017 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.
 *
 ****************************************************************************/

#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 33 34 35 36 37 38 39 40 41 42
//-----------------------------------------------------------------------------
class AirMapRuleFeature : public AirspaceRuleFeature
{
    Q_OBJECT
public:

    AirMapRuleFeature(QObject* parent = NULL);
    AirMapRuleFeature(airmap::RuleSet::Feature feature, QObject* parent = NULL);

    quint32         id              () override { return (quint32)_feature.id; }
    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);  }
    QVariant        value           () override { return _value; }
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:

Gus Grubba's avatar
Gus Grubba committed
57 58 59
    AirMapRule  (QObject* parent = NULL);
    AirMapRule  (const airmap::RuleSet::Rule& rule, QObject* parent = NULL);
    ~AirMapRule ();
60

Gus Grubba's avatar
Gus Grubba committed
61 62 63 64 65
    int                 order           () { return (int)_rule.display_order; }
    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 = NULL);
    ~AirMapRuleSet                  ();
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
    void                setROI      (const QGCGeoBoundingCube& roi) override;
113 114

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

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

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