diff --git a/plugins/channelrx/demodadsb/adsbdemodsettings.cpp b/plugins/channelrx/demodadsb/adsbdemodsettings.cpp index 5561296c3..32bd5e779 100644 --- a/plugins/channelrx/demodadsb/adsbdemodsettings.cpp +++ b/plugins/channelrx/demodadsb/adsbdemodsettings.cpp @@ -92,8 +92,8 @@ void ADSBDemodSettings::resetToDefaults() m_logEnabled = false; m_airspaces = QStringList({"A", "D", "TMZ"}); m_airspaceRange = 500.0f; -#if QT_VERSION == QT_VERSION_CHECK(5, 15, 3) || QT_VERSION == QT_VERSION_CHECK(5, 15, 4) - m_mapProvider = "mapboxgl"; // osm maps do not work in Qt 5.15.3 - https://github.com/f4exb/sdrangel/issues/1169 +#ifdef LINUX + m_mapProvider = "mapboxgl"; // osm maps do not work in some versions of Linux https://github.com/f4exb/sdrangel/issues/1169 & 1369 #else m_mapProvider = "osm"; #endif @@ -315,8 +315,8 @@ bool ADSBDemodSettings::deserialize(const QByteArray& data) d.readBlob(60, &m_geometryBytes); d.readBool(61, &m_hidden, false); d.readString(62, &m_checkWXAPIKey, ""); -#if QT_VERSION == QT_VERSION_CHECK(5, 15, 3) || QT_VERSION == QT_VERSION_CHECK(5, 15, 4) - d.readString(63, &m_mapProvider, "mapboxgl"); // osm maps do not work in Qt 5.15.3/4 - https://github.com/f4exb/sdrangel/issues/1169 +#ifdef LINUX + d.readString(63, &m_mapProvider, "mapboxgl"); #else d.readString(63, &m_mapProvider, "osm"); #endif diff --git a/plugins/feature/map/mapsettings.cpp b/plugins/feature/map/mapsettings.cpp index b9eaff565..22e2bfd39 100644 --- a/plugins/feature/map/mapsettings.cpp +++ b/plugins/feature/map/mapsettings.cpp @@ -88,8 +88,8 @@ MapSettings::~MapSettings() void MapSettings::resetToDefaults() { m_displayNames = true; -#if QT_VERSION == QT_VERSION_CHECK(5, 15, 3) || QT_VERSION == QT_VERSION_CHECK(5, 15, 4) - m_mapProvider = "mapboxgl"; // osm maps do not work in Qt 5.15.3/4 - https://github.com/f4exb/sdrangel/issues/1169 +#ifdef LINUX + m_mapProvider = "mapboxgl"; // osm maps do not work in some versions of Linux https://github.com/f4exb/sdrangel/issues/1169 & 1369 #else m_mapProvider = "osm"; #endif @@ -183,8 +183,8 @@ bool MapSettings::deserialize(const QByteArray& data) QByteArray blob; d.readBool(1, &m_displayNames, true); -#if QT_VERSION == QT_VERSION_CHECK(5, 15, 3) || QT_VERSION == QT_VERSION_CHECK(5, 15, 4) - d.readString(2, &m_mapProvider, "mapboxgl"); // osm maps do not work in Qt 5.15.3/4 - https://github.com/f4exb/sdrangel/issues/1169 +#ifdef LINUX + d.readString(2, &m_mapProvider, "mapboxgl"); #else d.readString(2, &m_mapProvider, "osm"); #endif diff --git a/plugins/feature/vorlocalizer/map/map.qml b/plugins/feature/vorlocalizer/map/map.qml index 0d6eb0508..ba4448629 100644 --- a/plugins/feature/vorlocalizer/map/map.qml +++ b/plugins/feature/vorlocalizer/map/map.qml @@ -6,48 +6,84 @@ import QtPositioning 5.12 Item { id: qmlMap property int vorZoomLevel: 11 + property string mapProvider: "osm" + property variant mapPtr + property string requestedMapType + property variant guiPtr - Plugin { - id: mapPlugin - name: "osm" + function createMap(pluginParameters, requestedMap, gui) { + requestedMapType = requestedMap + guiPtr = gui + + var paramString = "" + for (var prop in pluginParameters) { + var parameter = 'PluginParameter { name: "' + prop + '"; value: "' + pluginParameters[prop] + '"}' + paramString = paramString + parameter + } + var pluginString = 'import QtLocation 5.12; Plugin{ name:"' + mapProvider + '"; ' + paramString + '}' + var plugin = Qt.createQmlObject (pluginString, qmlMap) + + if (mapPtr) { + // Objects aren't destroyed immediately, so don't call findChild("map") + mapPtr.destroy() + mapPtr = null + } + mapPtr = actualMapComponent.createObject(page) + mapPtr.plugin = plugin + mapPtr.forceActiveFocus() + return mapPtr } - Map { - id: map - objectName: "map" + Item { + id: page anchors.fill: parent - plugin: mapPlugin - center: QtPositioning.coordinate(51.5, 0.125) // London - zoomLevel: 10 + } + Component { + id: actualMapComponent - MapItemView { - model: vorModel - delegate: vorRadialComponent - } + Map { + id: map + objectName: "map" + anchors.fill: parent + plugin: mapPlugin + center: QtPositioning.coordinate(51.5, 0.125) // London + zoomLevel: 10 - MapStation { - id: station - objectName: "station" - stationName: "Home" - coordinate: QtPositioning.coordinate(51.5, 0.125) - } + MapItemView { + model: vorModel + delegate: vorRadialComponent + } - MapItemView { - model: vorModel - delegate: vorComponent - } + MapStation { + id: station + objectName: "station" + stationName: "Home" + } - onZoomLevelChanged: { - if (zoomLevel > 11) { - station.zoomLevel = zoomLevel - vorZoomLevel = zoomLevel - } else { - station.zoomLevel = 11 - vorZoomLevel = 11 + MapItemView { + model: vorModel + delegate: vorComponent + } + + onZoomLevelChanged: { + if (zoomLevel > 11) { + station.zoomLevel = zoomLevel + vorZoomLevel = zoomLevel + } else { + station.zoomLevel = 11 + vorZoomLevel = 11 + } + } + + onSupportedMapTypesChanged : { + for (var i = 0; i < supportedMapTypes.length; i++) { + if (requestedMapType == supportedMapTypes[i].name) { + activeMapType = supportedMapTypes[i] + } + } } } - } Component { diff --git a/plugins/feature/vorlocalizer/vorlocalizergui.cpp b/plugins/feature/vorlocalizer/vorlocalizergui.cpp index 7f8811f4a..b1af65edd 100644 --- a/plugins/feature/vorlocalizer/vorlocalizergui.cpp +++ b/plugins/feature/vorlocalizer/vorlocalizergui.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -844,6 +845,87 @@ void VORLocalizerGUI::onMenuDialogCalled(const QPoint &p) resetContextMenuType(); } +void VORLocalizerGUI::applyMapSettings() +{ + // Get station position + Real stationLatitude = MainCore::instance()->getSettings().getLatitude(); + Real stationLongitude = MainCore::instance()->getSettings().getLongitude(); + Real stationAltitude = MainCore::instance()->getSettings().getAltitude(); + m_azEl.setLocation(stationLatitude, stationLongitude, stationAltitude); + + QQuickItem *item = ui->map->rootObject(); + + QObject *object = item->findChild("map"); + QGeoCoordinate coords; + double zoom; + if (object != nullptr) + { + // Save existing position of map + coords = object->property("center").value(); + zoom = object->property("zoomLevel").value(); + } + else + { + // Center on my location when map is first opened + coords.setLatitude(stationLatitude); + coords.setLongitude(stationLongitude); + coords.setAltitude(stationAltitude); + zoom = 10.0; + } + + // Create the map using the specified provider + QQmlProperty::write(item, "mapProvider", m_settings.m_mapProvider); + QVariantMap parameters; + QString mapType; + + if (m_settings.m_mapProvider == "osm") { + mapType = "Street Map"; + } else if (m_settings.m_mapProvider == "mapboxgl") { + mapType = "mapbox://styles/mapbox/streets-v10"; + } + + QVariant retVal; + if (!QMetaObject::invokeMethod(item, "createMap", Qt::DirectConnection, + Q_RETURN_ARG(QVariant, retVal), + Q_ARG(QVariant, QVariant::fromValue(parameters)), + Q_ARG(QVariant, mapType), + Q_ARG(QVariant, QVariant::fromValue(this)))) + { + qCritical() << "VORLocalizerGUI::applyMapSettings - Failed to invoke createMap"; + } + 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)); + } + } + else + { + qDebug() << "VORLocalizerGUI::applyMapSettings - createMap returned a nullptr"; + } + + // Move antenna icon to My Position + QObject *stationObject = newMap->findChild("station"); + if(stationObject != NULL) + { + QGeoCoordinate coords = stationObject->property("coordinate").value(); + coords.setLatitude(stationLatitude); + coords.setLongitude(stationLongitude); + coords.setAltitude(stationAltitude); + stationObject->setProperty("coordinate", QVariant::fromValue(coords)); + stationObject->setProperty("stationName", QVariant::fromValue(MainCore::instance()->getSettings().getStationName())); + } + else + { + qDebug() << "VORLocalizerGUI::applyMapSettings - Couldn't find station"; + } +} + VORLocalizerGUI::VORLocalizerGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *feature, QWidget* parent) : FeatureGUI(parent), ui(new Ui::VORLocalizerGUI), @@ -886,36 +968,7 @@ VORLocalizerGUI::VORLocalizerGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISe connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); - // Get station position - Real stationLatitude = MainCore::instance()->getSettings().getLatitude(); - Real stationLongitude = MainCore::instance()->getSettings().getLongitude(); - Real stationAltitude = MainCore::instance()->getSettings().getAltitude(); - m_azEl.setLocation(stationLatitude, stationLongitude, stationAltitude); - - // Centre map at My Position - QQuickItem *item = ui->map->rootObject(); - QObject *object = item->findChild("map"); - - if (object) - { - QGeoCoordinate coords = object->property("center").value(); - coords.setLatitude(stationLatitude); - coords.setLongitude(stationLongitude); - object->setProperty("center", QVariant::fromValue(coords)); - } - - // Move antenna icon to My Position to start with - QObject *stationObject = item->findChild("station"); - - if (stationObject) - { - QGeoCoordinate coords = stationObject->property("coordinate").value(); - coords.setLatitude(stationLatitude); - coords.setLongitude(stationLongitude); - coords.setAltitude(stationAltitude); - stationObject->setProperty("coordinate", QVariant::fromValue(coords)); - stationObject->setProperty("stationName", QVariant::fromValue(MainCore::instance()->getSettings().getStationName())); - } + applyMapSettings(); // Read in VOR information if it exists readNavAids(); diff --git a/plugins/feature/vorlocalizer/vorlocalizergui.h b/plugins/feature/vorlocalizer/vorlocalizergui.h index d0785a077..e877a9da7 100644 --- a/plugins/feature/vorlocalizer/vorlocalizergui.h +++ b/plugins/feature/vorlocalizer/vorlocalizergui.h @@ -268,6 +268,7 @@ private: void updateVORs(); void readNavAids(); void updateChannelList(); + void applyMapSettings(); private slots: void on_startStop_toggled(bool checked); diff --git a/plugins/feature/vorlocalizer/vorlocalizersettings.cpp b/plugins/feature/vorlocalizer/vorlocalizersettings.cpp index a6e4da6c7..fb27423f0 100644 --- a/plugins/feature/vorlocalizer/vorlocalizersettings.cpp +++ b/plugins/feature/vorlocalizer/vorlocalizersettings.cpp @@ -42,6 +42,11 @@ void VORLocalizerSettings::resetToDefaults() m_reverseAPIFeatureSetIndex = 0; m_reverseAPIFeatureIndex = 0; m_workspaceIndex = 0; +#ifdef LINUX + m_mapProvider = "mapboxgl"; // osm maps do not work in some versions of Linux https://github.com/f4exb/sdrangel/issues/1169 & 1369 +#else + m_mapProvider = "osm"; +#endif for (int i = 0; i < VORDEMOD_COLUMNS; i++) { @@ -71,6 +76,7 @@ QByteArray VORLocalizerSettings::serialize() const s.writeS32(20, m_workspaceIndex); s.writeBlob(21, m_geometryBytes); + s.writeString(22, m_mapProvider); for (int i = 0; i < VORDEMOD_COLUMNS; i++) { s.writeS32(100 + i, m_columnIndexes[i]); @@ -128,6 +134,11 @@ bool VORLocalizerSettings::deserialize(const QByteArray& data) d.readS32(20, &m_workspaceIndex, 0); d.readBlob(21, &m_geometryBytes); +#ifdef LINUX + d.readString(22, &m_mapProvider, "mapboxgl"); +#else + d.readString(22, &m_mapProvider, "osm"); +#endif for (int i = 0; i < VORDEMOD_COLUMNS; i++) { d.readS32(100 + i, &m_columnIndexes[i], i); diff --git a/plugins/feature/vorlocalizer/vorlocalizersettings.h b/plugins/feature/vorlocalizer/vorlocalizersettings.h index 0c50e3beb..359d9c9db 100644 --- a/plugins/feature/vorlocalizer/vorlocalizersettings.h +++ b/plugins/feature/vorlocalizer/vorlocalizersettings.h @@ -76,6 +76,7 @@ struct VORLocalizerSettings Serializable *m_rollupState; int m_workspaceIndex; QByteArray m_geometryBytes; + QString m_mapProvider; static const int VORDEMOD_COLUMNS = 10; static const int VOR_COL_NAME = 0;