@@ -68,6 +68,8 @@ def __init__(self, inLayer, outDb, outUri, parent=None):
68
68
# updates of UI
69
69
self .setupWorkingMode (self .mode )
70
70
self .cboSchema .currentIndexChanged .connect (self .populateTables )
71
+ self .widgetSourceSrid .setCrs (QgsProject .instance ().crs ())
72
+ self .widgetTargetSrid .setCrs (QgsProject .instance ().crs ())
71
73
72
74
def setupWorkingMode (self , mode ):
73
75
""" hide the widget to select a layer/file if the input layer is already set """
@@ -210,9 +212,10 @@ def updateInputLayer(self):
210
212
self .editGeomColumn .setText (geom )
211
213
212
214
srcCrs = self .inLayer .crs ()
213
- srid = srcCrs .postgisSrid () if srcCrs .isValid () else 4326
214
- self .editSourceSrid .setText ("%s" % srid )
215
- self .editTargetSrid .setText ("%s" % srid )
215
+ if not srcCrs .isValid ():
216
+ srcCrs = QgsCoordinateReferenceSystem (4326 )
217
+ self .widgetSourceSrid .setCrs (srcCrs )
218
+ self .widgetTargetSrid .setCrs (srcCrs )
216
219
217
220
return True
218
221
@@ -270,27 +273,23 @@ def accept(self):
270
273
271
274
# sanity checks
272
275
if self .inLayer is None :
273
- QMessageBox .information (self , self .tr ("Import to database " ), self .tr ("Input layer missing or not valid" ))
276
+ QMessageBox .critical (self , self .tr ("Import to Database " ), self .tr ("Input layer missing or not valid. " ))
274
277
return
275
278
276
279
if self .cboTable .currentText () == "" :
277
- QMessageBox .information (self , self .tr ("Import to database " ), self .tr ("Output table name is required" ))
280
+ QMessageBox .critical (self , self .tr ("Import to Database " ), self .tr ("Output table name is required. " ))
278
281
return
279
282
280
283
if self .chkSourceSrid .isEnabled () and self .chkSourceSrid .isChecked ():
281
- try :
282
- sourceSrid = self .editSourceSrid .text ()
283
- except ValueError :
284
- QMessageBox .information (self , self .tr ("Import to database" ),
285
- self .tr ("Invalid source srid: must be an integer" ))
284
+ if not self .widgetSourceSrid .crs ().isValid ():
285
+ QMessageBox .critical (self , self .tr ("Import to Database" ),
286
+ self .tr ("Invalid source srid: must be a valid crs." ))
286
287
return
287
288
288
289
if self .chkTargetSrid .isEnabled () and self .chkTargetSrid .isChecked ():
289
- try :
290
- targetSrid = self .editTargetSrid .text ()
291
- except ValueError :
292
- QMessageBox .information (self , self .tr ("Import to database" ),
293
- self .tr ("Invalid target srid: must be an integer" ))
290
+ if not self .widgetTargetSrid .crs ().isValid ():
291
+ QMessageBox .critical (self , self .tr ("Import to Database" ),
292
+ self .tr ("Invalid target srid: must be a valid crs." ))
294
293
return
295
294
296
295
with OverrideCursor (Qt .WaitCursor ):
@@ -344,13 +343,11 @@ def accept(self):
344
343
345
344
outCrs = QgsCoordinateReferenceSystem ()
346
345
if self .chkTargetSrid .isEnabled () and self .chkTargetSrid .isChecked ():
347
- targetSrid = int (self .editTargetSrid .text ())
348
- outCrs = QgsCoordinateReferenceSystem (targetSrid )
346
+ outCrs = self .widgetTargetSrid .crs ()
349
347
350
348
# update input layer crs and encoding
351
349
if self .chkSourceSrid .isEnabled () and self .chkSourceSrid .isChecked ():
352
- sourceSrid = int (self .editSourceSrid .text ())
353
- inCrs = QgsCoordinateReferenceSystem (sourceSrid )
350
+ inCrs = self .widgetSourceSrid .crs ()
354
351
self .inLayer .setCrs (inCrs )
355
352
356
353
if self .chkEncoding .isEnabled () and self .chkEncoding .isChecked ():
@@ -372,7 +369,7 @@ def accept(self):
372
369
373
370
if ret != 0 :
374
371
output = QgsMessageViewer ()
375
- output .setTitle (self .tr ("Import to database " ))
372
+ output .setTitle (self .tr ("Import to Database " ))
376
373
output .setMessageAsPlainText (self .tr ("Error {0}\n {1}" ).format (ret , errMsg ))
377
374
output .showMessage ()
378
375
return
@@ -383,7 +380,7 @@ def accept(self):
383
380
384
381
self .db .connection ().reconnect ()
385
382
self .db .refresh ()
386
- QMessageBox .information (self , self .tr ("Import to database " ), self .tr ("Import was successful." ))
383
+ QMessageBox .information (self , self .tr ("Import to Database " ), self .tr ("Import was successful." ))
387
384
return QDialog .accept (self )
388
385
389
386
def closeEvent (self , event ):
0 commit comments