Skip to content
Permalink
Browse files
Use expanded layers lists where needed
  • Loading branch information
nyalldawson committed Nov 23, 2021
1 parent b063d47 commit e5e596a952e8383090e352d530289f202a00a32e
@@ -402,7 +402,7 @@ void Qgs3DMapCanvasDockWidget::exportScene()

void Qgs3DMapCanvasDockWidget::onMainCanvasLayersChanged()
{
mCanvas->map()->setLayers( mMainCanvas->layers() );
mCanvas->map()->setLayers( mMainCanvas->layers( true ) );
}

void Qgs3DMapCanvasDockWidget::onMainCanvasColorChanged()
@@ -709,7 +709,7 @@ static QList<QgsMapToolIdentify::IdentifyResult> searchFeatureOnMap( QgsMapMouse
double x = mapPoint.x(), y = mapPoint.y();
const double sr = QgsMapTool::searchRadiusMU( canvas );

const QList<QgsMapLayer *> layers = canvas->layers();
const QList<QgsMapLayer *> layers = canvas->layers( true );
for ( QgsMapLayer *layer : layers )
{
if ( layer->type() == QgsMapLayerType::VectorLayer )
@@ -13783,7 +13783,7 @@ void QgisApp::new3DMapCanvas()
map->setOrigin( QgsVector3D( fullExtent.center().x(), fullExtent.center().y(), 0 ) );
map->setSelectionColor( mMapCanvas->selectionColor() );
map->setBackgroundColor( mMapCanvas->canvasColor() );
map->setLayers( mMapCanvas->layers() );
map->setLayers( mMapCanvas->layers( true ) );
// map->setTerrainLayers( mMapCanvas->layers() );
map->setTemporalRange( mMapCanvas->temporalRange() );

@@ -349,7 +349,7 @@ void QgsVectorLayerAndAttributeModel::applyVisibilityPreset( const QString &name

if ( name.isEmpty() )
{
const auto constLayers = QgisApp::instance()->mapCanvas()->layers();
const auto constLayers = QgisApp::instance()->mapCanvas()->layers( true );
for ( const QgsMapLayer *ml : constLayers )
{
const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( ml );
@@ -63,7 +63,7 @@ void QgsMapToolFeatureAction::canvasReleaseEvent( QgsMapMouseEvent *e )
return;
}

if ( !mCanvas->layers().contains( layer ) )
if ( !mCanvas->layers( true ).contains( layer ) )
{
// do not run actions on hidden layers
return;
@@ -255,7 +255,7 @@ void QgsMapToolSelectionHandler::selectPolygonPressEvent( QgsMapMouseEvent *e )
double x = mapPoint.x(), y = mapPoint.y();
const double sr = QgsMapTool::searchRadiusMU( mCanvas );

const QList<QgsMapLayer *> layers = mCanvas->layers();
const QList<QgsMapLayer *> layers = mCanvas->layers( true );
for ( auto layer : layers )
{
if ( layer->type() == QgsMapLayerType::VectorLayer )
@@ -118,7 +118,7 @@ void QgsMapToolSplitFeatures::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
! topologyTestPoints.isEmpty() )
{
//check if we need to add topological points to other layers
const auto layers = canvas()->layers();
const auto layers = canvas()->layers( true );
for ( QgsMapLayer *layer : layers )
{
QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( layer );
@@ -844,7 +844,7 @@ QgsPointLocator::Match QgsVertexTool::snapToEditableLayer( QgsMapMouseEvent *e )
{
if ( currentVlayer->isEditable() )
{
const auto layers = canvas()->layers();
const auto layers = canvas()->layers( true );
for ( QgsMapLayer *layer : layers )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
@@ -886,7 +886,7 @@ QgsPointLocator::Match QgsVertexTool::snapToEditableLayer( QgsMapMouseEvent *e )
// if there is no match from the current layer, try to use any editable vector layer
if ( !m.isValid() && mMode == AllLayers )
{
const auto layers = canvas()->layers();
const auto layers = canvas()->layers( true );
for ( QgsMapLayer *layer : layers )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
@@ -970,7 +970,7 @@ QgsPointLocator::Match QgsVertexTool::snapToPolygonInterior( QgsMapMouseEvent *e
// if there is no match from the current layer, try to use any editable vector layer
if ( !m.isValid() && mMode == AllLayers )
{
const auto layers = canvas()->layers();
const auto layers = canvas()->layers( true );
for ( QgsMapLayer *layer : layers )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
@@ -1039,7 +1039,7 @@ QSet<QPair<QgsVectorLayer *, QgsFeatureId> > QgsVertexTool::findAllEditableFeatu

if ( mMode == AllLayers )
{
const auto layers = canvas()->layers();
const auto layers = canvas()->layers( true );
for ( QgsMapLayer *layer : layers )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
@@ -1708,7 +1708,7 @@ void QgsVertexTool::startDragging( QgsMapMouseEvent *e )
QList<QgsVectorLayer *> QgsVertexTool::editableVectorLayers()
{
QList<QgsVectorLayer *> editableLayers;
const auto layers = canvas()->layers();
const auto layers = canvas()->layers( true );
for ( QgsMapLayer *layer : layers )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
@@ -469,7 +469,7 @@ QgsExpressionContextScope *QgsExpressionContextUtils::mapSettingsScope( const Qg

QVariantList layersIds;
QVariantList layers;
const QList<QgsMapLayer *> layersInMap = mapSettings.layers();
const QList<QgsMapLayer *> layersInMap = mapSettings.layers( true );
layersIds.reserve( layersInMap.count() );
layers.reserve( layersInMap.count() );
for ( QgsMapLayer *layer : layersInMap )
@@ -487,7 +487,7 @@ QgsExpressionContextScope *QgsExpressionContextUtils::mapSettingsScope( const Qg
// IMPORTANT: ANY CHANGES HERE ALSO NEED TO BE MADE TO QgsLayoutItemMap::createExpressionContext()
// (rationale is described in QgsLayoutItemMap::createExpressionContext() )

scope->addFunction( QStringLiteral( "is_layer_visible" ), new GetLayerVisibility( mapSettings.layers(), mapSettings.scale() ) );
scope->addFunction( QStringLiteral( "is_layer_visible" ), new GetLayerVisibility( mapSettings.layers( true ), mapSettings.scale() ) );

// IMPORTANT: ANY CHANGES HERE ALSO NEED TO BE MADE TO QgsLayoutItemMap::createExpressionContext()
// (rationale is described in QgsLayoutItemMap::createExpressionContext() )
@@ -57,7 +57,7 @@ void QgsMapHitTest::run()
QgsRenderContext context = QgsRenderContext::fromMapSettings( mSettings );
context.setPainter( &painter ); // we are not going to draw anything, but we still need a working painter

const auto constLayers = mSettings.layers();
const auto constLayers = mSettings.layers( true );
for ( QgsMapLayer *layer : constLayers )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
@@ -390,7 +390,7 @@ QgsPointLocator::Match QgsSnappingUtils::snapToMap( const QgsPointXY &pointMap,
QgsRectangle aoi = _areaOfInterest( pointMap, tolerance );

QList<LayerAndAreaOfInterest> layers;
const auto constLayers = mMapSettings.layers();
const auto constLayers = mMapSettings.layers( true );
for ( QgsMapLayer *layer : constLayers )
if ( QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer ) )
layers << qMakePair( vl, aoi );
@@ -632,7 +632,7 @@ QString QgsSnappingUtils::dump()
}
else if ( mSnappingConfig.mode() == QgsSnappingConfig::AllLayers )
{
const auto constLayers = mMapSettings.layers();
const auto constLayers = mMapSettings.layers( true );
for ( QgsMapLayer *layer : constLayers )
{
if ( QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer ) )
@@ -931,7 +931,7 @@ void QgsLayoutLegendWidget::mAddToolButton_clicked()
if ( visibleLayers.isEmpty() )
{
// just use current canvas layers as visible layers
visibleLayers = mMapCanvas->layers();
visibleLayers = mMapCanvas->layers( true );
}

QgsLayoutLegendLayersDialog addDialog( this );
@@ -141,7 +141,7 @@ void QgsMapCanvasAnnotationItem::onCanvasLayersChanged()
}
else
{
setVisible( mMapCanvas->mapSettings().layers().contains( mAnnotation->mapLayer() ) );
setVisible( mMapCanvas->mapSettings().layers( true ).contains( mAnnotation->mapLayer() ) );
}
}

@@ -105,7 +105,7 @@ void QgsMapCanvasTracer::configure()
setExtent( mCanvas->extent() );

QList<QgsVectorLayer *> layers;
const QList<QgsMapLayer *> visibleLayers = mCanvas->mapSettings().layers();
const QList<QgsMapLayer *> visibleLayers = mCanvas->mapSettings().layers( true );

switch ( mCanvas->snappingUtils()->config().mode() )
{
@@ -64,7 +64,7 @@ void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
// field defined as the label field in the layer configuration file/database

// Do not render map tips if the layer is not visible
if ( !pMapCanvas->layers().contains( pLayer ) )
if ( !pMapCanvas->layers( true ).contains( pLayer ) )
{
return;
}
@@ -157,23 +157,18 @@ QList<QgsMapToolIdentify::IdentifyResult> QgsMapToolIdentify::identify( const Qg
{
QApplication::setOverrideCursor( Qt::WaitCursor );

int layerCount;
QList< QgsMapLayer * > targetLayers;
if ( layerList.isEmpty() )
layerCount = mCanvas->layerCount();
targetLayers = mCanvas->layers( true );
else
layerCount = layerList.count();

targetLayers = layerList;

const int layerCount = targetLayers.size();
for ( int i = 0; i < layerCount; i++ )
{
QgsMapLayer *layer = targetLayers.value( i );

QgsMapLayer *layer = nullptr;
if ( layerList.isEmpty() )
layer = mCanvas->layer( i );
else
layer = layerList.value( i );

emit identifyProgress( i, mCanvas->layerCount() );
emit identifyProgress( i, layerCount );
emit identifyMessage( tr( "Identifying on %1…" ).arg( layer->name() ) );

if ( !layer->flags().testFlag( QgsMapLayer::Identifiable ) )
@@ -186,7 +181,7 @@ QList<QgsMapToolIdentify::IdentifyResult> QgsMapToolIdentify::identify( const Qg
}
}

emit identifyProgress( mCanvas->layerCount(), mCanvas->layerCount() );
emit identifyProgress( layerCount, layerCount );
emit identifyMessage( tr( "Identifying done." ) );
}

0 comments on commit e5e596a

Please sign in to comment.