Skip to content

Commit ff52a05

Browse files
committed
[MetaSearch] allow for overwriting OWS connections, or assiging to serialized string
1 parent 8561b45 commit ff52a05

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

python/plugins/MetaSearch/dialogs/maindialog.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
from MetaSearch.dialogs.xmldialog import XMLDialog
5353
from MetaSearch.util import (get_connections_from_file, get_ui_class,
5454
get_help_url, highlight_xml, normalize_text,
55-
open_url, render_template, StaticContext)
55+
open_url, render_template, serialize_string,
56+
StaticContext)
5657

5758
BASE_CLASS = get_ui_class('maindialog.ui')
5859

@@ -648,6 +649,8 @@ def navigate(self):
648649
def add_to_ows(self):
649650
"""add to OWS provider connection list"""
650651

652+
conn_name_matches = []
653+
651654
item = self.treeRecords.currentItem()
652655

653656
if not item:
@@ -678,13 +681,19 @@ def add_to_ows(self):
678681
keys = self.settings.childGroups()
679682
self.settings.endGroup()
680683

684+
for key in keys:
685+
if key.startswith(sname):
686+
conn_name_matches.append(key)
687+
if conn_name_matches:
688+
sname = matches[-1]
689+
681690
# check for duplicates
682691
if sname in keys:
683692
msg = self.tr('Connection %s exists. Overwrite?') % sname
684693
res = QMessageBox.warning(self, self.tr('Saving server'), msg,
685694
QMessageBox.Yes | QMessageBox.No)
686-
if res != QMessageBox.Yes:
687-
return
695+
if res != QMessageBox.Yes: # assign new name with serial
696+
sname = serialize_string(sname)
688697

689698
# no dups detected or overwrite is allowed
690699
self.settings.beginGroup('/Qgis/connections-%s' % stype[1])

python/plugins/MetaSearch/util.py

+16
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,19 @@ def normalize_text(text):
146146
"""tidy up string"""
147147

148148
return text.replace('\n', '')
149+
150+
151+
def serialize_string(input_string):
152+
"""apply a serial counter to a string"""
153+
154+
s = input_string.strip().split()
155+
156+
last_token = s[-1]
157+
all_other_tokens_as_string = input_string.replace(last_token, '')
158+
159+
if last_token.isdigit():
160+
value = '%s%s' % (all_other_tokens_as_string, int(last_token) + 1)
161+
else:
162+
value = '%s 1' % input_string
163+
164+
return value

0 commit comments

Comments
 (0)