diff --git a/src/GeoMapProvider.cpp b/src/GeoMapProvider.cpp index bac565344..89664bdfc 100644 --- a/src/GeoMapProvider.cpp +++ b/src/GeoMapProvider.cpp @@ -85,6 +85,8 @@ QList GeoMapProvider::airspaces(const QGeoCoordinate& position) QList result; foreach(auto airspace, _airspaces_) { + if (airspace.isNull()) // Paranoid safety + continue; if (airspace->polygon().contains(position)) result.append(airspace); } @@ -114,6 +116,8 @@ QList GeoMapProvider::filteredWaypointObjects(const QString &filter) QList result; foreach(auto wp, wps) { + if (wp.isNull()) + continue; bool allWordsFound = true; foreach(auto word, filterWords) { QString fullName = simplifySpecialChars(wp->get("NAM").toString()); @@ -139,6 +143,8 @@ QList GeoMapProvider::nearbyAirfields(const QGeoCoordinate& position) QList ADs; foreach(auto wp, wps) { + if (wp.isNull()) + continue; if (!wp->get("CAT").toString().startsWith("AD")) continue; ADs.append(wp); @@ -246,7 +252,6 @@ void GeoMapProvider::fillAviationDataCache(const QStringList& JSONFileNames, boo newFeatures += object; // Check if the current object is a waypoint. If so, add it to the list of waypoints. - // Comment: the list waypoints is used as a model in QML. I am unsure what happens if they get deleted while QML is still using them. I have therefore chosen to not delete them at all. This introduced a minor memory inefficiency when GeoJSON files get upated. auto wp = new Waypoint(object); if (wp->isValid()) { QQmlEngine::setObjectOwnership(wp, QQmlEngine::CppOwnership); @@ -273,6 +278,16 @@ void GeoMapProvider::fillAviationDataCache(const QStringList& JSONFileNames, boo std::sort(newWaypoints.begin(), newWaypoints.end(), [](Waypoint* a, Waypoint* b) {return a->get("NAM").toString() < b->get("NAM").toString(); }); _aviationDataMutex.lock(); + foreach(auto airspace, _airspaces_) { + if (airspace.isNull()) + continue; + airspace->deleteLater(); + } + foreach(auto waypoint, _waypoints_) { + if (waypoint.isNull()) + continue; + waypoint->deleteLater(); + } _airspaces_ = newAirspaces; _waypoints_ = newWaypoints; _combinedGeoJSON_ = geoDoc.toJson(QJsonDocument::JsonFormat::Compact); diff --git a/src/qml/pages/FlightRouteAddWPPage.qml b/src/qml/pages/FlightRouteAddWPPage.qml index 4cca721dd..e105929d0 100644 --- a/src/qml/pages/FlightRouteAddWPPage.qml +++ b/src/qml/pages/FlightRouteAddWPPage.qml @@ -84,4 +84,27 @@ Page { ScrollIndicator.vertical: ScrollIndicator {} } + Rectangle { + anchors.top: textInput.bottom + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right + + color: "white" + visible: wpList.count === 0 + + Label { + anchors.left: parent.left + anchors.right: parent.right + anchors.top: parent.top + anchors.topMargin: Qt.application.font.pixelSize*2 + + horizontalAlignment: Text.AlignHCenter + textFormat: Text.RichText + wrapMode: Text.Wrap + text: qsTr("

Sorry!

No waypoints available. Please make sure that an aviation map is installed.

") + onLinkActivated: Qt.openUrlExternally(link) + } + } + } // Page diff --git a/src/qml/pages/FlightRoutePage.qml b/src/qml/pages/FlightRoutePage.qml index 512eaefc4..0d831923c 100644 --- a/src/qml/pages/FlightRoutePage.qml +++ b/src/qml/pages/FlightRoutePage.qml @@ -365,7 +365,6 @@ Page { } } - // Add ToolButton to central application header when this page is shown Component.onCompleted: { headerMenuToolButton.visible = true @@ -373,74 +372,11 @@ Page { headerMenu.insertAction(1, clearAction) } Component.onDestruction: { - if (Qt.platform.os === "android") { - headerMenuToolButton.visible = false - headerMenu.removeAction(reverseAction) - headerMenu.removeAction(clearAction) - headerMenu.removeAction(importAction) - headerMenu.removeAction(saveAction) - headerMenu.removeAction(openWithAction) - headerMenu.removeAction(shareAction) - } else { - headerMenuToolButton.visible = false - headerMenu.removeAction(reverseAction) - headerMenu.removeAction(clearAction) -/* - headerMenu.removeAction(desktopImportAction) - headerMenu.removeAction(desktopSaveAction) - */ - } - } - - /* - FileDialog { - - id: importFileDialog - title: "Please choose a gpx file" - fileMode: FileDialog.OpenFile - nameFilters: ["gpx files (*.gpx)"] - defaultSuffix: "gpx" - folder: folderSettings.openFolder - onAccepted: { - flightRoute.fromGpx(String(importFileDialog.file)) - folderSettings.openFolder = importFileDialog.folder - } - onRejected: { - // do nothing - } - } -*/ - - // on desktop used only - // - function saveFile(fileUrl, text) { - var request = new XMLHttpRequest(); - request.open("PUT", fileUrl, false); - request.send(text); - return request.status; + headerMenuToolButton.visible = false + headerMenu.removeAction(reverseAction) + headerMenu.removeAction(clearAction) } - // on desktop used only - // - /* - FileDialog { - - id: saveFileDialog - title: "Please choose a gpx file" - fileMode: FileDialog.SaveFile - nameFilters: ["gpx files (*.gpx)"] - defaultSuffix: "gpx" - folder: folderSettings.saveFolder - onAccepted: { - // console.log("saveFileDialog path = " + saveFileDialog.file) - folderSettings.saveFolder = saveFileDialog.folder - saveFile(saveFileDialog.file, flightRoute.toGpx()) - } - onRejected: { - // do nothing - } - } -*/ Action { id: reverseAction diff --git a/src/qml/pages/NearbyAirfields.qml b/src/qml/pages/NearbyAirfields.qml index 00ea5d174..feecbb3e2 100644 --- a/src/qml/pages/NearbyAirfields.qml +++ b/src/qml/pages/NearbyAirfields.qml @@ -68,4 +68,24 @@ Page { Component.onCompleted: wpList.model = geoMapProvider.nearbyAirfields(satNav.lastValidCoordinate) } + Rectangle { + anchors.fill: parent + + color: "white" + visible: wpList.count === 0 + + Label { + anchors.left: parent.left + anchors.right: parent.right + anchors.top: parent.top + anchors.topMargin: Qt.application.font.pixelSize*2 + + horizontalAlignment: Text.AlignHCenter + textFormat: Text.RichText + wrapMode: Text.Wrap + text: qsTr("

Sorry!

No airfields available. Please make sure that an aviation map is installed.

") + onLinkActivated: Qt.openUrlExternally(link) + } + } + } // Page