Skip to content

Commit 80b5a07

Browse files
committedJun 4, 2013
DBManager: updated to new SIP API
1 parent edfa0fc commit 80b5a07

17 files changed

+147
-135
lines changed
 

‎python/plugins/db_manager/completer.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ def __init__(self, editor, db=None):
3737
from .sql_dictionary import getSqlDictionary
3838
dictionary = getSqlDictionary()
3939

40-
wordlist = QStringList()
40+
wordlist = []
4141
for name, value in dictionary.iteritems():
42-
wordlist << value
43-
wordlist = QStringList() << list(set( wordlist )) # remove duplicates
42+
wordlist += value # concat lists
43+
wordlist = list( set(wordlist) ) # remove duplicates
4444

4545
# setup the completer
4646
QCompleter.__init__(self, sorted(wordlist), editor)
@@ -70,10 +70,10 @@ def setCompleter(self, completer):
7070

7171
def insertCompletion(self, completion):
7272
tc = self.textCursor()
73-
extra = completion.length() - self.completer.completionPrefix().length()
73+
extra = len(completion) - len(self.completer.completionPrefix())
7474
tc.movePosition(QTextCursor.Left)
7575
tc.movePosition(QTextCursor.EndOfWord)
76-
tc.insertText(completion.right(extra))
76+
tc.insertText(completion[-extra:])
7777
self.setTextCursor(tc)
7878

7979
def textUnderCursor(self):
@@ -99,18 +99,18 @@ def keyPressEvent(self, event):
9999

100100
# ctrl or shift key on it's own??
101101
ctrlOrShift = event.modifiers() in (Qt.ControlModifier, Qt.ShiftModifier)
102-
if ctrlOrShift and event.text().isEmpty():
102+
if ctrlOrShift and event.text() == "":
103103
# ctrl or shift key on it's own
104104
return
105105

106-
eow = QString("~!@#$%^&*()+{}|:\"<>?,./;'[]\\-=") # end of word
106+
eow = "~!@#$%^&*()+{}|:\"<>?,./;'[]\\-=" # end of word
107107

108108
hasModifier = event.modifiers() != Qt.NoModifier and not ctrlOrShift
109109

110110
completionPrefix = self.textUnderCursor()
111111

112-
if not isShortcut and (hasModifier or event.text().isEmpty() or
113-
completionPrefix.length() < 3 or eow.contains(event.text().right(1))):
112+
if not isShortcut and (hasModifier or event.text() == "" or
113+
len(completionPrefix) < 3 or event.text()[-1] in eow):
114114
self.completer.popup().hide()
115115
return
116116

‎python/plugins/db_manager/db_manager.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def __init__(self, iface, parent=None):
4545

4646
# restore the window state
4747
settings = QSettings()
48-
self.restoreGeometry( settings.value("/DB_Manager/mainWindow/geometry").toByteArray() )
49-
self.restoreState( settings.value("/DB_Manager/mainWindow/windowState").toByteArray() )
48+
self.restoreGeometry( settings.value("/DB_Manager/mainWindow/geometry") )
49+
self.restoreState( settings.value("/DB_Manager/mainWindow/windowState") )
5050

5151
self.connect(self.tabs, SIGNAL("currentChanged(int)"), self.tabChanged)
5252
self.connect(self.tree, SIGNAL("selectedItemChanged"), self.itemChanged)
@@ -58,8 +58,8 @@ def closeEvent(self, e):
5858

5959
# save the window state
6060
settings = QSettings()
61-
settings.setValue( "/DB_Manager/mainWindow/windowState", QVariant(self.saveState()) )
62-
settings.setValue( "/DB_Manager/mainWindow/geometry", QVariant(self.saveGeometry()) )
61+
settings.setValue( "/DB_Manager/mainWindow/windowState", self.saveState() )
62+
settings.setValue( "/DB_Manager/mainWindow/geometry", self.saveGeometry() )
6363

6464
QMainWindow.closeEvent(self, e)
6565

@@ -236,7 +236,7 @@ def registerAction(self, action, menuName, callback=None):
236236
# get the placeholder's position to insert before it
237237
pos = 0
238238
for pos in range(len(menuActions)):
239-
if menuActions[pos].isSeparator() and menuActions[pos].objectName().endsWith("_placeholder"):
239+
if menuActions[pos].isSeparator() and menuActions[pos].objectName().endswith("_placeholder"):
240240
menuActions[pos].setVisible(True)
241241
break
242242

