mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
[DBManager] allow to export table data to supported ogr file formats other than shapefile (fix #12111)
This commit is contained in:
parent
2a1cacd5f4
commit
99211262f3
@ -38,8 +38,13 @@ class DlgExportVector(QDialog, Ui_Dialog):
|
||||
self.db = inDb
|
||||
self.setupUi(self)
|
||||
|
||||
vectorFilterName = "lastVectorFileFilter" # "lastRasterFileFilter"
|
||||
self.lastUsedVectorFilterSettingsKey = u"/UI/{0}".format(vectorFilterName)
|
||||
self.lastUsedVectorDirSettingsKey = u"/UI/{0}Dir".format(vectorFilterName)
|
||||
|
||||
# update UI
|
||||
self.setupWorkingMode()
|
||||
self.populateFileFilters()
|
||||
self.populateEncodings()
|
||||
|
||||
def setupWorkingMode(self):
|
||||
@ -61,18 +66,21 @@ class DlgExportVector(QDialog, Ui_Dialog):
|
||||
# self.chkSpatialIndex.setEnabled(allowSpatial and hasGeomType)
|
||||
|
||||
def chooseOutputFile(self):
|
||||
# get last used dir and format
|
||||
# get last used dir
|
||||
settings = QSettings()
|
||||
lastDir = settings.value("/db_manager/lastUsedDir", "")
|
||||
lastUsedDir = settings.value( self.lastUsedVectorDirSettingsKey, "." );
|
||||
|
||||
# get selected filter
|
||||
selectedFilter = self.cboFileFormat.itemData(self.cboFileFormat.currentIndex())
|
||||
|
||||
# ask for a filename
|
||||
filename = QFileDialog.getSaveFileName(self, self.tr("Choose where to save the file"), lastDir,
|
||||
self.tr("Shapefiles") + " (*.shp)")
|
||||
filename = QFileDialog.getSaveFileName(self, self.tr("Choose where to save the file"), lastUsedDir,
|
||||
selectedFilter)
|
||||
if filename == "":
|
||||
return
|
||||
if filename[-4:] != ".shp":
|
||||
filename += ".shp"
|
||||
# store the last used dir and format
|
||||
settings.setValue("/db_manager/lastUsedDir", QFileInfo(filename).filePath())
|
||||
|
||||
# store the last used dir
|
||||
settings.setValue( self.lastUsedVectorDirSettingsKey, QFileInfo(filename).filePath() )
|
||||
|
||||
self.editOutputFile.setText(filename)
|
||||
|
||||
@ -88,10 +96,25 @@ class DlgExportVector(QDialog, Ui_Dialog):
|
||||
idx = 0
|
||||
self.cboEncoding.setCurrentIndex(idx)
|
||||
|
||||
def populateFileFilters(self):
|
||||
# populate the combo with supported vector file formats
|
||||
for name, filt in qgis.core.QgsVectorFileWriter.ogrDriverList().iteritems():
|
||||
self.cboFileFormat.addItem(name, filt)
|
||||
|
||||
# set the last used filter
|
||||
settings = QSettings()
|
||||
filt = settings.value( self.lastUsedVectorFilterSettingsKey, "ESRI Shapefile" );
|
||||
|
||||
idx = self.cboFileFormat.findText(filt)
|
||||
if idx < 0:
|
||||
idx = 0
|
||||
self.cboFileFormat.setCurrentIndex(idx)
|
||||
|
||||
|
||||
def accept(self):
|
||||
# sanity checks
|
||||
if self.editOutputFile.text() == "":
|
||||
QMessageBox.information(self, self.tr("Export to file"), self.tr("Output table name is required"))
|
||||
QMessageBox.information(self, self.tr("Export to file"), self.tr("Output file name is required"))
|
||||
return
|
||||
|
||||
if self.chkSourceSrid.isEnabled() and self.chkSourceSrid.isChecked():
|
||||
@ -117,12 +140,13 @@ class DlgExportVector(QDialog, Ui_Dialog):
|
||||
try:
|
||||
uri = self.editOutputFile.text()
|
||||
providerName = "ogr"
|
||||
driverName = "ESRI Shapefile"
|
||||
|
||||
options = {}
|
||||
|
||||
# set the OGR driver will be used
|
||||
driverName = self.cboFileFormat.itemData(self.cboFileFormat.currentIndex())
|
||||
options['driverName'] = driverName
|
||||
|
||||
# set the output file encoding
|
||||
if self.chkEncoding.isEnabled() and self.chkEncoding.isChecked():
|
||||
enc = self.cboEncoding.currentText()
|
||||
|
@ -7,14 +7,34 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>514</width>
|
||||
<height>185</height>
|
||||
<height>253</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Export to vector file</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="editOutputFile">
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="3">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="2">
|
||||
<widget class="QComboBox" name="cboFileFormat"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
@ -23,30 +43,23 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Output file</string>
|
||||
<string>Save as</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="editOutputFile">
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QToolButton" name="btnChooseOutputFile">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="3">
|
||||
<item row="2" column="0" colspan="3">
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Options</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="chkDropTable">
|
||||
<property name="text">
|
||||
<string>Drop existing one</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
@ -127,23 +140,20 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="chkDropTable">
|
||||
<property name="text">
|
||||
<string>Drop existing one</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="3">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<item row="1" column="2">
|
||||
<widget class="QToolButton" name="btnChooseOutputFile">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Format</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user