Skip to content

Commit d3fe194

Browse files
committed
[BACKPORT] fTools: update layers lists after adding new layer to TOC (fix #4318)
1 parent 26528de commit d3fe194

10 files changed

+72
-33
lines changed

python/plugins/fTools/tools/doGeometry.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ def manageGui(self):
161161
self.cmbField.setVisible( False )
162162
self.field_label.setVisible( False )
163163
self.resize( 381, 100 )
164-
myList = []
164+
self.populateLayers()
165+
166+
def populateLayers( self ):
165167
self.inShape.clear()
166168
if self.myFunction == 3 or self.myFunction == 6:
167169
myList = ftools_utils.getLayerNames( [ QGis.Polygon, QGis.Line ] )
@@ -176,7 +178,6 @@ def manageGui(self):
176178
else:
177179
myList = ftools_utils.getLayerNames( [ QGis.Point, QGis.Line, QGis.Polygon ] )
178180
self.inShape.addItems( myList )
179-
return
180181

181182
#1: Singleparts to multipart
182183
#2: Multipart to singleparts
@@ -241,6 +242,7 @@ def runFinishedFromThread( self, success ):
241242
if addToTOC == QMessageBox.Yes:
242243
if not ftools_utils.addShapeToCanvas( unicode( self.shapefileName ) ):
243244
QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%1" ).arg( unicode( self.shapefileName ) ))
245+
self.populateLayers()
244246
else:
245247
QMessageBox.warning( self, self.tr("Geometry"), self.tr( "Error writing output shapefile." ) )
246248

python/plugins/fTools/tools/doGeoprocessing.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ def manageGui( self ):
182182
self.label_2.setText( self.tr( "Union layer" ) )
183183
self.setWindowTitle( self.tr( "Union" ) )
184184
self.resize(381, 100)
185+
self.populateLayers()
186+
187+
def populateLayers( self ):
185188
myListA = []
186189
myListB = []
187190
self.inShapeA.clear()
@@ -195,7 +198,6 @@ def manageGui( self ):
195198
myListB = ftools_utils.getLayerNames( [ QGis.Point, QGis.Line, QGis.Polygon ] )
196199
self.inShapeA.addItems( myListA )
197200
self.inShapeB.addItems( myListB )
198-
return
199201

200202
#1: Buffer
201203
#2: Convex Hull
@@ -257,6 +259,7 @@ def runFinishedFromThread( self, results ):
257259
if addToTOC == QMessageBox.Yes:
258260
if not ftools_utils.addShapeToCanvas( unicode( self.shapefileName ) ):
259261
QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%1" ).arg( unicode( self.shapefileName ) ))
262+
self.populateLayers()
260263

261264
def runStatusFromThread( self, status ):
262265
self.progressBar.setValue( status )
@@ -1103,7 +1106,7 @@ def union( self ):
11031106
writer.addFeature( outFeat )
11041107
except:
11051108
FEATURE_EXCEPT = False
1106-
# this really shouldn't happen, as we
1109+
# this really shouldn't happen, as we
11071110
# haven't edited the input geom at all
11081111
# continue
11091112
else:
@@ -1144,7 +1147,7 @@ def union( self ):
11441147
# print str(err)
11451148
FEATURE_EXCEPT = False
11461149
# else:
1147-
# # this only happends if the bounding box
1150+
# # this only happends if the bounding box
11481151
# # intersects, but the geometry doesn't
11491152
# try:
11501153
# outFeat.setGeometry( geom )

python/plugins/fTools/tools/doIntersectLines.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ def __init__(self, iface):
4646
QObject.connect(self.inLine2, SIGNAL("currentIndexChanged(QString)"), self.update2)
4747
self.setWindowTitle( self.tr("Line intersections") )
4848
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
49-
# populate layer list
5049
self.progressBar.setValue(0)
51-
mapCanvas = self.iface.mapCanvas()
50+
self.populateLayers()
51+
52+
def populateLayers( self ):
5253
layers = ftools_utils.getLayerNames([QGis.Line])
54+
self.inLine1.clear()
55+
self.inLine2.clear()
5356
self.inLine1.addItems(layers)
5457
self.inLine2.addItems(layers)
5558

@@ -92,6 +95,7 @@ def accept(self):
9295
if addToTOC == QMessageBox.Yes:
9396
if not ftools_utils.addShapeToCanvas( unicode( outPath ) ):
9497
QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%1" ).arg( unicode( outPath ) ))
98+
self.populateLayers()
9599
self.progressBar.setValue(0)
96100
self.buttonOk.setEnabled( True )
97101

python/plugins/fTools/tools/doMeanCoords.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,15 @@ def __init__(self, iface, function):
4545
QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile)
4646
QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
4747
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
48-
49-
# populate layer list
5048
self.progressBar.setValue(0)
51-
mapCanvas = self.iface.mapCanvas()
49+
self.populateLayers()
50+
51+
def populateLayers( self ):
5252
layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon])
53+
QObject.disconnect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
54+
self.inShape.clear()
5355
self.inShape.addItems(layers)
56+
QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
5457

