Skip to content

Commit eab76e8

Browse files
authoredApr 18, 2018
Merge pull request #6335 from Fanevanjanahary/crs_widget
use crs widget picker in db_manager
2 parents 9f41a9b + 77ca11e commit eab76e8

File tree

2 files changed

+115
-119
lines changed

2 files changed

+115
-119
lines changed
 

‎python/plugins/db_manager/dlg_import_vector.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ def __init__(self, inLayer, outDb, outUri, parent=None):
6868
# updates of UI
6969
self.setupWorkingMode(self.mode)
7070
self.cboSchema.currentIndexChanged.connect(self.populateTables)
71+
self.widgetSourceSrid.setCrs(QgsProject.instance().crs())
72+
self.widgetTargetSrid.setCrs(QgsProject.instance().crs())
7173

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

212214
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)
216219

217220
return True
218221

@@ -270,27 +273,23 @@ def accept(self):
270273

271274
# sanity checks
272275
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."))
274277
return
275278

276279
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."))
278281
return
279282

280283
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."))
286287
return
287288

288289
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."))
294293
return
295294

296295
with OverrideCursor(Qt.WaitCursor):
@@ -344,13 +343,11 @@ def accept(self):
344343

345344
outCrs = QgsCoordinateReferenceSystem()
346345
if self.chkTargetSrid.isEnabled() and self.chkTargetSrid.isChecked():
347-
targetSrid = int(self.editTargetSrid.text())
348-
outCrs = QgsCoordinateReferenceSystem(targetSrid)
346+
outCrs = self.widgetTargetSrid.crs()
349347

350348
# update input layer crs and encoding
351349
if self.chkSourceSrid.isEnabled() and self.chkSourceSrid.isChecked():
352-
sourceSrid = int(self.editSourceSrid.text())
353-
inCrs = QgsCoordinateReferenceSystem(sourceSrid)
350+
inCrs = self.widgetSourceSrid.crs()
354351
self.inLayer.setCrs(inCrs)
355352

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

373370
if ret != 0:
374371
output = QgsMessageViewer()
375-
output.setTitle(self.tr("Import to database"))
372+
output.setTitle(self.tr("Import to Database"))
376373
output.setMessageAsPlainText(self.tr("Error {0}\n{1}").format(ret, errMsg))
377374
output.showMessage()
378375
return
@@ -383,7 +380,7 @@ def accept(self):
383380

384381
self.db.connection().reconnect()
385382
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."))
387384
return QDialog.accept(self)
388385

389386
def closeEvent(self, event):

‎python/plugins/db_manager/ui/DlgImportVector.ui

