AirMapRulesetsManager.h 4.61 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 54
{
    Q_OBJECT
public:

    AirMapRule(QObject* parent = NULL);
55
    AirMapRule(const airmap::RuleSet::Rule& rule, QObject* parent = NULL);
56

57
    int             order           () { return (int)_rule.display_order; }
58 59 60 61 62 63 64 65 66 67
    Status          status          () override;
    QString         shortText       () override { return QString::fromStdString(_rule.short_text);  }
    QString         description     () override { return QString::fromStdString(_rule.description); }

private:
    airmap::RuleSet::Rule _rule;
};

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

//-----------------------------------------------------------------------------
95 96 97 98
class AirMapRulesetsManager : public AirspaceRulesetsProvider, public LifetimeChecker
{
    Q_OBJECT
public:
Gus Grubba's avatar
Gus Grubba committed
99
    AirMapRulesetsManager       (AirMapSharedState& shared);
100

101
    bool                valid       () override { return _valid; }
102
    QmlObjectListModel* ruleSets    () override { return &_ruleSets; }
103 104
    QmlObjectListModel* features    () override { return &_features; }
    QString         selectedRuleSets() override;
105 106

    void                setROI      (const QGeoCoordinate& center) override;
107

108 109 110
    //-- Selected rules
    QStringList         rulesetsIDs ();

111
signals:
112 113 114 115
    void        error               (const QString& what, const QString& airmapdMessage, const QString& airmapdDetails);

private slots:
    void        _selectedChanged    ();
116 117 118 119 120 121

private:
    enum class State {
        Idle,
        RetrieveItems,
    };
Gus Grubba's avatar
Gus Grubba committed
122 123 124
    bool                            _valid;
    State                           _state = State::Idle;
    AirMapSharedState&              _shared;
125
    QmlObjectListModel              _ruleSets;
126 127
    //-- TODO: Connect to AirMapRuleSet::selectedChanged and rebuild features based on it.
    QmlObjectListModel              _features;
128 129 130
};