Skip to content

Commit

Permalink
use crs widget picker in db_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Fanevanjanahary committed Feb 20, 2018
1 parent e3fbb4c commit 2d2390d
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 116 deletions.
33 changes: 15 additions & 18 deletions python/plugins/db_manager/dlg_import_vector.py
Expand Up @@ -36,7 +36,7 @@
QgsVectorLayerExporter,
QgsProject,
QgsSettings)
from qgis.gui import QgsMessageViewer
from qgis.gui import QgsMessageViewer, QgsProjectionSelectionWidget
from qgis.utils import OverrideCursor

from .ui.ui_DlgImportVector import Ui_DbManagerDlgImportVector as Ui_Dialog
Expand Down 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.setOptionVisible(QgsProjectionSelectionWidget.CrsNotSet, True)
self.widgetTargetSrid.setOptionVisible(QgsProjectionSelectionWidget.CrsNotSet, True)

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 @@ -278,19 +281,15 @@ def accept(self):
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 Down
195 changes: 97 additions & 98 deletions python/plugins/db_manager/ui/DlgImportVector.ui
Expand Up @@ -153,6 +153,13 @@
<string>Options</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="chkDropTable">
<property name="text">
<string>Replace destination table (if exists)</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="chkPrimaryKey">
<property name="text">
Expand Down Expand Up @@ -181,62 +188,14 @@
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="chkSourceSrid">
<property name="text">
<string>Source SRID</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="editSourceSrid">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer name="spacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="chkTargetSrid">
<property name="text">
<string>Target SRID</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="editTargetSrid">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QCheckBox" name="chkEncoding">
<property name="text">
<string>Encoding</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="QComboBox" name="cboEncoding">
<property name="enabled">
<bool>false</bool>
Expand All @@ -246,31 +205,52 @@
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<item row="7" column="0" colspan="2">
<widget class="QCheckBox" name="chkSinglePart">
<property name="text">
<string>Create single-part geometries instead of multi-part</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<item row="9" column="0" colspan="2">
<widget class="QCheckBox" name="chkSpatialIndex">
<property name="text">
<string>Create spatial index</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="chkDropTable">
<item row="8" column="0">
<widget class="QCheckBox" name="chkLowercaseFieldNames">
<property name="text">
<string>Replace destination table (if exists)</string>
<string>Convert field names to lowercase</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QCheckBox" name="chkLowercaseFieldNames">
<item row="3" column="0">
<widget class="QCheckBox" name="chkTargetSrid">
<property name="text">
<string>Convert field names to lowercase</string>
<string>Target SRID</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QgsProjectionSelectionWidget" name="widgetTargetSrid" native="true">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QgsProjectionSelectionWidget" name="widgetSourceSrid" native="true">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="chkSourceSrid">
<property name="text">
<string>Source SRID</string>
</property>
</widget>
</item>
Expand All @@ -293,14 +273,33 @@
<zorder>groupBox_3</zorder>
<zorder>wdgInput</zorder>
</widget>
<customwidgets>
<customwidget>
<class>QgsProjectionSelectionWidget</class>
<extends>QWidget</extends>
<header>qgis.gui</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>cboInputLayer</tabstop>
<tabstop>btnChooseInputFile</tabstop>
<tabstop>chkSelectedFeatures</tabstop>
<tabstop>btnUpdateInputLayer</tabstop>
<tabstop>cboSchema</tabstop>
<tabstop>cboTable</tabstop>
<tabstop>chkPrimaryKey</tabstop>
<tabstop>editPrimaryKey</tabstop>
<tabstop>chkGeomColumn</tabstop>
<tabstop>editGeomColumn</tabstop>
<tabstop>chkSourceSrid</tabstop>
<tabstop>editSourceSrid</tabstop>
<tabstop>chkTargetSrid</tabstop>
<tabstop>chkEncoding</tabstop>
<tabstop>cboEncoding</tabstop>
<tabstop>chkDropTable</tabstop>
<tabstop>chkSinglePart</tabstop>
<tabstop>chkLowercaseFieldNames</tabstop>
<tabstop>chkSpatialIndex</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
Expand All @@ -311,8 +310,8 @@
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>325</x>
<y>518</y>
<x>334</x>
<y>486</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
Expand All @@ -327,12 +326,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>108</x>
<y>347</y>
<x>129</x>
<y>239</y>
</hint>
<hint type="destinationlabel">
<x>207</x>
<y>345</y>
<x>460</x>
<y>239</y>
</hint>
</hints>
</connection>
Expand All @@ -343,76 +342,76 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>120</x>
<y>367</y>
<x>141</x>
<y>265</y>
</hint>
<hint type="destinationlabel">
<x>188</x>
<y>367</y>
<x>442</x>
<y>265</y>
</hint>
</hints>
</connection>
<connection>
<sender>chkSourceSrid</sender>
<sender>chkEncoding</sender>
<signal>toggled(bool)</signal>
<receiver>editSourceSrid</receiver>
<receiver>cboEncoding</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>115</x>
<y>390</y>
<x>119</x>
<y>343</y>
</hint>
<hint type="destinationlabel">
<x>166</x>
<y>394</y>
<x>455</x>
<y>343</y>
</hint>
</hints>
</connection>
<connection>
<sender>chkTargetSrid</sender>
<signal>toggled(bool)</signal>
<receiver>editTargetSrid</receiver>
<slot>setEnabled(bool)</slot>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DbManagerDlgImportVector</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>360</x>
<y>396</y>
<x>461</x>
<y>486</y>
</hint>
<hint type="destinationlabel">
<x>435</x>
<y>394</y>
<x>508</x>
<y>243</y>
</hint>
</hints>
</connection>
<connection>
<sender>chkEncoding</sender>
<sender>chkSourceSrid</sender>
<signal>toggled(bool)</signal>
<receiver>cboEncoding</receiver>
<receiver>widgetSourceSrid</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>98</x>
<y>415</y>
<x>134</x>
<y>281</y>
</hint>
<hint type="destinationlabel">
<x>201</x>
<y>414</y>
<x>357</x>
<y>281</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DbManagerDlgImportVector</receiver>
<slot>accept()</slot>
<sender>chkTargetSrid</sender>
<signal>toggled(bool)</signal>
<receiver>widgetTargetSrid</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>452</x>
<y>505</y>
<x>134</x>
<y>307</y>
</hint>
<hint type="destinationlabel">
<x>508</x>
<y>243</y>
<x>357</x>
<y>307</y>
</hint>
</hints>
</connection>
Expand Down

0 comments on commit 2d2390d

Please sign in to comment.