Skip to content

Commit

Permalink
show/hide pois for favorites
Browse files Browse the repository at this point in the history
  • Loading branch information
janbar committed Oct 24, 2023
1 parent 35926e9 commit 6238f01
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 25 deletions.
12 changes: 12 additions & 0 deletions gui/controls2_515/ConfigureMap.qml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ PopOver {
}
}

MapCheckBox {
id: favorites
width: parent.width
color: styleMap.popover.foregroundColor
text: qsTr("Favorites")
checked: settings.showFavorites
onClicked: {
settings.showFavorites = !settings.showFavorites;
mainView.showFavorites = settings.showFavorites;
}
}

MapCheckBox {
id: showAltLanguage
width: parent.width
Expand Down
12 changes: 11 additions & 1 deletion gui/controls2_515/MapView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ MapPage {
flags.push({ "name": "daylight", "value": !nightView });
setStyleFlags(flags);
}

// show/hide favorite POIs
if (mainView.showFavorites)
overlayManager.showFavorites();
}

property QtObject mark: QtObject {
Expand Down Expand Up @@ -1163,13 +1167,19 @@ MapPage {
}
}

// On android disable navigation when the app is suspended
Connections {
target: mainView
function onApplicationSuspendedChanged() {
// On android disable navigation when the app is suspended
if ((Android || DeviceMobile) && applicationSuspended && navigation)
navigation = false;
}
function onShowFavoritesChanged() {
if (showFavorites)
overlayManager.showFavorites();
else
overlayManager.hideFavorites();
}
}

////////////////////////////////////////////////////////////////////////////
Expand Down
59 changes: 48 additions & 11 deletions gui/controls2_515/components/OverlayManager.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ QtObject {
// the map to handle
property Map map

property QtObject internal: QtObject {
property bool showFavorites: false
}

// add the route on the map
function addRoute(routeWay) {
var ovs = MapExtras.findOverlays("ROUTE", 0);
Expand Down Expand Up @@ -95,22 +99,22 @@ QtObject {
return true;
}

// add a way point on the map
function addWayPoint(id, lat, lon) {
var wpt = map.createOverlayNode("_waypoint");
wpt.addPoint(lat, lon);
wpt.name = "Pos: " + lat.toFixed(4) + " " + lon.toFixed(4);
var ovs = MapExtras.findOverlays("WAYPOINT", id);
// add a POI on the map
function addPOI(group, id, lat, lon, label, type) {
var poi = map.createOverlayNode(type);
poi.addPoint(lat, lon);
poi.name = label;
var ovs = MapExtras.findOverlays(group, id);
if (ovs.length > 0)
map.addOverlayObject(ovs[0], wpt);
map.addOverlayObject(ovs[0], poi);
else
map.addOverlayObject(MapExtras.addOverlay("WAYPOINT", id), wpt);
map.addOverlayObject(MapExtras.addOverlay(group, id), poi);
return true;
}

// remove a way point on the map
function removeWayPoint(id) {
var ovs = MapExtras.clearOverlays("WAYPOINT", id);
// remove a POI on the map
function removePOI(group, id) {
var ovs = MapExtras.clearOverlays(group, id);
ovs.forEach(function(e){ map.removeOverlayObject(e); });
MapExtras.releaseOverlayIds(ovs);
return true;
Expand Down Expand Up @@ -165,4 +169,37 @@ QtObject {
});
return true;
}

function addFavoritePOI(id) {
var poi = FavoritesModel.getById(id);
addPOI("FAVORITE", id, poi.lat, poi.lon, poi.label, "_waypoint_favorite");
}

function removeFavoritePOI(id) {
var ovs = MapExtras.clearOverlays("FAVORITE", id);
ovs.forEach(function(e){ map.removeOverlayObject(e); });
MapExtras.releaseOverlayIds(ovs);
}

function showFavorites() {
if (!internal.showFavorites) {
internal.showFavorites = true;
for (var i = 0; i < FavoritesModel.rowCount(); ++i) {
addFavoritePOI(FavoritesModel.get(i).id)
}
FavoritesModel.appended.connect(addFavoritePOI);
FavoritesModel.removed.connect(removeFavoritePOI);
}
}

function hideFavorites() {
if (internal.showFavorites) {
var keys = MapExtras.findOverlayKeys("FAVORITE");
keys.forEach(function(k){ removeFavoritePOI(k); });
FavoritesModel.appended.disconnect(addFavoritePOI);
FavoritesModel.removed.disconnect(removeFavoritePOI);
internal.showFavorites = false;
}
}

}
28 changes: 15 additions & 13 deletions gui/controls2_515/osmin.qml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ ApplicationWindow {

// Extra settings
property string styleFlags: "[]"
property bool showFavorites: true
}

Material.accent: Material.Grey
Expand Down Expand Up @@ -125,6 +126,9 @@ ApplicationWindow {
readonly property int queueBatchSize: 100
readonly property real minSizeGU: 44

// show/hide favorite POIs
property bool showFavorites: false

minimumHeight: units.gu(minSizeGU)
minimumWidth: units.gu(minSizeGU)

Expand Down Expand Up @@ -324,6 +328,8 @@ ApplicationWindow {
Osmin.Converter.southeast = qsTr("southeast");
Osmin.Converter.system = settings.systemOfUnits;
Osmin.Tracker.magneticDip = settings.magneticDip;

showFavorites = settings.showFavorites;
positionSource.active = true;
launcher.start();
}
Expand Down Expand Up @@ -397,21 +403,17 @@ ApplicationWindow {
//// Global requests
////

// Add a new favorite
// Add a new favorite and return its id
function createFavorite(lat, lon, label, type) {
var index = Osmin.FavoritesModel.append();
var id = Osmin.FavoritesModel.data(index, Osmin.FavoritesModel.IdRole)
Osmin.FavoritesModel.setData(index, lat, Osmin.FavoritesModel.LatRole);
Osmin.FavoritesModel.setData(index, lon, Osmin.FavoritesModel.LonRole);
Osmin.FavoritesModel.setData(index, 0.0, Osmin.FavoritesModel.AltRole);
Osmin.FavoritesModel.setData(index, new Date(), Osmin.FavoritesModel.TimestampRole);
Osmin.FavoritesModel.setData(index, label, Osmin.FavoritesModel.LabelRole);
if (type) // optional
Osmin.FavoritesModel.setData(index, type, Osmin.FavoritesModel.TypeRole);
if (Osmin.FavoritesModel.storeData())
return id;
var id = Osmin.FavoritesModel.append(lat, lon, label, type);
if (id > 0) {
if (Osmin.FavoritesModel.storeData())
return id;
Osmin.FavoritesModel.remove(id); // rollback
} else {
console.log("Failed to append new favorite: count " + Osmin.FavoritesModel.count + " item(s)");
}
mainInfo.open(qsTr("Saving change failed"));
Osmin.FavoritesModel.remove(id);
return 0;
}

Expand Down

0 comments on commit 6238f01

Please sign in to comment.