5558
def updateUi(self):
5659
if self.function == 1:
@@ -96,6 +99,7 @@ def accept(self):
9699
if addToTOC == QMessageBox.Yes:
97100
vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
98101
QgsMapLayerRegistry.instance().addMapLayer(vlayer)
102+
self.populateLayers()
99103
self.progressBar.setValue(0)
100104
self.buttonOk.setEnabled( True )
101105

python/plugins/fTools/tools/doPointsInPolygon.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,18 @@ def __init__(self, iface):
4444
QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile)
4545
self.setWindowTitle(self.tr("Count Points in Polygon"))
4646
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
47-
# populate layer list
4847
self.progressBar.setValue(0)
49-
mapCanvas = self.iface.mapCanvas()
48+
self.populateLayers()
49+
50+
def populateLayers( self ):
5051
layers = ftools_utils.getLayerNames([QGis.Polygon])
52+
self.inPolygon.clear()
5153
self.inPolygon.addItems(layers)
54+
55+
self.inPoint.clear()
5256
layers = ftools_utils.getLayerNames([QGis.Point])
5357
self.inPoint.addItems(layers)
54-
58+
5559
def accept(self):
5660
self.buttonOk.setEnabled( False )
5761
if self.inPolygon.currentText() == "":
@@ -79,6 +83,7 @@ def accept(self):
7983
if addToTOC == QMessageBox.Yes:
8084
self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
8185
QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
86+
self.populateLayers()
8287
self.progressBar.setValue(0)
8388
self.buttonOk.setEnabled( True )
8489

@@ -112,7 +117,6 @@ def compute(self, inPoly, inPts, inField, outPath, progressBar):
112117
if not QgsVectorFileWriter.deleteShapeFile(self.shapefileName):
113118
return
114119
writer = QgsVectorFileWriter(self.shapefileName, self.encoding, fieldList, polyProvider.geometryType(), sRs)
115-
#writer = QgsVectorFileWriter(outPath, "UTF-8", fieldList, polyProvider.geometryType(), sRs)
116120
inFeat = QgsFeature()
117121
inFeatB = QgsFeature()
118122
outFeat = QgsFeature()

python/plugins/fTools/tools/doRandPoints.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,14 @@ def __init__(self, iface):
4646
self.progressBar.setValue(0)
4747
self.setWindowTitle(self.tr("Random Points"))
4848
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
49-
self.mapCanvas = self.iface.mapCanvas()
49+
self.populateLayers()
50+
51+
def populateLayers( self ):
5052
layers = ftools_utils.getLayerNames([QGis.Polygon, "Raster"])
53+
QObject.disconnect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
54+
self.inShape.clear()
5155
self.inShape.addItems(layers)
56+
QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
5257

