Skip to content

Commit 1f0fce7

Browse files
committedJun 22, 2016
db manager: fix drag and drop import (fixes #13712)
1 parent 4677a3a commit 1f0fce7

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed
 

‎python/plugins/db_manager/db_model.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141

4242

4343
class TreeItem(QObject):
44-
itemRemoved = pyqtSignal()
45-
itemChanged = pyqtSignal()
44+
deleted = pyqtSignal()
45+
changed = pyqtSignal()
4646

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

5555
def childRemoved(self):
56-
self.itemWasChanged()
56+
self.itemChanged()
5757

58-
def itemWasChanged(self):
59-
self.itemChanged.emit()
58+
def itemChanged(self):
59+
self.changed.emit()
6060

61-
def itemWasRemoved(self):
62-
self.itemRemoved.emit()
61+
def itemDeleted(self):
62+
self.deleted.emit()
6363

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

7171
def appendChild(self, child):
7272
self.childItems.append(child)
73-
child.itemRemoved.connect(self.childRemoved)
73+
child.deleted.connect(self.childRemoved)
7474

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

7878
def removeChild(self, row):
7979
if row >= 0 and row < len(self.childItems):
8080
self.childItems[row].itemData.deleteLater()
81-
self.childItems[row].itemRemoved.disconnect(self.childRemoved)
81+
self.childItems[row].deleted.disconnect(self.childRemoved)
8282
del self.childItems[row]
8383

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

141141
def __init__(self, connection, parent=None):
142142
TreeItem.__init__(self, connection, parent)
143-
connection.changed.connect(self.itemWasChanged)
144-
connection.deleted.connect(self.itemWasRemoved)
143+
connection.changed.connect(self.itemChanged)
144+
connection.deleted.connect(self.itemDeleted)
145145

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

171171
database = connection.database()
172-
database.changed.connect(self.itemWasChanged)
173-
database.deleted.connect(self.itemWasRemoved)
172+
database.changed.connect(self.itemChanged)
173+
database.deleted.connect(self.itemDeleted)
174174

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

196196
def __init__(self, schema, parent):
197197
TreeItem.__init__(self, schema, parent)
198-
schema.changed.connect(self.itemWasChanged)
199-
schema.deleted.connect(self.itemWasRemoved)
198+
schema.changed.connect(self.itemChanged)
199+
schema.deleted.connect(self.itemDeleted)
200200

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

226226
def __init__(self, table, parent):
227227
TreeItem.__init__(self, table, parent)
228-
table.changed.connect(self.itemWasChanged)
229-
table.deleted.connect(self.itemWasRemoved)
228+
table.changed.connect(self.itemChanged)
229+
table.deleted.connect(self.itemDeleted)
230230
self.populate()
231231

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

308308
def refreshItem(self, item):
309309
if isinstance(item, TreeItem):
@@ -487,7 +487,7 @@ def _refreshIndex(self, index, force=False):
487487
if prevPopulated or force:
488488
if item.populate():
489489
for child in item.childItems:
490-
child.itemChanged.connect(partial(self.refreshItem, child))
490+
child.changed.connect(partial(self.refreshItem, child))
491491
self._onDataChanged(index)
492492
else:
493493
self.notPopulated.emit(index)
@@ -559,7 +559,7 @@ def dropMimeData(self, data, action, row, column, parent):
559559
uri = QgsDataSourceURI()
560560
uri.setDatabase(filename)
561561
item.getItemData().addConnection(conn_name, uri)
562-
item.itemChanged.emit(item)
562+
item.changed.emit()
563563
added += 1
564564
continue
565565

‎python/plugins/db_manager/db_plugins/spatialite/connector.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,19 @@ def isValidDatabase(self, path):
6363
conn = sqlite.connect(path)
6464
except self.connection_error_types():
6565
return False
66+
67+
isValid = False
68+
69+
try:
70+
c = conn.cursor()
71+
c.execute("SELECT count(*) FROM sqlite_master")
72+
c.fetchone()
73+
isValid = True
74+
except sqlite.DatabaseError:
75+
pass
76+
6677
conn.close()
67-
return True
78+
return isValid
6879

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

2 commit comments

Comments
 (2)

slarosa commented on Jun 22, 2016

@slarosa
Member

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 commented on Jun 22, 2016

@jef-n
MemberAuthor

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.