mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
[composer] Remove more use of composition map settings
Use relevant composer map item CRS instead of composition mapsetting's CRS. For items directly linked to a map (eg scalebar, legend) we use that map's CRS, for others (eg labels, html items) we use the composition's reference map CRS. (Note that the CRS cannot be set for a map, and is still currently linked to the canvas CRS. Fixing that is a future TODO.)
This commit is contained in:
parent
b119744773
commit
e3ad5b1e3b
@ -127,6 +127,8 @@ class QgsComposerMap : QgsComposerItem
|
||||
//! @note not available in python bindings
|
||||
// QgsRectangle* currentMapExtent();
|
||||
|
||||
QgsCoordinateReferenceSystem crs() const;
|
||||
|
||||
PreviewMode previewMode() const;
|
||||
void setPreviewMode( PreviewMode m );
|
||||
|
||||
|
@ -1035,7 +1035,7 @@ void QgsComposerMapGridWidget::on_mMapGridCRSButton_clicked()
|
||||
|
||||
QgsGenericProjectionSelector crsDialog( this );
|
||||
QgsCoordinateReferenceSystem crs = mComposerMapGrid->crs();
|
||||
QString currentAuthId = crs.isValid() ? crs.authid() : mComposerMap->composition()->mapSettings().destinationCrs().authid();
|
||||
QString currentAuthId = crs.isValid() ? crs.authid() : mComposerMap->crs().authid();
|
||||
crsDialog.setSelectedAuthId( currentAuthId );
|
||||
|
||||
if ( crsDialog.exec() == QDialog::Accepted )
|
||||
|
@ -439,7 +439,7 @@ void QgsAtlasComposition::computeExtent( QgsComposerMap* map )
|
||||
// QgsGeometry::boundingBox is expressed in the geometry"s native CRS
|
||||
// We have to transform the grometry to the destination CRS and ask for the bounding box
|
||||
// Note: we cannot directly take the transformation of the bounding box, since transformations are not linear
|
||||
mTransformedFeatureBounds = currentGeometry( map->composition()->mapSettings().destinationCrs() ).boundingBox();
|
||||
mTransformedFeatureBounds = currentGeometry( map->crs() ).boundingBox();
|
||||
}
|
||||
|
||||
void QgsAtlasComposition::prepareMap( QgsComposerMap* map )
|
||||
@ -481,7 +481,7 @@ void QgsAtlasComposition::prepareMap( QgsComposerMap* map )
|
||||
if ( map->atlasScalingMode() == QgsComposerMap::Fixed || map->atlasScalingMode() == QgsComposerMap::Predefined || isPointLayer )
|
||||
{
|
||||
QgsScaleCalculator calc;
|
||||
calc.setMapUnits( composition()->mapSettings().mapUnits() );
|
||||
calc.setMapUnits( map->crs().mapUnits() );
|
||||
calc.setDpi( 25.4 );
|
||||
double originalScale = calc.calculate( mOrigExtent, map->rect().width() );
|
||||
double geomCenterX = ( xa1 + xa2 ) / 2.0;
|
||||
|
@ -422,7 +422,7 @@ bool QgsComposerAttributeTableV2::getTableContents( QgsComposerTableContents &co
|
||||
if ( layer )
|
||||
{
|
||||
//transform back to layer CRS
|
||||
QgsCoordinateTransform coordTransform( layer->crs(), mComposition->mapSettings().destinationCrs() );
|
||||
QgsCoordinateTransform coordTransform( layer->crs(), mComposerMap->crs() );
|
||||
try
|
||||
{
|
||||
selectionRect = coordTransform.transformBoundingBox( selectionRect, QgsCoordinateTransform::ReverseTransform );
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "qgsdistancearea.h"
|
||||
#include "qgsjsonutils.h"
|
||||
#include "qgsmapsettings.h"
|
||||
#include "qgscomposermap.h"
|
||||
|
||||
#include "qgswebpage.h"
|
||||
#include "qgswebframe.h"
|
||||
@ -542,7 +543,9 @@ void QgsComposerHtml::setExpressionContext( const QgsFeature &feature, QgsVector
|
||||
else if ( mComposition )
|
||||
{
|
||||
//set to composition's mapsettings' crs
|
||||
mDistanceArea->setSourceCrs( mComposition->mapSettings().destinationCrs().srsid() );
|
||||
QgsComposerMap* referenceMap = mComposition->referenceMap();
|
||||
if ( referenceMap )
|
||||
mDistanceArea->setSourceCrs( referenceMap->crs().srsid() );
|
||||
}
|
||||
if ( mComposition )
|
||||
{
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "qgsfontutils.h"
|
||||
#include "qgsexpressioncontext.h"
|
||||
#include "qgsmapsettings.h"
|
||||
#include "qgscomposermap.h"
|
||||
|
||||
#include "qgswebview.h"
|
||||
#include "qgswebframe.h"
|
||||
@ -261,8 +262,10 @@ void QgsComposerLabel::refreshExpressionContext()
|
||||
}
|
||||
else
|
||||
{
|
||||
//set to composition's mapsettings' crs
|
||||
mDistanceArea->setSourceCrs( mComposition->mapSettings().destinationCrs().srsid() );
|
||||
//set to composition's reference map's crs
|
||||
QgsComposerMap* referenceMap = mComposition->referenceMap();
|
||||
if ( referenceMap )
|
||||
mDistanceArea->setSourceCrs( referenceMap->crs().srsid() );
|
||||
}
|
||||
mDistanceArea->setEllipsoidalMode( true );
|
||||
mDistanceArea->setEllipsoid( mComposition->project()->ellipsoid() );
|
||||
|
@ -704,7 +704,7 @@ void QgsComposerLegend::doUpdateFilterByMap()
|
||||
QgsGeometry filterPolygon;
|
||||
if ( mInAtlas )
|
||||
{
|
||||
filterPolygon = composition()->atlasComposition().currentGeometry( composition()->mapSettings().destinationCrs() );
|
||||
filterPolygon = composition()->atlasComposition().currentGeometry( mComposerMap->crs() );
|
||||
}
|
||||
mLegendModel->setLegendFilter( &ms, /* useExtent */ mInAtlas || mLegendFilterByMap, filterPolygon, /* useExpressions */ true );
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ QgsMapSettings QgsComposerMap::mapSettings( const QgsRectangle& extent, QSizeF s
|
||||
jobMapSettings.setExtent( extent );
|
||||
jobMapSettings.setOutputSize( size.toSize() );
|
||||
jobMapSettings.setOutputDpi( dpi );
|
||||
jobMapSettings.setMapUnits( ms.mapUnits() );
|
||||
jobMapSettings.setMapUnits( crs().mapUnits() );
|
||||
jobMapSettings.setBackgroundColor( Qt::transparent );
|
||||
jobMapSettings.setOutputImageFormat( ms.outputImageFormat() );
|
||||
jobMapSettings.setRotation( mEvaluatedMapRotation );
|
||||
@ -233,7 +233,7 @@ QgsMapSettings QgsComposerMap::mapSettings( const QgsRectangle& extent, QSizeF s
|
||||
}
|
||||
jobMapSettings.setLayers( layers );
|
||||
jobMapSettings.setLayerStyleOverrides( layerStyleOverridesToRender( expressionContext ) );
|
||||
jobMapSettings.setDestinationCrs( ms.destinationCrs() );
|
||||
jobMapSettings.setDestinationCrs( crs() );
|
||||
jobMapSettings.setCrsTransformEnabled( ms.hasCrsTransformEnabled() );
|
||||
jobMapSettings.setFlags( ms.flags() );
|
||||
jobMapSettings.setFlag( QgsMapSettings::DrawSelection, false );
|
||||
@ -625,7 +625,7 @@ QMap<QString, QString> QgsComposerMap::layerStyleOverridesToRender( const QgsExp
|
||||
double QgsComposerMap::scale() const
|
||||
{
|
||||
QgsScaleCalculator calculator;
|
||||
calculator.setMapUnits( mComposition->mapSettings().mapUnits() );
|
||||
calculator.setMapUnits( crs().mapUnits() );
|
||||
calculator.setDpi( 25.4 ); //QGraphicsView units are mm
|
||||
return calculator.calculate( *currentMapExtent(), rect().width() );
|
||||
}
|
||||
@ -717,7 +717,7 @@ void QgsComposerMap::zoomContent( const double factor, const QPointF point, cons
|
||||
//and also apply to the map's original extent (see #9602)
|
||||
//we can't use the scaleRatio calculated earlier, as the scale can vary depending on extent for geographic coordinate systems
|
||||
QgsScaleCalculator calculator;
|
||||
calculator.setMapUnits( mComposition->mapSettings().mapUnits() );
|
||||
calculator.setMapUnits( crs().mapUnits() );
|
||||
calculator.setDpi( 25.4 ); //QGraphicsView units are mm
|
||||
double scaleRatio = scale() / calculator.calculate( mExtent, rect().width() );
|
||||
mExtent.scale( scaleRatio );
|
||||
@ -871,6 +871,18 @@ QgsRectangle* QgsComposerMap::currentMapExtent()
|
||||
}
|
||||
}
|
||||
|
||||
QgsCoordinateReferenceSystem QgsComposerMap::crs() const
|
||||
{
|
||||
if ( mComposition )
|
||||
{
|
||||
return mComposition->mapSettings().destinationCrs();
|
||||
}
|
||||
else
|
||||
{
|
||||
return QgsCoordinateReferenceSystem();
|
||||
}
|
||||
}
|
||||
|
||||
const QgsRectangle* QgsComposerMap::currentMapExtent() const
|
||||
{
|
||||
//const version
|
||||
@ -905,7 +917,7 @@ void QgsComposerMap::setNewScale( double scaleDenominator, bool forceUpdate )
|
||||
//and also apply to the map's original extent (see #9602)
|
||||
//we can't use the scaleRatio calculated earlier, as the scale can vary depending on extent for geographic coordinate systems
|
||||
QgsScaleCalculator calculator;
|
||||
calculator.setMapUnits( mComposition->mapSettings().mapUnits() );
|
||||
calculator.setMapUnits( crs().mapUnits() );
|
||||
calculator.setDpi( 25.4 ); //QGraphicsView units are mm
|
||||
scaleRatio = scaleDenominator / calculator.calculate( mExtent, rect().width() );
|
||||
mExtent.scale( scaleRatio );
|
||||
@ -1826,9 +1838,10 @@ QgsExpressionContext QgsComposerMap::createExpressionContext() const
|
||||
|
||||
if ( mComposition )
|
||||
{
|
||||
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs" ), mComposition->mapSettings().destinationCrs().authid(), true ) );
|
||||
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_definition" ), mComposition->mapSettings().destinationCrs().toProj4(), true ) );
|
||||
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_units" ), QgsUnitTypes::toString( mComposition->mapSettings().mapUnits() ), true ) );
|
||||
QgsCoordinateReferenceSystem mapCrs = crs();
|
||||
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs" ), mapCrs.authid(), true ) );
|
||||
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_definition" ), mapCrs.toProj4(), true ) );
|
||||
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_units" ), QgsUnitTypes::toString( mapCrs.mapUnits() ), true ) );
|
||||
}
|
||||
|
||||
context.appendScope( scope );
|
||||
@ -1979,12 +1992,12 @@ QPointF QgsComposerMap::composerMapPosForItem( const QgsAnnotation* annotation )
|
||||
|
||||
mapX = annotation->mapPosition().x();
|
||||
mapY = annotation->mapPosition().y();
|
||||
QgsCoordinateReferenceSystem crs = annotation->mapPositionCrs();
|
||||
QgsCoordinateReferenceSystem annotationCrs = annotation->mapPositionCrs();
|
||||
|
||||
if ( crs != mComposition->mapSettings().destinationCrs() )
|
||||
if ( annotationCrs != crs() )
|
||||
{
|
||||
//need to reproject
|
||||
QgsCoordinateTransform t( crs, mComposition->mapSettings().destinationCrs() );
|
||||
QgsCoordinateTransform t( annotationCrs, crs() );
|
||||
double z = 0.0;
|
||||
t.transformInPlace( mapX, mapY, z );
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "qgis_core.h"
|
||||
#include "qgscomposeritem.h"
|
||||
#include "qgsrectangle.h"
|
||||
#include "qgscoordinatereferencesystem.h"
|
||||
#include <QFont>
|
||||
#include <QGraphicsRectItem>
|
||||
|
||||
@ -166,6 +167,12 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
|
||||
//! @note not available in python bindings
|
||||
QgsRectangle* currentMapExtent();
|
||||
|
||||
/**
|
||||
* Returns the map's coordinate reference system.
|
||||
* @note added in QGIS 3.0
|
||||
*/
|
||||
QgsCoordinateReferenceSystem crs() const;
|
||||
|
||||
PreviewMode previewMode() const {return mPreviewMode;}
|
||||
void setPreviewMode( PreviewMode m );
|
||||
|
||||
|
@ -651,7 +651,7 @@ void QgsComposerMapGrid::draw( QPainter* p )
|
||||
QList< QPair< double, QLineF > > horizontalLines;
|
||||
|
||||
//is grid in a different crs than map?
|
||||
if ( mGridUnit == MapUnit && mCRS.isValid() && mCRS != ms.destinationCrs() )
|
||||
if ( mGridUnit == MapUnit && mCRS.isValid() && mCRS != mComposerMap->crs() )
|
||||
{
|
||||
drawGridCrsTransform( context, dotsPerMM, horizontalLines, verticalLines );
|
||||
}
|
||||
@ -1416,7 +1416,7 @@ QString QgsComposerMapGrid::gridAnnotationString( double value, QgsComposerMapGr
|
||||
}
|
||||
else if ( mComposerMap && mComposerMap->composition() )
|
||||
{
|
||||
geographic = mComposerMap->composition()->mapSettings().destinationCrs().isGeographic();
|
||||
geographic = mComposerMap->crs().isGeographic();
|
||||
}
|
||||
|
||||
if ( geographic && coord == QgsComposerMapGrid::Longitude &&
|
||||
@ -2072,7 +2072,7 @@ void QgsComposerMapGrid::calculateMaxExtension( double& top, double& right, doub
|
||||
//collect grid lines
|
||||
QList< QPair< double, QLineF > > verticalLines;
|
||||
QList< QPair< double, QLineF > > horizontalLines;
|
||||
if ( mGridUnit == MapUnit && mCRS.isValid() && mCRS != ms.destinationCrs() )
|
||||
if ( mGridUnit == MapUnit && mCRS.isValid() && mCRS != mComposerMap->crs() )
|
||||
{
|
||||
drawGridCrsTransform( context, 0, horizontalLines, verticalLines, false );
|
||||
}
|
||||
@ -2340,7 +2340,7 @@ int QgsComposerMapGrid::crsGridParams( QgsRectangle& crsRect, QgsCoordinateTrans
|
||||
|
||||
try
|
||||
{
|
||||
QgsCoordinateTransform tr( mComposerMap->composition()->mapSettings().destinationCrs(), mCRS );
|
||||
QgsCoordinateTransform tr( mComposerMap->crs(), mCRS );
|
||||
QPolygonF mapPolygon = mComposerMap->transformedMapPolygon();
|
||||
QRectF mbr = mapPolygon.boundingRect();
|
||||
QgsRectangle mapBoundingRect( mbr.left(), mbr.bottom(), mbr.right(), mbr.top() );
|
||||
@ -2372,7 +2372,7 @@ int QgsComposerMapGrid::crsGridParams( QgsRectangle& crsRect, QgsCoordinateTrans
|
||||
}
|
||||
|
||||
inverseTransform.setSourceCrs( mCRS );
|
||||
inverseTransform.setDestinationCrs( mComposerMap->composition()->mapSettings().destinationCrs() );
|
||||
inverseTransform.setDestinationCrs( mComposerMap->crs() );
|
||||
}
|
||||
catch ( QgsCsException & cse )
|
||||
{
|
||||
|
@ -426,7 +426,7 @@ void QgsComposerPicture::updateMapRotation()
|
||||
case TrueNorth:
|
||||
{
|
||||
QgsPoint center = mRotationMap->currentMapExtent()->center();
|
||||
QgsCoordinateReferenceSystem crs = mComposition->mapSettings().destinationCrs();
|
||||
QgsCoordinateReferenceSystem crs = mRotationMap->crs();
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -303,7 +303,7 @@ double QgsComposerScaleBar::mapWidth() const
|
||||
{
|
||||
QgsDistanceArea da;
|
||||
da.setEllipsoidalMode( true );
|
||||
da.setSourceCrs( mComposition->mapSettings().destinationCrs().srsid() );
|
||||
da.setSourceCrs( mComposerMap->crs().srsid() );
|
||||
da.setEllipsoid( mComposition->project()->ellipsoid() );
|
||||
|
||||
QgsUnitTypes::DistanceUnit units = QgsUnitTypes::DistanceMeters;
|
||||
|
@ -2850,7 +2850,7 @@ void QgsComposition::georeferenceOutput( const QString& file, QgsComposerMap* ma
|
||||
//TODO - metadata can be set here, e.g.:
|
||||
GDALSetMetadataItem( outputDS, "AUTHOR", "me", nullptr );
|
||||
#endif
|
||||
GDALSetProjection( outputDS, mMapSettings.destinationCrs().toWkt().toLocal8Bit().constData() );
|
||||
GDALSetProjection( outputDS, map->crs().toWkt().toLocal8Bit().constData() );
|
||||
GDALClose( outputDS );
|
||||
}
|
||||
CPLSetConfigOption( "GDAL_PDF_DPI", nullptr );
|
||||
|
Loading…
x
Reference in New Issue
Block a user