Skip to content

Commit

Permalink
[DBManager] do not add new connection per drag&drop (partially revert 8…
Browse files Browse the repository at this point in the history
  • Loading branch information
brushtyler committed Sep 2, 2015
1 parent cc18882 commit 71afc9a
Showing 1 changed file with 24 additions and 44 deletions.
68 changes: 24 additions & 44 deletions python/plugins/db_manager/db_model.py
Expand Up @@ -134,6 +134,8 @@ class ConnectionItem(TreeItem):

def __init__(self, connection, parent=None):
TreeItem.__init__(self, connection, parent)
self.connect(connection, SIGNAL("changed"), self.itemChanged)
self.connect(connection, SIGNAL("deleted"), self.itemRemoved)

# load (shared) icon with first instance of table item
if not hasattr(ConnectionItem, 'connectedIcon'):
Expand Down Expand Up @@ -285,7 +287,8 @@ def __init__(self, parent=None):
self.rootItem = TreeItem(None, None)
for dbtype in supportedDbTypes():
dbpluginclass = createDbPlugin(dbtype)
PluginItem(dbpluginclass, self.rootItem)
item = PluginItem(dbpluginclass, self.rootItem)
self.connect(item, SIGNAL("itemChanged"), self.refreshItem)

def refreshItem(self, item):
if isinstance(item, TreeItem):
Expand Down Expand Up @@ -364,9 +367,6 @@ def flags(self, index):
if index.column() == 0:
item = index.internalPointer()

if not isinstance(item, SchemaItem) and not isinstance(item, TableItem):
flags |= Qt.ItemIsDropEnabled

if isinstance(item, SchemaItem) or isinstance(item, TableItem):
flags |= Qt.ItemIsEditable

Expand Down Expand Up @@ -514,48 +514,28 @@ def dropMimeData(self, data, action, row, column, parent):
added = 0

if data.hasUrls():
if row == -1 and column == -1:
for u in data.urls():
filename = u.toLocalFile()
if self.addConnection(filename, parent):
added += 1
else:
for u in data.urls():
filename = u.toLocalFile()
if filename == "":
continue

if qgis.core.QgsRasterLayer.isValidRasterFileName(filename):
layerType = 'raster'
providerKey = 'gdal'
else:
layerType = 'vector'
providerKey = 'ogr'

layerName = QFileInfo(filename).completeBaseName()

if self.importLayer(layerType, providerKey, layerName, filename, parent):
added += 1

if data.hasFormat(self.QGIS_URI_MIME):
for uri in qgis.core.QgsMimeDataUtils.decodeUriList(data):
if self.importLayer(uri.layerType, uri.providerKey, uri.name, uri.uri, parent):
added += 1
for u in data.urls():
filename = u.toLocalFile()
if filename == "":
continue
if qgis.core.QgsRasterLayer.isValidRasterFileName(filename):
layerType = 'raster'
providerKey = 'gdal'
else:
layerType = 'vector'
providerKey = 'ogr'

return added > 0
layerName = QFileInfo(filename).completeBaseName()

def addConnection(self, filename, index):
file = filename.split("/")[-1]
if filename == "":
return False
s = QSettings()
connKey = index.internalPointer().getItemData().connectionSettingsKey()
conn = index.internalPointer().getItemData().connectionSettingsFileKey()
s.beginGroup("/%s/%s" % (connKey, file))
s.setValue(conn, filename)
self.treeView.setCurrentIndex(index)
self.treeView.mainWindow.refreshActionSlot()
return True
if self.importLayer(layerType, providerKey, layerName, filename, parent):
added += 1

if data.hasFormat(self.QGIS_URI_MIME):
for uri in qgis.core.QgsMimeDataUtils.decodeUriList(data):
if self.importLayer(uri.layerType, uri.providerKey, uri.name, uri.uri, parent):
added += 1

return added > 0

def importLayer(self, layerType, providerKey, layerName, uriString, parent):
if not self.isImportVectorAvail:
Expand Down

0 comments on commit 71afc9a

Please sign in to comment.