@@ -71,31 +71,33 @@ def setupWorkingMode(self, mode):
71
71
QObject .connect (self .cboInputLayer , SIGNAL ("editTextChanged(const QString &)" ), self .inputPathChanged )
72
72
#QObject.connect( self.cboInputLayer, SIGNAL("currentIndexChanged(int)"), self.updateInputLayer )
73
73
QObject .connect (self .btnUpdateInputLayer , SIGNAL ("clicked()" ), self .updateInputLayer )
74
+
75
+ self .editPrimaryKey .setText (self .default_pk )
76
+ self .editGeomColumn .setText (self .default_geom )
74
77
else :
75
78
# set default values
76
- pk = self .outUri .keyColumn ()
77
- self .editPrimaryKey .setText (pk if pk != "" else self .default_pk )
78
- if self .inLayer .hasGeometryType ():
79
- geom = self .outUri .geometryColumn ()
80
- self .editGeomColumn .setText (geom if geom != "" else self .default_geom )
81
-
82
- inCrs = self .inLayer .crs ()
83
- srid = inCrs .postgisSrid () if inCrs .isValid () else 4236
84
- self .editSourceSrid .setText ("%s" % srid )
85
- self .editTargetSrid .setText ("%s" % srid )
86
-
87
79
self .checkSupports ()
80
+ self .updateInputLayer ()
88
81
89
82
def checkSupports (self ):
90
83
""" update options available for the current input layer """
91
84
allowSpatial = self .db .connector .hasSpatialSupport ()
92
85
hasGeomType = self .inLayer and self .inLayer .hasGeometryType ()
93
86
isShapefile = self .inLayer and self .inLayer .providerType () == "ogr" and self .inLayer .storageType () == "ESRI Shapefile"
87
+
94
88
self .chkGeomColumn .setEnabled (allowSpatial and hasGeomType )
89
+ if not self .chkGeomColumn .isEnabled (): self .chkGeomColumn .setChecked (False )
90
+
95
91
self .chkSourceSrid .setEnabled (allowSpatial and hasGeomType )
92
+ if not self .chkSourceSrid .isEnabled (): self .chkSourceSrid .setChecked (False )
96
93
self .chkTargetSrid .setEnabled (allowSpatial and hasGeomType )
94
+ if not self .chkTargetSrid .isEnabled (): self .chkTargetSrid .setChecked (False )
95
+
97
96
self .chkSinglePart .setEnabled (allowSpatial and hasGeomType and isShapefile )
97
+ if not self .chkSinglePart .isEnabled (): self .chkSinglePart .setChecked (False )
98
+
98
99
self .chkSpatialIndex .setEnabled (allowSpatial and hasGeomType )
100
+ if not self .chkSpatialIndex .isEnabled (): self .chkSpatialIndex .setChecked (False )
99
101
100
102
def populateLayers (self ):
101
103
self .cboInputLayer .clear ()
@@ -139,10 +141,10 @@ def inputPathChanged(self, path):
139
141
self .cboInputLayer .setEditText (path )
140
142
self .cboInputLayer .blockSignals (False )
141
143
142
- def updateInputLayer (self ):
144
+ def reloadInputLayer (self ):
143
145
""" create the input layer and update available options """
144
146
if self .mode != self .ASK_FOR_INPUT_MODE :
145
- return
147
+ return True
146
148
147
149
self .deleteInputLayer ()
148
150
@@ -166,10 +168,27 @@ def updateInputLayer(self):
166
168
self .inLayer = iface .legendInterface ().layers ()[legendIndex ]
167
169
self .inLayerMustBeDestroyed = False
168
170
169
- # update the output table name
171
+ self .checkSupports ()
172
+ return True
173
+
174
+ def updateInputLayer (self ):
175
+ if not self .reloadInputLayer () or not self .inLayer :
176
+ return False
177
+
178
+ # update the output table name, pk and geom column
170
179
self .cboTable .setEditText (self .inLayer .name ())
171
180
172
- self .checkSupports ()
181
+ srcUri = qgis .core .QgsDataSourceURI (self .inLayer .source ())
182
+ pk = srcUri .keyColumn () if srcUri .keyColumn () else self .default_pk
183
+ self .editPrimaryKey .setText (pk )
184
+ geom = srcUri .geometryColumn () if srcUri .geometryColumn () else self .default_geom
185
+ self .editGeomColumn .setText (geom )
186
+
187
+ srcCrs = self .inLayer .crs ()
188
+ srid = srcCrs .postgisSrid () if srcCrs .isValid () else 4326
189
+ self .editSourceSrid .setText ("%s" % srid )
190
+ self .editTargetSrid .setText ("%s" % srid )
191
+
173
192
return True
174
193
175
194
def populateSchemas (self ):
@@ -221,13 +240,9 @@ def populateEncodings(self):
221
240
def accept (self ):
222
241
if self .mode == self .ASK_FOR_INPUT_MODE :
223
242
# create the input layer (if not already done) and
224
- # update available options w/o changing the tablename!
225
- self .cboTable .blockSignals (True )
226
- table = self .cboTable .currentText ()
227
- self .updateInputLayer ()
228
- self .cboTable .setEditText (table )
229
- self .cboTable .blockSignals (False )
230
-
243
+ # update available options
244
+ self .reloadInputLayer ()
245
+
231
246
# sanity checks
232
247
if self .inLayer is None :
233
248
QMessageBox .information (self , self .tr ("Import to database" ), self .tr ("Input layer missing or not valid" ))
@@ -265,11 +280,14 @@ def accept(self):
265
280
266
281
# get pk and geom field names from the source layer or use the
267
282
# ones defined by the user
268
- pk = self .outUri .keyColumn () if not self .chkPrimaryKey .isChecked () else self .editPrimaryKey .text ()
283
+ srcUri = qgis .core .QgsDataSourceURI (self .inLayer .source ())
284
+
285
+ pk = srcUri .keyColumn () if not self .chkPrimaryKey .isChecked () else self .editPrimaryKey .text ()
286
+ if not pk : pk = self .default_pk
269
287
270
288
if self .inLayer .hasGeometryType () and self .chkGeomColumn .isEnabled ():
271
- geom = self . outUri .geometryColumn () if not self .chkGeomColumn .isChecked () else self .editGeomColumn .text ()
272
- geom = geom if geom != "" else self .default_geom
289
+ geom = srcUri .geometryColumn () if not self .chkGeomColumn .isChecked () else self .editGeomColumn .text ()
290
+ if not geom : geom = self .default_geom
273
291
else :
274
292
geom = None
275
293
0 commit comments