Skip to content
Permalink
Browse files

db manager: fix drag and drop import (fixes #13712)

  • Loading branch information
jef-n committed Jun 22, 2016
1 parent 4677a3a commit 1f0fce7852e9f6a27af967d7ac7ee3989dce7b45
Showing with 32 additions and 21 deletions.
  1. +20 −20 python/plugins/db_manager/db_model.py
  2. +12 −1 python/plugins/db_manager/db_plugins/spatialite/connector.py
@@ -41,8 +41,8 @@


class TreeItem(QObject):
itemRemoved = pyqtSignal()
itemChanged = pyqtSignal()
deleted = pyqtSignal()
changed = pyqtSignal()

def __init__(self, data, parent=None):
QObject.__init__(self, parent)
@@ -53,13 +53,13 @@ def __init__(self, data, parent=None):
parent.appendChild(self)

def childRemoved(self):
self.itemWasChanged()
self.itemChanged()

def itemWasChanged(self):
self.itemChanged.emit()
def itemChanged(self):
self.changed.emit()

def itemWasRemoved(self):
self.itemRemoved.emit()
def itemDeleted(self):
self.deleted.emit()

def populate(self):
self.populated = True
@@ -70,15 +70,15 @@ def getItemData(self):

def appendChild(self, child):
self.childItems.append(child)
child.itemRemoved.connect(self.childRemoved)
child.deleted.connect(self.childRemoved)

def child(self, row):
return self.childItems[row]

def removeChild(self, row):
if row >= 0 and row < len(self.childItems):
self.childItems[row].itemData.deleteLater()
self.childItems[row].itemRemoved.disconnect(self.childRemoved)
self.childItems[row].deleted.disconnect(self.childRemoved)
del self.childItems[row]

def childCount(self):
@@ -140,8 +140,8 @@ class ConnectionItem(TreeItem):

def __init__(self, connection, parent=None):
TreeItem.__init__(self, connection, parent)
connection.changed.connect(self.itemWasChanged)
connection.deleted.connect(self.itemWasRemoved)
connection.changed.connect(self.itemChanged)
connection.deleted.connect(self.itemDeleted)

# load (shared) icon with first instance of table item
if not hasattr(ConnectionItem, 'connectedIcon'):
@@ -169,8 +169,8 @@ def populate(self):
return False

database = connection.database()
database.changed.connect(self.itemWasChanged)
database.deleted.connect(self.itemWasRemoved)
database.changed.connect(self.itemChanged)
database.deleted.connect(self.itemDeleted)

schemas = database.schemas()
if schemas is not None:
@@ -195,8 +195,8 @@ class SchemaItem(TreeItem):

def __init__(self, schema, parent):
TreeItem.__init__(self, schema, parent)
schema.changed.connect(self.itemWasChanged)
schema.deleted.connect(self.itemWasRemoved)
schema.changed.connect(self.itemChanged)
schema.deleted.connect(self.itemDeleted)

# load (shared) icon with first instance of schema item
if not hasattr(SchemaItem, 'schemaIcon'):
@@ -225,8 +225,8 @@ class TableItem(TreeItem):

def __init__(self, table, parent):
TreeItem.__init__(self, table, parent)
table.changed.connect(self.itemWasChanged)
table.deleted.connect(self.itemWasRemoved)
table.changed.connect(self.itemChanged)
table.deleted.connect(self.itemDeleted)
self.populate()

# load (shared) icon with first instance of table item
@@ -303,7 +303,7 @@ def __init__(self, parent=None):
for dbtype in supportedDbTypes():
dbpluginclass = createDbPlugin(dbtype)
item = PluginItem(dbpluginclass, self.rootItem)
item.itemChanged.connect(partial(self.refreshItem, item))
item.changed.connect(partial(self.refreshItem, item))

def refreshItem(self, item):
if isinstance(item, TreeItem):
@@ -487,7 +487,7 @@ def _refreshIndex(self, index, force=False):
if prevPopulated or force:
if item.populate():
for child in item.childItems:
child.itemChanged.connect(partial(self.refreshItem, child))
child.changed.connect(partial(self.refreshItem, child))
self._onDataChanged(index)
else:
self.notPopulated.emit(index)
@@ -559,7 +559,7 @@ def dropMimeData(self, data, action, row, column, parent):
uri = QgsDataSourceURI()
uri.setDatabase(filename)
item.getItemData().addConnection(conn_name, uri)
item.itemChanged.emit(item)
item.changed.emit()
added += 1
continue

@@ -63,8 +63,19 @@ def isValidDatabase(self, path):
conn = sqlite.connect(path)
except self.connection_error_types():
return False

isValid = False

try:
c = conn.cursor()
c.execute("SELECT count(*) FROM sqlite_master")
c.fetchone()
isValid = True
except sqlite.DatabaseError:
pass

conn.close()
return True
return isValid

def _checkSpatial(self):
""" check if it's a valid spatialite db """

2 comments on commit 1f0fce7

@slarosa

This comment has been minimized.

Copy link
Member

@slarosa slarosa replied Jun 22, 2016

Thank you, your solution is very good to validate the database (better than #3205). Just one curiosity: why you have "changed" the name of the signals?

@jef-n

This comment has been minimized.

Copy link
Member Author

@jef-n jef-n replied Jun 22, 2016

Well, I changed them before when we migrated from old style signals to new style signals. itemChanged used to be a slot and a signal and with new style signals that doesn't work anymore. In other modules the signals where called "changed" and "deleted" so I aligned it her - and renaming back the itemWasChanged method.

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