| 1 | // LocationController.hxx - GUI launcher dialog using Qt5 |
| 2 | // |
| 3 | // Written by James Turner, started October 2015. |
| 4 | // |
| 5 | // Copyright (C) 2015 James Turner <[email protected]> |
| 6 | // |
| 7 | // This program is free software; you can redistribute it and/or |
| 8 | // modify it under the terms of the GNU General Public License as |
| 9 | // published by the Free Software Foundation; either version 2 of the |
| 10 | // License, or (at your option) any later version. |
| 11 | // |
| 12 | // This program is distributed in the hope that it will be useful, but |
| 13 | // WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | // General Public License for more details. |
| 16 | // |
| 17 | // You should have received a copy of the GNU General Public License |
| 18 | // along with this program; if not, write to the Free Software |
| 19 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | |
| 21 | #ifndef LOCATION_CONTROLLER_HXX |
| 22 | #define LOCATION_CONTROLLER_HXX |
| 23 | |
| 24 | #include <QObjectList> |
| 25 | |
| 26 | #include <Navaids/positioned.hxx> |
| 27 | #include <Airports/airports_fwd.hxx> |
| 28 | |
| 29 | #include "CarriersLocationModel.hxx" |
| 30 | #include "LaunchConfig.hxx" |
| 31 | #include "QmlPositioned.hxx" |
| 32 | #include "QtLauncher_fwd.hxx" |
| 33 | #include "UnitsModel.hxx" |
| 34 | |
| 35 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 36 | Q_MOC_INCLUDE("NavaidSearchModel.hxx") |
| 37 | Q_MOC_INCLUDE("QmlPositionedModel.hxx") |
| 38 | #endif |
| 39 | |
| 40 | class NavaidSearchModel; |
| 41 | class QmlPositionedModel; |
| 42 | class LocationController : public QObject |
| 43 | { |
| 44 | Q_OBJECT |
| 45 | |
| 46 | Q_PROPERTY(QString description READ description NOTIFY descriptionChanged) |
| 47 | |
| 48 | Q_PROPERTY(NavaidSearchModel* searchModel MEMBER m_searchModel CONSTANT) |
| 49 | Q_PROPERTY(CarriersLocationModel* carriersModel MEMBER m_carriersModel CONSTANT) |
| 50 | |
| 51 | Q_PROPERTY(QmlPositionedModel* airportRunways READ airportRunways CONSTANT) |
| 52 | Q_PROPERTY(QmlPositionedModel* airportParkings READ airportParkings CONSTANT) |
| 53 | Q_PROPERTY(QmlPositionedModel* airportHelipads READ airportHelipads CONSTANT) |
| 54 | |
| 55 | Q_PROPERTY(bool offsetEnabled READ offsetEnabled WRITE setOffsetEnabled NOTIFY offsetChanged) |
| 56 | Q_PROPERTY(QuantityValue offsetRadial READ offsetRadial WRITE setOffsetRadial NOTIFY offsetChanged) |
| 57 | Q_PROPERTY(QuantityValue offsetDistance READ offsetDistance WRITE setOffsetDistance NOTIFY offsetChanged) |
| 58 | |
| 59 | Q_PROPERTY(bool headingEnabled MEMBER m_headingEnabled NOTIFY configChanged) |
| 60 | Q_PROPERTY(bool speedEnabled MEMBER m_speedEnabled NOTIFY configChanged) |
| 61 | Q_PROPERTY(bool altitudeEnabled MEMBER m_altitudeEnabled NOTIFY configChanged) |
| 62 | |
| 63 | Q_PROPERTY(QuantityValue heading MEMBER m_heading NOTIFY configChanged) |
| 64 | Q_PROPERTY(QuantityValue altitude MEMBER m_altitude NOTIFY configChanged) |
| 65 | Q_PROPERTY(QuantityValue airspeed MEMBER m_airspeed NOTIFY configChanged) |
| 66 | Q_PROPERTY(bool onFinal READ onFinal WRITE setOnFinal NOTIFY configChanged) |
| 67 | |
| 68 | Q_PROPERTY(bool isAirportLocation READ isAirportLocation NOTIFY baseLocationChanged) |
| 69 | Q_PROPERTY(bool useActiveRunway READ useActiveRunway WRITE setUseActiveRunway NOTIFY configChanged) |
| 70 | Q_PROPERTY(bool useAvailableParking READ useAvailableParking WRITE setUseAvailableParking NOTIFY configChanged) |
| 71 | |
| 72 | Q_PROPERTY(bool tuneNAV1 READ tuneNAV1 WRITE setTuneNAV1 NOTIFY configChanged) |
| 73 | Q_PROPERTY(QmlGeod baseGeod READ baseGeod WRITE setBaseGeod NOTIFY baseLocationChanged) |
| 74 | |
| 75 | Q_PROPERTY(QmlPositioned* base READ baseLocation CONSTANT) |
| 76 | Q_PROPERTY(QmlPositioned* detail READ detail CONSTANT) |
| 77 | Q_PROPERTY(bool isBaseLatLon READ isBaseLatLon NOTIFY baseLocationChanged) |
| 78 | |
| 79 | Q_PROPERTY(bool isCarrier READ isCarrier NOTIFY baseLocationChanged) |
| 80 | Q_PROPERTY(QString carrier READ carrierName WRITE setCarrierLocation NOTIFY baseLocationChanged) |
| 81 | Q_PROPERTY(QStringList carrierParkings READ carrierParkings NOTIFY baseLocationChanged) |
| 82 | Q_PROPERTY(bool useCarrierFLOLS READ useCarrierFLOLS WRITE setUseCarrierFLOLS NOTIFY configChanged) |
| 83 | Q_PROPERTY(QString carrierParking READ carrierParking WRITE setCarrierParking NOTIFY configChanged) |
| 84 | Q_PROPERTY(bool abeam READ abeam WRITE setAbeam NOTIFY configChanged) |
| 85 | |
| 86 | |
| 87 | // allow collecting the location properties to be disabled, if the |
| 88 | // user is setting conflicting ones |
| 89 | Q_PROPERTY(bool skipFromArgs MEMBER m_skipFromArgs NOTIFY skipFromArgsChanged) |
| 90 | public: |
| 91 | explicit LocationController(QObject *parent = nullptr); |
| 92 | ~LocationController(); |
| 93 | |
| 94 | void setLaunchConfig(LaunchConfig* config); |
| 95 | |
| 96 | QString description() const; |
| 97 | |
| 98 | void setBaseLocation(FGPositionedRef ref); |
| 99 | |
| 100 | bool shouldStartPaused() const; |
| 101 | |
| 102 | void setLocationProperties(); |
| 103 | |
| 104 | void restoreLocation(QVariantMap l); |
| 105 | QVariantMap saveLocation() const; |
| 106 | |
| 107 | void restoreSearchHistory(); |
| 108 | |
| 109 | /// used to automatically select aircraft state |
| 110 | bool isParkedLocation() const; |
| 111 | |
| 112 | /// used to automatically select aircraft state |
| 113 | bool isAirborneLocation() const; |
| 114 | |
| 115 | QuantityValue offsetRadial() const; |
| 116 | |
| 117 | QuantityValue offsetDistance() const |
| 118 | { |
| 119 | return m_offsetDistance; |
| 120 | } |
| 121 | |
| 122 | Q_INVOKABLE void setBaseLocation(QmlPositioned* pos); |
| 123 | |
| 124 | Q_INVOKABLE void setDetailLocation(QmlPositioned* pos); |
| 125 | |
| 126 | QmlGeod baseGeod() const; |
| 127 | void setBaseGeod(QmlGeod geod); |
| 128 | |
| 129 | QString carrierName() const; |
| 130 | void setCarrierLocation(QString name); |
| 131 | |
| 132 | bool isAirportLocation() const; |
| 133 | |
| 134 | bool offsetEnabled() const |
| 135 | { |
| 136 | return m_offsetEnabled; |
| 137 | } |
| 138 | |
| 139 | bool onFinal() const |
| 140 | { |
| 141 | return m_onFinal; |
| 142 | } |
| 143 | |
| 144 | void setUseActiveRunway(bool b); |
| 145 | |
| 146 | bool useActiveRunway() const |
| 147 | { |
| 148 | return m_useActiveRunway; |
| 149 | } |
| 150 | |
| 151 | Q_INVOKABLE void addToRecent(QmlPositioned* pos); |
| 152 | |
| 153 | QmlPositionedModel* airportRunways() const |
| 154 | { |
| 155 | return m_runwaysModel; |
| 156 | } |
| 157 | |
| 158 | QmlPositionedModel* airportHelipads() const |
| 159 | { |
| 160 | return m_helipadsModel; |
| 161 | } |
| 162 | |
| 163 | QmlPositionedModel* airportParkings() const |
| 164 | { |
| 165 | return m_parkingsModel; |
| 166 | } |
| 167 | |
| 168 | Q_INVOKABLE void showHistoryInSearchModel(); |
| 169 | |
| 170 | Q_INVOKABLE QmlGeod parseStringAsGeod(QString string) const; |
| 171 | |
| 172 | QString carrierParking() const; |
| 173 | void setCarrierParking(QString name); |
| 174 | |
| 175 | bool tuneNAV1() const |
| 176 | { |
| 177 | return m_tuneNAV1; |
| 178 | } |
| 179 | |
| 180 | QmlPositioned* detail() const; |
| 181 | |
| 182 | QmlPositioned* baseLocation() const; |
| 183 | |
| 184 | bool useAvailableParking() const |
| 185 | { |
| 186 | return m_useAvailableParking; |
| 187 | } |
| 188 | |
| 189 | bool isBaseLatLon() const |
| 190 | { |
| 191 | return m_locationIsLatLon; |
| 192 | } |
| 193 | |
| 194 | QuantityValue altitude() const |
| 195 | { |
| 196 | return m_altitude; |
| 197 | } |
| 198 | |
| 199 | bool isCarrier() const |
| 200 | { |
| 201 | return m_locationIsCarrier; |
| 202 | } |
| 203 | |
| 204 | QStringList carrierParkings() const; |
| 205 | |
| 206 | bool useCarrierFLOLS() const |
| 207 | { |
| 208 | return m_useCarrierFLOLS; |
| 209 | } |
| 210 | |
| 211 | bool abeam() const |
| 212 | { |
| 213 | return m_abeam; |
| 214 | } |
| 215 | |
| 216 | public slots: |
| 217 | void setOffsetRadial(QuantityValue offsetRadial); |
| 218 | |
| 219 | void setOffsetDistance(QuantityValue offsetNm); |
| 220 | |
| 221 | void setOffsetEnabled(bool offsetEnabled); |
| 222 | |
| 223 | void setOnFinal(bool onFinal); |
| 224 | |
| 225 | void setTuneNAV1(bool tuneNAV1); |
| 226 | |
| 227 | void setUseAvailableParking(bool useAvailableParking); |
| 228 | |
| 229 | void setUseCarrierFLOLS(bool useCarrierFLOLS); |
| 230 | |
| 231 | void setAbeam(bool abeam); |
| 232 | |
| 233 | Q_SIGNALS: |
| 234 | void descriptionChanged(); |
| 235 | void offsetChanged(); |
| 236 | void baseLocationChanged(); |
| 237 | void configChanged(); |
| 238 | void skipFromArgsChanged(); |
| 239 | |
| 240 | private Q_SLOTS: |
| 241 | void onCollectConfig(); |
| 242 | void onRestoreCurrentLocation(); |
| 243 | void onSaveCurrentLocation(); |
| 244 | private: |
| 245 | void clearLocation(); |
| 246 | void updateAirportModels(); |
| 247 | |
| 248 | void onSearchComplete(); |
| 249 | void addToRecent(FGPositionedRef pos); |
| 250 | void setNavRadioOption(); |
| 251 | |
| 252 | void applyPositionOffset(); |
| 253 | void applyAltitude(); |
| 254 | void applyAirspeed(); |
| 255 | void applyOnFinal(); |
| 256 | |
| 257 | QString compassPointFromHeading(int heading) const; |
| 258 | |
| 259 | NavaidSearchModel* m_searchModel = nullptr; |
| 260 | CarriersLocationModel* m_carriersModel = nullptr; |
| 261 | |
| 262 | FGPositionedRef m_location; |
| 263 | FGAirportRef m_airportLocation; // valid if m_location is an FGAirport |
| 264 | FGPositionedRef m_detailLocation; // parking stand or runway detail |
| 265 | bool m_locationIsLatLon = false; |
| 266 | SGGeod m_geodLocation; |
| 267 | bool m_locationIsCarrier = false; |
| 268 | QString m_carrierName; |
| 269 | |
| 270 | FGPositionedList m_recentLocations; |
| 271 | LaunchConfig* m_config = nullptr; |
| 272 | QmlPositioned* m_detailQml = nullptr; |
| 273 | QmlPositioned* m_baseQml = nullptr; |
| 274 | |
| 275 | QmlPositionedModel* m_runwaysModel; |
| 276 | QmlPositionedModel* m_helipadsModel; |
| 277 | QmlPositionedModel* m_parkingsModel; |
| 278 | |
| 279 | bool m_offsetEnabled = false; |
| 280 | QuantityValue m_offsetRadial; |
| 281 | QuantityValue m_offsetDistance; |
| 282 | QuantityValue m_heading; |
| 283 | QuantityValue m_altitude; |
| 284 | QuantityValue m_airspeed; |
| 285 | |
| 286 | QuantityValue m_defaultAirspeed, m_defaultAltitude, |
| 287 | m_defaultHeading, m_defaultOffsetDistance, m_defaultOffsetRadial; |
| 288 | |
| 289 | bool m_onFinal = false; |
| 290 | bool m_useActiveRunway = true; |
| 291 | bool m_tuneNAV1 = false; |
| 292 | bool m_useAvailableParking; |
| 293 | bool m_headingEnabled = false; |
| 294 | bool m_speedEnabled = false; |
| 295 | bool m_altitudeEnabled = false; |
| 296 | bool m_skipFromArgs = false; |
| 297 | bool m_abeam; |
| 298 | |
| 299 | bool m_useCarrierFLOLS = false; |
| 300 | QString m_carrierParking; |
| 301 | QStringList m_carrierParkings; |
| 302 | }; |
| 303 | |
| 304 | #endif // LOCATION_CONTROLLER_HXX |