From df7b763eab5f42c570eacd22468e8e427d6f0c12 Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Thu, 16 Feb 2023 11:00:30 +0000 Subject: [PATCH] Optionally reenamable smoothing on 2D maps, as 16 MSAA isn't always available --- plugins/channelrx/demodadsb/adsbdemodgui.cpp | 13 ++++++++--- plugins/channelrx/demodadsb/map/map.qml | 17 +++++++------- plugins/feature/map/map/map.qml | 14 ++++++------ plugins/feature/map/mapgui.cpp | 13 ++++++++--- sdrbase/settings/mainsettings.h | 7 ++++++ sdrbase/settings/preferences.cpp | 5 +++- sdrbase/settings/preferences.h | 9 ++++++-- sdrgui/gui/graphicsdialog.cpp | 2 ++ sdrgui/gui/graphicsdialog.ui | 24 +++++++++++++++++++- 9 files changed, 79 insertions(+), 25 deletions(-) diff --git a/plugins/channelrx/demodadsb/adsbdemodgui.cpp b/plugins/channelrx/demodadsb/adsbdemodgui.cpp index 446ce3f46..3fe544f6f 100644 --- a/plugins/channelrx/demodadsb/adsbdemodgui.cpp +++ b/plugins/channelrx/demodadsb/adsbdemodgui.cpp @@ -4492,6 +4492,7 @@ void ADSBDemodGUI::applyMapSettings() } // Create the map using the specified provider + QQmlProperty::write(item, "smoothing", MainCore::instance()->getSettings().getMapSmoothing()); QQmlProperty::write(item, "mapProvider", m_settings.m_mapProvider); QVariantMap parameters; QString mapType; @@ -4619,7 +4620,8 @@ ADSBDemodGUI::ADSBDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, Baseb connect(rollupContents, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); // Enable MSAA antialiasing on 2D map - // This is much faster than using layer.smooth in the QML, when there are many items + // This can be much faster than using layer.smooth in the QML, when there are many items + // However, only seems to work when set to 16, and doesn't seem to be supported on all graphics cards int multisamples = MainCore::instance()->getSettings().getMapMultisampling(); if (multisamples > 0) { @@ -4628,7 +4630,7 @@ ADSBDemodGUI::ADSBDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, Baseb ui->map->setFormat(format); } - m_osmPort = 0; // Pick a free port + m_osmPort = 0; // Pick a free port m_templateServer = new ADSBOSMTemplateServer("q2RVNAe3eFKCH4XsrE3r", m_osmPort); ui->map->setAttribute(Qt::WA_AcceptTouchEvents, true); @@ -5726,7 +5728,7 @@ void ADSBDemodGUI::preferenceChanged(int elementType) } } } - if (pref == Preferences::StationName) + else if (pref == Preferences::StationName) { // Update icon label on Map QQuickItem *item = ui->map->rootObject(); @@ -5739,6 +5741,11 @@ void ADSBDemodGUI::preferenceChanged(int elementType) } } } + else if (pref == Preferences::MapSmoothing) + { + QQuickItem *item = ui->map->rootObject(); + QQmlProperty::write(item, "smoothing", MainCore::instance()->getSettings().getMapSmoothing()); + } } void ADSBDemodGUI::initAviationWeather() diff --git a/plugins/channelrx/demodadsb/map/map.qml b/plugins/channelrx/demodadsb/map/map.qml index 78cdbe368..54d491261 100644 --- a/plugins/channelrx/demodadsb/map/map.qml +++ b/plugins/channelrx/demodadsb/map/map.qml @@ -14,6 +14,7 @@ Item { property string requestedMapType property bool lightIcons property variant guiPtr + property bool smoothing function createMap(pluginParameters, requestedMap, gui) { requestedMapType = requestedMap @@ -140,8 +141,8 @@ Item { Grid { horizontalItemAlignment: Grid.AlignHCenter columnSpacing: 5 - //layer.enabled: true - //layer.smooth: true + layer.enabled: smoothing + layer.smooth: smoothing Image { id: image source: navAidImage @@ -206,8 +207,8 @@ Item { sourceItem: Grid { columns: 1 Grid { - //layer.enabled: true - //layer.smooth: true + layer.enabled: smoothing + layer.smooth: smoothing horizontalItemAlignment: Grid.AlignHCenter Text { id: airspaceText @@ -239,8 +240,8 @@ Item { sourceItem: Grid { columns: 1 Grid { - //layer.enabled: true - //layer.smooth: true + layer.enabled: smoothing + layer.smooth: smoothing horizontalItemAlignment: Grid.AlignHCenter Image { id: image @@ -334,8 +335,8 @@ Item { columns: 1 Grid { horizontalItemAlignment: Grid.AlignHCenter - //layer.enabled: true - //layer.smooth: true + layer.enabled: smoothing + layer.smooth: smoothing Image { id: image source: airportImage diff --git a/plugins/feature/map/map/map.qml b/plugins/feature/map/map/map.qml index ab8c81775..c120bc871 100644 --- a/plugins/feature/map/map/map.qml +++ b/plugins/feature/map/map/map.qml @@ -10,6 +10,7 @@ Item { property string mapProvider: "osm" property variant mapPtr property variant guiPtr + property bool smoothing function createMap(pluginParameters, gui) { guiPtr = gui @@ -187,8 +188,8 @@ Item { sourceItem: Grid { columns: 1 Grid { - //layer.enabled: true - //layer.smooth: true + layer.enabled: smoothing + layer.smooth: smoothing horizontalItemAlignment: Grid.AlignHCenter Text { id: polygonText @@ -219,8 +220,8 @@ Item { sourceItem: Grid { columns: 1 Grid { - //layer.enabled: true - //layer.smooth: true + layer.enabled: smoothing + layer.smooth: smoothing horizontalItemAlignment: Grid.AlignHCenter Text { id: polylineText @@ -247,9 +248,8 @@ Item { Grid { horizontalItemAlignment: Grid.AlignHCenter columnSpacing: 5 - // This is very slow with lots of items, so we use MSAA for the whole map instead - //layer.enabled: true - //layer.smooth: true + layer.enabled: smoothing + layer.smooth: smoothing Image { id: image rotation: mapImageRotation diff --git a/plugins/feature/map/mapgui.cpp b/plugins/feature/map/mapgui.cpp index 70bbec72a..590a1a619 100644 --- a/plugins/feature/map/mapgui.cpp +++ b/plugins/feature/map/mapgui.cpp @@ -201,8 +201,9 @@ MapGUI::MapGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *featur rollupContents->arrangeRollups(); connect(rollupContents, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); - // Enable MSAA antialiasing on 2D map, otherwise text is not clear - // This is much faster than using layer.smooth in the QML, when there are many items + // Enable MSAA antialiasing on 2D map + // This can be much faster than using layer.smooth in the QML, when there are many items + // However, only seems to work when set to 16, and doesn't seem to be supported on all graphics cards int multisamples = MainCore::instance()->getSettings().getMapMultisampling(); if (multisamples > 0) { @@ -1041,6 +1042,7 @@ void MapGUI::applyMap2DSettings(bool reloadMap) } // Create the map using the specified provider + QQmlProperty::write(item, "smoothing", MainCore::instance()->getSettings().getMapSmoothing()); QQmlProperty::write(item, "mapProvider", m_settings.m_mapProvider); QVariantMap parameters; if (!m_settings.m_mapBoxAPIKey.isEmpty() && m_settings.m_mapProvider == "mapbox") @@ -1731,13 +1733,18 @@ void MapGUI::preferenceChanged(int elementType) } } } - if (pref == Preferences::StationName) + else if (pref == Preferences::StationName) { // Update station name m_antennaMapItem.setLabel(new QString(MainCore::instance()->getSettings().getStationName())); m_antennaMapItem.setText(new QString(MainCore::instance()->getSettings().getStationName())); update(m_map, &m_antennaMapItem, "Station"); } + else if (pref == Preferences::MapSmoothing) + { + QQuickItem *item = ui->map->rootObject(); + QQmlProperty::write(item, "smoothing", MainCore::instance()->getSettings().getMapSmoothing()); + } } void MapGUI::makeUIConnections() diff --git a/sdrbase/settings/mainsettings.h b/sdrbase/settings/mainsettings.h index b76b3c2f3..4807555d9 100644 --- a/sdrbase/settings/mainsettings.h +++ b/sdrbase/settings/mainsettings.h @@ -203,6 +203,13 @@ public: emit preferenceChanged(Preferences::MapMultisampling); } + bool getMapSmoothing() const { return m_preferences.getMapSmoothing(); } + void setMapSmoothing(bool smoothing) + { + m_preferences.setMapSmoothing(smoothing); + emit preferenceChanged(Preferences::MapSmoothing); + } + signals: void preferenceChanged(int); diff --git a/sdrbase/settings/preferences.cpp b/sdrbase/settings/preferences.cpp index 4f92f4ede..7670ca60f 100644 --- a/sdrbase/settings/preferences.cpp +++ b/sdrbase/settings/preferences.cpp @@ -23,7 +23,8 @@ void Preferences::resetToDefaults() m_consoleMinLogLevel = QtDebugMsg; m_fileMinLogLevel = QtDebugMsg; m_multisampling = 0; - m_mapMultisampling = 16; + m_mapMultisampling = 0; + m_mapSmoothing = true; } QByteArray Preferences::serialize() const @@ -45,6 +46,7 @@ QByteArray Preferences::serialize() const s.writeS32((int) Multisampling, m_multisampling); s.writeBool((int) AutoUpdatePosition, m_autoUpdatePosition); s.writeS32((int) MapMultisampling, m_mapMultisampling); + s.writeBool((int) MapSmoothing, m_mapSmoothing); return s.final(); } @@ -101,6 +103,7 @@ bool Preferences::deserialize(const QByteArray& data) d.readS32((int) Multisampling, &m_multisampling, 0); d.readBool((int) AutoUpdatePosition, &m_autoUpdatePosition, true); d.readS32((int) MapMultisampling, &m_mapMultisampling, 16); + d.readBool((int) MapSmoothing, &m_mapSmoothing, true); return true; } diff --git a/sdrbase/settings/preferences.h b/sdrbase/settings/preferences.h index 9298a5bda..2c521be8d 100644 --- a/sdrbase/settings/preferences.h +++ b/sdrbase/settings/preferences.h @@ -24,7 +24,8 @@ public: SourceItemIndex, Multisampling, AutoUpdatePosition, - MapMultisampling + MapMultisampling, + MapSmoothing }; Preferences(); @@ -83,6 +84,9 @@ public: int getMapMultisampling() const { return m_mapMultisampling; } void setMapMultisampling(int samples) { m_mapMultisampling = samples; } + bool getMapSmoothing() const { return m_mapSmoothing; } + void setMapSmoothing(bool smoothing) { m_mapSmoothing = smoothing; } + protected: QString m_sourceDevice; //!< Identification of the source used in R0 tab (GUI flavor) at startup int m_sourceIndex; //!< Index of the source used in R0 tab (GUI flavor) at startup @@ -103,7 +107,8 @@ protected: QString m_logFileName; int m_multisampling; //!< Number of samples to use for multisampling anti-aliasing for spectrums (typically 0 or 4) - int m_mapMultisampling; //!< Number of samples to use for multisampling anti-aliasing for 2D maps (16 gives best text) + int m_mapMultisampling; //!< Number of samples to use for multisampling anti-aliasing for 2D maps (16 gives best text, if not using mapSmoothing) + bool m_mapSmoothing; //!< Whether to use smoothing for text boxes on 2D maps }; #endif // INCLUDE_PREFERENCES_H diff --git a/sdrgui/gui/graphicsdialog.cpp b/sdrgui/gui/graphicsdialog.cpp index f4a821397..cc81c5962 100644 --- a/sdrgui/gui/graphicsdialog.cpp +++ b/sdrgui/gui/graphicsdialog.cpp @@ -38,6 +38,7 @@ GraphicsDialog::GraphicsDialog(MainSettings& mainSettings, QWidget* parent) : } else { ui->mapMultisampling->setCurrentText(QString::number(samples)); } + ui->mapSmoothing->setChecked(m_mainSettings.getMapSmoothing()); } GraphicsDialog::~GraphicsDialog() @@ -49,5 +50,6 @@ void GraphicsDialog::accept() { m_mainSettings.setMultisampling(ui->multisampling->currentText().toInt()); m_mainSettings.setMapMultisampling(ui->mapMultisampling->currentText().toInt()); + m_mainSettings.setMapSmoothing(ui->mapSmoothing->isChecked()); QDialog::accept(); } diff --git a/sdrgui/gui/graphicsdialog.ui b/sdrgui/gui/graphicsdialog.ui index f37a06b25..761658d73 100644 --- a/sdrgui/gui/graphicsdialog.ui +++ b/sdrgui/gui/graphicsdialog.ui @@ -7,7 +7,7 @@ 0 0 282 - 131 + 155 @@ -95,6 +95,11 @@ Requires windows to be reopened to take effect + + Number of samples to use for mulitsampling anti-aliasing (MSAA) for 2D Map + +Requires windows to be reopened to take effect + Off @@ -122,6 +127,23 @@ Requires windows to be reopened to take effect + + + + Whether smoothing should be enabled for text on 2D maps + + + + + + + + + + 2D Map Text Smoothing + + +