Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 20283a4
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions python/plugins/db_manager/dlg_sql_window.py
Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'])
Expand All @@ -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)

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

QApplication.restoreOverrideCursor()

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

0 comments on commit 20283a4

Please sign in to comment.