Skip to content

Commit 8094cf9

Browse files
committed
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.
1 parent 0f6d015 commit 8094cf9

18 files changed

+30
-131
lines changed

doc/api_break.dox

+4-1
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ QgsDxfExport {#qgis_api_break_3_0_QgsDxfExport}
936936
- writeSolid() was removed. Use writePolygon() instead.
937937
- The signature for writeLine() has changed.
938938
- writePoint(), writeFilledCircle(), writeCircle(), writeText() and writeMText() now take QgsPointV2 arguments
939-
939+
- setMapUnits() was removed. The map units are dictated by the units for the destination CRS.
940940

941941

942942
QgsEditFormConfig {#qgis_api_break_3_0_QgsEditFormConfig}
@@ -1322,6 +1322,8 @@ QgsMapCanvas {#qgis_api_break_3_0_QgsMapCanvas}
13221322
- 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.
13231323
- the duplicate mapToolSet signal with a single QgsMapTool argument has been removed. Use the signal with arguments for new and old map tool instead.
13241324
- setCrsTransformEnabled(), hasCrsTransformEnabled(), hasCrsTransformEnabledChanged() were removed. CRS transformation is now always enabled.
1325+
- setMapUnits() was removed. The map units are dictated by the units for the destination CRS.
1326+
- The mapUnitsChanged() signal was removed. Listen for the destinationCrsChanged() signal instead, as the destination CRS dictates the map units.
13251327

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

14341437

14351438
QgsMarkerSymbolLayer {#qgis_api_break_3_0_QgsMarkerSymbolLayer}

python/core/dxf/qgsdxfexport.sip

-11
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,6 @@ class QgsDxfExport
6565
*/
6666
double symbologyScaleDenominator() const;
6767

68-
/**
69-
* Set map units
70-
* @param u unit
71-
*/
72-
void setMapUnits( QgsUnitTypes::DistanceUnit u );
73-
74-
/**
75-
* Retrieve map units
76-
* @returns unit
77-
* @see setMapUnits
78-
*/
7968
QgsUnitTypes::DistanceUnit mapUnits() const;
8069

8170
/**

python/core/qgsmapsettings.sip

-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ class QgsMapSettings
9090

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

9694
//! Set the background color of the map
9795
void setBackgroundColor( const QColor& color );

python/gui/qgsmapcanvas.sip

-7
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,6 @@ class QgsMapCanvas : QGraphicsView
188188
*/
189189
bool isFrozen();
190190

191-
//! Set map units (needed by project properties dialog)
192-
void setMapUnits( QgsUnitTypes::DistanceUnit mapUnits );
193-
194191
//! Get the current canvas map units
195192
QgsUnitTypes::DistanceUnit mapUnits() const;
196193

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

454-
//! Emitted when map units are changed
455-
//! @note added in 2.4
456-
void mapUnitsChanged();
457-
458451
//! Emitted when the current layer is changed
459452
//! @note added in 2.8
460453
void currentLayerChanged( QgsMapLayer* layer );

src/app/qgisapp.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -4597,10 +4597,6 @@ void QgisApp::fileNew( bool promptToSaveFlag, bool forceBlank )
45974597
// write the projections _proj string_ to project settings
45984598
prj->setCrs( srs );
45994599
prj->setDirty( false );
4600-
if ( srs.mapUnits() != QgsUnitTypes::DistanceUnknownUnit )
4601-
{
4602-
mMapCanvas->setMapUnits( srs.mapUnits() );
4603-
}
46044600

46054601
updateCrsStatusBar();
46064602

@@ -5252,7 +5248,6 @@ void QgisApp::dxfExport()
52525248
dxfExport.setDestinationCrs( d.crs() );
52535249
if ( mapCanvas() )
52545250
{
5255-
dxfExport.setMapUnits( mapCanvas()->mapUnits() );
52565251
//extent
52575252
if ( d.exportMapExtent() )
52585253
{
@@ -8776,10 +8771,6 @@ void QgisApp::setProjectCrsFromLayer()
87768771
mMapCanvas->freeze();
87778772
mMapCanvas->setDestinationCrs( crs );
87788773
QgsProject::instance()->setCrs( crs );
8779-
if ( crs.mapUnits() != QgsUnitTypes::DistanceUnknownUnit )
8780-
{
8781-
mMapCanvas->setMapUnits( crs.mapUnits() );
8782-
}
87838774
mMapCanvas->freeze( false );
87848775
mMapCanvas->refresh();
87858776
}

src/app/qgsdecorationgrid.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ QgsDecorationGrid::QgsDecorationGrid( QObject* parent )
6262
mMarkerSymbol = nullptr;
6363
projectRead();
6464

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

6969
QgsDecorationGrid::~QgsDecorationGrid()

src/app/qgsprojectproperties.cpp

-24
Original file line numberDiff line numberDiff line change
@@ -727,23 +727,6 @@ QgsProjectProperties::~QgsProjectProperties()
727727
saveState();
728728
}
729729

730-
// return the map units
731-
QgsUnitTypes::DistanceUnit QgsProjectProperties::mapUnits() const
732-
{
733-
return mMapCanvas->mapSettings().mapUnits();
734-
}
735-
736-
void QgsProjectProperties::setMapUnits( QgsUnitTypes::DistanceUnit unit )
737-
{
738-
// select the button
739-
if ( unit == QgsUnitTypes::DistanceUnknownUnit )
740-
{
741-
unit = QgsUnitTypes::DistanceMeters;
742-
}
743-
744-
mMapCanvas->setMapUnits( unit );
745-
}
746-
747730
QString QgsProjectProperties::title() const
748731
{
749732
return titleEdit->text();
@@ -774,13 +757,6 @@ void QgsProjectProperties::apply()
774757
QgsDebugMsg( QString( "SpatialRefSys/ProjectCRSProj4String: %1" ).arg( projectionSelector->crs().toProj4() ) );
775758
QgsProject::instance()->setCrs( srs );
776759

777-
// Set the map units to the projected coordinates if we are projecting
778-
779-
// If we couldn't get the map units, default to the value in the
780-
// projectproperties dialog box (set above)
781-
if ( srs.mapUnits() != QgsUnitTypes::DistanceUnknownUnit )
782-
mMapCanvas->setMapUnits( srs.mapUnits() );
783-
784760
// mark selected projection for push to front
785761
projectionSelector->pushProjectionToFront();
786762
}

src/app/qgsprojectproperties.h

-9
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,6 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
4747

4848
~QgsProjectProperties();
4949

50-
/** Gets the currently select map units
51-
*/
52-
QgsUnitTypes::DistanceUnit mapUnits() const;
53-
54-
/*!
55-
* Set the map units
56-
*/
57-
void setMapUnits( QgsUnitTypes::DistanceUnit );
58-
5950
/*!
6051
Every project has a title
6152
*/

src/app/qgssnappingwidget.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject* project, QgsMapCanvas* canvas,
224224
// connect settings changed and map units changed to properly update the widget
225225
connect( project, &QgsProject::snappingConfigChanged, this, &QgsSnappingWidget::projectSnapSettingsChanged );
226226
connect( project, &QgsProject::topologicalEditingChanged, this, &QgsSnappingWidget::projectTopologicalEditingChanged );
227-
connect( mCanvas, SIGNAL( mapUnitsChanged() ), this, SLOT( updateToleranceDecimals() ) );
227+
connect( mCanvas, &QgsMapCanvas::destinationCrsChanged, this, &QgsSnappingWidget::updateToleranceDecimals );
228228

229229

230230
// Slightly modify the config so the settings changed code doesn't early exit

src/core/composer/qgscomposermap.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ QgsMapSettings QgsComposerMap::mapSettings( const QgsRectangle& extent, QSizeF s
151151
jobMapSettings.setExtent( extent );
152152
jobMapSettings.setOutputSize( size.toSize() );
153153
jobMapSettings.setOutputDpi( dpi );
154-
jobMapSettings.setMapUnits( renderCrs.mapUnits() );
155154
jobMapSettings.setBackgroundColor( Qt::transparent );
156155
jobMapSettings.setRotation( mEvaluatedMapRotation );
157156

src/core/dxf/qgsdxfexport.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,11 @@ int QgsDxfExport::writeToFile( QIODevice* d, const QString& encoding )
536536
}
537537
}
538538

539-
mMapSettings.setMapUnits( mMapUnits );
539+
QgsUnitTypes::DistanceUnit mapUnits = mCrs.mapUnits();
540540
mMapSettings.setExtent( mExtent );
541541

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

558+
QgsUnitTypes::DistanceUnit QgsDxfExport::mapUnits() const
559+
{
560+
return mMapUnits;
561+
}
562+
558563
void QgsDxfExport::writeHeader( const QString& codepage )
559564
{
560565
writeGroup( 999, QStringLiteral( "DXF created from QGIS" ) );
@@ -4434,6 +4439,7 @@ void QgsDxfExport::registerDxfLayer( const QString& layerId, QgsFeatureId fid, c
44344439
void QgsDxfExport::setDestinationCrs( const QgsCoordinateReferenceSystem& crs )
44354440
{
44364441
mCrs = crs;
4442+
mMapUnits = crs.mapUnits();
44374443
}
44384444

44394445
QgsCoordinateReferenceSystem QgsDxfExport::destinationCrs() const

src/core/dxf/qgsdxfexport.h

+1-8
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,11 @@ class CORE_EXPORT QgsDxfExport
8989
*/
9090
double symbologyScaleDenominator() const { return mSymbologyScaleDenominator; }
9191

92-
/**
93-
* Set map units
94-
* @param u unit
95-
*/
96-
void setMapUnits( QgsUnitTypes::DistanceUnit u ) { mMapUnits = u; }
97-
9892
/**
9993
* Retrieve map units
10094
* @returns unit
101-
* @see setMapUnits
10295
*/
103-
QgsUnitTypes::DistanceUnit mapUnits() const { return mMapUnits; }
96+
QgsUnitTypes::DistanceUnit mapUnits() const;
10497

10598
/**
10699
* Set destination CRS

src/core/qgsmapsettings.cpp

+7-17
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ QgsMapSettings::QgsMapSettings()
5050
, mMapUnitsPerPixel( 1 )
5151
, mScale( 1 )
5252
{
53-
updateDerived();
54-
5553
// set default map units - we use WGS 84 thus use degrees
56-
setMapUnits( QgsUnitTypes::DistanceDegrees );
54+
mScaleCalculator.setMapUnits( QgsUnitTypes::DistanceDegrees );
55+
56+
updateDerived();
5757
}
5858

5959
void QgsMapSettings::setMagnificationFactor( double factor )
@@ -284,22 +284,17 @@ void QgsMapSettings::setDestinationCrs( const QgsCoordinateReferenceSystem& crs
284284
{
285285
mDestCRS = crs;
286286
mDatumTransformStore.setDestinationCrs( crs );
287+
288+
mScaleCalculator.setMapUnits( crs.mapUnits() );
289+
// Since the map units have changed, force a recalculation of the scale.
290+
updateDerived();
287291
}
288292

289293
QgsCoordinateReferenceSystem QgsMapSettings::destinationCrs() const
290294
{
291295
return mDestCRS;
292296
}
293297

294-
295-
void QgsMapSettings::setMapUnits( QgsUnitTypes::DistanceUnit u )
296-
{
297-
mScaleCalculator.setMapUnits( u );
298-
299-
// Since the map units have changed, force a recalculation of the scale.
300-
updateDerived();
301-
}
302-
303298
void QgsMapSettings::setFlags( QgsMapSettings::Flags flags )
304299
{
305300
mFlags = flags;
@@ -563,11 +558,6 @@ QgsRectangle QgsMapSettings::fullExtent() const
563558

564559
void QgsMapSettings::readXml( QDomNode& node )
565560
{
566-
// set units
567-
QDomNode mapUnitsNode = node.namedItem( QStringLiteral( "units" ) );
568-
QgsUnitTypes::DistanceUnit units = QgsXmlUtils::readMapUnits( mapUnitsNode.toElement() );
569-
setMapUnits( units );
570-
571561
// set destination CRS
572562
QgsCoordinateReferenceSystem srs;
573563
QDomNode srsNode = node.namedItem( QStringLiteral( "destinationsrs" ) );

src/core/qgsmapsettings.h

-2
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ class CORE_EXPORT QgsMapSettings
140140

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

146144
//! Set the background color of the map
147145
void setBackgroundColor( const QColor& color ) { mBackgroundColor = color; }

src/gui/qgsmapcanvas.cpp

+3-20
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,12 @@ void QgsMapCanvas::setDestinationCrs( const QgsCoordinateReferenceSystem &crs )
359359
setExtent( rect );
360360
}
361361

362+
mSettings.setDestinationCrs( crs );
363+
updateScale();
364+
362365
QgsDebugMsg( "refreshing after destination CRS changed" );
363366
refresh();
364367

365-
mSettings.setDestinationCrs( crs );
366-
367368
updateDatumTransformEntries();
368369

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

1573-
1574-
void QgsMapCanvas::setMapUnits( QgsUnitTypes::DistanceUnit u )
1575-
{
1576-
if ( mSettings.mapUnits() == u )
1577-
return;
1578-
1579-
QgsDebugMsg( "Setting map units to " + QString::number( static_cast<int>( u ) ) );
1580-
mSettings.setMapUnits( u );
1581-
1582-
updateScale();
1583-
1584-
refresh(); // this will force the scale bar to be updated
1585-
1586-
emit mapUnitsChanged();
1587-
}
1588-
1589-
15901574
QgsUnitTypes::DistanceUnit QgsMapCanvas::mapUnits() const
15911575
{
15921576
return mapSettings().mapUnits();
@@ -1794,7 +1778,6 @@ void QgsMapCanvas::readProject( const QDomDocument & doc )
17941778

17951779
QgsMapSettings tmpSettings;
17961780
tmpSettings.readXml( node );
1797-
setMapUnits( tmpSettings.mapUnits() );
17981781
setDestinationCrs( tmpSettings.destinationCrs() );
17991782
setExtent( tmpSettings.extent() );
18001783
setRotation( tmpSettings.rotation() );

src/gui/qgsmapcanvas.h

+4-8
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
246246
*/
247247
bool isFrozen();
248248

249-
//! Set map units (needed by project properties dialog)
250-
void setMapUnits( QgsUnitTypes::DistanceUnit mapUnits );
251-
252-
//! Get the current canvas map units
249+
/**
250+
* Convience function for returning the current canvas map units. The map units
251+
* are dictated by the canvas' destinationCrs() map units.
252+
*/
253253
QgsUnitTypes::DistanceUnit mapUnits() const;
254254

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

526-
//! Emitted when map units are changed
527-
//! @note added in 2.4
528-
void mapUnitsChanged();
529-
530526
//! Emitted when the current layer is changed
531527
//! @note added in 2.8
532528
void currentLayerChanged( QgsMapLayer* layer );

src/server/services/wms/qgswmsrenderer.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -1313,8 +1313,6 @@ namespace QgsWms
13131313
throw QgsBadRequestException( QStringLiteral( "InvalidParameterValue" ), QStringLiteral( "Invalid BBOX parameter" ) );
13141314
}
13151315

1316-
QgsUnitTypes::DistanceUnit mapUnits = QgsUnitTypes::DistanceDegrees;
1317-
13181316
QString crs = mParameters.value( QStringLiteral( "CRS" ), mParameters.value( QStringLiteral( "SRS" ) ) );
13191317
if ( crs.compare( "CRS:84", Qt::CaseInsensitive ) == 0 )
13201318
{
@@ -1336,9 +1334,6 @@ namespace QgsWms
13361334

13371335
//then set destinationCrs
13381336
mapSettings.setDestinationCrs( outputCRS );
1339-
mapUnits = outputCRS.mapUnits();
1340-
1341-
mapSettings.setMapUnits( mapUnits );
13421337

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

0 commit comments

Comments
 (0)