Skip to content
Permalink
Browse files

Unified the way the column comboboxes are filled when executing the q…

…uery and when pressing the load columns button.
  • Loading branch information
SebDieBln committed Oct 17, 2015
1 parent 35c3ad7 commit 20283a4dfc1623e7d27eb0e4aa05d67a53613e7c
Showing with 13 additions and 10 deletions.
  1. +13 −10 python/plugins/db_manager/dlg_sql_window.py
@@ -161,9 +161,6 @@ def executeSql(self):
if old_model:
old_model.deleteLater()

self.uniqueCombo.clear()
self.geomCombo.clear()

try:
# set the new model
model = self.db.sqlResultModel(sql, self)
@@ -173,11 +170,12 @@ def executeSql(self):
except BaseError as e:
QApplication.restoreOverrideCursor()
DlgDbError.showError(e, self)
self.uniqueCombo.clear()
self.geomCombo.clear()
return

cols = sorted(self.viewResult.model().columnNames())
self.uniqueCombo.addItems(cols)
self.geomCombo.addItems(cols)
cols = self.viewResult.model().columnNames()
self.setColumnCombos(cols)

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

QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
self.uniqueCombo.clear()
self.geomCombo.clear()

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

finally:
if c:
c.close()
del c

self.setColumnCombos(cols)

QApplication.restoreOverrideCursor()

def setColumnCombos(self, cols):
# 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)
try:
defaultGeomCol = next(col for col in cols if col in ['geom', 'geometry', 'the_geom', 'way'])
@@ -283,6 +286,8 @@ def fillColumnCombos(self):
defaultUniqueCol = None

cols.sort()
self.uniqueCombo.clear()
self.geomCombo.clear()
self.uniqueCombo.addItems(cols)
self.geomCombo.addItems(cols)

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

QApplication.restoreOverrideCursor()

def copySelectedResults(self):
if len(self.viewResult.selectedIndexes()) <= 0:
return

0 comments on commit 20283a4

Please sign in to comment.
You can’t perform that action at this time.