Skip to content

Commit

Permalink
Remove support for setting map units in QgsMapSettings, QgsMapCanvas …
Browse files Browse the repository at this point in the history
…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 8094cf9
Show file tree
Hide file tree
Showing 18 changed files with 30 additions and 131 deletions.
5 changes: 4 additions & 1 deletion doc/api_break.dox
Expand Up @@ -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}
Expand Down Expand Up @@ -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}
----------------
Expand Down Expand Up @@ -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}
Expand Down
11 changes: 0 additions & 11 deletions python/core/dxf/qgsdxfexport.sip
Expand Up @@ -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;

/**
Expand Down
2 changes: 0 additions & 2 deletions python/core/qgsmapsettings.sip
Expand Up @@ -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 );
Expand Down
7 changes: 0 additions & 7 deletions python/gui/qgsmapcanvas.sip
Expand Up @@ -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;

Expand Down Expand Up @@ -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 );
Expand Down
9 changes: 0 additions & 9 deletions src/app/qgisapp.cpp
Expand Up @@ -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();

Expand Down Expand Up @@ -5252,7 +5248,6 @@ void QgisApp::dxfExport()
dxfExport.setDestinationCrs( d.crs() );
if ( mapCanvas() )
{
dxfExport.setMapUnits( mapCanvas()->mapUnits() );
//extent
if ( d.exportMapExtent() )
{
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsdecorationgrid.cpp
Expand Up @@ -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()
Expand Down
24 changes: 0 additions & 24 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down
9 changes: 0 additions & 9 deletions src/app/qgsprojectproperties.h
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgssnappingwidget.cpp
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/core/composer/qgscomposermap.cpp
Expand Up @@ -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 );

Expand Down
10 changes: 8 additions & 2 deletions src/core/dxf/qgsdxfexport.cpp
Expand Up @@ -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() )
Expand All @@ -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" ) );
Expand Down Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions src/core/dxf/qgsdxfexport.h
Expand Up @@ -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
Expand Down
24 changes: 7 additions & 17 deletions src/core/qgsmapsettings.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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" ) );
Expand Down
2 changes: 0 additions & 2 deletions src/core/qgsmapsettings.h
Expand Up @@ -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; }
Expand Down
23 changes: 3 additions & 20 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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() );
Expand Down
12 changes: 4 additions & 8 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -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.
Expand Down Expand Up @@ -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 );
Expand Down
5 changes: 0 additions & 5 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -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 )
{
Expand All @@ -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" ) );
Expand Down

0 comments on commit 8094cf9

Please sign in to comment.