5358
# If input layer is changed, update field list
5459
def update(self, inputLayer):
@@ -123,6 +128,7 @@ def accept(self):
123128
if addToTOC == QMessageBox.Yes:
124129
self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
125130
QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
131+
self.populateLayers()
126132
self.progressBar.setValue(0)
127133
self.buttonOk.setEnabled( True )
128134

@@ -208,7 +214,7 @@ def randomize(self, inLayer, outPath, minimum, design, value):
208214
points = self.vectorRandom(int(value), inLayer,
209215
ext.xMinimum(), ext.xMaximum(), ext.yMinimum(), ext.yMaximum())
210216
else: points = self.loopThruPolygons(inLayer, value, design)
211-
crs = self.mapCanvas.mapRenderer().destinationSrs()
217+
crs = self.iface.mapCanvas().mapRenderer().destinationSrs()
212218
if not crs.isValid(): crs = None
213219
fields = { 0 : QgsField("ID", QVariant.Int) }
214220
check = QFile(self.shapefileName)

python/plugins/fTools/tools/doRegPoints.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ def __init__(self, iface):
5050
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
5151
self.progressBar.setValue(0)
5252
self.mapCanvas = self.iface.mapCanvas()
53+
self.populateLayers()
54+
55+
def populateLayers( self ):
5356
layers = ftools_utils.getLayerNames("all")
57+
self.inShape.clear()
5458
self.inShape.addItems(layers)
5559

5660
def accept(self):
@@ -89,6 +93,7 @@ def accept(self):
8993
if addToTOC == QMessageBox.Yes:
9094
self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
9195
QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
96+
self.populateLayers()
9297
self.progressBar.setValue(0)
9398
self.buttonOk.setEnabled( True )
9499

@@ -98,7 +103,7 @@ def outFile(self):
98103
if self.shapefileName is None or self.encoding is None:
99104
return
100105
self.outShape.setText( QString( self.shapefileName ) )
101-
106+
102107
# Generate list of random points
103108
def simpleRandom(self, n, bound, xmin, xmax, ymin, ymax):
104109
seed()
@@ -109,7 +114,7 @@ def simpleRandom(self, n, bound, xmin, xmax, ymin, ymax):
109114
if pGeom.intersects(bound):
110115
points.append(pGeom)
111116
i = i + 1
112-
return points
117+
return points
113118

114119
def regularize(self, bound, outPath, offset, value, gridType, inset, crs):
115120
area = bound.width() * bound.height()

python/plugins/fTools/tools/doSimplify.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,27 @@ def __init__( self, iface, function ):
4747

4848
self.workThread = None
4949

50+
if self.myFunction == 2:
51+
self.setWindowTitle( self.tr( "Densify geometries" ) )
52+
self.lblTolerance.setText( self.tr( "Vertices to add" ) )
53+
self.spnTolerance.setDecimals( 0 )
54+
self.spnTolerance.setMinimum( 1 )
55+
self.spnTolerance.setSingleStep( 1 )
56+
self.spnTolerance.setValue( 1.0 )
57+
5058
self.btnOk = self.buttonBox.button( QDialogButtonBox.Ok )
5159
self.btnClose = self.buttonBox.button( QDialogButtonBox.Close )
5260

5361
QObject.connect( self.chkWriteShapefile, SIGNAL( "stateChanged( int )" ), self.updateGui )
5462
QObject.connect( self.btnSelectOutputFile, SIGNAL( "clicked()" ), self.selectOutputFile )
5563

56-
self.manageGui()
64+
self.populateLayers()
5765

58-
def manageGui( self ):
66+
def populateLayers( self ):
5967
layers = ftools_utils.getLayerNames( [ QGis.Polygon, QGis.Line ] )
68+
self.cmbInputLayer.clear()
6069
self.cmbInputLayer.addItems( layers )
6170

