Skip to content

Commit

Permalink
Use expanded layers lists where needed
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 23, 2021
1 parent b063d47 commit e5e596a
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/app/3d/qgs3dmapcanvasdockwidget.cpp
Expand Up @@ -402,7 +402,7 @@ void Qgs3DMapCanvasDockWidget::exportScene()

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

void Qgs3DMapCanvasDockWidget::onMainCanvasColorChanged()
Expand Down
2 changes: 1 addition & 1 deletion src/app/mesh/qgsmaptooleditmeshframe.cpp
Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -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() );

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsdxfexportdialog.cpp
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolfeatureaction.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolselectionhandler.cpp
Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolsplitfeatures.cpp
Expand Up @@ -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 );
Expand Down
10 changes: 5 additions & 5 deletions src/app/vertextool/qgsvertextool.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions src/core/expression/qgsexpressioncontextutils.cpp
Expand Up @@ -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 )
Expand All @@ -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() )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsmaphittest.cpp
Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgssnappingutils.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 ) )
Expand Down
2 changes: 1 addition & 1 deletion src/gui/layout/qgslayoutlegendwidget.cpp
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmapcanvasannotationitem.cpp
Expand Up @@ -141,7 +141,7 @@ void QgsMapCanvasAnnotationItem::onCanvasLayersChanged()
}
else
{
setVisible( mMapCanvas->mapSettings().layers().contains( mAnnotation->mapLayer() ) );
setVisible( mMapCanvas->mapSettings().layers( true ).contains( mAnnotation->mapLayer() ) );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmapcanvastracer.cpp
Expand Up @@ -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() )
{
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmaptip.cpp
Expand Up @@ -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;
}
Expand Down
19 changes: 7 additions & 12 deletions src/gui/qgsmaptoolidentify.cpp
Expand Up @@ -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 ) )
Expand All @@ -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." ) );
}

Expand Down

0 comments on commit e5e596a

Please sign in to comment.