Skip to content

Commit

Permalink
[processing] show layers sorted only for single selection widget and use
Browse files Browse the repository at this point in the history
legend order for multiple selection
  • Loading branch information
alexbruy committed Oct 4, 2014
1 parent ec64e1d commit e0fc515
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
6 changes: 3 additions & 3 deletions python/plugins/processing/gui/ParametersPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,11 @@ def getWidgetFromParameter(self, param):
item = MultipleFileInputPanel()
else:
if param.datatype == ParameterMultipleInput.TYPE_RASTER:
options = dataobjects.getRasterLayers()
options = dataobjects.getRasterLayers(sorting=False)
elif param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
options = dataobjects.getVectorLayers()
options = dataobjects.getVectorLayers(sorting=False)
else:
options = dataobjects.getVectorLayers([param.datatype])
options = dataobjects.getVectorLayers([param.datatype], sorting=False)
opts = []
for opt in options:
opts.append(self.getExtendedLayerName(opt))
Expand Down
21 changes: 15 additions & 6 deletions python/plugins/processing/tools/dataobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,21 @@ def getSupportedOutputTableExtensions():
return exts


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

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


def getVectorLayers(shapetype=[-1]):
def getVectorLayers(shapetype=[-1], sorting=True):
layers = QgsMapLayerRegistry.instance().mapLayers().values()
vector = []
for layer in layers:
Expand All @@ -88,7 +91,10 @@ def getVectorLayers(shapetype=[-1]):
uri = unicode(layer.source())
if not uri.lower().endswith('csv') and not uri.lower().endswith('dbf'):
vector.append(layer)
return sorted(vector, key=lambda layer: layer.name().lower())
if sorting:
return sorted(vector, key=lambda layer: layer.name().lower())
else:
return vector


def getAllLayers():
Expand All @@ -98,13 +104,16 @@ def getAllLayers():
return sorted(layers, key=lambda layer: layer.name().lower())


def getTables():
def getTables(sorting=True):
layers = QgsMapLayerRegistry.instance().mapLayers().values()
tables = list()
for layer in layers:
if layer.type() == layer.VectorLayer:
tables.append(layer)
return sorted(tables, key=lambda table: table.name().lower())
if sorting:
return sorted(tables, key=lambda table: table.name().lower())
else:
return tables


def extent(layers):
Expand Down

0 comments on commit e0fc515

Please sign in to comment.