Skip to content

Commit

Permalink
Add "import only selected features" option to db manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Augustin authored and m-kuhn committed Sep 9, 2015
1 parent 5f19dff commit 2a5f262
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
16 changes: 9 additions & 7 deletions python/plugins/db_manager/dlg_import_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def setupWorkingMode(self, mode):
QObject.connect(self.btnChooseInputFile, SIGNAL("clicked()"), self.chooseInputFile)
# QObject.connect( self.cboInputLayer.lineEdit(), SIGNAL("editingFinished()"), self.updateInputLayer )
QObject.connect(self.cboInputLayer, SIGNAL("editTextChanged(const QString &)"), self.inputPathChanged)
#QObject.connect( self.cboInputLayer, SIGNAL("currentIndexChanged(int)"), self.updateInputLayer )
# QObject.connect( self.cboInputLayer, SIGNAL("currentIndexChanged(int)"), self.updateInputLayer )
QObject.connect(self.btnUpdateInputLayer, SIGNAL("clicked()"), self.updateInputLayer)

self.editPrimaryKey.setText(self.default_pk)
Expand Down Expand Up @@ -326,12 +326,14 @@ def accept(self):
enc = self.cboEncoding.currentText()
self.inLayer.setProviderEncoding(enc)

onlySelected = self.chkSelectedFeatures.isChecked()

# do the import!
ret, errMsg = qgis.core.QgsVectorLayerImport.importLayer(self.inLayer, uri, providerName, outCrs, False,
ret, errMsg = qgis.core.QgsVectorLayerImport.importLayer(self.inLayer, uri, providerName, outCrs, onlySelected, False, options)
False, options)
except Exception as e:
ret = -1
errMsg = unicode(e)
ret=-1
errMsg=unicode(e)

finally:
# restore input layer crs and encoding
Expand All @@ -341,7 +343,7 @@ def accept(self):
QApplication.restoreOverrideCursor()

if ret != 0:
output = qgis.gui.QgsMessageViewer()
output=qgis.gui.QgsMessageViewer()
output.setTitle(self.tr("Import to database"))
output.setMessageAsPlainText(self.tr("Error %d\n%s") % (ret, errMsg))
output.showMessage()
Expand All @@ -364,7 +366,7 @@ def closeEvent(self, event):
if __name__ == '__main__':
import sys

a = QApplication(sys.argv)
dlg = DlgImportVector()
a=QApplication(sys.argv)
dlg=DlgImportVector()
dlg.show()
sys.exit(a.exec_())
7 changes: 7 additions & 0 deletions python/plugins/db_manager/ui/DlgImportVector.ui
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@
</item>
<item row="1" column="0" colspan="4">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="chkSelectedFeatures">
<property name="text">
<string>Import only selected features</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
Expand Down

0 comments on commit 2a5f262

Please sign in to comment.