Lines changed: 97 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@
153153
<string>Options</string>
154154
</property>
155155
<layout class="QGridLayout" name="gridLayout">
156+
<item row="5" column="0" colspan="2">
157+
<widget class="QCheckBox" name="chkDropTable">
158+
<property name="text">
159+
<string>Replace destination table (if exists)</string>
160+
</property>
161+
</widget>
162+
</item>
156163
<item row="0" column="0">
157164
<widget class="QCheckBox" name="chkPrimaryKey">
158165
<property name="text">
@@ -181,62 +188,14 @@
181188
</property>
182189
</widget>
183190
</item>
184-
<item row="2" column="0" colspan="2">
185-
<layout class="QHBoxLayout" name="horizontalLayout">
186-
<item>
187-
<widget class="QCheckBox" name="chkSourceSrid">
188-
<property name="text">
189-
<string>Source SRID</string>
190-
</property>
191-
</widget>
192-
</item>
193-
<item>
194-
<widget class="QLineEdit" name="editSourceSrid">
195-
<property name="enabled">
196-
<bool>false</bool>
197-
</property>
198-
</widget>
199-
</item>
200-
<item>
201-
<spacer name="spacer">
202-
<property name="orientation">
203-
<enum>Qt::Horizontal</enum>
204-
</property>
205-
<property name="sizeType">
206-
<enum>QSizePolicy::Fixed</enum>
207-
</property>
208-
<property name="sizeHint" stdset="0">
209-
<size>
210-
<width>40</width>
211-
<height>20</height>
212-
</size>
213-
</property>
214-
</spacer>
215-
</item>
216-
<item>
217-
<widget class="QCheckBox" name="chkTargetSrid">
218-
<property name="text">
219-
<string>Target SRID</string>
220-
</property>
221-
</widget>
222-
</item>
223-
<item>
224-
<widget class="QLineEdit" name="editTargetSrid">
225-
<property name="enabled">
226-
<bool>false</bool>
227-
</property>
228-
</widget>
229-
</item>
230-
</layout>
231-
</item>
232-
<item row="3" column="0">
191+
<item row="4" column="0">
233192
<widget class="QCheckBox" name="chkEncoding">
234193
<property name="text">
235194
<string>Encoding</string>
236195
</property>
237196
</widget>
238197
</item>
239-
<item row="3" column="1">
198+
<item row="4" column="1">
240199
<widget class="QComboBox" name="cboEncoding">
241200
<property name="enabled">
242201
<bool>false</bool>
@@ -246,31 +205,52 @@
246205
</property>
247206
</widget>
248207
</item>
249-
<item row="6" column="0" colspan="2">
208+
<item row="7" column="0" colspan="2">
250209
<widget class="QCheckBox" name="chkSinglePart">
251210
<property name="text">
252211
<string>Create single-part geometries instead of multi-part</string>
253212
</property>
254213
</widget>
255214
</item>
256-
<item row="8" column="0" colspan="2">
215+
<item row="9" column="0" colspan="2">
257216
<widget class="QCheckBox" name="chkSpatialIndex">
258217
<property name="text">
259218
<string>Create spatial index</string>
260219
</property>
261220
</widget>
262221
</item>
263-
<item row="4" column="0" colspan="2">
264-
<widget class="QCheckBox" name="chkDropTable">
222+
<item row="8" column="0">
223+
<widget class="QCheckBox" name="chkLowercaseFieldNames">
265224
<property name="text">
266-
<string>Replace destination table (if exists)</string>
225+
<string>Convert field names to lowercase</string>
267226
</property>
268227
</widget>
269228
</item>
270-
<item row="7" column="0">
271-
<widget class="QCheckBox" name="chkLowercaseFieldNames">
229+
<item row="3" column="0">
230+
<widget class="QCheckBox" name="chkTargetSrid">
272231
<property name="text">
273-
<string>Convert field names to lowercase</string>
232+
<string>Target SRID</string>
233+
</property>
234+
</widget>
235+
</item>
236+
<item row="3" column="1">
237+
<widget class="QgsProjectionSelectionWidget" name="widgetTargetSrid" native="true">
238+
<property name="enabled">
239+
<bool>false</bool>
240+
</property>
241+
</widget>
242+
</item>
243+
<item row="2" column="1">
244+
<widget class="QgsProjectionSelectionWidget" name="widgetSourceSrid" native="true">
245+
<property name="enabled">
246+
<bool>false</bool>
247+
</property>
248+
</widget>
249+
</item>
250+
<item row="2" column="0">
251+
<widget class="QCheckBox" name="chkSourceSrid">
252+
<property name="text">
253+
<string>Source SRID</string>
274254
</property>
275255
</widget>
276256
</item>
@@ -293,14 +273,33 @@
293273
<zorder>groupBox_3</zorder>
294274
<zorder>wdgInput</zorder>
295275
</widget>
276+
<customwidgets>
277+
<customwidget>
278+
<class>QgsProjectionSelectionWidget</class>
279+
<extends>QWidget</extends>
280+
<header>qgis.gui</header>
281+
<container>1</container>
282+
</customwidget>
283+
</customwidgets>
296284
<tabstops>
285+
<tabstop>cboInputLayer</tabstop>
286+
<tabstop>btnChooseInputFile</tabstop>
287+
<tabstop>chkSelectedFeatures</tabstop>
288+
<tabstop>btnUpdateInputLayer</tabstop>
289+
<tabstop>cboSchema</tabstop>
290+
<tabstop>cboTable</tabstop>
291+
<tabstop>chkPrimaryKey</tabstop>
292+
<tabstop>editPrimaryKey</tabstop>
293+
<tabstop>chkGeomColumn</tabstop>
294+
<tabstop>editGeomColumn</tabstop>
297295
<tabstop>chkSourceSrid</tabstop>
298-
<tabstop>editSourceSrid</tabstop>
296+
<tabstop>chkTargetSrid</tabstop>
299297
<tabstop>chkEncoding</tabstop>
300298
<tabstop>cboEncoding</tabstop>
299+
<tabstop>chkDropTable</tabstop>
301300
<tabstop>chkSinglePart</tabstop>
301+
<tabstop>chkLowercaseFieldNames</tabstop>
302302
<tabstop>chkSpatialIndex</tabstop>
303-
<tabstop>buttonBox</tabstop>
304303
</tabstops>
305304
<resources/>
306305
<connections>
@@ -311,8 +310,8 @@
311310
<slot>reject()</slot>
312311
<hints>
313312
<hint type="sourcelabel">
314-
<x>325</x>
315-
<y>518</y>
313+
<x>334</x>
314+
<y>486</y>
316315
</hint>
317316
<hint type="destinationlabel">
318317
<x>286</x>
@@ -327,12 +326,12 @@
327326
<slot>setEnabled(bool)</slot>
328327
<hints>
329328
<hint type="sourcelabel">
330-
<x>108</x>
331-
<y>347</y>
329+
<x>129</x>
330+
<y>239</y>
332331
</hint>
333332
<hint type="destinationlabel">
334-
<x>207</x>
335-
<y>345</y>
333+
<x>460</x>
334+
<y>239</y>
336335
</hint>
337336
</hints>
338337
</connection>
@@ -343,76 +342,76 @@
343342
<slot>setEnabled(bool)</slot>
344343
<hints>
345344
<hint type="sourcelabel">
346-
<x>120</x>
347-
<y>367</y>
345+
<x>141</x>
346+
<y>265</y>
348347
</hint>
349348
<hint type="destinationlabel">
350-
<x>188</x>
351-
<y>367</y>
349+
<x>442</x>
350+
<y>265</y>
352351
</hint>
353352
</hints>
354353
</connection>
355354
<connection>
356-
<sender>chkSourceSrid</sender>
355+
<sender>chkEncoding</sender>
357356
<signal>toggled(bool)</signal>
358-
<receiver>editSourceSrid</receiver>
357+
<receiver>cboEncoding</receiver>
359358
<slot>setEnabled(bool)</slot>
360359
<hints>
361360
<hint type="sourcelabel">
362-
<x>115</x>
363-
<y>390</y>
361+
<x>119</x>
362+
<y>343</y>
364363
</hint>
365364
<hint type="destinationlabel">
366-
<x>166</x>
367-
<y>394</y>
365+
<x>455</x>
366+
<y>343</y>
368367
</hint>
369368
</hints>
370369
</connection>
371370
<connection>
372-
<sender>chkTargetSrid</sender>
373-
<signal>toggled(bool)</signal>
374-
<receiver>editTargetSrid</receiver>
375-
<slot>setEnabled(bool)</slot>
371+
<sender>buttonBox</sender>
372+
<signal>accepted()</signal>
373+
<receiver>DbManagerDlgImportVector</receiver>
374+
<slot>accept()</slot>
376375
<hints>
377376
<hint type="sourcelabel">
378-
<x>360</x>
379-
<y>396</y>
377+
<x>461</x>
378+
<y>486</y>
380379
</hint>
381380
<hint type="destinationlabel">
382-
<x>435</x>
383-
<y>394</y>
381+
<x>508</x>
382+
<y>243</y>
384383
</hint>
385384
</hints>
386385
</connection>
387386
<connection>
388-
<sender>chkEncoding</sender>
387+
<sender>chkSourceSrid</sender>
389388
<signal>toggled(bool)</signal>
390-
<receiver>cboEncoding</receiver>
389+
<receiver>widgetSourceSrid</receiver>
391390
<slot>setEnabled(bool)</slot>
392391
<hints>
393392
<hint type="sourcelabel">
394-
<x>98</x>
395-
<y>415</y>
393+
<x>134</x>
394+
<y>281</y>
396395
</hint>
397396
<hint type="destinationlabel">
398-
<x>201</x>
399-
<y>414</y>
397+
<x>357</x>
398+
<y>281</y>
400399
</hint>
401400
</hints>
402401
</connection>
403402
<connection>
404-
<sender>buttonBox</sender>
405-
<signal>accepted()</signal>
406-
<receiver>DbManagerDlgImportVector</receiver>
407-
<slot>accept()</slot>
403+
<sender>chkTargetSrid</sender>
404+
<signal>toggled(bool)</signal>
405+
<receiver>widgetTargetSrid</receiver>
406+
<slot>setEnabled(bool)</slot>
408407
<hints>
409408
<hint type="sourcelabel">
410-
<x>452</x>
411-
<y>505</y>
409+
<x>134</x>
410+
<y>307</y>
412411
</hint>
413412
<hint type="destinationlabel">
414-
<x>508</x>
415-
<y>243</y>
413+
<x>357</x>
414+
<y>307</y>
416415
</hint>
417416
</hints>
418417
</connection>

0 commit comments

Comments
 (0)
Please sign in to comment.