From 9e1ba962f58d05c74dba862a43d59e39b8b6ce00 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 20 Mar 2025 11:51:52 +1000 Subject: [PATCH] Respect project scale method in processing algorithms Algorithms which use map settings now respect the current project scale method --- src/analysis/processing/qgsalgorithmdxfexport.cpp | 2 ++ src/analysis/processing/qgsalgorithmdxfexport.h | 1 + src/analysis/processing/qgsalgorithmextractlabels.cpp | 3 +++ src/analysis/processing/qgsalgorithmextractlabels.h | 1 + src/analysis/processing/qgsalgorithmrasterize.cpp | 2 ++ src/analysis/processing/qgsalgorithmxyztiles.cpp | 3 +++ src/analysis/processing/qgsalgorithmxyztiles.h | 1 + 7 files changed, 13 insertions(+) diff --git a/src/analysis/processing/qgsalgorithmdxfexport.cpp b/src/analysis/processing/qgsalgorithmdxfexport.cpp index ddfdd0088e0..d83a9126a9c 100644 --- a/src/analysis/processing/qgsalgorithmdxfexport.cpp +++ b/src/analysis/processing/qgsalgorithmdxfexport.cpp @@ -88,6 +88,7 @@ bool QgsDxfExportAlgorithm::prepareAlgorithm( const QVariantMap ¶meters, Qgs { mMapThemeStyleOverrides = context.project()->mapThemeCollection()->mapThemeStyleOverrides( mapTheme ); } + mScaleMethod = context.project()->scaleMethod(); return true; } @@ -96,6 +97,7 @@ QVariantMap QgsDxfExportAlgorithm::processAlgorithm( const QVariantMap ¶mete QgsMapSettings mapSettings; mapSettings.setTransformContext( context.transformContext() ); mapSettings.setLayerStyleOverrides( mMapThemeStyleOverrides ); + mapSettings.setScaleMethod( mScaleMethod ); QList mapLayers; diff --git a/src/analysis/processing/qgsalgorithmdxfexport.h b/src/analysis/processing/qgsalgorithmdxfexport.h index b26a1cd16ef..f2549e78daa 100644 --- a/src/analysis/processing/qgsalgorithmdxfexport.h +++ b/src/analysis/processing/qgsalgorithmdxfexport.h @@ -41,6 +41,7 @@ class QgsDxfExportAlgorithm : public QgsProcessingAlgorithm private: QMap mMapThemeStyleOverrides; + Qgis::ScaleCalculationMethod mScaleMethod = Qgis::ScaleCalculationMethod::HorizontalMiddle; }; ///@endcond PRIVATE diff --git a/src/analysis/processing/qgsalgorithmextractlabels.cpp b/src/analysis/processing/qgsalgorithmextractlabels.cpp index 44c50abde28..c9e1eab3c5e 100644 --- a/src/analysis/processing/qgsalgorithmextractlabels.cpp +++ b/src/analysis/processing/qgsalgorithmextractlabels.cpp @@ -398,6 +398,7 @@ QVariantMap QgsExtractLabelsAlgorithm::processAlgorithm( const QVariantMap ¶ mapSettings.setLayers( mMapLayers ); mapSettings.setLayerStyleOverrides( mMapThemeStyleOverrides ); mapSettings.setLabelingEngineSettings( mLabelSettings ); + mapSettings.setScaleMethod( mScaleMethod ); //build the expression context QgsExpressionContext expressionContext; @@ -613,6 +614,8 @@ bool QgsExtractLabelsAlgorithm::prepareAlgorithm( const QVariantMap ¶meters, mLabelSettings.setFlag( Qgis::LabelingFlag::DrawUnplacedLabels, includeUnplaced ); mLabelSettings.setFlag( Qgis::LabelingFlag::CollectUnplacedLabels, includeUnplaced ); + mScaleMethod = context.project()->scaleMethod(); + return true; } diff --git a/src/analysis/processing/qgsalgorithmextractlabels.h b/src/analysis/processing/qgsalgorithmextractlabels.h index 8f988bc7ba4..96e0d562517 100644 --- a/src/analysis/processing/qgsalgorithmextractlabels.h +++ b/src/analysis/processing/qgsalgorithmextractlabels.h @@ -52,6 +52,7 @@ class QgsExtractLabelsAlgorithm : public QgsProcessingAlgorithm QMap mMapThemeStyleOverrides; QgsLabelingEngineSettings mLabelSettings; QgsCoordinateReferenceSystem mCrs; + Qgis::ScaleCalculationMethod mScaleMethod = Qgis::ScaleCalculationMethod::HorizontalMiddle; }; ///@endcond PRIVATE diff --git a/src/analysis/processing/qgsalgorithmrasterize.cpp b/src/analysis/processing/qgsalgorithmrasterize.cpp index 85c845d4e53..9a707123bc4 100644 --- a/src/analysis/processing/qgsalgorithmrasterize.cpp +++ b/src/analysis/processing/qgsalgorithmrasterize.cpp @@ -411,6 +411,8 @@ bool QgsRasterizeAlgorithm::prepareAlgorithm( const QVariantMap ¶meters, Qgs } mMapSettings.setBackgroundColor( bgColor ); + mMapSettings.setScaleMethod( context.project()->scaleMethod() ); + return mMapLayers.size() > 0; } diff --git a/src/analysis/processing/qgsalgorithmxyztiles.cpp b/src/analysis/processing/qgsalgorithmxyztiles.cpp index 77dbb6370f5..cad09c7351f 100644 --- a/src/analysis/processing/qgsalgorithmxyztiles.cpp +++ b/src/analysis/processing/qgsalgorithmxyztiles.cpp @@ -200,6 +200,8 @@ bool QgsXyzTilesBaseAlgorithm::prepareAlgorithm( const QVariantMap ¶meters, feedback->pushWarning( QObject::tr( "Background color setting ignored, the JPG format only supports fully opaque colors" ) ); } + mScaleMethod = project->scaleMethod(); + return true; } @@ -241,6 +243,7 @@ void QgsXyzTilesBaseAlgorithm::startJobs() settings.setLayers( mLayers ); settings.setOutputDpi( mDpi ); settings.setFlag( Qgis::MapSettingsFlag::Antialiasing, mAntialias ); + settings.setScaleMethod( mScaleMethod ); if ( mTileFormat == QLatin1String( "PNG" ) || mBackgroundColor.alpha() == 255 ) { settings.setBackgroundColor( mBackgroundColor ); diff --git a/src/analysis/processing/qgsalgorithmxyztiles.h b/src/analysis/processing/qgsalgorithmxyztiles.h index 7b4c85c524c..803d95bbdb7 100644 --- a/src/analysis/processing/qgsalgorithmxyztiles.h +++ b/src/analysis/processing/qgsalgorithmxyztiles.h @@ -130,6 +130,7 @@ class QgsXyzTilesBaseAlgorithm : public QgsProcessingAlgorithm QPointer mEventLoop; QList mMetaTiles; QMap mRendererJobs; + Qgis::ScaleCalculationMethod mScaleMethod = Qgis::ScaleCalculationMethod::HorizontalMiddle; };