Skip to content
Permalink
Browse files

[processing] more robust layer sorting in multiple selection widget (f…

…ixes #11429)
  • Loading branch information
alexbruy committed Oct 18, 2014
1 parent 99cec14 commit b1e7ede36baba2694ae9e9b065e45dc82d945eb0
@@ -175,9 +175,9 @@ def setParamValue(self, param, widget):
return param.setValue(widget.selectedoptions)
else:
if param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
options = dataobjects.getVectorLayers()
options = dataobjects.getVectorLayers(sorting=False)
else:
options = dataobjects.getRasterLayers()
options = dataobjects.getRasterLayers(sorting=False)
return param.setValue([options[i] for i in widget.selectedoptions])
elif isinstance(param, (ParameterNumber, ParameterFile, ParameterCrs,
ParameterExtent)):
@@ -69,28 +69,30 @@ def getSupportedOutputTableExtensions():


def getRasterLayers(sorting=True):
layers = QgsMapLayerRegistry.instance().mapLayers().values()
layers = QgsProject.instance().layerTreeRoot().findLayers()
raster = []

for layer in layers:
if layer.type() == layer.RasterLayer:
if layer.providerType() == 'gdal': # only gdal file-based layers
raster.append(layer)
mapLayer = layer.layer()
if mapLayer.type() == QgsMapLayer.RasterLayer:
if mapLayer.providerType() == 'gdal': # only gdal file-based layers
raster.append(mapLayer)
if sorting:
return sorted(raster, key=lambda layer: layer.name().lower())
else:
return raster


def getVectorLayers(shapetype=[-1], sorting=True):
layers = QgsMapLayerRegistry.instance().mapLayers().values()
layers = QgsProject.instance().layerTreeRoot().findLayers()
vector = []
for layer in layers:
if layer.type() == layer.VectorLayer:
if shapetype == ALL_TYPES or layer.geometryType() in shapetype:
uri = unicode(layer.source())
mapLayer = layer.layer()
if mapLayer.type() == QgsMapLayer.VectorLayer:
if shapetype == ALL_TYPES or mapLayer.geometryType() in shapetype:
uri = unicode(mapLayer.source())
if not uri.lower().endswith('csv') and not uri.lower().endswith('dbf'):
vector.append(layer)
vector.append(mapLayer)
if sorting:
return sorted(vector, key=lambda layer: layer.name().lower())
else:
@@ -105,11 +107,12 @@ def getAllLayers():


def getTables(sorting=True):
layers = QgsMapLayerRegistry.instance().mapLayers().values()
tables = list()
layers = QgsProject.instance().layerTreeRoot().findLayers()
tables = []
for layer in layers:
if layer.type() == layer.VectorLayer:
tables.append(layer)
mapLayer = layer.layer()
if mapLayer.type() == QgsMapLayer.VectorLayer:
tables.append(mapLayer)
if sorting:
return sorted(tables, key=lambda table: table.name().lower())
else:
@@ -119,7 +122,7 @@ def getTables(sorting=True):
def extent(layers):
first = True
for layer in layers:
if not isinstance(layer, (QgsRasterLayer, QgsVectorLayer)):
if not isinstance(layer, (QgsMapLayer.QgsRasterLayer, QgsMapLayer.QgsVectorLayer)):
layer = getObjectFromUri(layer)
if layer is None:
continue

0 comments on commit b1e7ede

Please sign in to comment.
You can’t perform that action at this time.