Skip to content
Permalink
Browse files

[dbmanager] fix some import statement

  • Loading branch information
slarosa committed Jun 10, 2016
1 parent c578f3a commit 3b998d21edc15972904ab381f9e88b8f3ec2724d
@@ -21,7 +21,7 @@
"""

from functools import partial
from qgis.PyQt.QtCore import Qt, QObject, qDebug, QByteArray, QMimeData, QDataStream, QIODevice, QFileInfo, QAbstractItemModel, QModelIndex, pyqtSignal, pyqtSlot
from qgis.PyQt.QtCore import Qt, QObject, qDebug, QByteArray, QMimeData, QDataStream, QIODevice, QFileInfo, QAbstractItemModel, QModelIndex, pyqtSignal
from qgis.PyQt.QtWidgets import QApplication, QMessageBox
from qgis.PyQt.QtGui import QIcon

@@ -26,7 +26,7 @@
from qgis.PyQt.QtWidgets import QDialog, QFileDialog, QMessageBox, QApplication
from qgis.PyQt.QtGui import QCursor

import qgis.core
from qgis.core import QgsVectorFileWriter, QgsVectorDataProvider, QgsCoordinateReferenceSystem, QgsVectorLayerImport

from .ui.ui_DlgExportVector import Ui_DbManagerDlgExportVector as Ui_Dialog

@@ -80,7 +80,7 @@ def chooseOutputFile(self):
if filename == "":
return

filterString = qgis.core.QgsVectorFileWriter.filterForDriver(selectedFilter)
filterString = QgsVectorFileWriter.filterForDriver(selectedFilter)
ext = filterString[filterString.find('.'):]
ext = ext[:ext.find(' ')]

@@ -94,7 +94,7 @@ def chooseOutputFile(self):

def populateEncodings(self):
# populate the combo with supported encodings
self.cboEncoding.addItems(qgis.core.QgsVectorDataProvider.availableEncodings())
self.cboEncoding.addItems(QgsVectorDataProvider.availableEncodings())

# set the last used encoding
enc = self.inLayer.dataProvider().encoding()
@@ -106,7 +106,7 @@ def populateEncodings(self):

def populateFileFilters(self):
# populate the combo with supported vector file formats
for name, filt in qgis.core.QgsVectorFileWriter.ogrDriverList().items():
for name, filt in QgsVectorFileWriter.ogrDriverList().items():
self.cboFileFormat.addItem(name, filt)

# set the last used filter
@@ -165,17 +165,17 @@ def accept(self):
outCrs = None
if self.chkTargetSrid.isEnabled() and self.chkTargetSrid.isChecked():
targetSrid = int(self.editTargetSrid.text())
outCrs = qgis.core.QgsCoordinateReferenceSystem(targetSrid)
outCrs = QgsCoordinateReferenceSystem(targetSrid)

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

# do the export!
ret, errMsg = qgis.core.QgsVectorLayerImport.importLayer(self.inLayer, uri, providerName, outCrs, False,
False, options)
ret, errMsg = QgsVectorLayerImport.importLayer(self.inLayer, uri, providerName, outCrs, False,
False, options)
except Exception as e:
ret = -1
errMsg = unicode(e)
@@ -26,7 +26,8 @@
from qgis.PyQt.QtWidgets import QDialog, QFileDialog, QMessageBox, QApplication
from qgis.PyQt.QtGui import QCursor

import qgis.core
from qgis.core import QgsDataSourceURI, QgsVectorLayer, QgsRasterLayer, QgsMimeDataUtils, QgsMapLayer, QgsProviderRegistry, QgsCoordinateReferenceSystem, QgsVectorLayerImport
from qgis.gui import QgsMessageViewer
from qgis.utils import iface

from .ui.ui_DlgImportVector import Ui_DbManagerDlgImportVector as Ui_Dialog
@@ -109,7 +110,7 @@ def populateLayers(self):
self.cboInputLayer.clear()
for index, layer in enumerate(iface.legendInterface().layers()):
# TODO: add import raster support!
if layer.type() == qgis.core.QgsMapLayer.VectorLayer:
if layer.type() == QgsMapLayer.VectorLayer:
self.cboInputLayer.addItem(layer.name(), index)

def deleteInputLayer(self):
@@ -123,7 +124,7 @@ def deleteInputLayer(self):
return False

def chooseInputFile(self):
vectorFormats = qgis.core.QgsProviderRegistry.instance().fileVectorFilters()
vectorFormats = QgsProviderRegistry.instance().fileVectorFilters()
# get last used dir and format
settings = QSettings()
lastDir = settings.value("/db_manager/lastUsedDir", "")
@@ -161,8 +162,8 @@ def reloadInputLayer(self):
return False

layerName = QFileInfo(filename).completeBaseName()
layer = qgis.core.QgsVectorLayer(filename, layerName, "ogr")
if not layer.isValid() or layer.type() != qgis.core.QgsMapLayer.VectorLayer:
layer = QgsVectorLayer(filename, layerName, "ogr")
if not layer.isValid() or layer.type() != QgsMapLayer.VectorLayer:
layer.deleteLater()
return False

@@ -184,7 +185,7 @@ def updateInputLayer(self):
# update the output table name, pk and geom column
self.cboTable.setEditText(self.inLayer.name())

srcUri = qgis.core.QgsDataSourceURI(self.inLayer.source())
srcUri = QgsDataSourceURI(self.inLayer.source())
pk = srcUri.keyColumn() if srcUri.keyColumn() else self.default_pk
self.editPrimaryKey.setText(pk)
geom = srcUri.geometryColumn() if srcUri.geometryColumn() else self.default_geom
@@ -286,7 +287,7 @@ def accept(self):

# get pk and geom field names from the source layer or use the
# ones defined by the user
srcUri = qgis.core.QgsDataSourceURI(self.inLayer.source())
srcUri = QgsDataSourceURI(self.inLayer.source())

pk = srcUri.keyColumn() if not self.chkPrimaryKey.isChecked() else self.editPrimaryKey.text()
if not pk:
@@ -315,12 +316,12 @@ def accept(self):
outCrs = None
if self.chkTargetSrid.isEnabled() and self.chkTargetSrid.isChecked():
targetSrid = int(self.editTargetSrid.text())
outCrs = qgis.core.QgsCoordinateReferenceSystem(targetSrid)
outCrs = QgsCoordinateReferenceSystem(targetSrid)

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

if self.chkEncoding.isEnabled() and self.chkEncoding.isChecked():
@@ -330,7 +331,7 @@ def accept(self):
onlySelected = self.chkSelectedFeatures.isChecked()

# do the import!
ret, errMsg = qgis.core.QgsVectorLayerImport.importLayer(self.inLayer, uri, providerName, outCrs, onlySelected, False, options)
ret, errMsg = QgsVectorLayerImport.importLayer(self.inLayer, uri, providerName, outCrs, onlySelected, False, options)
except Exception as e:
ret = -1
errMsg = unicode(e)
@@ -343,7 +344,7 @@ def accept(self):
QApplication.restoreOverrideCursor()

if ret != 0:
output = qgis.gui.QgsMessageViewer()
output = QgsMessageViewer()
output.setTitle(self.tr("Import to database"))
output.setMessageAsPlainText(self.tr("Error %d\n%s") % (ret, errMsg))
output.showMessage()

0 comments on commit 3b998d2

Please sign in to comment.
You can’t perform that action at this time.