<p dir="ltr"><br>
On 6 Jun 2016 6:28 AM, "Heikki Vesanto" <<a href="mailto:heikki.vesanto@gmail.com">heikki.vesanto@gmail.com</a>> wrote:<br>
><br>
> Hey,<br>
><br>
> I had a feature request through for a python plugin to sort layer<br>
> drop-down lists alphabetically:<br>
><br>
> <a href="https://github.com/HeikkiVesanto/QGIS_Centroid_Within/issues/3">https://github.com/HeikkiVesanto/QGIS_Centroid_Within/issues/3</a><br>
><br>
> This is a list of vector layers that are open, that are selected using<br>
> a QComboBox QT drop-down. I get the layers using:<br>
><br>
> layers = QgsMapLayerRegistry.instance().mapLayers().values()<br>
><br>
> Before adding them to the QT dialog:<br>
><br>
> for layer in layers:<br>
>             if layer.type() == QgsMapLayer.VectorLayer:<br>
>                 self.dlg.selectWithCombo.addItem( <a href="http://layer.name">layer.name</a>(), layer )<br>
>                 self.dlg.selectFromCombo.addItem( <a href="http://layer.name">layer.name</a>(), layer )<br>
><br>
> I would like to sort these layers based on their name, so <a href="http://layer.name">layer.name</a>().<br>
><br>
> I got as far as sorting by name:<br>
> layers.sort(key=operator.methodcaller("name"), reverse=False)<br>
><br>
> However this is case sensitive, with upper case appearing first. Does<br>
> anyone know of a plugin that implements sorting? Or an easy way to do<br>
> it. If all else fails I can revert back to case sensitive sorting.</p>
<p dir="ltr">Why not use QgsMapLayerComboBox instead? This has sorting built in, and will help your plugin match the standard QGIS layer selector behaviour.</p>
<p dir="ltr">Nyall<br>
><br>
> -Heikki<br>
> _______________________________________________<br>
> Qgis-developer mailing list<br>
> <a href="mailto:Qgis-developer@lists.osgeo.org">Qgis-developer@lists.osgeo.org</a><br>
> List info: <a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
> Unsubscribe: <a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a></p>