AirMapRulesetsManager.h 4.8 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"
Gus Grubba's avatar
Gus Grubba committed
15 16

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

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

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

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
//-----------------------------------------------------------------------------
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; }
    void            setValue        (const QVariant val) override { _value = val; emit valueChanged(); }
private:
    airmap::RuleSet::Feature _feature;
    QVariant _value;
};

Gus Grubba's avatar
Gus Grubba committed
48 49
//-----------------------------------------------------------------------------
class AirMapRule : public AirspaceRule
50 51 52 53
{
    Q_OBJECT
public:

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

Gus Grubba's avatar
Gus Grubba committed
58 59 60 61 62
    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; }
63 64 65

private:
    airmap::RuleSet::Rule _rule;
Gus Grubba's avatar
Gus Grubba committed
66
    QmlObjectListModel    _features;
67 68 69 70
};

//-----------------------------------------------------------------------------
class AirMapRuleSet : public AirspaceRuleSet
Gus Grubba's avatar
Gus Grubba committed
71 72 73
{
    Q_OBJECT
    friend class AirMapRulesetsManager;
Gus Grubba's avatar
Gus Grubba committed
74
    friend class AirMapFlightPlanManager;
Gus Grubba's avatar
Gus Grubba committed
75
public:
76 77
    AirMapRuleSet                   (QObject* parent = NULL);
    ~AirMapRuleSet                  ();
78 79 80 81
    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
82
    QString         shortName       () override { return _shortName; }
83
    SelectionType   selectionType   () override { return _selectionType; }
Gus Grubba's avatar
Gus Grubba committed
84 85
    bool            selected        () override { return _selected; }
    void            setSelected     (bool sel) override { _selected = sel; emit selectedChanged(); }
86
    QmlObjectListModel* rules       () override { return &_rules; }
Gus Grubba's avatar
Gus Grubba committed
87
private:
88 89 90 91 92 93 94 95
    QString             _id;
    QString             _description;
    bool                _isDefault;
    bool                _selected;
    QString             _name;
    QString             _shortName;
    SelectionType       _selectionType;
    QmlObjectListModel  _rules;
Gus Grubba's avatar
Gus Grubba committed
96 97 98
};

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

105
    bool                valid       () override { return _valid; }
106
    QmlObjectListModel* ruleSets    () override { return &_ruleSets; }
107 108
    QmlObjectListModel* features    () override { return &_features; }
    QString         selectedRuleSets() override;
109 110

    void                setROI      (const QGeoCoordinate& center) override;
111

112 113 114
    //-- Selected rules
    QStringList         rulesetsIDs ();

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;
130 131
    //-- TODO: Connect to AirMapRuleSet::selectedChanged and rebuild features based on it.
    QmlObjectListModel              _features;
132 133 134
};