Skip to content

Commit

Permalink
db manager: fix drag and drop import (fixes #13712)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jun 22, 2016
1 parent 4677a3a commit 1f0fce7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
40 changes: 20 additions & 20 deletions python/plugins/db_manager/db_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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'):
Expand Down Expand Up @@ -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:
Expand All @@ -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'):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
13 changes: 12 additions & 1 deletion python/plugins/db_manager/db_plugins/spatialite/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down

2 comments on commit 1f0fce7

@slarosa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member Author

@jef-n jef-n commented on 1f0fce7 Jun 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.