From 785a968f47adff50afa9bbe31046848464e2c7e8 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Wed, 11 Dec 2024 06:21:58 +1000 Subject: [PATCH] Fix coverity issues in QgsStacSourceSelect::showItemsContextMenu - Unchecked dynamic_cast - Fix access to temporary reference from lambda slot --- src/gui/stac/qgsstacsourceselect.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/gui/stac/qgsstacsourceselect.cpp b/src/gui/stac/qgsstacsourceselect.cpp index ea185c3f41f7..292fdec93ab5 100644 --- a/src/gui/stac/qgsstacsourceselect.cpp +++ b/src/gui/stac/qgsstacsourceselect.cpp @@ -490,23 +490,24 @@ void QgsStacSourceSelect::showItemsContextMenu( QPoint point ) QMenu *menu = new QMenu( this ); QgsMessageBar *bar = nullptr; - QgsDataSourceManagerDialog *dsm = qobject_cast( window() ); - if ( dsm ) + if ( QgsDataSourceManagerDialog *dsm = qobject_cast( window() ) ) bar = dsm->messageBar(); - const QgsStacItem *item = dynamic_cast( index.data( QgsStacItemListModel::Role::StacObject ).value() ); QMenu *assetsMenu = menu->addMenu( tr( "Add Layer" ) ); - const QMap assets = item->assets(); - for ( const QgsStacAsset &asset : assets ) + if ( const QgsStacItem *item = dynamic_cast( index.data( QgsStacItemListModel::Role::StacObject ).value() ) ) { - if ( asset.isCloudOptimized() ) + const QMap assets = item->assets(); + for ( const QgsStacAsset &asset : assets ) { - QAction *loadAssetAction = new QAction( asset.title(), assetsMenu ); - connect( loadAssetAction, &QAction::triggered, this, [this, &asset] { - QgsTemporaryCursorOverride cursorOverride( Qt::WaitCursor ); - loadUri( asset.uri() ); - } ); - assetsMenu->addAction( loadAssetAction ); + if ( asset.isCloudOptimized() ) + { + QAction *loadAssetAction = new QAction( asset.title(), assetsMenu ); + connect( loadAssetAction, &QAction::triggered, this, [this, uri = asset.uri()] { + QgsTemporaryCursorOverride cursorOverride( Qt::WaitCursor ); + loadUri( uri ); + } ); + assetsMenu->addAction( loadAssetAction ); + } } }