Skip to content
Permalink
Browse files

[layer tree] Avoid needless layer tree model computations for scale-b…

…ased layer visibility
  • Loading branch information
nirvn committed Sep 28, 2020
1 parent ef7ecbf commit 9d105d9d591d7d7747cdf9d47e7609d0a735f3ec
@@ -374,7 +374,7 @@ Updates model when node's name has changed
emit :py:func:`~QgsLayerTreeModel.dataChanged` for layer tree node items
%End

void refreshScaleBasedLayers( const QModelIndex &index = QModelIndex() );
void refreshScaleBasedLayers( const QModelIndex &index = QModelIndex(), double previousScale = 0.0 );
%Docstring
Updates layer data for scale dependent layers, should be called when map scale changes.
Emits :py:func:`~QgsLayerTreeModel.dataChanged` for all scale dependent layers.
@@ -690,14 +690,16 @@ void QgsLayerTreeModel::setLegendMapViewData( double mapUnitsPerPixel, int dpi,
if ( mLegendMapViewDpi == dpi && qgsDoubleNear( mLegendMapViewMupp, mapUnitsPerPixel ) && qgsDoubleNear( mLegendMapViewScale, scale ) )
return;

double previousScale = mLegendMapViewScale;
mLegendMapViewScale = scale;
mLegendMapViewMupp = mapUnitsPerPixel;
mLegendMapViewDpi = dpi;
mLegendMapViewScale = scale;

// now invalidate legend nodes!
legendInvalidateMapBasedData();

refreshScaleBasedLayers();
if ( scale != previousScale )
refreshScaleBasedLayers( QModelIndex(), previousScale );
}

void QgsLayerTreeModel::legendMapViewData( double *mapUnitsPerPixel, int *dpi, double *scale ) const
@@ -1020,7 +1022,7 @@ void QgsLayerTreeModel::recursivelyEmitDataChanged( const QModelIndex &idx )
recursivelyEmitDataChanged( index( i, 0, idx ) );
}

void QgsLayerTreeModel::refreshScaleBasedLayers( const QModelIndex &idx )
void QgsLayerTreeModel::refreshScaleBasedLayers( const QModelIndex &idx, double previousScale )
{
QgsLayerTreeNode *node = index2node( idx );
if ( !node )
@@ -1031,12 +1033,13 @@ void QgsLayerTreeModel::refreshScaleBasedLayers( const QModelIndex &idx )
const QgsMapLayer *layer = QgsLayerTree::toLayer( node )->layer();
if ( layer && layer->hasScaleBasedVisibility() )
{
emit dataChanged( idx, idx );
if ( layer->isInScaleRange( mLegendMapViewScale ) != layer->isInScaleRange( previousScale ) )
emit dataChanged( idx, idx, QVector<int>() << Qt::FontRole << Qt::ForegroundRole );
}
}
int count = node->children().count();
for ( int i = 0; i < count; ++i )
refreshScaleBasedLayers( index( i, 0, idx ) );
refreshScaleBasedLayers( index( i, 0, idx ), previousScale );
}

Qt::DropActions QgsLayerTreeModel::supportedDropActions() const
@@ -340,7 +340,7 @@ class CORE_EXPORT QgsLayerTreeModel : public QAbstractItemModel
* Emits dataChanged() for all scale dependent layers.
* \since QGIS 2.16
*/
void refreshScaleBasedLayers( const QModelIndex &index = QModelIndex() );
void refreshScaleBasedLayers( const QModelIndex &index = QModelIndex(), double previousScale = 0.0 );

static QIcon iconGroup();

0 comments on commit 9d105d9

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