Skip to content
Permalink
Browse files
Better tooltips for map layers
Including CRS information
  • Loading branch information
nyalldawson committed Apr 27, 2017
1 parent 0674361 commit 1012f2587548763be2f5be6f69e1ba9a099caa05
Showing with 26 additions and 10 deletions.
  1. +13 −5 src/core/layertree/qgslayertreemodel.cpp
  2. +13 −5 src/core/qgsmaplayermodel.cpp
@@ -321,12 +321,20 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
{
if ( QgsMapLayer *layer = QgsLayerTree::toLayer( node )->layer() )
{
QString tooltip = "<b>" +
( layer->title().isEmpty() ? layer->shortName() : layer->title() ) + "</b>";
QStringList parts;
QString title = layer->title().isEmpty() ? layer->shortName() : layer->title();
if ( title.isEmpty() )
title = layer->name();
title = "<b>" + title + "</b>";
if ( layer->crs().isValid() )
title = tr( "%1 (%2)" ).arg( title, layer->crs().authid() );

parts << title;

if ( !layer->abstract().isEmpty() )
tooltip += "<br/>" + layer->abstract().replace( QLatin1String( "\n" ), QLatin1String( "<br/>" ) );
tooltip += "<br/><i>" + layer->publicSource() + "</i>";
return tooltip;
parts << "<br/>" + layer->abstract().replace( QLatin1String( "\n" ), QLatin1String( "<br/>" ) );
parts << "<i>" + layer->publicSource() + "</i>";
return parts.join( "<br/>" );
}
}
}
@@ -284,12 +284,20 @@ QVariant QgsMapLayerModel::data( const QModelIndex &index, int role ) const
QgsMapLayer *layer = static_cast<QgsMapLayer *>( index.internalPointer() );
if ( layer )
{
QString tooltip = "<b>" +
( layer->title().isEmpty() ? layer->shortName() : layer->title() ) + "</b>";
QStringList parts;
QString title = layer->title().isEmpty() ? layer->shortName() : layer->title();
if ( title.isEmpty() )
title = layer->name();
title = "<b>" + title + "</b>";
if ( layer->crs().isValid() )
title = tr( "%1 (%2)" ).arg( title, layer->crs().authid() );

parts << title;

if ( !layer->abstract().isEmpty() )
tooltip += "<br/>" + layer->abstract().replace( QLatin1String( "\n" ), QLatin1String( "<br/>" ) );
tooltip += "<br/><i>" + layer->publicSource() + "</i>";
return tooltip;
parts << "<br/>" + layer->abstract().replace( QLatin1String( "\n" ), QLatin1String( "<br/>" ) );
parts << "<i>" + layer->publicSource() + "</i>";
return parts.join( "<br/>" );
}
return QVariant();
}

0 comments on commit 1012f25

Please sign in to comment.