@@ -314,7 +314,7 @@ def unregisterAction(self, action, menuName):
314314
# hide the placeholder if there're no other registered actions
315315
if len(self._registeredDbActions[menuName]) <= 0:
316316
for i in range(len(menuActions)):
317-
if menuActions[i].isSeparator() and menuActions[i].objectName().endsWith("_placeholder"):
317+
if menuActions[i].isSeparator() and menuActions[i].objectName().endswith("_placeholder"):
318318
menuActions[i].setVisible(False)
319319
break
320320

‎python/plugins/db_manager/db_model.py

+24-21
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ def icon(self):
9292
return None
9393

9494
def path(self):
95-
pathList = QStringList()
96-
if self.parent(): pathList << self.parent().path()
97-
return pathList << self.data(0)
95+
pathList = []
96+
if self.parent():
97+
pathList.append( self.parent().path() )
98+
pathList.append( self.data(0) )
99+
return pathList
98100

99101

100102
class PluginItem(TreeItem):
@@ -122,7 +124,7 @@ def icon(self):
122124
return self.getItemData().icon()
123125

124126
def path(self):
125-
return QStringList() << self.getItemData().typeName()
127+
return [ self.getItemData().typeName() ]
126128

127129
class ConnectionItem(TreeItem):
128130
def __init__(self, connection, parent=None):
@@ -249,13 +251,14 @@ def icon(self):
249251
return self.tableIcon
250252

251253
def path(self):
252-
pathList = QStringList()
253-
if self.parent(): pathList << self.parent().path()
254+
pathList = []
255+
if self.parent():
256+
pathList.append( self.parent().path() )
254257

255258
if self.getItemData().type == Table.VectorType:
256-
pathList << "%s::%s" % ( self.data(0), self.getItemData().geomColumn )
259+
pathList.append( "%s::%s" % ( self.data(0), self.getItemData().geomColumn ) )
257260
else:
258-
pathList << self.data(0)
261+
pathList.append( self.data(0) )
259262

260263
return pathList
261264

@@ -330,17 +333,17 @@ def columnCount(self, parent):
330333

331334
def data(self, index, role):
332335
if not index.isValid():
333-
return QVariant()
336+
return None
334337

335338
if role == Qt.DecorationRole and index.column() == 0:
336339
icon = index.internalPointer().icon()
337-
if icon: return QVariant(icon)
340+
if icon: return icon
338341

339342
if role != Qt.DisplayRole and role != Qt.EditRole:
340-
return QVariant()
343+
return None
341344

342345
retval = index.internalPointer().data(index.column())
343-
return QVariant(retval) if retval else QVariant()
346+
return retval
344347

345348
def flags(self, index):
346349
if not index.isValid():
@@ -367,8 +370,8 @@ def flags(self, index):
367370

368371
def headerData(self, section, orientation, role):
369372
if orientation == Qt.Horizontal and role == Qt.DisplayRole and section < len(self.header):
370-
return QVariant(self.header[section])
371-
return QVariant()
373+
return self.header[section]
374+
return None
372375

373376
def index(self, row, column, parent):
374377
if not self.hasIndex(row, column, parent):
@@ -409,7 +412,7 @@ def setData(self, index, value, role):
409412
return False
410413

411414
item = index.internalPointer()
412-
new_value = unicode(value.toString())
415+
new_value = unicode(value)
413416

414417
if isinstance(item, SchemaItem) or isinstance(item, TableItem):
415418
obj = item.getItemData()
@@ -470,7 +473,7 @@ def _onDataChanged(self, indexFrom, indexTo=None):
470473
QGIS_URI_MIME = "application/x-vnd.qgis.qgis.uri"
471474

472475
def mimeTypes(self):
473-
return QStringList() << "text/uri-list" << self.QGIS_URI_MIME
476+
return ["text/uri-list", self.QGIS_URI_MIME]
474477

475478
def mimeData(self, indexes):
476479
mimeData = QMimeData()
@@ -502,7 +505,7 @@ def dropMimeData(self, data, action, row, column, parent):
502505
if data.hasUrls():
503506
for u in data.urls():
504507
filename = u.toLocalFile()
505-
if filename.isEmpty():
508+
if filename == "":
506509
continue
507510

508511
if qgis.core.QgsRasterLayer.isValidRasterFileName( filename ):
@@ -524,7 +527,7 @@ def dropMimeData(self, data, action, row, column, parent):
524527
while not stream.atEnd():
525528
mimeUri = stream.readQString()
526529

