Skip to content

Commit

Permalink
Handling of WMS legend graphic
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed May 21, 2014
1 parent 0e79551 commit 3180dee
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
30 changes: 29 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -380,7 +380,35 @@ void QgisApp::emitCustomSrsValidation( QgsCoordinateReferenceSystem &srs )

void QgisApp::layerTreeViewDoubleClicked( const QModelIndex& index )
{
Q_UNUSED( index );
// temporary solution for WMS legend
if ( mLayerTreeView->layerTreeModel()->index2symnode( index ) )
{
QModelIndex parent = mLayerTreeView->layerTreeModel()->parent( index );
QgsLayerTreeNode* node = mLayerTreeView->layerTreeModel()->index2node( parent );
if ( QgsLayerTree::isLayer( node ) )
{
QgsMapLayer* layer = QgsLayerTree::toLayer( node )->layer();
QgsRasterLayer* rlayer = qobject_cast<QgsRasterLayer*>( layer );
if ( rlayer && rlayer->providerType() == "wms" )
{
QImage img = rlayer->dataProvider()->getLegendGraphic( mMapCanvas->scale() );

QFrame* popup = new QFrame();
popup->setAttribute( Qt::WA_DeleteOnClose );
popup->setFrameStyle( QFrame::Box | QFrame::Raised );
popup->setLineWidth( 2 );
popup->setAutoFillBackground( true );
QVBoxLayout *layout = new QVBoxLayout;
QLabel *label = new QLabel( popup );
label->setPixmap( QPixmap::fromImage( img ) );
layout->addWidget( label );
popup->setLayout( layout );
popup->move( mLayerTreeView->visualRect( index ).bottomLeft() );
popup->show();
return;
}
}
}

QSettings settings;
switch ( settings.value( "/qgis/legendDoubleClickAction", 0 ).toInt() )
Expand Down
1 change: 0 additions & 1 deletion src/core/layertree/qgslayertreelayer.cpp
Expand Up @@ -84,7 +84,6 @@ QgsLayerTreeLayer* QgsLayerTreeLayer::readXML( QDomElement& element )

QgsLayerTreeLayer* nodeLayer = 0;

// TODO: maybe allow other sources of layers than just registry singleton?
QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerID );

if ( layer )
Expand Down
8 changes: 7 additions & 1 deletion src/gui/layertree/qgslayertreemodel.cpp
Expand Up @@ -534,7 +534,13 @@ void QgsLayerTreeModel::addSymbologyToRasterLayer( QgsLayerTreeLayer* nodeL )

QList<QgsLayerTreeModelSymbologyNode*>& lst = mSymbologyNodes[nodeL];

// TODO: WMS
// temporary solution for WMS. Ideally should be done with a delegate.
if ( rlayer->providerType() == "wms" )
{
QImage img = rlayer->dataProvider()->getLegendGraphic( 1000 ); // dummy scale - should not be required!
if ( !img.isNull() )
lst << new QgsLayerTreeModelSymbologyNode( nodeL, tr( "Double-click to view legend" ) );
}

// Paletted raster may have many colors, for example UInt16 may have 65536 colors
// and it is very slow, so we limit max count
Expand Down

0 comments on commit 3180dee

Please sign in to comment.