diff --git a/python/gui/qgslegendinterface.sip b/python/gui/qgslegendinterface.sip index c5e3a14015d..cee1b7d65b8 100644 --- a/python/gui/qgslegendinterface.sip +++ b/python/gui/qgslegendinterface.sip @@ -22,7 +22,12 @@ class QgsLegendInterface : QObject //! Return the relationship between groups and layers in the legend virtual QList< QPair< QString, QList > > groupLayerRelationship(); - //! Return all layers in the project in legend order + //! Returns the currently selected layers of QgsLegendLayers. + //! @param inDrawOrder return layers in drawing order (added in 1.9) + //! @returns list of layers, else an empty list + virtual QList selectedLayers( bool inDrawOrder = false ) const = 0; + + //! Return all layers in the project in drawing order //! @note added in 1.5 virtual QList< QgsMapLayer * > layers() const = 0; diff --git a/src/app/legend/qgsapplegendinterface.cpp b/src/app/legend/qgsapplegendinterface.cpp index 50c4400d072..6ef6abdd552 100644 --- a/src/app/legend/qgsapplegendinterface.cpp +++ b/src/app/legend/qgsapplegendinterface.cpp @@ -166,6 +166,11 @@ bool QgsAppLegendInterface::isLayerVisible( QgsMapLayer * ml ) return ( Qt::Checked == mLegend->layerCheckState( ml ) ); } +QList QgsAppLegendInterface::selectedLayers( bool inDrawOrder ) const +{ + return mLegend->selectedLayers( inDrawOrder ); +} + QList< QgsMapLayer * > QgsAppLegendInterface::layers() const { return mLegend->layers(); diff --git a/src/app/legend/qgsapplegendinterface.h b/src/app/legend/qgsapplegendinterface.h index a7b0c7652d3..00295eff723 100644 --- a/src/app/legend/qgsapplegendinterface.h +++ b/src/app/legend/qgsapplegendinterface.h @@ -46,7 +46,10 @@ class QgsAppLegendInterface : public QgsLegendInterface //! Return the relationship between groups and layers in the legend QList< GroupLayerInfo > groupLayerRelationship(); - //! Return all layers in the project in legend order + //! Returns the currently selected layers of QgsLegendLayers. + QList selectedLayers( bool inDrawOrder = false ) const; + + //! Return all layers in the project in drawing order QList< QgsMapLayer * > layers() const; //! Check if a group exists diff --git a/src/app/legend/qgslegend.cpp b/src/app/legend/qgslegend.cpp index 201e8a3e8d8..640419d94d3 100644 --- a/src/app/legend/qgslegend.cpp +++ b/src/app/legend/qgslegend.cpp @@ -1093,15 +1093,26 @@ QgsMapLayer* QgsLegend::currentLayer() } } -QList QgsLegend::selectedLayers() +QList QgsLegend::selectedLayers( bool inDrawOrder ) { QList layers; - foreach ( QTreeWidgetItem * item, selectedItems() ) + if ( inDrawOrder ) { - QgsLegendLayer *ll = dynamic_cast( item ); - if ( ll ) - layers << ll->layer(); + foreach ( QgsLegendLayer *ll, legendLayers() ) + { + if ( ll->isSelected() ) + layers << ll->layer(); + } + } + else + { + foreach ( QTreeWidgetItem * item, selectedItems() ) + { + QgsLegendLayer *ll = dynamic_cast( item ); + if ( ll ) + layers << ll->layer(); + } } return layers; diff --git a/src/app/legend/qgslegend.h b/src/app/legend/qgslegend.h index 8f257d6be88..e7dd980672d 100644 --- a/src/app/legend/qgslegend.h +++ b/src/app/legend/qgslegend.h @@ -117,9 +117,10 @@ class QgsLegend : public QTreeWidget Else, 0 is returned.*/ QgsMapLayer* currentLayer(); - /*!Returns the currently selected layer QgsLegendLayers. - Else, an empty list is returned.*/ - QList selectedLayers(); + /** Returns the currently selected layers of QgsLegendLayers. + * @param inDrawOrder return layers in drawing order (added in 1.9) + * @returns list of layers, else an empty list */ + QList selectedLayers( bool inDrawOrder = false ); /*!Returns all layers loaded in QgsMapCanvas in drawing order Else, an empty list is returned.*/ diff --git a/src/gui/qgslegendinterface.h b/src/gui/qgslegendinterface.h index 1679bc34269..177489f0b22 100644 --- a/src/gui/qgslegendinterface.h +++ b/src/gui/qgslegendinterface.h @@ -54,7 +54,12 @@ class GUI_EXPORT QgsLegendInterface : public QObject //! Return the relationship between groups and layers in the legend virtual QList< GroupLayerInfo > groupLayerRelationship() { return QList< GroupLayerInfo >(); } - //! Return all layers in the project in legend order + //! Returns the currently selected layers of QgsLegendLayers. + //! @param inDrawOrder return layers in drawing order (added in 1.9) + //! @returns list of layers, else an empty list + virtual QList selectedLayers( bool inDrawOrder = false ) const = 0; + + //! Return all layers in the project in drawing order //! @note added in 1.5 virtual QList< QgsMapLayer * > layers() const = 0;