Skip to content

Commit

Permalink
More list comprehensions, str.join()
Browse files Browse the repository at this point in the history
  • Loading branch information
dericke committed Jan 24, 2021
1 parent 4b50c1a commit 4e41ee6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 30 deletions.
8 changes: 4 additions & 4 deletions python/plugins/db_manager/db_plugins/data_model.py
Expand Up @@ -50,10 +50,10 @@ def headerToString(self, sep=u"\t"):
return sep.join(header)

def rowToString(self, row, sep=u"\t"):
text = u""
for col in range(self.columnCount()):
text += u"%s" % self.getData(row, col) + sep
return text[:-1]
return sep.join(
u"%s" % self.getData(row, col)
for col in range(self.columnCount())
)

def getData(self, row, col):
return self.resdata[row][col]
Expand Down
25 changes: 14 additions & 11 deletions python/plugins/db_manager/dlg_sql_layer_window.py
Expand Up @@ -300,17 +300,20 @@ def executeSql(self):

def _getSqlLayer(self, _filter):
hasUniqueField = self.uniqueColumnCheck.checkState() == Qt.Checked
if hasUniqueField:
if self.allowMultiColumnPk:
checkedCols = []
for item in self.uniqueModel.findItems("*", Qt.MatchWildcard):
if item.checkState() == Qt.Checked:
checkedCols.append(item.data())
uniqueFieldName = ",".join(checkedCols)
elif self.uniqueCombo.currentIndex() >= 0:
uniqueFieldName = self.uniqueModel.item(self.uniqueCombo.currentIndex()).data()
else:
uniqueFieldName = None
if hasUniqueField and self.allowMultiColumnPk:
checkedCols = [
item.data()
for item in self.uniqueModel.findItems("*", Qt.MatchWildcard)
if item.checkState() == Qt.Checked
]

uniqueFieldName = ",".join(checkedCols)
elif (
hasUniqueField
and not self.allowMultiColumnPk
and self.uniqueCombo.currentIndex() >= 0
):
uniqueFieldName = self.uniqueModel.item(self.uniqueCombo.currentIndex()).data()
else:
uniqueFieldName = None
hasGeomCol = self.hasGeometryCol.checkState() == Qt.Checked
Expand Down
32 changes: 17 additions & 15 deletions python/plugins/db_manager/dlg_sql_window.py
Expand Up @@ -441,17 +441,20 @@ def showError(self, error):

def _getSqlLayer(self, _filter):
hasUniqueField = self.uniqueColumnCheck.checkState() == Qt.Checked
if hasUniqueField:
if self.allowMultiColumnPk:
checkedCols = []
for item in self.uniqueModel.findItems("*", Qt.MatchWildcard):
if item.checkState() == Qt.Checked:
checkedCols.append(item.data())
uniqueFieldName = ",".join(checkedCols)
elif self.uniqueCombo.currentIndex() >= 0:
uniqueFieldName = self.uniqueModel.item(self.uniqueCombo.currentIndex()).data()
else:
uniqueFieldName = None
if hasUniqueField and self.allowMultiColumnPk:
checkedCols = [
item.data()
for item in self.uniqueModel.findItems("*", Qt.MatchWildcard)
if item.checkState() == Qt.Checked
]

uniqueFieldName = ",".join(checkedCols)
elif (
hasUniqueField
and not self.allowMultiColumnPk
and self.uniqueCombo.currentIndex() >= 0
):
uniqueFieldName = self.uniqueModel.item(self.uniqueCombo.currentIndex()).data()
else:
uniqueFieldName = None
hasGeomCol = self.hasGeometryCol.checkState() == Qt.Checked
Expand Down Expand Up @@ -489,10 +492,9 @@ def _getSqlLayer(self, _filter):
self.avoidSelectById.isChecked(), _filter)
if layer.isValid():
return layer
else:
e = BaseError(self.tr("There was an error creating the SQL layer, please check the logs for further information."))
DlgDbError.showError(e, self)
return None
e = BaseError(self.tr("There was an error creating the SQL layer, please check the logs for further information."))
DlgDbError.showError(e, self)
return None

def loadSqlLayer(self):
with OverrideCursor(Qt.WaitCursor):
Expand Down

0 comments on commit 4e41ee6

Please sign in to comment.