Skip to content

Commit

Permalink
Fix coverity issues in QgsStacSourceSelect::showItemsContextMenu
Browse files Browse the repository at this point in the history
- Unchecked dynamic_cast
- Fix access to temporary reference from lambda slot
  • Loading branch information
nyalldawson committed Dec 10, 2024
1 parent 98c5bf8 commit 785a968
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/gui/stac/qgsstacsourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,23 +490,24 @@ void QgsStacSourceSelect::showItemsContextMenu( QPoint point )
QMenu *menu = new QMenu( this );

QgsMessageBar *bar = nullptr;
QgsDataSourceManagerDialog *dsm = qobject_cast<QgsDataSourceManagerDialog *>( window() );
if ( dsm )
if ( QgsDataSourceManagerDialog *dsm = qobject_cast<QgsDataSourceManagerDialog *>( window() ) )
bar = dsm->messageBar();

const QgsStacItem *item = dynamic_cast<QgsStacItem *>( index.data( QgsStacItemListModel::Role::StacObject ).value<QgsStacObject *>() );
QMenu *assetsMenu = menu->addMenu( tr( "Add Layer" ) );
const QMap<QString, QgsStacAsset> assets = item->assets();
for ( const QgsStacAsset &asset : assets )
if ( const QgsStacItem *item = dynamic_cast<QgsStacItem *>( index.data( QgsStacItemListModel::Role::StacObject ).value<QgsStacObject *>() ) )
{
if ( asset.isCloudOptimized() )
const QMap<QString, QgsStacAsset> 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 );
}
}
}

Expand Down

0 comments on commit 785a968

Please sign in to comment.