Skip to content

Commit 20283a4

Browse files
committedOct 17, 2015
Unified the way the column comboboxes are filled when executing the query and when pressing the load columns button.
1 parent 35c3ad7 commit 20283a4

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed
 

‎python/plugins/db_manager/dlg_sql_window.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@ def executeSql(self):
161161
if old_model:
162162
old_model.deleteLater()
163163

164-
self.uniqueCombo.clear()
165-
self.geomCombo.clear()
166-
167164
try:
168165
# set the new model
169166
model = self.db.sqlResultModel(sql, self)
@@ -173,11 +170,12 @@ def executeSql(self):
173170
except BaseError as e:
174171
QApplication.restoreOverrideCursor()
175172
DlgDbError.showError(e, self)
173+
self.uniqueCombo.clear()
174+
self.geomCombo.clear()
176175
return
177176

178-
cols = sorted(self.viewResult.model().columnNames())
179-
self.uniqueCombo.addItems(cols)
180-
self.geomCombo.addItems(cols)
177+
cols = self.viewResult.model().columnNames()
178+
self.setColumnCombos(cols)
181179

182180
self.update()
183181
QApplication.restoreOverrideCursor()
@@ -236,8 +234,6 @@ def fillColumnCombos(self):
236234
return
237235

238236
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
239-
self.uniqueCombo.clear()
240-
self.geomCombo.clear()
241237

242238
# get a new alias
243239
aliasIndex = 0
@@ -265,13 +261,20 @@ def fillColumnCombos(self):
265261
except BaseError as e:
266262
QApplication.restoreOverrideCursor()
267263
DlgDbError.showError(e, self)
264+
self.uniqueCombo.clear()
265+
self.geomCombo.clear()
268266
return
269267

270268
finally:
271269
if c:
272270
c.close()
273271
del c
274272

273+
self.setColumnCombos(cols)
274+
275+
QApplication.restoreOverrideCursor()
276+
277+
def setColumnCombos(self, cols):
275278
# get sensible default columns. do this before sorting in case there's hints in the column order (eg, id is more likely to be first)
276279
try:
277280
defaultGeomCol = next(col for col in cols if col in ['geom', 'geometry', 'the_geom', 'way'])
@@ -283,6 +286,8 @@ def fillColumnCombos(self):
283286
defaultUniqueCol = None
284287

285288
cols.sort()
289+
self.uniqueCombo.clear()
290+
self.geomCombo.clear()
286291
self.uniqueCombo.addItems(cols)
287292
self.geomCombo.addItems(cols)
288293

@@ -296,8 +301,6 @@ def fillColumnCombos(self):
296301
except:
297302
pass
298303

299-
QApplication.restoreOverrideCursor()
300-
301304
def copySelectedResults(self):
302305
if len(self.viewResult.selectedIndexes()) <= 0:
303306
return

0 commit comments

Comments
 (0)
Please sign in to comment.