Skip to content

Commit c3c79b9

Browse files
committedDec 5, 2012
dbmanager: minor fixes
1 parent c99fdd4 commit c3c79b9

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed
 

‎python/plugins/db_manager/db_manager.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,13 @@ def importActionSlot(self):
150150
QMessageBox.information(self, "Sorry", "No database selected or you are not connected to it.")
151151
return
152152

153+
outUri = db.uri()
154+
schema = self.tree.currentSchema()
155+
if schema:
156+
outUri.setDataSource( schema.name, "", "", "" )
157+
153158
from .dlg_import_vector import DlgImportVector
154-
dlg = DlgImportVector(None, db, db.uri(), self)
159+
dlg = DlgImportVector(None, db, outUri, self)
155160
dlg.exec_()
156161

157162
def exportActionSlot(self):

‎python/plugins/db_manager/dlg_import_vector.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,27 @@ def __init__(self, inLayer, outDb, outUri, parent=None):
4444
self.default_pk = "id"
4545
self.default_geom = "geom"
4646

47-
# updates of UI
48-
self.setupWorkingMode()
47+
self.mode = self.ASK_FOR_INPUT_MODE if self.inLayer is None else self.HAS_INPUT_MODE
4948

50-
self.cboTable.setEditText(self.outUri.table())
51-
52-
self.populateLayers()
49+
# updates of UI
50+
self.setupWorkingMode( self.mode )
5351

5452
self.connect(self.cboSchema, SIGNAL("currentIndexChanged(int)"), self.populateTables)
5553
self.populateSchemas()
5654
self.populateTables()
57-
55+
self.populateLayers()
5856
self.populateEncodings()
5957

6058

61-
def setupWorkingMode(self):
62-
""" display the widget to select a layer/file if there's no input layer """
63-
self.mode = self.ASK_FOR_INPUT_MODE if self.inLayer is None else self.HAS_INPUT_MODE
64-
self.wdgInput.setVisible( self.mode == self.ASK_FOR_INPUT_MODE )
59+
def setupWorkingMode(self, mode):
60+
""" hide the widget to select a layer/file if the input layer
61+
is already set """
62+
self.wdgInput.setVisible( mode == self.ASK_FOR_INPUT_MODE )
63+
self.resize( 200, 200 )
64+
65+
self.cboTable.setEditText(self.outUri.table())
6566

66-
if not self.inLayer:
67+
if mode == self.ASK_FOR_INPUT_MODE:
6768
QObject.connect( self.btnChooseInputFile, SIGNAL("clicked()"), self.chooseInputFile )
6869
#QObject.connect( self.cboInputLayer.lineEdit(), SIGNAL("editingFinished()"), self.updateInputLayer )
6970
QObject.connect( self.cboInputLayer, SIGNAL("editTextChanged(const QString &)"), self.inputPathChanged )
@@ -114,7 +115,7 @@ def deleteInputLayer(self):
114115
return False
115116

116117
def chooseInputFile(self):
117-
vectorFormats = qgis.core.QgsVectorFileWriter.fileFilterString()
118+
vectorFormats = qgis.core.QgsProviderRegistry.instance().fileVectorFilters()
118119
# get last used dir and format
119120
settings = QSettings()
120121
lastDir = settings.value("/db_manager/lastUsedDir", "").toString()
@@ -216,12 +217,19 @@ def populateEncodings(self):
216217
self.cboEncoding.setCurrentIndex(2)
217218

218219
def accept(self):
220+
if self.mode == self.ASK_FOR_INPUT_MODE:
221+
# create the input layer (if not already done) and
222+
# update available options w/o changing the tablename!
223+
self.cboTable.blockSignals(True)
224+
table = self.cboTable.currentText()
225+
self.updateInputLayer()
226+
self.cboTable.setEditText(table)
227+
self.cboTable.blockSignals(False)
228+
219229
# sanity checks
220230
if self.inLayer is None:
221-
# create the input layer and update available options
222-
if not self.updateInputLayer():
223-
QMessageBox.information(self, "Import to database", "Input layer missing or not valid")
224-
return
231+
QMessageBox.information(self, "Import to database", "Input layer missing or not valid")
232+
return
225233

226234
if self.cboTable.currentText() == "":
227235
QMessageBox.information(self, "Import to database", "Output table name is required")

0 commit comments

Comments
 (0)
Please sign in to comment.