Newer
Older
/****************************************************************************
*
* (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
#include "LifetimeChecker.h"
#include "AirspaceRulesetsProvider.h"
Gus Grubba
committed
#include "QGCGeoBoundingCube.h"
#include <QStringList>
/**
* @file AirMapRulesetsManager.h
* Class to download rulesets from AirMap
*/
//-----------------------------------------------------------------------------
class AirMapRuleFeature : public AirspaceRuleFeature
{
Q_OBJECT
public:
Gus Grubba
committed
AirMapRuleFeature(QObject* parent = nullptr);
AirMapRuleFeature(airmap::RuleSet::Feature feature, QObject* parent = nullptr);
Gus Grubba
committed
quint32 id () override { return static_cast<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); }
private:
airmap::RuleSet::Feature _feature;
QVariant _value;
};
//-----------------------------------------------------------------------------
class AirMapRule : public AirspaceRule
Gus Grubba
committed
friend class AirMapFlightPlanManager;
Gus Grubba
committed
AirMapRule (QObject* parent = nullptr);
AirMapRule (const airmap::RuleSet::Rule& rule, QObject* parent = nullptr);
~AirMapRule () override;
Gus Grubba
committed
int order () { return static_cast<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; }
private:
airmap::RuleSet::Rule _rule;
};
//-----------------------------------------------------------------------------
class AirMapRuleSet : public AirspaceRuleSet
Gus Grubba
committed
AirMapRuleSet (QObject* parent = nullptr);
~AirMapRuleSet () override;
QString id () override { return _id; }
QString description () override { return _description; }
bool isDefault () override { return _isDefault; }
QString name () override { return _name; }
SelectionType selectionType () override { return _selectionType; }
QmlObjectListModel* rules () override { return &_rules; }
QString _id;
QString _description;
bool _isDefault;
bool _selected;
QString _name;
QString _shortName;
SelectionType _selectionType;
QmlObjectListModel _rules;
};
//-----------------------------------------------------------------------------
class AirMapRulesetsManager : public AirspaceRulesetsProvider, public LifetimeChecker
{
Q_OBJECT
public:
bool valid () override { return _valid; }
QmlObjectListModel* ruleSets () override { return &_ruleSets; }
Gus Grubba
committed
void setROI (const QGCGeoBoundingCube& roi, bool reset = false) override;
void clearAllFeatures() override;
Gus Grubba
committed
void error (const QString& what, const QString& airmapdMessage, const QString& airmapdDetails);
private slots:
void _selectedChanged ();
private:
enum class State {
Idle,
RetrieveItems,
};
bool _valid;
State _state = State::Idle;
AirMapSharedState& _shared;
Gus Grubba
committed
QmlObjectListModel _ruleSets; //-- List of AirMapRuleSet elements