Skip to content

Commit

Permalink
Make out of range layers greyed out in the tree
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Valsecchi committed Mar 9, 2016
1 parent 3efc73b commit a112dfe
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/core/layertree/qgslayertreemodel.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
33 changes: 33 additions & 0 deletions src/core/layertree/qgslayertreemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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
{
Expand Down
2 changes: 2 additions & 0 deletions src/core/layertree/qgslayertreemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

2 comments on commit a112dfe

@nirvn
Copy link
Contributor

@nirvn nirvn commented on a112dfe Mar 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@NathanW2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.