Skip to content

Commit

Permalink
[dbmanager] fix some import statement
Browse files Browse the repository at this point in the history
  • Loading branch information
slarosa committed Jun 10, 2016
1 parent c578f3a commit 3b998d2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion python/plugins/db_manager/db_model.py
Expand Up @@ -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

Expand Down
16 changes: 8 additions & 8 deletions python/plugins/db_manager/dlg_export_vector.py
Expand Up @@ -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

Expand Down Expand Up @@ -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(' ')]

Expand All @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
23 changes: 12 additions & 11 deletions python/plugins/db_manager/dlg_import_vector.py
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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", "")
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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():
Expand All @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit 3b998d2

Please sign in to comment.