Commit ff21304c authored by Gus Grubba's avatar Gus Grubba

Collecting rules from rulesets

parent 5e7603d5
......@@ -12,12 +12,54 @@
using namespace airmap;
//-----------------------------------------------------------------------------
AirMapRuleFeature::AirMapRuleFeature(QObject* parent)
: AirspaceRuleFeature(parent)
{
}
//-----------------------------------------------------------------------------
AirMapRuleFeature::AirMapRuleFeature(airmap::RuleSet::Feature feature, QObject* parent)
: AirspaceRuleFeature(parent)
, _feature(feature)
{
//-- TODO: Read possible saved value from previous runs
}
//-----------------------------------------------------------------------------
AirspaceRuleFeature::Type
AirMapRuleFeature::type()
{
return AirspaceRuleFeature::Unknown;
}
//-----------------------------------------------------------------------------
AirspaceRuleFeature::Unit
AirMapRuleFeature::unit()
{
return AirspaceRuleFeature::UnknownUnit;
}
//-----------------------------------------------------------------------------
AirspaceRuleFeature::Measurement
AirMapRuleFeature::measurement()
{
return AirspaceRuleFeature::UnknownMeasurement;
}
//-----------------------------------------------------------------------------
AirMapRule::AirMapRule(QObject* parent)
: AirspaceRule(parent)
{
}
//-----------------------------------------------------------------------------
AirMapRule::AirMapRule(const airmap::RuleSet::Rule& rule, QObject* parent)
: AirspaceRule(parent)
, _rule(rule)
{
}
//-----------------------------------------------------------------------------
AirspaceRule::Status
AirMapRule::status()
......@@ -44,12 +86,28 @@ AirMapRuleSet::AirMapRuleSet(QObject* parent)
{
}
//-----------------------------------------------------------------------------
AirMapRuleSet::~AirMapRuleSet()
{
_rules.deleteListAndContents();
}
//-----------------------------------------------------------------------------
AirMapRulesetsManager::AirMapRulesetsManager(AirMapSharedState& shared)
: _shared(shared)
{
}
//-----------------------------------------------------------------------------
static bool
rules_sort(QObject* a, QObject* b)
{
AirMapRule* aa = qobject_cast<AirMapRule*>(a);
AirMapRule* bb = qobject_cast<AirMapRule*>(b);
if(!aa || !bb) return false;
return (int)aa->order() > (int)bb->order();
}
//-----------------------------------------------------------------------------
void AirMapRulesetsManager::setROI(const QGeoCoordinate& center)
{
......@@ -101,6 +159,13 @@ void AirMapRulesetsManager::setROI(const QGeoCoordinate& center)
pRuleSet->_selectionType = AirspaceRuleSet::Optional;
break;
}
//-- Iterate Rules
for (const auto& rule : ruleset.rules) {
AirMapRule* pRule = new AirMapRule(rule, this);
pRuleSet->_rules.append(pRule);
}
//-- Sort rules by display order
std::sort(pRuleSet->_rules.objectList()->begin(), pRuleSet->_rules.objectList()->end(), rules_sort);
_ruleSets.append(pRuleSet);
qCDebug(AirMapManagerLog) << "Adding ruleset" << pRuleSet->name();
/*
......@@ -115,7 +180,7 @@ void AirMapRulesetsManager::setROI(const QGeoCoordinate& center)
qDebug() << airspaceType.data();
}
qDebug() << "Rules:";
for (const auto& rule : ruleset.rulesets) {
for (const auto& rule : ruleset.rules) {
qDebug() << " --------------------------------------";
qDebug() << " " << rule.short_text.data();
qDebug() << " " << rule.description.data();
......
......@@ -23,6 +23,28 @@
* Class to download rulesets from AirMap
*/
//-----------------------------------------------------------------------------
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;
};
//-----------------------------------------------------------------------------
class AirMapRule : public AirspaceRule
{
......@@ -30,7 +52,9 @@ class AirMapRule : public AirspaceRule
public:
AirMapRule(QObject* parent = NULL);
AirMapRule(const airmap::RuleSet::Rule& rule, QObject* parent = NULL);
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); }
......@@ -45,7 +69,8 @@ class AirMapRuleSet : public AirspaceRuleSet
Q_OBJECT
friend class AirMapRulesetsManager;
public:
AirMapRuleSet (QObject* parent = NULL);
AirMapRuleSet (QObject* parent = NULL);
~AirMapRuleSet ();
QString id () override { return _id; }
QString description () override { return _description; }
bool isDefault () override { return _isDefault; }
......@@ -75,7 +100,8 @@ public:
bool valid () override { return _valid; }
QmlObjectListModel* ruleSets () override { return &_ruleSets; }
QString selectedRuleSets() override;
QmlObjectListModel* features () override { return &_features; }
QString selectedRuleSets() override;
void setROI (const QGeoCoordinate& center) override;
......@@ -97,6 +123,8 @@ private:
State _state = State::Idle;
AirMapSharedState& _shared;
QmlObjectListModel _ruleSets;
//-- TODO: Connect to AirMapRuleSet::selectedChanged and rebuild features based on it.
QmlObjectListModel _features;
};
......@@ -9,6 +9,11 @@
#include "AirspaceRulesetsProvider.h"
AirspaceRuleFeature::AirspaceRuleFeature(QObject* parent)
: QObject(parent)
{
}
AirspaceRule::AirspaceRule(QObject *parent)
: QObject(parent)
{
......
......@@ -53,17 +53,25 @@ public:
AirspaceRuleFeature(QObject* parent = NULL);
Q_PROPERTY(quint32 id READ id CONSTANT)
Q_PROPERTY(Type type READ type CONSTANT)
Q_PROPERTY(Unit unit READ unit CONSTANT)
Q_PROPERTY(Measurement measurement READ measurement CONSTANT)
Q_PROPERTY(QString name READ name CONSTANT)
Q_PROPERTY(QString description READ description CONSTANT)
Q_PROPERTY(QVariant value READ description CONSTANT)
Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged)
virtual Measurement measurement () = 0;
virtual quint32 id () = 0;
virtual Type type () = 0;
virtual Unit unit () = 0;
virtual Measurement measurement () = 0;
virtual QString name () = 0;
virtual QString description () = 0;
virtual QVariant value () = 0;
virtual void setValue (const QVariant val) = 0;
signals:
void valueChanged ();
};
//-----------------------------------------------------------------------------
......@@ -143,9 +151,11 @@ public:
Q_PROPERTY(bool valid READ valid NOTIFY ruleSetsChanged)
Q_PROPERTY(QString selectedRuleSets READ selectedRuleSets NOTIFY selectedRuleSetsChanged)
Q_PROPERTY(QmlObjectListModel* ruleSets READ ruleSets NOTIFY ruleSetsChanged)
Q_PROPERTY(QmlObjectListModel* features READ features NOTIFY ruleSetsChanged)
virtual bool valid () = 0; ///< Current ruleset is valid
virtual QmlObjectListModel* ruleSets () = 0; ///< List of AirspaceRuleSet
virtual QmlObjectListModel* features () = 0; ///< List of AirspaceRuleFeature (Aggregate of all features of selected rulesets)
virtual QString selectedRuleSets() = 0; ///< All selected rules concatenated into a string
/**
* Set region of interest that should be queried. When finished, the rulesChanged() signal will be emmited.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment