Skip to content
Permalink
Browse files

Make out of range layers greyed out in the tree

  • Loading branch information
Patrick Valsecchi
Patrick Valsecchi committed Mar 9, 2016
1 parent 3efc73b commit a112dfe63e2c53b52b94cb00f0161e0ac5074e24
@@ -230,6 +230,7 @@ class QgsLayerTreeModel : QAbstractItemModel

//! emit dataChanged() for layer tree node items
void recursivelyEmitDataChanged( const QModelIndex& index = QModelIndex() );
void refreshScaleBasedLayers( const QModelIndex& index = QModelIndex() );

static const QIcon& iconGroup();

@@ -271,6 +271,19 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
f.setUnderline( true );
return f;
}
else if ( role == Qt::ForegroundRole )
{
QBrush brush( Qt::black, Qt::SolidPattern );
if ( QgsLayerTree::isLayer( node ) )
{
const QgsMapLayer* layer = QgsLayerTree::toLayer( node )->layer();
if ( layer && !layer->isInScaleRange( mLegendMapViewScale ) )
{
brush.setColor( Qt::lightGray );
}
}
return brush;
}
else if ( role == Qt::ToolTipRole )
{
if ( QgsLayerTree::isLayer( node ) )
@@ -633,6 +646,8 @@ void QgsLayerTreeModel::setLegendMapViewData( double mapUnitsPerPixel, int dpi,

// now invalidate legend nodes!
legendInvalidateMapBasedData();

refreshScaleBasedLayers();
}

void QgsLayerTreeModel::legendMapViewData( double* mapUnitsPerPixel, int* dpi, double* scale )
@@ -919,6 +934,24 @@ void QgsLayerTreeModel::recursivelyEmitDataChanged( const QModelIndex& idx )
recursivelyEmitDataChanged( index( i, 0, idx ) );
}

void QgsLayerTreeModel::refreshScaleBasedLayers( const QModelIndex& idx )
{
QgsLayerTreeNode* node = index2node( idx );
if ( !node )
return;

if ( node->nodeType() == QgsLayerTreeNode::NodeLayer )
{
const QgsMapLayer* layer = QgsLayerTree::toLayer( node )->layer();
if ( layer->hasScaleBasedVisibility() )
{
emit dataChanged( idx, idx );
}
}
int count = node->children().count();
for ( int i = 0; i < count; ++i )
refreshScaleBasedLayers( index( i, 0, idx ) );
}

Qt::DropActions QgsLayerTreeModel::supportedDropActions() const
{
@@ -254,6 +254,8 @@ class CORE_EXPORT QgsLayerTreeModel : public QAbstractItemModel

//! emit dataChanged() for layer tree node items
void recursivelyEmitDataChanged( const QModelIndex& index = QModelIndex() );
//! emit dataChanged() for scale dependent layers
void refreshScaleBasedLayers( const QModelIndex& index = QModelIndex() );

static const QIcon& iconGroup();

2 comments on commit a112dfe

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Mar 10, 2016

@pvalsecc thanks for this commit, it's a really nice UX improvement.

@NathanW2

This comment has been minimized.

Copy link
Member

@NathanW2 NathanW2 replied Mar 10, 2016

+++++++++++1 We might also need to adjust tooltip to say that it is out of range

Please sign in to comment.
You can’t perform that action at this time.