Skip to content

Commit

Permalink
Update QgsLegend::selectedLayers() and add to QgsLegendInterface
Browse files Browse the repository at this point in the history
- Add option to return selected layers in drawing order
  • Loading branch information
dakcarto committed Nov 28, 2012
1 parent a4484b2 commit 8260eab
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 11 deletions.
7 changes: 6 additions & 1 deletion python/gui/qgslegendinterface.sip
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ class QgsLegendInterface : QObject
//! Return the relationship between groups and layers in the legend
virtual QList< QPair< QString, QList<QString> > > 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<QgsMapLayer *> 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;

Expand Down
5 changes: 5 additions & 0 deletions src/app/legend/qgsapplegendinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ bool QgsAppLegendInterface::isLayerVisible( QgsMapLayer * ml )
return ( Qt::Checked == mLegend->layerCheckState( ml ) );
}

QList<QgsMapLayer *> QgsAppLegendInterface::selectedLayers( bool inDrawOrder ) const
{
return mLegend->selectedLayers( inDrawOrder );
}

QList< QgsMapLayer * > QgsAppLegendInterface::layers() const
{
return mLegend->layers();
Expand Down
5 changes: 4 additions & 1 deletion src/app/legend/qgsapplegendinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QgsMapLayer *> selectedLayers( bool inDrawOrder = false ) const;

//! Return all layers in the project in drawing order
QList< QgsMapLayer * > layers() const;

//! Check if a group exists
Expand Down
21 changes: 16 additions & 5 deletions src/app/legend/qgslegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1093,15 +1093,26 @@ QgsMapLayer* QgsLegend::currentLayer()
}
}

QList<QgsMapLayer *> QgsLegend::selectedLayers()
QList<QgsMapLayer *> QgsLegend::selectedLayers( bool inDrawOrder )
{
QList<QgsMapLayer *> layers;

foreach ( QTreeWidgetItem * item, selectedItems() )
if ( inDrawOrder )
{
QgsLegendLayer *ll = dynamic_cast<QgsLegendLayer *>( 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<QgsLegendLayer *>( item );
if ( ll )
layers << ll->layer();
}
}

return layers;
Expand Down
7 changes: 4 additions & 3 deletions src/app/legend/qgslegend.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QgsMapLayer *> 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<QgsMapLayer *> selectedLayers( bool inDrawOrder = false );

/*!Returns all layers loaded in QgsMapCanvas in drawing order
Else, an empty list is returned.*/
Expand Down
7 changes: 6 additions & 1 deletion src/gui/qgslegendinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QgsMapLayer *> 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;

Expand Down

0 comments on commit 8260eab

Please sign in to comment.