Skip to content

Commit

Permalink
Stress test code, added extra safeguards
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Kebekus committed Apr 18, 2020
1 parent 04a1c0b commit 172ca2a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 68 deletions.
17 changes: 16 additions & 1 deletion src/GeoMapProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ QList<QObject*> GeoMapProvider::airspaces(const QGeoCoordinate& position)

QList<Airspace*> result;
foreach(auto airspace, _airspaces_) {
if (airspace.isNull()) // Paranoid safety
continue;
if (airspace->polygon().contains(position))
result.append(airspace);
}
Expand Down Expand Up @@ -114,6 +116,8 @@ QList<QObject*> GeoMapProvider::filteredWaypointObjects(const QString &filter)

QList<QObject*> result;
foreach(auto wp, wps) {
if (wp.isNull())
continue;
bool allWordsFound = true;
foreach(auto word, filterWords) {
QString fullName = simplifySpecialChars(wp->get("NAM").toString());
Expand All @@ -139,6 +143,8 @@ QList<QObject*> GeoMapProvider::nearbyAirfields(const QGeoCoordinate& position)

QList<Waypoint*> ADs;
foreach(auto wp, wps) {
if (wp.isNull())
continue;
if (!wp->get("CAT").toString().startsWith("AD"))
continue;
ADs.append(wp);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
23 changes: 23 additions & 0 deletions src/qml/pages/FlightRouteAddWPPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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("<h3>Sorry!</h3><p>No waypoints available. Please make sure that an aviation map is installed.</p>")
onLinkActivated: Qt.openUrlExternally(link)
}
}

} // Page
70 changes: 3 additions & 67 deletions src/qml/pages/FlightRoutePage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -365,82 +365,18 @@ Page {
}
}


// Add ToolButton to central application header when this page is shown
Component.onCompleted: {
headerMenuToolButton.visible = true
headerMenu.insertAction(0, reverseAction)
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

Expand Down
20 changes: 20 additions & 0 deletions src/qml/pages/NearbyAirfields.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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("<h3>Sorry!</h3><p>No airfields available. Please make sure that an aviation map is installed.</p>")
onLinkActivated: Qt.openUrlExternally(link)
}
}

} // Page

0 comments on commit 172ca2a

Please sign in to comment.