527-
parts = QStringList() << unicode(mimeUri).split(":", 3)
530+
parts = mimeUri.split(":", 3)
528531
if len(parts) != 4:
529532
# invalid qgis mime uri
530533
QMessageBox.warning(None, "Invalid MIME uri", "The dropped object is not a valid QGis layer")
@@ -570,8 +573,8 @@ def importLayer(self, layerType, providerKey, layerName, uriString, parent):
570573

571574
if inLayer.type() == inLayer.VectorLayer:
572575
# create the output uri
573-
schema = outSchema.name if outDb.schemas() != None and outSchema != None else QString()
574-
pkCol = geomCol = QString()
576+
schema = outSchema.name if outDb.schemas() != None and outSchema != None else ""
577+
pkCol = geomCol = ""
575578

576579
# default pk and geom field name value
577580
if providerKey in ['postgres', 'spatialite']:
@@ -580,7 +583,7 @@ def importLayer(self, layerType, providerKey, layerName, uriString, parent):
580583
geomCol = inUri.geometryColumn()
581584

582585
outUri = outDb.uri()
583-
outUri.setDataSource( schema, layerName, geomCol, QString(), pkCol )
586+
outUri.setDataSource( schema, layerName, geomCol, "", pkCol )
584587

585588
self.emit( SIGNAL("importVector"), inLayer, outDb, outUri, toIndex )
586589
return True

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def _execute_and_commit(self, sql):
9393
def _get_cursor(self, name=None):
9494
try:
9595
if name != None:
96-
name = QString( unicode(name).encode('ascii', 'replace') ).replace( QRegExp("\W"), "_" ).toAscii()
96+
name = unicode(name).encode('ascii', 'replace').replace( '?', "_" )
9797
self._last_cursor_named_id = 0 if not hasattr(self, '_last_cursor_named_id') else self._last_cursor_named_id + 1
9898
return self.connection.cursor( "%s_%d" % (name, self._last_cursor_named_id) )
9999

‎python/plugins/db_manager/db_plugins/data_model.py

+35-35
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ def __init__(self, header=None, data=None, parent=None):
3232
self.resdata = data if data else []
3333

3434
def headerToString(self, sep=u"\t"):
35-
header = QStringList() << self._header
36-
return header.join( sep )
35+
header = self._header
36+
return sep.join(header)
3737

3838
def rowToString(self, row, sep=u"\t"):
39-
text = QString()
39+
text = u""
4040
for col in range(self.columnCount()):
4141
text += u"%s" % self.getData(row, col) + sep
4242
return text[:-1]
@@ -55,37 +55,37 @@ def columnCount(self, parent=None):
5555

5656
def data(self, index, role):
5757
if role != Qt.DisplayRole and role != Qt.FontRole:
58-
return QVariant()
58+
return None
5959

6060
val = self.getData(index.row(), index.column())
6161

6262
if role == Qt.FontRole: # draw NULL in italic
6363
if val != None:
64-
return QVariant()
64+
return None
6565
f = QFont()
6666
f.setItalic(True)
67-
return QVariant(f)
67+
return f
6868

6969
if val == None:
70-
return QVariant("NULL")
70+
return "NULL"
7171
elif isinstance(val, buffer):
7272
# hide binary data
73-
return QVariant()
74-
elif isinstance(val, (str, unicode, QString)) and len(val) > 300:
73+
return None
74+
elif isinstance(val, (str, unicode)) and len(val) > 300:
7575
# too much data to display, elide the string
76-
return QVariant( u"%s..." % val[:300] )
77-
return QVariant( unicode(val) ) # convert to string
76+
return u"%s..." % val[:300]
77+
return unicode(val) # convert to string
7878

7979
def headerData(self, section, orientation, role):
8080
if role != Qt.DisplayRole:
81-
return QVariant()
81+
return None
8282

8383
if orientation == Qt.Vertical:
8484
# header for a row
85-
return QVariant(section+1)
85+
return section+1
8686
else:
8787
# header for a column
88-
return QVariant(self._header[section])
88+
return self._header[section]
8989

9090

9191
class TableDataModel(BaseTableModel):
@@ -180,8 +180,8 @@ def rowFromData(self, data):
180180

181181
def headerData(self, section, orientation, role):
182182
if orientation == Qt.Horizontal and role == Qt.DisplayRole:
183-
return QVariant(self.header[section])
184-
return QVariant()
183+
return self.header[section]
184+
return None
185185

186186
def _getNewObject(self):
187187
pass
@@ -201,37 +201,37 @@ def __init__(self, parent, editable=False):
201201

202202
def headerData(self, section, orientation, role):
203203
if orientation == Qt.Vertical and role == Qt.DisplayRole:
204-
return QVariant(section+1)
204+
return section+1
205205
return SimpleTableModel.headerData(self, section, orientation, role)
206206

