Skip to content

Commit

Permalink
Update MetaSearch with new settings API
Browse files Browse the repository at this point in the history
fixes #54144
  • Loading branch information
3nids authored and nyalldawson committed Aug 18, 2023
1 parent b35600f commit ff67437
Showing 1 changed file with 32 additions and 27 deletions.
59 changes: 32 additions & 27 deletions python/plugins/MetaSearch/dialogs/maindialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from qgis.core import (Qgis, QgsApplication, QgsCoordinateReferenceSystem,
QgsCoordinateTransform, QgsGeometry, QgsPointXY,
QgsProviderRegistry, QgsSettings, QgsProject,
QgsRectangle)
QgsRectangle, QgsSettingsTree)
from qgis.gui import QgsRubberBand, QgsGui
from qgis.utils import OverrideCursor

Expand Down Expand Up @@ -718,35 +718,45 @@ def add_to_ows(self):

caller = self.sender().objectName()

# stype = human name,/qgis/connections-%s,providername
if caller == 'mActionAddWms':
stype = ['OGC:WMS/OGC:WMTS', 'wms', 'wms']
service_type = 'OGC:WMS/OGC:WMTS'
sname = 'WMS'
dyn_param = ['wms']
provider_name = 'wms'
setting_node = QgsSettingsTree.node('connections').childNode('ows').childNode('connections')
data_url = item_data['wms']
elif caller == 'mActionAddWfs':
stype = ['OGC:WFS', 'wfs', 'WFS']
service_type = 'OGC:WFS'
sname = 'WFS'
dyn_param = ['wfs']
provider_name = 'WFS'
setting_node = QgsSettingsTree.node('connections').childNode('ows').childNode('connections')
data_url = item_data['wfs']
elif caller == 'mActionAddWcs':
stype = ['OGC:WCS', 'wcs', 'wcs']
service_type = 'OGC:WCS'
sname = 'WCS'
dyn_param = ['wcs']
provider_name = 'wcs'
setting_node = QgsSettingsTree.node('connections').childNode('ows').childNode('connections')
data_url = item_data['wcs']
elif caller == 'mActionAddAms':
stype = ['ESRI:ArcGIS:MapServer', 'ams', 'arcgismapserver']
# TODO: this doesn't exist anymore?
service_type = 'ESRI:ArcGIS:MapServer'
sname = 'AMS'
dyn_param = []
provider_name = 'arcgismapserver'
data_url = item_data['ams'].split('MapServer')[0] + 'MapServer'
elif caller == 'mActionAddAfs':
stype = ['ESRI:ArcGIS:FeatureServer', 'afs', 'arcgisfeatureserver']
data_url = (item_data['afs'].split('FeatureServer')[0] +
'FeatureServer')
service_type = 'ESRI:ArcGIS:FeatureServer'
sname = 'AFS'
dyn_param = []
provider_name = 'arcgisfeatureserver'
setting_node = QgsSettingsTree.node('connections').childNode('arcgisfeatureserver')
data_url = (item_data['afs'].split('FeatureServer')[0] + 'FeatureServer')

sname = '%s from MetaSearch' % stype[1]

# store connection
# check if there is a connection with same name
if caller in ['mActionAddAms', 'mActionAddAfs']:
self.settings.beginGroup('/qgis/connections-%s' % stype[2])
else:
self.settings.beginGroup('/qgis/connections-%s' % stype[1])
keys = self.settings.childGroups()
self.settings.endGroup()
keys = setting_node.items(dyn_param)

sname = '%s from MetaSearch' % sname
for key in keys:
if key.startswith(sname):
conn_name_matches.append(key)
Expand All @@ -765,19 +775,14 @@ def add_to_ows(self):
return

# no dups detected or overwrite is allowed
if caller in ['mActionAddAms', 'mActionAddAfs']:
self.settings.beginGroup('/qgis/connections-%s' % stype[2])
else:
self.settings.beginGroup('/qgis/connections-%s' % stype[1])
self.settings.setValue('/%s/url' % sname, clean_ows_url(data_url))
self.settings.endGroup()
dyn_param.append(sname)
setting_node.childSetting('url').setValue(clean_ows_url(data_url), dyn_param)

# open provider window
ows_provider = QgsGui.sourceSelectProviderRegistry().\
createSelectionWidget(
stype[2], self, Qt.Widget,
provider_name, self, Qt.Widget,
QgsProviderRegistry.WidgetMode.Embedded)
service_type = stype[0]

# connect dialog signals to iface slots
if service_type == 'OGC:WMS/OGC:WMTS':
Expand Down

0 comments on commit ff67437

Please sign in to comment.