Skip to content
Permalink
Browse files
Handling of WMS legend graphic
  • Loading branch information
wonder-sk committed May 21, 2014
1 parent 0e79551 commit 3180dee4fa3bd9c0c3f8139f95939cd5ed154130
Showing with 36 additions and 3 deletions.
  1. +29 −1 src/app/qgisapp.cpp
  2. +0 −1 src/core/layertree/qgslayertreelayer.cpp
  3. +7 −1 src/gui/layertree/qgslayertreemodel.cpp
@@ -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() )
@@ -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 )
@@ -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

0 comments on commit 3180dee

Please sign in to comment.