Skip to content
Permalink
Browse files

Merge pull request #1582 from nyalldawson/db_manager_fixes

Usability improvements for db manager
  • Loading branch information
nyalldawson committed Sep 22, 2014
2 parents bb3ead3 + 4e3510e commit 86cbc2ef43aa34108d1ca4bca63789bd05d03dd0
Showing with 31 additions and 2 deletions.
  1. +2 −1 python/plugins/db_manager/db_manager_plugin.py
  2. +29 −1 python/plugins/db_manager/dlg_sql_window.py
@@ -65,10 +65,11 @@ def run(self):
# keep opened only one instance
if self.dlg == None:
from db_manager import DBManager
self.dlg = DBManager(self.iface, self.iface.mainWindow())
self.dlg = DBManager(self.iface)
QObject.connect(self.dlg, SIGNAL("destroyed(QObject *)"), self.onDestroyed)
self.dlg.show()
self.dlg.raise_()
self.dlg.setWindowState( self.dlg.windowState() & ~Qt.WindowMinimized )
self.dlg.activateWindow()

def onDestroyed(self, obj):
@@ -173,6 +173,10 @@ def loadSqlLayer(self):
query = self.editSql.text()
if query == "":
return

# remove a trailing ';' from query if present
if query.strip().endswith(';'):
query = query.strip()[:-1]

QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))

@@ -216,7 +220,11 @@ def fillColumnCombos(self):
if not escaped.search(query):
break
aliasIndex += 1


# remove a trailing ';' from query if present
if query.strip().endswith(';'):
query = query.strip()[:-1]

# get all the columns
cols = []
connector = self.db.connector
@@ -236,11 +244,31 @@ def fillColumnCombos(self):
if c:
c.close()
del c

# 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'])
except:
defaultGeomCol = None
try:
defaultUniqueCol = [col for col in cols if 'id' in col][0]
except:
defaultUniqueCol = None

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

# set sensible default columns
try:
self.geomCombo.setCurrentIndex( cols.index(defaultGeomCol) )
except:
pass
try:
self.uniqueCombo.setCurrentIndex( cols.index(defaultUniqueCol) )
except:
pass

QApplication.restoreOverrideCursor()

def copySelectedResults(self):

0 comments on commit 86cbc2e

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