Skip to content
Permalink
Browse files

Remove support for setting map units in QgsMapSettings, QgsMapCanvas …

…and QgsDxfExport

In a post-OTF-disabled world these are no longer required. The
map units are dictated by the map units for the destination
CRS.

It's dangerous to separate these two properties as setting
the incorrect map units for a given CRS will result in
incorrect scale calculations.
  • Loading branch information
nyalldawson committed Feb 28, 2017
1 parent 0f6d015 commit 8094cf996b68654d2602e1e0507a050b29a732f7
@@ -936,7 +936,7 @@ QgsDxfExport {#qgis_api_break_3_0_QgsDxfExport}
- writeSolid() was removed. Use writePolygon() instead.
- The signature for writeLine() has changed.
- writePoint(), writeFilledCircle(), writeCircle(), writeText() and writeMText() now take QgsPointV2 arguments

- setMapUnits() was removed. The map units are dictated by the units for the destination CRS.


QgsEditFormConfig {#qgis_api_break_3_0_QgsEditFormConfig}
@@ -1322,6 +1322,8 @@ QgsMapCanvas {#qgis_api_break_3_0_QgsMapCanvas}
- enableOverviewMode() and updateOverview() have been removed. Map canvas does not keep pointer to overview canvas anymore. Use QgsLayerTreeMapCanvasBridge::setOverviewCanvas() to set up updates of overview canvas together with main canvas.
- the duplicate mapToolSet signal with a single QgsMapTool argument has been removed. Use the signal with arguments for new and old map tool instead.
- setCrsTransformEnabled(), hasCrsTransformEnabled(), hasCrsTransformEnabledChanged() were removed. CRS transformation is now always enabled.
- setMapUnits() was removed. The map units are dictated by the units for the destination CRS.
- The mapUnitsChanged() signal was removed. Listen for the destinationCrsChanged() signal instead, as the destination CRS dictates the map units.

QgsMapCanvasItem {#qgis_api_break_3_0_QgsMapCanvasItem}
----------------
@@ -1430,6 +1432,7 @@ be returned instead of a null pointer if no transformation is required.
- destinationCrs() now returns a copy instead of a reference to the CRS. This has no effect on PyQGIS code, but c++
plugins calling this method will need to be updated.
- setCrsTransformEnabled() and hasCrsTransformEnabled() were removed. CRS transformation is now always enabled.
- setMapUnits() was removed. The map units are dictated by the units for the destination CRS.


QgsMarkerSymbolLayer {#qgis_api_break_3_0_QgsMarkerSymbolLayer}
@@ -65,17 +65,6 @@ class QgsDxfExport
*/
double symbologyScaleDenominator() const;

/**
* Set map units
* @param u unit
*/
void setMapUnits( QgsUnitTypes::DistanceUnit u );

/**
* Retrieve map units
* @returns unit
* @see setMapUnits
*/
QgsUnitTypes::DistanceUnit mapUnits() const;

/**
@@ -90,8 +90,6 @@ class QgsMapSettings

//! Get units of map's geographical coordinates - used for scale calculation
QgsUnitTypes::DistanceUnit mapUnits() const;
//! Set units of map's geographical coordinates - used for scale calculation
void setMapUnits( QgsUnitTypes::DistanceUnit u );

//! Set the background color of the map
void setBackgroundColor( const QColor& color );
@@ -188,9 +188,6 @@ class QgsMapCanvas : QGraphicsView
*/
bool isFrozen();

//! Set map units (needed by project properties dialog)
void setMapUnits( QgsUnitTypes::DistanceUnit mapUnits );

//! Get the current canvas map units
QgsUnitTypes::DistanceUnit mapUnits() const;

@@ -451,10 +448,6 @@ class QgsMapCanvas : QGraphicsView
//! @note added in 2.4
void destinationCrsChanged();

//! Emitted when map units are changed
//! @note added in 2.4
void mapUnitsChanged();

//! Emitted when the current layer is changed
//! @note added in 2.8
void currentLayerChanged( QgsMapLayer* layer );
@@ -4597,10 +4597,6 @@ void QgisApp::fileNew( bool promptToSaveFlag, bool forceBlank )
// write the projections _proj string_ to project settings
prj->setCrs( srs );
prj->setDirty( false );
if ( srs.mapUnits() != QgsUnitTypes::DistanceUnknownUnit )
{
mMapCanvas->setMapUnits( srs.mapUnits() );
}

updateCrsStatusBar();

@@ -5252,7 +5248,6 @@ void QgisApp::dxfExport()
dxfExport.setDestinationCrs( d.crs() );
if ( mapCanvas() )
{
dxfExport.setMapUnits( mapCanvas()->mapUnits() );
//extent
if ( d.exportMapExtent() )
{
@@ -8776,10 +8771,6 @@ void QgisApp::setProjectCrsFromLayer()
mMapCanvas->freeze();
mMapCanvas->setDestinationCrs( crs );
QgsProject::instance()->setCrs( crs );
if ( crs.mapUnits() != QgsUnitTypes::DistanceUnknownUnit )
{
mMapCanvas->setMapUnits( crs.mapUnits() );
}
mMapCanvas->freeze( false );
mMapCanvas->refresh();
}
@@ -62,8 +62,8 @@ QgsDecorationGrid::QgsDecorationGrid( QObject* parent )
mMarkerSymbol = nullptr;
projectRead();

connect( QgisApp::instance()->mapCanvas(), SIGNAL( mapUnitsChanged() ),
this, SLOT( checkMapUnitsChanged() ) );
connect( QgisApp::instance()->mapCanvas(), &QgsMapCanvas::destinationCrsChanged,
this, &QgsDecorationGrid::checkMapUnitsChanged );
}

QgsDecorationGrid::~QgsDecorationGrid()
@@ -727,23 +727,6 @@ QgsProjectProperties::~QgsProjectProperties()
saveState();
}

// return the map units
QgsUnitTypes::DistanceUnit QgsProjectProperties::mapUnits() const
{
return mMapCanvas->mapSettings().mapUnits();
}

void QgsProjectProperties::setMapUnits( QgsUnitTypes::DistanceUnit unit )
{
// select the button
if ( unit == QgsUnitTypes::DistanceUnknownUnit )
{
unit = QgsUnitTypes::DistanceMeters;
}

mMapCanvas->setMapUnits( unit );
}

QString QgsProjectProperties::title() const
{
return titleEdit->text();
@@ -774,13 +757,6 @@ void QgsProjectProperties::apply()
QgsDebugMsg( QString( "SpatialRefSys/ProjectCRSProj4String: %1" ).arg( projectionSelector->crs().toProj4() ) );
QgsProject::instance()->setCrs( srs );

// Set the map units to the projected coordinates if we are projecting

// If we couldn't get the map units, default to the value in the
// projectproperties dialog box (set above)
if ( srs.mapUnits() != QgsUnitTypes::DistanceUnknownUnit )
mMapCanvas->setMapUnits( srs.mapUnits() );

// mark selected projection for push to front
projectionSelector->pushProjectionToFront();
}
@@ -47,15 +47,6 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:

~QgsProjectProperties();

/** Gets the currently select map units
*/
QgsUnitTypes::DistanceUnit mapUnits() const;

/*!
* Set the map units
*/
void setMapUnits( QgsUnitTypes::DistanceUnit );

/*!
Every project has a title
*/
@@ -224,7 +224,7 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject* project, QgsMapCanvas* canvas,
// connect settings changed and map units changed to properly update the widget
connect( project, &QgsProject::snappingConfigChanged, this, &QgsSnappingWidget::projectSnapSettingsChanged );
connect( project, &QgsProject::topologicalEditingChanged, this, &QgsSnappingWidget::projectTopologicalEditingChanged );
connect( mCanvas, SIGNAL( mapUnitsChanged() ), this, SLOT( updateToleranceDecimals() ) );
connect( mCanvas, &QgsMapCanvas::destinationCrsChanged, this, &QgsSnappingWidget::updateToleranceDecimals );


// Slightly modify the config so the settings changed code doesn't early exit
@@ -151,7 +151,6 @@ QgsMapSettings QgsComposerMap::mapSettings( const QgsRectangle& extent, QSizeF s
jobMapSettings.setExtent( extent );
jobMapSettings.setOutputSize( size.toSize() );
jobMapSettings.setOutputDpi( dpi );
jobMapSettings.setMapUnits( renderCrs.mapUnits() );
jobMapSettings.setBackgroundColor( Qt::transparent );
jobMapSettings.setRotation( mEvaluatedMapRotation );

@@ -536,11 +536,11 @@ int QgsDxfExport::writeToFile( QIODevice* d, const QString& encoding )
}
}

mMapSettings.setMapUnits( mMapUnits );
QgsUnitTypes::DistanceUnit mapUnits = mCrs.mapUnits();
mMapSettings.setExtent( mExtent );

int dpi = 96;
mFactor = 1000 * dpi / mSymbologyScaleDenominator / 25.4 * QgsUnitTypes::fromUnitToUnitFactor( mMapUnits, QgsUnitTypes::DistanceMeters );
mFactor = 1000 * dpi / mSymbologyScaleDenominator / 25.4 * QgsUnitTypes::fromUnitToUnitFactor( mapUnits, QgsUnitTypes::DistanceMeters );
mMapSettings.setOutputSize( QSize( mExtent.width() * mFactor, mExtent.height() * mFactor ) );
mMapSettings.setOutputDpi( dpi );
if ( mCrs.isValid() )
@@ -555,6 +555,11 @@ int QgsDxfExport::writeToFile( QIODevice* d, const QString& encoding )
return 0;
}

QgsUnitTypes::DistanceUnit QgsDxfExport::mapUnits() const
{
return mMapUnits;
}

void QgsDxfExport::writeHeader( const QString& codepage )
{
writeGroup( 999, QStringLiteral( "DXF created from QGIS" ) );
@@ -4434,6 +4439,7 @@ void QgsDxfExport::registerDxfLayer( const QString& layerId, QgsFeatureId fid, c
void QgsDxfExport::setDestinationCrs( const QgsCoordinateReferenceSystem& crs )
{
mCrs = crs;
mMapUnits = crs.mapUnits();
}

QgsCoordinateReferenceSystem QgsDxfExport::destinationCrs() const
@@ -89,18 +89,11 @@ class CORE_EXPORT QgsDxfExport
*/
double symbologyScaleDenominator() const { return mSymbologyScaleDenominator; }

/**
* Set map units
* @param u unit
*/
void setMapUnits( QgsUnitTypes::DistanceUnit u ) { mMapUnits = u; }

/**
* Retrieve map units
* @returns unit
* @see setMapUnits
*/
QgsUnitTypes::DistanceUnit mapUnits() const { return mMapUnits; }
QgsUnitTypes::DistanceUnit mapUnits() const;

/**
* Set destination CRS
@@ -50,10 +50,10 @@ QgsMapSettings::QgsMapSettings()
, mMapUnitsPerPixel( 1 )
, mScale( 1 )
{
updateDerived();

// set default map units - we use WGS 84 thus use degrees
setMapUnits( QgsUnitTypes::DistanceDegrees );
mScaleCalculator.setMapUnits( QgsUnitTypes::DistanceDegrees );

updateDerived();
}

void QgsMapSettings::setMagnificationFactor( double factor )
@@ -284,22 +284,17 @@ void QgsMapSettings::setDestinationCrs( const QgsCoordinateReferenceSystem& crs
{
mDestCRS = crs;
mDatumTransformStore.setDestinationCrs( crs );

mScaleCalculator.setMapUnits( crs.mapUnits() );
// Since the map units have changed, force a recalculation of the scale.
updateDerived();
}

QgsCoordinateReferenceSystem QgsMapSettings::destinationCrs() const
{
return mDestCRS;
}


void QgsMapSettings::setMapUnits( QgsUnitTypes::DistanceUnit u )
{
mScaleCalculator.setMapUnits( u );

// Since the map units have changed, force a recalculation of the scale.
updateDerived();
}

void QgsMapSettings::setFlags( QgsMapSettings::Flags flags )
{
mFlags = flags;
@@ -563,11 +558,6 @@ QgsRectangle QgsMapSettings::fullExtent() const

void QgsMapSettings::readXml( QDomNode& node )
{
// set units
QDomNode mapUnitsNode = node.namedItem( QStringLiteral( "units" ) );
QgsUnitTypes::DistanceUnit units = QgsXmlUtils::readMapUnits( mapUnitsNode.toElement() );
setMapUnits( units );

// set destination CRS
QgsCoordinateReferenceSystem srs;
QDomNode srsNode = node.namedItem( QStringLiteral( "destinationsrs" ) );
@@ -140,8 +140,6 @@ class CORE_EXPORT QgsMapSettings

//! Get units of map's geographical coordinates - used for scale calculation
QgsUnitTypes::DistanceUnit mapUnits() const;
//! Set units of map's geographical coordinates - used for scale calculation
void setMapUnits( QgsUnitTypes::DistanceUnit u );

//! Set the background color of the map
void setBackgroundColor( const QColor& color ) { mBackgroundColor = color; }
@@ -359,11 +359,12 @@ void QgsMapCanvas::setDestinationCrs( const QgsCoordinateReferenceSystem &crs )
setExtent( rect );
}

mSettings.setDestinationCrs( crs );
updateScale();

QgsDebugMsg( "refreshing after destination CRS changed" );
refresh();

mSettings.setDestinationCrs( crs );

updateDatumTransformEntries();

emit destinationCrsChanged();
@@ -1570,23 +1571,6 @@ double QgsMapCanvas::mapUnitsPerPixel() const
return mapSettings().mapUnitsPerPixel();
} // mapUnitsPerPixel


void QgsMapCanvas::setMapUnits( QgsUnitTypes::DistanceUnit u )
{
if ( mSettings.mapUnits() == u )
return;

QgsDebugMsg( "Setting map units to " + QString::number( static_cast<int>( u ) ) );
mSettings.setMapUnits( u );

updateScale();

refresh(); // this will force the scale bar to be updated

emit mapUnitsChanged();
}


QgsUnitTypes::DistanceUnit QgsMapCanvas::mapUnits() const
{
return mapSettings().mapUnits();
@@ -1794,7 +1778,6 @@ void QgsMapCanvas::readProject( const QDomDocument & doc )

QgsMapSettings tmpSettings;
tmpSettings.readXml( node );
setMapUnits( tmpSettings.mapUnits() );
setDestinationCrs( tmpSettings.destinationCrs() );
setExtent( tmpSettings.extent() );
setRotation( tmpSettings.rotation() );
@@ -246,10 +246,10 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
*/
bool isFrozen();

//! Set map units (needed by project properties dialog)
void setMapUnits( QgsUnitTypes::DistanceUnit mapUnits );

//! Get the current canvas map units
/**
* Convience function for returning the current canvas map units. The map units
* are dictated by the canvas' destinationCrs() map units.
*/
QgsUnitTypes::DistanceUnit mapUnits() const;

//! Getter for stored overrides of styles for layers.
@@ -523,10 +523,6 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! @note added in 2.4
void destinationCrsChanged();

//! Emitted when map units are changed
//! @note added in 2.4
void mapUnitsChanged();

//! Emitted when the current layer is changed
//! @note added in 2.8
void currentLayerChanged( QgsMapLayer* layer );
@@ -1313,8 +1313,6 @@ namespace QgsWms
throw QgsBadRequestException( QStringLiteral( "InvalidParameterValue" ), QStringLiteral( "Invalid BBOX parameter" ) );
}

QgsUnitTypes::DistanceUnit mapUnits = QgsUnitTypes::DistanceDegrees;

QString crs = mParameters.value( QStringLiteral( "CRS" ), mParameters.value( QStringLiteral( "SRS" ) ) );
if ( crs.compare( "CRS:84", Qt::CaseInsensitive ) == 0 )
{
@@ -1336,9 +1334,6 @@ namespace QgsWms

//then set destinationCrs
mapSettings.setDestinationCrs( outputCRS );
mapUnits = outputCRS.mapUnits();

mapSettings.setMapUnits( mapUnits );

// Change x- and y- of BBOX for WMS 1.3.0 if axis inverted
QString version = mParameters.value( QStringLiteral( "VERSION" ), QStringLiteral( "1.3.0" ) );

0 comments on commit 8094cf9

Please sign in to comment.
You can’t perform that action at this time.