207207
def append(self, fld):
208208
data = [fld.name, fld.type2String(), not fld.notNull, fld.default2String()]
209209
self.appendRow( self.rowFromData(data) )
210210
row = self.rowCount()-1
211-
self.setData(self.index(row, 0), QVariant(fld), Qt.UserRole)
212-
self.setData(self.index(row, 1), QVariant(fld.primaryKey), Qt.UserRole)
211+
self.setData(self.index(row, 0), fld, Qt.UserRole)
212+
self.setData(self.index(row, 1), fld.primaryKey, Qt.UserRole)
213213

214214
def _getNewObject(self):
215215
from .plugin import TableField
216216
return TableField(None)
217217

218218
def getObject(self, row):
219219
val = self.data(self.index(row, 0), Qt.UserRole)
220-
fld = val.toPyObject() if val.isValid() else self._getNewObject()
221-
fld.name = self.data(self.index(row, 0)).toString()
220+
fld = val if val != None else self._getNewObject()
221+
fld.name = self.data(self.index(row, 0)) or ""
222222

223-
typestr = self.data(self.index(row, 1)).toString()
223+
typestr = self.data(self.index(row, 1)) or ""
224224
regex = QRegExp( "([^\(]+)\(([^\)]+)\)" )
225-
startpos = regex.indexIn( QString(typestr) )
225+
startpos = regex.indexIn( typestr )
226226
if startpos >= 0:
227-
fld.dataType = regex.cap(1).trimmed()
228-
fld.modifier = regex.cap(2).trimmed()
227+
fld.dataType = regex.cap(1).strip()
228+
fld.modifier = regex.cap(2).strip()
229229
else:
230230
fld.modifier = None
231231
fld.dataType = typestr
232232

233-
fld.notNull = not self.data(self.index(row, 2)).toBool()
234-
fld.primaryKey = self.data(self.index(row, 1), Qt.UserRole).toBool()
233+
fld.notNull = self.data(self.index(row, 2)) != "true"
234+
fld.primaryKey = self.data(self.index(row, 1), Qt.UserRole)
235235
return fld
236236

237237
def getFields(self):
@@ -250,9 +250,9 @@ def append(self, constr):
250250
data = [constr.name, constr.type2String(), u", ".join(field_names)]
251251
self.appendRow( self.rowFromData(data) )
252252
row = self.rowCount()-1
253-
self.setData(self.index(row, 0), QVariant(constr), Qt.UserRole)
254-
self.setData(self.index(row, 1), QVariant(constr.type), Qt.UserRole)
255-
self.setData(self.index(row, 2), QVariant(constr.columns), Qt.UserRole)
253+
self.setData(self.index(row, 0), constr, Qt.UserRole)
254+
self.setData(self.index(row, 1), constr.type, Qt.UserRole)
255+
self.setData(self.index(row, 2), constr.columns, Qt.UserRole)
256256

257257
def _getNewObject(self):
258258
from .plugin import TableConstraint
@@ -261,9 +261,9 @@ def _getNewObject(self):
261261
def getObject(self, row):
262262
val = self.data(self.index(row, 0), Qt.UserRole)
263263
constr = val.toPyObject() if val.isValid() else self._getNewObject()
264-
constr.name = self.data(self.index(row, 0)).toString()
265-
constr.type = self.data(self.index(row, 1), Qt.UserRole).toInt()[0]
266-
constr.columns = self.data(self.index(row, 2), Qt.UserRole).toList()
264+
constr.name = self.data(self.index(row, 0)) or ""
265+
constr.type = self.data(self.index(row, 1), Qt.UserRole)
266+
constr.columns = self.data(self.index(row, 2), Qt.UserRole)
267267
return constr
268268

269269
def getConstraints(self):
@@ -282,8 +282,8 @@ def append(self, idx):
282282
data = [idx.name, u", ".join(field_names)]
283283
self.appendRow( self.rowFromData(data) )
284284
row = self.rowCount()-1
285-
self.setData(self.index(row, 0), QVariant(idx), Qt.UserRole)
286-
self.setData(self.index(row, 1), QVariant(idx.columns), Qt.UserRole)
285+
self.setData(self.index(row, 0), idx, Qt.UserRole)
286+
self.setData(self.index(row, 1), idx.columns, Qt.UserRole)
287287

288288
def _getNewObject(self):
289289
from .plugin import TableIndex

0 commit comments

Comments
 (0)
Please sign in to comment.