Skip to content

Commit

Permalink
Merge pull request #1582 from nyalldawson/db_manager_fixes
Browse files Browse the repository at this point in the history
Usability improvements for db manager
  • Loading branch information
nyalldawson committed Sep 22, 2014
2 parents bb3ead3 + 4e3510e commit 86cbc2e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
3 changes: 2 additions & 1 deletion python/plugins/db_manager/db_manager_plugin.py
Expand Up @@ -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):
Expand Down
30 changes: 29 additions & 1 deletion python/plugins/db_manager/dlg_sql_window.py
Expand Up @@ -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))

Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit 86cbc2e

Please sign in to comment.