diff --git a/src/GUI/FlightPlanController.cxx b/src/GUI/FlightPlanController.cxx index 295812942..97c9a579f 100644 --- a/src/GUI/FlightPlanController.cxx +++ b/src/GUI/FlightPlanController.cxx @@ -204,6 +204,9 @@ void FlightPlanController::clearPlan() _fp->addDelegate(_delegate.get()); _legs->setFlightPlan(fp); emit infoChanged(); + + _enabled = false; + emit enabledChanged(_enabled); } bool FlightPlanController::loadFromPath(QString path) @@ -220,6 +223,9 @@ bool FlightPlanController::loadFromPath(QString path) _fp->addDelegate(_delegate.get()); _legs->setFlightPlan(fp); + _enabled = true; + emit enabledChanged(_enabled); + // notify that everything changed emit infoChanged(); return true; @@ -233,6 +239,9 @@ bool FlightPlanController::saveToPath(QString path) const void FlightPlanController::onCollectConfig() { + if (!_enabled) + return; + SGPath p = globals->get_fg_home() / "launcher.fgfp"; _fp->save(p); @@ -248,6 +257,9 @@ void FlightPlanController::onSave() void FlightPlanController::onRestore() { + _enabled = _config->getValueForKey("", "fp-enabled", false).toBool(); + emit enabledChanged(_enabled); + std::string planXML = _config->getValueForKey("", "fp", QString()).toString().toStdString(); if (!planXML.empty()) { std::istringstream ss(planXML); diff --git a/src/GUI/FlightPlanController.hxx b/src/GUI/FlightPlanController.hxx index 8505d36f7..30fa5dae6 100644 --- a/src/GUI/FlightPlanController.hxx +++ b/src/GUI/FlightPlanController.hxx @@ -18,6 +18,8 @@ class FlightPlanController : public QObject { Q_OBJECT + Q_PROPERTY(bool enabled MEMBER _enabled NOTIFY enabledChanged) + Q_PROPERTY(QString callsign READ callsign WRITE setCallsign NOTIFY infoChanged) Q_PROPERTY(QString remarks READ remarks WRITE setRemarks NOTIFY infoChanged) Q_PROPERTY(QString aircraftType READ aircraftType WRITE setAircraftType NOTIFY infoChanged) @@ -110,6 +112,8 @@ signals: void infoChanged(); void waypointsChanged(); + void enabledChanged(bool enabled); + public slots: void setFlightType(FlightType ty); @@ -143,6 +147,7 @@ private: LegsModel* _legs = nullptr; std::unique_ptr _delegate; LaunchConfig* _config = nullptr; + bool _enabled = false; }; #endif // FLIGHTPLANCONTROLLER_HXX diff --git a/src/GUI/qml/FlightPlan.qml b/src/GUI/qml/FlightPlan.qml index 4f430ce38..40e46d2b2 100644 --- a/src/GUI/qml/FlightPlan.qml +++ b/src/GUI/qml/FlightPlan.qml @@ -36,9 +36,19 @@ Item { Row { width: parent.width spacing: Style.margin - height: childrenRect.height + height: loadButton.height + + ToggleSwitch { + label: qsTr("Fly with a flight-plan") + checked: _launcher.flightPlan.enabled + function toggle(newChecked) { + _launcher.flightPlan.enabled = newChecked + } + anchors.verticalCenter: parent.verticalCenter + } Button { + id: loadButton text: qsTr("Load"); onClicked: { var ok = _launcher.flightPlan.loadPlan();