62-
if self.myFunction == 2:
63-
self.setWindowTitle( self.tr( "Densify geometries" ) )
64-
self.lblTolerance.setText( self.tr( "Vertices to add" ) )
65-
self.spnTolerance.setDecimals( 0 )
66-
self.spnTolerance.setMinimum( 1 )
67-
self.spnTolerance.setSingleStep( 1 )
68-
self.spnTolerance.setValue( 1.0 )
69-
7071
def updateGui( self ):
7172
if self.chkWriteShapefile.isChecked():
7273
self.edOutputFile.setEnabled( True )
@@ -140,6 +141,7 @@ def processFinished( self, pointsCount ):
140141
QMessageBox.warning( self, self.tr( "Error" ),
141142
self.tr( "Error loading output shapefile:\n%1" )
142143
.arg( unicode( self.shapeFileName ) ) )
144+
self.populateLayers()
143145

144146
QMessageBox.information( self, self.tr( "Finished" ), self.tr( "Processing completed." ) )
145147
self.iface.mapCanvas().refresh()

python/plugins/fTools/tools/doSumLines.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,17 @@ def __init__(self, iface):
4444
QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile)
4545
self.setWindowTitle(self.tr("Sum line lengths"))
4646
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
47-
# populate layer list
4847
self.progressBar.setValue(0)
49-
mapCanvas = self.iface.mapCanvas()
48+
self.populateLayers()
49+
50+
def populateLayers( self ):
5051
layers = ftools_utils.getLayerNames([QGis.Line])
52+
self.inPoint.clear()
5153
self.inPoint.addItems(layers)
5254
layers = ftools_utils.getLayerNames([QGis.Polygon])
55+
self.inPolygon.clear()
5356
self.inPolygon.addItems(layers)
54-
57+
5558
def accept(self):
5659
self.buttonOk.setEnabled( False )
5760
if self.inPolygon.currentText() == "":
@@ -79,6 +82,7 @@ def accept(self):
7982
if addToTOC == QMessageBox.Yes:
8083
self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
8184
QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
85+
self.populateLayers()
8286
self.progressBar.setValue(0)
8387
self.buttonOk.setEnabled( True )
8488

python/plugins/fTools/tools/doVectorGrid.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ def __init__(self, iface):
5050
self.xMax.setValidator(QDoubleValidator(self.xMax))
5151
self.yMin.setValidator(QDoubleValidator(self.yMin))
5252
self.yMax.setValidator(QDoubleValidator(self.yMax))
53+
self.populateLayers()
54+
55+
def populateLayers( self ):
56+
self.inShape.clear()
5357
layermap = QgsMapLayerRegistry.instance().mapLayers()
5458
for name, layer in layermap.iteritems():
5559
self.inShape.addItem( unicode( layer.name() ) )
@@ -64,12 +68,12 @@ def updateLayer( self ):
6468
mLayer = ftools_utils.getMapLayerByName( unicode( mLayerName ) )
6569
boundBox = mLayer.extent()
6670
self.updateExtents( boundBox )
67-
71+
6872
def updateCanvas( self ):
6973
canvas = self.iface.mapCanvas()
7074
boundBox = canvas.extent()
7175
self.updateExtents( boundBox )
72-
76+
7377
def updateExtents( self, boundBox ):
7478
self.xMin.setText( unicode( boundBox.xMinimum() ) )
7579
self.yMin.setText( unicode( boundBox.yMinimum() ) )
@@ -100,6 +104,7 @@ def accept(self):
100104
addToTOC = QMessageBox.question(self, self.tr("Generate Vector Grid"), self.tr("Created output shapefile:\n%1\n\nWould you like to add the new layer to the TOC?").arg(unicode(self.shapefileName)), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton)
101105
if addToTOC == QMessageBox.Yes:
102106
ftools_utils.addShapeToCanvas( self.shapefileName )
107+
self.populateLayers()
103108
self.progressBar.setValue( 0 )
104109
self.buttonOk.setEnabled( True )
105110

0 commit comments

Comments
 (0)