mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-15 00:07:25 -05:00
[BACKPORT] fTools: update layers lists after adding new layer to TOC (fix #4318)
This commit is contained in:
parent
26528def45
commit
d3fe1941fd
@ -161,7 +161,9 @@ class GeometryDialog(QDialog, Ui_Dialog):
|
||||
self.cmbField.setVisible( False )
|
||||
self.field_label.setVisible( False )
|
||||
self.resize( 381, 100 )
|
||||
myList = []
|
||||
self.populateLayers()
|
||||
|
||||
def populateLayers( self ):
|
||||
self.inShape.clear()
|
||||
if self.myFunction == 3 or self.myFunction == 6:
|
||||
myList = ftools_utils.getLayerNames( [ QGis.Polygon, QGis.Line ] )
|
||||
@ -176,7 +178,6 @@ class GeometryDialog(QDialog, Ui_Dialog):
|
||||
else:
|
||||
myList = ftools_utils.getLayerNames( [ QGis.Point, QGis.Line, QGis.Polygon ] )
|
||||
self.inShape.addItems( myList )
|
||||
return
|
||||
|
||||
#1: Singleparts to multipart
|
||||
#2: Multipart to singleparts
|
||||
@ -241,6 +242,7 @@ class GeometryDialog(QDialog, Ui_Dialog):
|
||||
if addToTOC == QMessageBox.Yes:
|
||||
if not ftools_utils.addShapeToCanvas( unicode( self.shapefileName ) ):
|
||||
QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%1" ).arg( unicode( self.shapefileName ) ))
|
||||
self.populateLayers()
|
||||
else:
|
||||
QMessageBox.warning( self, self.tr("Geometry"), self.tr( "Error writing output shapefile." ) )
|
||||
|
||||
|
||||
@ -182,6 +182,9 @@ class GeoprocessingDialog( QDialog, Ui_Dialog ):
|
||||
self.label_2.setText( self.tr( "Union layer" ) )
|
||||
self.setWindowTitle( self.tr( "Union" ) )
|
||||
self.resize(381, 100)
|
||||
self.populateLayers()
|
||||
|
||||
def populateLayers( self ):
|
||||
myListA = []
|
||||
myListB = []
|
||||
self.inShapeA.clear()
|
||||
@ -195,7 +198,6 @@ class GeoprocessingDialog( QDialog, Ui_Dialog ):
|
||||
myListB = ftools_utils.getLayerNames( [ QGis.Point, QGis.Line, QGis.Polygon ] )
|
||||
self.inShapeA.addItems( myListA )
|
||||
self.inShapeB.addItems( myListB )
|
||||
return
|
||||
|
||||
#1: Buffer
|
||||
#2: Convex Hull
|
||||
@ -257,6 +259,7 @@ class GeoprocessingDialog( QDialog, Ui_Dialog ):
|
||||
if addToTOC == QMessageBox.Yes:
|
||||
if not ftools_utils.addShapeToCanvas( unicode( self.shapefileName ) ):
|
||||
QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%1" ).arg( unicode( self.shapefileName ) ))
|
||||
self.populateLayers()
|
||||
|
||||
def runStatusFromThread( self, status ):
|
||||
self.progressBar.setValue( status )
|
||||
@ -1103,7 +1106,7 @@ class geoprocessingThread( QThread ):
|
||||
writer.addFeature( outFeat )
|
||||
except:
|
||||
FEATURE_EXCEPT = False
|
||||
# this really shouldn't happen, as we
|
||||
# this really shouldn't happen, as we
|
||||
# haven't edited the input geom at all
|
||||
# continue
|
||||
else:
|
||||
@ -1144,7 +1147,7 @@ class geoprocessingThread( QThread ):
|
||||
# print str(err)
|
||||
FEATURE_EXCEPT = False
|
||||
# else:
|
||||
# # this only happends if the bounding box
|
||||
# # this only happends if the bounding box
|
||||
# # intersects, but the geometry doesn't
|
||||
# try:
|
||||
# outFeat.setGeometry( geom )
|
||||
|
||||
@ -46,10 +46,13 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
QObject.connect(self.inLine2, SIGNAL("currentIndexChanged(QString)"), self.update2)
|
||||
self.setWindowTitle( self.tr("Line intersections") )
|
||||
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
|
||||
# populate layer list
|
||||
self.progressBar.setValue(0)
|
||||
mapCanvas = self.iface.mapCanvas()
|
||||
self.populateLayers()
|
||||
|
||||
def populateLayers( self ):
|
||||
layers = ftools_utils.getLayerNames([QGis.Line])
|
||||
self.inLine1.clear()
|
||||
self.inLine2.clear()
|
||||
self.inLine1.addItems(layers)
|
||||
self.inLine2.addItems(layers)
|
||||
|
||||
@ -92,6 +95,7 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
if addToTOC == QMessageBox.Yes:
|
||||
if not ftools_utils.addShapeToCanvas( unicode( outPath ) ):
|
||||
QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%1" ).arg( unicode( outPath ) ))
|
||||
self.populateLayers()
|
||||
self.progressBar.setValue(0)
|
||||
self.buttonOk.setEnabled( True )
|
||||
|
||||
|
||||
@ -45,12 +45,15 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile)
|
||||
QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
|
||||
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
|
||||
|
||||
# populate layer list
|
||||
self.progressBar.setValue(0)
|
||||
mapCanvas = self.iface.mapCanvas()
|
||||
self.populateLayers()
|
||||
|
||||
def populateLayers( self ):
|
||||
layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon])
|
||||
QObject.disconnect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
|
||||
self.inShape.clear()
|
||||
self.inShape.addItems(layers)
|
||||
QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
|
||||
|
||||
def updateUi(self):
|
||||
if self.function == 1:
|
||||
@ -96,6 +99,7 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
if addToTOC == QMessageBox.Yes:
|
||||
vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
|
||||
QgsMapLayerRegistry.instance().addMapLayer(vlayer)
|
||||
self.populateLayers()
|
||||
self.progressBar.setValue(0)
|
||||
self.buttonOk.setEnabled( True )
|
||||
|
||||
|
||||
@ -44,14 +44,18 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile)
|
||||
self.setWindowTitle(self.tr("Count Points in Polygon"))
|
||||
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
|
||||
# populate layer list
|
||||
self.progressBar.setValue(0)
|
||||
mapCanvas = self.iface.mapCanvas()
|
||||
self.populateLayers()
|
||||
|
||||
def populateLayers( self ):
|
||||
layers = ftools_utils.getLayerNames([QGis.Polygon])
|
||||
self.inPolygon.clear()
|
||||
self.inPolygon.addItems(layers)
|
||||
|
||||
self.inPoint.clear()
|
||||
layers = ftools_utils.getLayerNames([QGis.Point])
|
||||
self.inPoint.addItems(layers)
|
||||
|
||||
|
||||
def accept(self):
|
||||
self.buttonOk.setEnabled( False )
|
||||
if self.inPolygon.currentText() == "":
|
||||
@ -79,6 +83,7 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
if addToTOC == QMessageBox.Yes:
|
||||
self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
|
||||
QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
|
||||
self.populateLayers()
|
||||
self.progressBar.setValue(0)
|
||||
self.buttonOk.setEnabled( True )
|
||||
|
||||
@ -112,7 +117,6 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
if not QgsVectorFileWriter.deleteShapeFile(self.shapefileName):
|
||||
return
|
||||
writer = QgsVectorFileWriter(self.shapefileName, self.encoding, fieldList, polyProvider.geometryType(), sRs)
|
||||
#writer = QgsVectorFileWriter(outPath, "UTF-8", fieldList, polyProvider.geometryType(), sRs)
|
||||
inFeat = QgsFeature()
|
||||
inFeatB = QgsFeature()
|
||||
outFeat = QgsFeature()
|
||||
|
||||
@ -46,9 +46,14 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
self.progressBar.setValue(0)
|
||||
self.setWindowTitle(self.tr("Random Points"))
|
||||
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
|
||||
self.mapCanvas = self.iface.mapCanvas()
|
||||
self.populateLayers()
|
||||
|
||||
def populateLayers( self ):
|
||||
layers = ftools_utils.getLayerNames([QGis.Polygon, "Raster"])
|
||||
QObject.disconnect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
|
||||
self.inShape.clear()
|
||||
self.inShape.addItems(layers)
|
||||
QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
|
||||
|
||||
# If input layer is changed, update field list
|
||||
def update(self, inputLayer):
|
||||
@ -123,6 +128,7 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
if addToTOC == QMessageBox.Yes:
|
||||
self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
|
||||
QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
|
||||
self.populateLayers()
|
||||
self.progressBar.setValue(0)
|
||||
self.buttonOk.setEnabled( True )
|
||||
|
||||
@ -208,7 +214,7 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
points = self.vectorRandom(int(value), inLayer,
|
||||
ext.xMinimum(), ext.xMaximum(), ext.yMinimum(), ext.yMaximum())
|
||||
else: points = self.loopThruPolygons(inLayer, value, design)
|
||||
crs = self.mapCanvas.mapRenderer().destinationSrs()
|
||||
crs = self.iface.mapCanvas().mapRenderer().destinationSrs()
|
||||
if not crs.isValid(): crs = None
|
||||
fields = { 0 : QgsField("ID", QVariant.Int) }
|
||||
check = QFile(self.shapefileName)
|
||||
|
||||
@ -50,7 +50,11 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
|
||||
self.progressBar.setValue(0)
|
||||
self.mapCanvas = self.iface.mapCanvas()
|
||||
self.populateLayers()
|
||||
|
||||
def populateLayers( self ):
|
||||
layers = ftools_utils.getLayerNames("all")
|
||||
self.inShape.clear()
|
||||
self.inShape.addItems(layers)
|
||||
|
||||
def accept(self):
|
||||
@ -89,6 +93,7 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
if addToTOC == QMessageBox.Yes:
|
||||
self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
|
||||
QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
|
||||
self.populateLayers()
|
||||
self.progressBar.setValue(0)
|
||||
self.buttonOk.setEnabled( True )
|
||||
|
||||
@ -98,7 +103,7 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
if self.shapefileName is None or self.encoding is None:
|
||||
return
|
||||
self.outShape.setText( QString( self.shapefileName ) )
|
||||
|
||||
|
||||
# Generate list of random points
|
||||
def simpleRandom(self, n, bound, xmin, xmax, ymin, ymax):
|
||||
seed()
|
||||
@ -109,7 +114,7 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
if pGeom.intersects(bound):
|
||||
points.append(pGeom)
|
||||
i = i + 1
|
||||
return points
|
||||
return points
|
||||
|
||||
def regularize(self, bound, outPath, offset, value, gridType, inset, crs):
|
||||
area = bound.width() * bound.height()
|
||||
|
||||
@ -47,18 +47,6 @@ class Dialog( QDialog, Ui_Dialog ):
|
||||
|
||||
self.workThread = None
|
||||
|
||||
self.btnOk = self.buttonBox.button( QDialogButtonBox.Ok )
|
||||
self.btnClose = self.buttonBox.button( QDialogButtonBox.Close )
|
||||
|
||||
QObject.connect( self.chkWriteShapefile, SIGNAL( "stateChanged( int )" ), self.updateGui )
|
||||
QObject.connect( self.btnSelectOutputFile, SIGNAL( "clicked()" ), self.selectOutputFile )
|
||||
|
||||
self.manageGui()
|
||||
|
||||
def manageGui( self ):
|
||||
layers = ftools_utils.getLayerNames( [ QGis.Polygon, QGis.Line ] )
|
||||
self.cmbInputLayer.addItems( layers )
|
||||
|
||||
if self.myFunction == 2:
|
||||
self.setWindowTitle( self.tr( "Densify geometries" ) )
|
||||
self.lblTolerance.setText( self.tr( "Vertices to add" ) )
|
||||
@ -67,6 +55,19 @@ class Dialog( QDialog, Ui_Dialog ):
|
||||
self.spnTolerance.setSingleStep( 1 )
|
||||
self.spnTolerance.setValue( 1.0 )
|
||||
|
||||
self.btnOk = self.buttonBox.button( QDialogButtonBox.Ok )
|
||||
self.btnClose = self.buttonBox.button( QDialogButtonBox.Close )
|
||||
|
||||
QObject.connect( self.chkWriteShapefile, SIGNAL( "stateChanged( int )" ), self.updateGui )
|
||||
QObject.connect( self.btnSelectOutputFile, SIGNAL( "clicked()" ), self.selectOutputFile )
|
||||
|
||||
self.populateLayers()
|
||||
|
||||
def populateLayers( self ):
|
||||
layers = ftools_utils.getLayerNames( [ QGis.Polygon, QGis.Line ] )
|
||||
self.cmbInputLayer.clear()
|
||||
self.cmbInputLayer.addItems( layers )
|
||||
|
||||
def updateGui( self ):
|
||||
if self.chkWriteShapefile.isChecked():
|
||||
self.edOutputFile.setEnabled( True )
|
||||
@ -140,6 +141,7 @@ class Dialog( QDialog, Ui_Dialog ):
|
||||
QMessageBox.warning( self, self.tr( "Error" ),
|
||||
self.tr( "Error loading output shapefile:\n%1" )
|
||||
.arg( unicode( self.shapeFileName ) ) )
|
||||
self.populateLayers()
|
||||
|
||||
QMessageBox.information( self, self.tr( "Finished" ), self.tr( "Processing completed." ) )
|
||||
self.iface.mapCanvas().refresh()
|
||||
|
||||
@ -44,14 +44,17 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile)
|
||||
self.setWindowTitle(self.tr("Sum line lengths"))
|
||||
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
|
||||
# populate layer list
|
||||
self.progressBar.setValue(0)
|
||||
mapCanvas = self.iface.mapCanvas()
|
||||
self.populateLayers()
|
||||
|
||||
def populateLayers( self ):
|
||||
layers = ftools_utils.getLayerNames([QGis.Line])
|
||||
self.inPoint.clear()
|
||||
self.inPoint.addItems(layers)
|
||||
layers = ftools_utils.getLayerNames([QGis.Polygon])
|
||||
self.inPolygon.clear()
|
||||
self.inPolygon.addItems(layers)
|
||||
|
||||
|
||||
def accept(self):
|
||||
self.buttonOk.setEnabled( False )
|
||||
if self.inPolygon.currentText() == "":
|
||||
@ -79,6 +82,7 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
if addToTOC == QMessageBox.Yes:
|
||||
self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
|
||||
QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
|
||||
self.populateLayers()
|
||||
self.progressBar.setValue(0)
|
||||
self.buttonOk.setEnabled( True )
|
||||
|
||||
|
||||
@ -50,6 +50,10 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
self.xMax.setValidator(QDoubleValidator(self.xMax))
|
||||
self.yMin.setValidator(QDoubleValidator(self.yMin))
|
||||
self.yMax.setValidator(QDoubleValidator(self.yMax))
|
||||
self.populateLayers()
|
||||
|
||||
def populateLayers( self ):
|
||||
self.inShape.clear()
|
||||
layermap = QgsMapLayerRegistry.instance().mapLayers()
|
||||
for name, layer in layermap.iteritems():
|
||||
self.inShape.addItem( unicode( layer.name() ) )
|
||||
@ -64,12 +68,12 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
mLayer = ftools_utils.getMapLayerByName( unicode( mLayerName ) )
|
||||
boundBox = mLayer.extent()
|
||||
self.updateExtents( boundBox )
|
||||
|
||||
|
||||
def updateCanvas( self ):
|
||||
canvas = self.iface.mapCanvas()
|
||||
boundBox = canvas.extent()
|
||||
self.updateExtents( boundBox )
|
||||
|
||||
|
||||
def updateExtents( self, boundBox ):
|
||||
self.xMin.setText( unicode( boundBox.xMinimum() ) )
|
||||
self.yMin.setText( unicode( boundBox.yMinimum() ) )
|
||||
@ -100,6 +104,7 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
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)
|
||||
if addToTOC == QMessageBox.Yes:
|
||||
ftools_utils.addShapeToCanvas( self.shapefileName )
|
||||
self.populateLayers()
|
||||
self.progressBar.setValue( 0 )
|
||||
self.buttonOk.setEnabled( True )
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user