| 1 | #ifndef FLIGHTPLANCONTROLLER_HXX |
| 2 | #define FLIGHTPLANCONTROLLER_HXX |
| 3 | |
| 4 | #include <memory> |
| 5 | |
| 6 | #include <QAbstractListModel> |
| 7 | #include <QObject> |
| 8 | |
| 9 | #include <Navaids/FlightPlan.hxx> |
| 10 | |
| 11 | #include "QmlPositioned.hxx" |
| 12 | #include "UnitsModel.hxx" |
| 13 | |
| 14 | class FPDelegate; |
| 15 | class LaunchConfig; |
| 16 | |
| 17 | class LegsModel : public QAbstractListModel |
| 18 | { |
| 19 | Q_OBJECT |
| 20 | |
| 21 | Q_PROPERTY(int numLegs READ numLegs NOTIFY numLegsChanged) |
| 22 | public: |
| 23 | void setFlightPlan(flightgear::FlightPlanRef f); |
| 24 | |
| 25 | int rowCount(const QModelIndex& parent) const override; |
| 26 | QVariant data(const QModelIndex& index, int role) const override; |
| 27 | QHash<int, QByteArray> roleNames() const override; |
| 28 | |
| 29 | |
| 30 | void waypointsChanged(); |
| 31 | int numLegs() const; |
| 32 | |
| 33 | signals: |
| 34 | void numLegsChanged(); |
| 35 | |
| 36 | private: |
| 37 | flightgear::FlightPlanRef _fp; |
| 38 | }; |
| 39 | class FlightPlanController : public QObject |
| 40 | { |
| 41 | Q_OBJECT |
| 42 | |
| 43 | Q_PROPERTY(bool enabled MEMBER _enabled NOTIFY enabledChanged) |
| 44 | Q_PROPERTY(QString description READ description NOTIFY descriptionChanged) |
| 45 | |
| 46 | Q_PROPERTY(QString callsign READ callsign WRITE setCallsign NOTIFY infoChanged) |
| 47 | Q_PROPERTY(QString remarks READ remarks WRITE setRemarks NOTIFY infoChanged) |
| 48 | Q_PROPERTY(QString aircraftType READ aircraftType WRITE setAircraftType NOTIFY infoChanged) |
| 49 | |
| 50 | Q_PROPERTY(LegsModel* legs READ legs CONSTANT) |
| 51 | |
| 52 | Q_PROPERTY(QString icaoRoute READ icaoRoute NOTIFY waypointsChanged) |
| 53 | |
| 54 | Q_ENUMS(FlightRules) |
| 55 | Q_ENUMS(FlightType) |
| 56 | |
| 57 | Q_PROPERTY(FlightRules flightRules READ flightRules WRITE setFlightRules NOTIFY infoChanged) |
| 58 | Q_PROPERTY(FlightType flightType READ flightType WRITE setFlightType NOTIFY infoChanged) |
| 59 | |
| 60 | // planned departure date + time |
| 61 | |
| 62 | Q_PROPERTY(QuantityValue totalDistanceNm READ totalDistanceNm NOTIFY infoChanged) |
| 63 | |
| 64 | Q_PROPERTY(int estimatedDurationMinutes READ estimatedDurationMinutes WRITE setEstimatedDurationMinutes NOTIFY infoChanged) |
| 65 | |
| 66 | Q_PROPERTY(QuantityValue cruiseAltitude READ cruiseAltitude WRITE setCruiseAltitude NOTIFY infoChanged) |
| 67 | Q_PROPERTY(QuantityValue cruiseSpeed READ cruiseSpeed WRITE setCruiseSpeed NOTIFY infoChanged) |
| 68 | |
| 69 | Q_PROPERTY(QmlPositioned* departure READ departure WRITE setDeparture NOTIFY infoChanged) |
| 70 | Q_PROPERTY(QmlPositioned* destination READ destination WRITE setDestination NOTIFY infoChanged) |
| 71 | Q_PROPERTY(QmlPositioned* alternate READ alternate WRITE setAlternate NOTIFY infoChanged) |
| 72 | |
| 73 | // equipment |
| 74 | public: |
| 75 | virtual ~FlightPlanController(); |
| 76 | |
| 77 | // alias these enums to QML |
| 78 | enum FlightRules |
| 79 | { |
| 80 | VFR = 0, |
| 81 | IFR, |
| 82 | IFR_VFR, |
| 83 | VFR_IFR |
| 84 | }; |
| 85 | |
| 86 | enum FlightType |
| 87 | { |
| 88 | Scheduled = 0, |
| 89 | NonScheduled, |
| 90 | GeneralAviation, |
| 91 | Military, |
| 92 | Other |
| 93 | }; |
| 94 | |
| 95 | explicit FlightPlanController(QObject *parent, |
| 96 | LaunchConfig* config); |
| 97 | |
| 98 | bool loadFromPath(QString path); |
| 99 | bool saveToPath(QString path) const; |
| 100 | |
| 101 | QuantityValue cruiseAltitude() const; |
| 102 | void setCruiseAltitude(QuantityValue alt); |
| 103 | |
| 104 | QString description() const; |
| 105 | |
| 106 | QmlPositioned* departure() const; |
| 107 | QmlPositioned* destination() const; |
| 108 | QmlPositioned* alternate() const; |
| 109 | |
| 110 | QuantityValue cruiseSpeed() const; |
| 111 | |
| 112 | FlightRules flightRules() const; |
| 113 | FlightType flightType() const; |
| 114 | |
| 115 | QString callsign() const; |
| 116 | QString remarks() const; |
| 117 | QString aircraftType() const; |
| 118 | |
| 119 | int estimatedDurationMinutes() const; |
| 120 | QuantityValue totalDistanceNm() const; |
| 121 | |
| 122 | Q_INVOKABLE bool tryParseRoute(QString routeDesc); |
| 123 | |
| 124 | Q_INVOKABLE bool tryGenerateRoute(); |
| 125 | Q_INVOKABLE void clearRoute(); |
| 126 | |
| 127 | LegsModel* legs() const |
| 128 | { return _legs; } |
| 129 | |
| 130 | QString icaoRoute() const; |
| 131 | |
| 132 | flightgear::FlightPlanRef flightplan() const |
| 133 | { return _fp; } |
| 134 | |
| 135 | Q_INVOKABLE bool loadPlan(); |
| 136 | signals: |
| 137 | void infoChanged(); |
| 138 | void waypointsChanged(); |
| 139 | |
| 140 | void enabledChanged(bool enabled); |
| 141 | void descriptionChanged(QString description); |
| 142 | |
| 143 | public slots: |
| 144 | |
| 145 | void setFlightType(FlightType ty); |
| 146 | void setFlightRules(FlightRules r); |
| 147 | |
| 148 | void setCallsign(QString s); |
| 149 | void setRemarks(QString r); |
| 150 | void setAircraftType(QString ty); |
| 151 | |
| 152 | void setDeparture(QmlPositioned* destinationAirport); |
| 153 | void setDestination(QmlPositioned* destinationAirport); |
| 154 | void setAlternate(QmlPositioned* apt); |
| 155 | |
| 156 | void setCruiseSpeed(QuantityValue cruiseSpeed); |
| 157 | |
| 158 | void setEstimatedDurationMinutes(int mins); |
| 159 | |
| 160 | void computeDuration(); |
| 161 | |
| 162 | void clearPlan(); |
| 163 | void savePlan(); |
| 164 | private slots: |
| 165 | void onCollectConfig(); |
| 166 | void onSave(); |
| 167 | void onRestore(); |
| 168 | |
| 169 | private: |
| 170 | friend class FPDelegate; |
| 171 | |
| 172 | flightgear::FlightPlanRef _fp; |
| 173 | LegsModel* _legs = nullptr; |
| 174 | std::unique_ptr<FPDelegate> _delegate; |
| 175 | LaunchConfig* _config = nullptr; |
| 176 | bool _enabled = false; |
| 177 | }; |
| 178 | |
| 179 | #endif // FLIGHTPLANCONTROLLER_HXX |