mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-12 00:06:43 -04:00
[MetaSearch] allow for overwriting OWS connections, or assiging to serialized string
This commit is contained in:
parent
8561b45b1d
commit
ff52a0504e
@ -52,7 +52,8 @@ from MetaSearch.dialogs.recorddialog import RecordDialog
|
||||
from MetaSearch.dialogs.xmldialog import XMLDialog
|
||||
from MetaSearch.util import (get_connections_from_file, get_ui_class,
|
||||
get_help_url, highlight_xml, normalize_text,
|
||||
open_url, render_template, StaticContext)
|
||||
open_url, render_template, serialize_string,
|
||||
StaticContext)
|
||||
|
||||
BASE_CLASS = get_ui_class('maindialog.ui')
|
||||
|
||||
@ -648,6 +649,8 @@ class MetaSearchDialog(QDialog, BASE_CLASS):
|
||||
def add_to_ows(self):
|
||||
"""add to OWS provider connection list"""
|
||||
|
||||
conn_name_matches = []
|
||||
|
||||
item = self.treeRecords.currentItem()
|
||||
|
||||
if not item:
|
||||
@ -678,13 +681,19 @@ class MetaSearchDialog(QDialog, BASE_CLASS):
|
||||
keys = self.settings.childGroups()
|
||||
self.settings.endGroup()
|
||||
|
||||
for key in keys:
|
||||
if key.startswith(sname):
|
||||
conn_name_matches.append(key)
|
||||
if conn_name_matches:
|
||||
sname = matches[-1]
|
||||
|
||||
# check for duplicates
|
||||
if sname in keys:
|
||||
msg = self.tr('Connection %s exists. Overwrite?') % sname
|
||||
res = QMessageBox.warning(self, self.tr('Saving server'), msg,
|
||||
QMessageBox.Yes | QMessageBox.No)
|
||||
if res != QMessageBox.Yes:
|
||||
return
|
||||
if res != QMessageBox.Yes: # assign new name with serial
|
||||
sname = serialize_string(sname)
|
||||
|
||||
# no dups detected or overwrite is allowed
|
||||
self.settings.beginGroup('/Qgis/connections-%s' % stype[1])
|
||||
|
@ -146,3 +146,19 @@ def normalize_text(text):
|
||||
"""tidy up string"""
|
||||
|
||||
return text.replace('\n', '')
|
||||
|
||||
|
||||
def serialize_string(input_string):
|
||||
"""apply a serial counter to a string"""
|
||||
|
||||
s = input_string.strip().split()
|
||||
|
||||
last_token = s[-1]
|
||||
all_other_tokens_as_string = input_string.replace(last_token, '')
|
||||
|
||||
if last_token.isdigit():
|
||||
value = '%s%s' % (all_other_tokens_as_string, int(last_token) + 1)
|
||||
else:
|
||||
value = '%s 1' % input_string
|
||||
|
||||
return value
|
||||
|
Loading…
x
Reference in New Issue
Block a user