From 320b3afd1c86bfcad1f0f6172514b4116fb74d87 Mon Sep 17 00:00:00 2001 From: Tom Christian Date: Fri, 26 Sep 2025 14:39:07 -0700 Subject: [PATCH] feat(#62838): refactor duplicated logic --- .../auto_generated/stac/qgsstacasset.sip.in | 8 ++++ .../auto_generated/stac/qgsstacasset.sip.in | 8 ++++ src/core/stac/qgsstacasset.cpp | 14 +++++++ src/core/stac/qgsstacasset.h | 8 +++- src/core/stac/qgsstacdataitems.cpp | 38 +------------------ 5 files changed, 39 insertions(+), 37 deletions(-) diff --git a/python/PyQt6/core/auto_generated/stac/qgsstacasset.sip.in b/python/PyQt6/core/auto_generated/stac/qgsstacasset.sip.in index 96241fa3040..19dcfac882b 100644 --- a/python/PyQt6/core/auto_generated/stac/qgsstacasset.sip.in +++ b/python/PyQt6/core/auto_generated/stac/qgsstacasset.sip.in @@ -76,6 +76,14 @@ Returns the format name for cloud optimized formats QgsMimeDataUtils::Uri uri() const; %Docstring Returns a uri for the asset if it is a cloud optimized file like COG or +COPC, empty auth configuration + +.. versionadded:: 3.42 +%End + + QgsMimeDataUtils::Uri uri( QString authcfg ) const; +%Docstring +Returns a uri for the asset if it is a cloud optimized file like COG or COPC .. versionadded:: 3.42 diff --git a/python/core/auto_generated/stac/qgsstacasset.sip.in b/python/core/auto_generated/stac/qgsstacasset.sip.in index 96241fa3040..19dcfac882b 100644 --- a/python/core/auto_generated/stac/qgsstacasset.sip.in +++ b/python/core/auto_generated/stac/qgsstacasset.sip.in @@ -76,6 +76,14 @@ Returns the format name for cloud optimized formats QgsMimeDataUtils::Uri uri() const; %Docstring Returns a uri for the asset if it is a cloud optimized file like COG or +COPC, empty auth configuration + +.. versionadded:: 3.42 +%End + + QgsMimeDataUtils::Uri uri( QString authcfg ) const; +%Docstring +Returns a uri for the asset if it is a cloud optimized file like COG or COPC .. versionadded:: 3.42 diff --git a/src/core/stac/qgsstacasset.cpp b/src/core/stac/qgsstacasset.cpp index ac6d3d5b026..dd8f0e2b9cf 100644 --- a/src/core/stac/qgsstacasset.cpp +++ b/src/core/stac/qgsstacasset.cpp @@ -79,6 +79,12 @@ QString QgsStacAsset::formatName() const } QgsMimeDataUtils::Uri QgsStacAsset::uri() const +{ + return uri( QString() ); +} + + +QgsMimeDataUtils::Uri QgsStacAsset::uri( QString authcfg ) const { QgsMimeDataUtils::Uri uri; QUrl url( href() ); @@ -90,6 +96,8 @@ QgsMimeDataUtils::Uri QgsStacAsset::uri() const href().startsWith( QLatin1String( "ftp" ), Qt::CaseInsensitive ) ) { uri.uri = QStringLiteral( "/vsicurl/%1" ).arg( href() ); + if ( !authcfg.isEmpty() ) + uri.uri.append( QStringLiteral( " authcfg='%1'" ).arg( authcfg ) ); } else if ( href().startsWith( QLatin1String( "s3://" ), Qt::CaseInsensitive ) ) { @@ -105,12 +113,16 @@ QgsMimeDataUtils::Uri QgsStacAsset::uri() const uri.layerType = QStringLiteral( "pointcloud" ); uri.providerKey = QStringLiteral( "copc" ); uri.uri = href(); + if ( !authcfg.isEmpty() ) + uri.uri.append( QStringLiteral( " authcfg='%1'" ).arg( authcfg ) ); } else if ( formatName() == QLatin1String( "EPT" ) ) { uri.layerType = QStringLiteral( "pointcloud" ); uri.providerKey = QStringLiteral( "ept" ); uri.uri = href(); + if ( !authcfg.isEmpty() ) + uri.uri.append( QStringLiteral( " authcfg='%1'" ).arg( authcfg ) ); } else if ( formatName() == QLatin1String( "Zarr" ) ) { @@ -120,6 +132,8 @@ QgsMimeDataUtils::Uri QgsStacAsset::uri() const href().startsWith( QLatin1String( "ftp" ), Qt::CaseInsensitive ) ) { uri.uri = QStringLiteral( "ZARR:\"/vsicurl/%1\"" ).arg( href() ); + if ( !authcfg.isEmpty() ) + uri.uri.append( QStringLiteral( " authcfg='%1'" ).arg( authcfg ) ); } else if ( href().startsWith( QLatin1String( "s3://" ), Qt::CaseInsensitive ) ) { diff --git a/src/core/stac/qgsstacasset.h b/src/core/stac/qgsstacasset.h index 4cabaae8fd7..3e5138acd00 100644 --- a/src/core/stac/qgsstacasset.h +++ b/src/core/stac/qgsstacasset.h @@ -73,11 +73,17 @@ class CORE_EXPORT QgsStacAsset QString formatName() const; /** - * Returns a uri for the asset if it is a cloud optimized file like COG or COPC + * Returns a uri for the asset if it is a cloud optimized file like COG or COPC, empty auth configuration * \since QGIS 3.42 */ QgsMimeDataUtils::Uri uri() const; + /** + * Returns a uri for the asset if it is a cloud optimized file like COG or COPC + * \since QGIS 3.42 + */ + QgsMimeDataUtils::Uri uri( QString authcfg ) const; + private: QString mHref; QString mTitle; diff --git a/src/core/stac/qgsstacdataitems.cpp b/src/core/stac/qgsstacdataitems.cpp index 075455e65bb..57e11eee987 100644 --- a/src/core/stac/qgsstacdataitems.cpp +++ b/src/core/stac/qgsstacdataitems.cpp @@ -109,44 +109,10 @@ QgsMimeDataUtils::UriList QgsStacItemItem::mimeUris() const { uri.uri = it->href(); } - else if ( it->mediaType() == QLatin1String( "image/tiff; application=geotiff; profile=cloud-optimized" ) || - it->mediaType() == QLatin1String( "image/vnd.stac.geotiff; cloud-optimized=true" ) ) + else { - uri.layerType = QStringLiteral( "raster" ); - uri.providerKey = QStringLiteral( "gdal" ); - if ( it->href().startsWith( QLatin1String( "http" ), Qt::CaseInsensitive ) || - it->href().startsWith( QLatin1String( "ftp" ), Qt::CaseInsensitive ) ) - { - uri.uri = QStringLiteral( "/vsicurl/%1" ).arg( it->href() ); - if ( !authcfg.isEmpty() ) - uri.uri.append( QStringLiteral( " authcfg='%1'" ).arg( authcfg ) ); - } - else if ( it->href().startsWith( QLatin1String( "s3://" ), Qt::CaseInsensitive ) ) - { - uri.uri = QStringLiteral( "/vsis3/%1" ).arg( it->href().mid( 5 ) ); - } - else - { - uri.uri = it->href(); - } + uri = it->uri( authcfg ); } - else if ( it->mediaType() == QLatin1String( "application/vnd.laszip+copc" ) ) - { - uri.layerType = QStringLiteral( "pointcloud" ); - uri.providerKey = QStringLiteral( "copc" ); - uri.uri = it->href(); - if ( !authcfg.isEmpty() ) - uri.uri.append( QStringLiteral( " authcfg='%1'" ).arg( authcfg ) ); - } - else if ( it->href().endsWith( QLatin1String( "/ept.json" ) ) ) - { - uri.layerType = QStringLiteral( "pointcloud" ); - uri.providerKey = QStringLiteral( "ept" ); - uri.uri = it->href(); - if ( !authcfg.isEmpty() ) - uri.uri.append( QStringLiteral( " authcfg='%1'" ).arg( authcfg ) ); - } - uri.name = it->title().isEmpty() ? url.fileName() : it->title(); uris.append( uri ); }