From 65e6f89214c45c3eea6422bd1d16677d2e707fc9 Mon Sep 17 00:00:00 2001 From: srcejon Date: Tue, 10 Jun 2025 18:03:57 +0100 Subject: [PATCH] Restore position of 2D map after changing settings. #2458 --- plugins/feature/map/mapgui.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/plugins/feature/map/mapgui.cpp b/plugins/feature/map/mapgui.cpp index 42c534c20..82c7fea28 100644 --- a/plugins/feature/map/mapgui.cpp +++ b/plugins/feature/map/mapgui.cpp @@ -1745,22 +1745,36 @@ void MapGUI::applyMap2DSettings(bool reloadMap) { qCritical() << "MapGUI::applyMap2DSettings - Failed to invoke createMap"; } + + supportedMapsChanged(); + QObject *newMap = retVal.value(); - // Restore position of map if (newMap != nullptr) { if (coords.isValid()) { - newMap->setProperty("zoomLevel", QVariant::fromValue(zoom)); - newMap->setProperty("center", QVariant::fromValue(coords)); + // Restore position of map + // With Qt5, we could set the properties immediately, but with Qt6, it seems we need a delay + // otherwise they are overwritten. Is there a signal we should use instead? + //newMap->setProperty("zoomLevel", QVariant::fromValue(zoom)); + //newMap->setProperty("center", QVariant::fromValue(coords)); + QTimer::singleShot(200, [this, zoom, coords]() { + QQuickItem *root = ui->map->rootObject(); + if (root) + { + QObject *mapObject = root->findChild("map"); + if (mapObject) { + mapObject->setProperty("zoomLevel", QVariant::fromValue(zoom)); + mapObject->setProperty("center", QVariant::fromValue(coords)); + } + } + }); } } else { qCritical() << "MapGUI::applyMap2DSettings - createMap returned a nullptr"; } - - supportedMapsChanged(); } } @@ -1824,6 +1838,7 @@ void MapGUI::orientationChanged(Qt::ScreenOrientation orientation) void MapGUI::displayToolbar() { ui->mapTypes->setVisible(m_settings.m_map2DEnabled); + // Replace buttons with menu when window gets narrow bool narrow = this->screen()->availableGeometry().width() < 400; ui->layersMenu->setVisible(narrow);