Skip to content

Commit

Permalink
Merge pull request #6335 from Fanevanjanahary/crs_widget
Browse files Browse the repository at this point in the history
use crs widget picker in db_manager
  • Loading branch information
m-kuhn committed Apr 18, 2018
2 parents 9f41a9b + 77ca11e commit eab76e8
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 119 deletions.
39 changes: 18 additions & 21 deletions python/plugins/db_manager/dlg_import_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def __init__(self, inLayer, outDb, outUri, parent=None):
# updates of UI
self.setupWorkingMode(self.mode)
self.cboSchema.currentIndexChanged.connect(self.populateTables)
self.widgetSourceSrid.setCrs(QgsProject.instance().crs())
self.widgetTargetSrid.setCrs(QgsProject.instance().crs())

def setupWorkingMode(self, mode):
""" hide the widget to select a layer/file if the input layer is already set """
Expand Down Expand Up @@ -210,9 +212,10 @@ def updateInputLayer(self):
self.editGeomColumn.setText(geom)

srcCrs = self.inLayer.crs()
srid = srcCrs.postgisSrid() if srcCrs.isValid() else 4326
self.editSourceSrid.setText("%s" % srid)
self.editTargetSrid.setText("%s" % srid)
if not srcCrs.isValid():
srcCrs = QgsCoordinateReferenceSystem(4326)
self.widgetSourceSrid.setCrs(srcCrs)
self.widgetTargetSrid.setCrs(srcCrs)

return True

Expand Down Expand Up @@ -270,27 +273,23 @@ def accept(self):

# sanity checks
if self.inLayer is None:
QMessageBox.information(self, self.tr("Import to database"), self.tr("Input layer missing or not valid"))
QMessageBox.critical(self, self.tr("Import to Database"), self.tr("Input layer missing or not valid."))
return

if self.cboTable.currentText() == "":
QMessageBox.information(self, self.tr("Import to database"), self.tr("Output table name is required"))
QMessageBox.critical(self, self.tr("Import to Database"), self.tr("Output table name is required."))
return

if self.chkSourceSrid.isEnabled() and self.chkSourceSrid.isChecked():
try:
sourceSrid = self.editSourceSrid.text()
except ValueError:
QMessageBox.information(self, self.tr("Import to database"),
self.tr("Invalid source srid: must be an integer"))
if not self.widgetSourceSrid.crs().isValid():
QMessageBox.critical(self, self.tr("Import to Database"),
self.tr("Invalid source srid: must be a valid crs."))
return

if self.chkTargetSrid.isEnabled() and self.chkTargetSrid.isChecked():
try:
targetSrid = self.editTargetSrid.text()
except ValueError:
QMessageBox.information(self, self.tr("Import to database"),
self.tr("Invalid target srid: must be an integer"))
if not self.widgetTargetSrid.crs().isValid():
QMessageBox.critical(self, self.tr("Import to Database"),
self.tr("Invalid target srid: must be a valid crs."))
return

with OverrideCursor(Qt.WaitCursor):
Expand Down Expand Up @@ -344,13 +343,11 @@ def accept(self):

outCrs = QgsCoordinateReferenceSystem()
if self.chkTargetSrid.isEnabled() and self.chkTargetSrid.isChecked():
targetSrid = int(self.editTargetSrid.text())
outCrs = QgsCoordinateReferenceSystem(targetSrid)
outCrs = self.widgetTargetSrid.crs()

# update input layer crs and encoding
if self.chkSourceSrid.isEnabled() and self.chkSourceSrid.isChecked():
sourceSrid = int(self.editSourceSrid.text())
inCrs = QgsCoordinateReferenceSystem(sourceSrid)
inCrs = self.widgetSourceSrid.crs()
self.inLayer.setCrs(inCrs)

if self.chkEncoding.isEnabled() and self.chkEncoding.isChecked():
Expand All @@ -372,7 +369,7 @@ def accept(self):

if ret != 0:
output = QgsMessageViewer()
output.setTitle(self.tr("Import to database"))
output.setTitle(self.tr("Import to Database"))
output.setMessageAsPlainText(self.tr("Error {0}\n{1}").format(ret, errMsg))
output.showMessage()
return
Expand All @@ -383,7 +380,7 @@ def accept(self):

self.db.connection().reconnect()
self.db.refresh()
QMessageBox.information(self, self.tr("Import to database"), self.tr("Import was successful."))
QMessageBox.information(self, self.tr("Import to Database"), self.tr("Import was successful."))
return QDialog.accept(self)

def closeEvent(self, event):
Expand Down
Loading

0 comments on commit eab76e8

Please sign in to comment.