Skip to content

Commit

Permalink
Fix most remaining methods which return a reference to
Browse files Browse the repository at this point in the history
QgsCoordinateReferenceSystem or which take a pointer to a
CRS
  • Loading branch information
nyalldawson committed Jul 14, 2016
1 parent 726569c commit 7d2027f
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 34 deletions.
37 changes: 37 additions & 0 deletions doc/api_break.dox
Expand Up @@ -18,6 +18,13 @@ This page tries to maintain a list with incompatible changes that happened in pr

\section qgis_api_break_3_0 QGIS 3.0

\subsection qgis_api_break_3_0_QgsCoordinateTransform QgsCoordinateTransform

<ul>
<li>sourceCrs() and destCrs() now return a copy instead of a reference to the CRS. This has no effect on PyQGIS code, but c++
plugins calling these methods will need to be updated.</li>
</ul>

\subsection qgis_api_break_3_0_DataProviders Data Providers

<ul>
Expand Down Expand Up @@ -47,6 +54,13 @@ only affects third party c++ providers, and does not affect PyQGIS scripts.</li>
<li>crs() now returns a QgsCoordinateReferenceSystem object, not a reference. This change has no effect for PyQGIS code.</li>
</ul>

\subsection qgis_api_break_3_0_QgsJSONExporter QgsJSONExporter

<ul>
<li>sourceCrs() 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.</li>
</ul>

\subsection qgis_api_break_3_0_QgsVectorLayerImport QgsVectorLayerImport

<ul>
Expand All @@ -56,6 +70,29 @@ pointers makes for more robust, safer code. Use an invalid (default constructed)
in code which previously passed a null pointer to QgsVectorLayerImport.</li>
</ul>

\subsection qgis_api_break_3_0_QgsPointLocator QgsPointLocator

<ul>
<li>The constructor now takes a reference rather than a pointer to a CRS. This has no effect on PyQGIS code, but c++
plugins calling this method will need to be updated.</li>
<li>destCrs() 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.</li>
</ul>

\subsection qgis_api_break_3_0_QgsMapSettings QgsMapSettings

<ul>
<li>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.</li>
</ul>

\subsection qgis_api_break_3_0_QgsGraphBuilderInterface QgsGraphBuilderInterface

<ul>
<li>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.</li>
</ul>

\subsection qgis_api_break_3_0_QgsVectorFileWriter QgsVectorFileWriter

<ul>
Expand Down
2 changes: 1 addition & 1 deletion python/analysis/network/qgsgraphbuilderintr.sip
Expand Up @@ -30,7 +30,7 @@ class QgsGraphBuilderInterface
*/
QgsGraphBuilderInterface( const QgsCoordinateReferenceSystem& crs, bool ctfEnabled = true, double topologyTolerance = 0.0, const QString& ellipsoidID = "WGS84" );

QgsCoordinateReferenceSystem& destinationCrs();
QgsCoordinateReferenceSystem destinationCrs() const;

//! get coordinate transformation enabled
bool coordinateTransformationEnabled();
Expand Down
4 changes: 2 additions & 2 deletions python/core/qgscoordinatetransform.sip
Expand Up @@ -79,13 +79,13 @@ class QgsCoordinateTransform : QObject
* Get the QgsCoordinateReferenceSystem representation of the layer's coordinate system
* @return QgsCoordinateReferenceSystem of the layer's coordinate system
*/
const QgsCoordinateReferenceSystem& sourceCrs() const;
QgsCoordinateReferenceSystem sourceCrs() const;

/*!
* Get the QgsCoordinateReferenceSystem representation of the map canvas coordinate system
* @return QgsCoordinateReferenceSystem of the map canvas coordinate system
*/
const QgsCoordinateReferenceSystem& destCRS() const;
QgsCoordinateReferenceSystem destCRS() const;

/** Transform the point from Source Coordinate System to Destination Coordinate System
* If the direction is ForwardTransform then coordinates are transformed from layer CS --> map canvas CS,
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsjsonutils.sip
Expand Up @@ -90,7 +90,7 @@ class QgsJSONExporter
* correctly automatically reprojected to WGS 84, to match GeoJSON specifications.
* @see setSourceCrs()
*/
const QgsCoordinateReferenceSystem& sourceCrs() const;
QgsCoordinateReferenceSystem sourceCrs() const;

/** Sets the list of attributes to include in the JSON exports.
* @param attributes list of attribute indexes, or an empty list to include all
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsmapsettings.sip
Expand Up @@ -88,7 +88,7 @@ class QgsMapSettings
//! sets destination coordinate reference system
void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
//! returns CRS of destination coordinate reference system
const QgsCoordinateReferenceSystem& destinationCrs() const;
QgsCoordinateReferenceSystem destinationCrs() const;

//! Get units of map's geographical coordinates - used for scale calculation
QGis::UnitType mapUnits() const;
Expand Down
11 changes: 7 additions & 4 deletions python/core/qgspointlocator.sip
Expand Up @@ -19,20 +19,23 @@ class QgsPointLocator : QObject
%End

public:

/** Construct point locator for a layer.
* @arg destCRS if not null, will do the searches on data reprojected to the given CRS
* @arg destCRS if a valid QgsCoordinateReferenceSystem is passed then the locator will
* do the searches on data reprojected to the given CRS
* @arg extent if not null, will index only a subset of the layer
*/
explicit QgsPointLocator( QgsVectorLayer* layer, const QgsCoordinateReferenceSystem* destCRS = 0, const QgsRectangle* extent = 0 );
explicit QgsPointLocator( QgsVectorLayer* layer, const QgsCoordinateReferenceSystem& destCRS = QgsCoordinateReferenceSystem(),
const QgsRectangle* extent = nullptr );

~QgsPointLocator();

//! Get associated layer
//! @note added in QGIS 2.14
QgsVectorLayer* layer() const;
//! Get destination CRS - may be null if not doing OTF reprojection
//! Get destination CRS - may be an invalid QgsCoordinateReferenceSystem if not doing OTF reprojection
//! @note added in QGIS 2.14
const QgsCoordinateReferenceSystem* destCRS() const;
QgsCoordinateReferenceSystem destCRS() const;
//! Get extent of the area point locator covers - if null then it caches the whole layer
//! @note added in QGIS 2.14
const QgsRectangle* extent() const;
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/network/qgsgraphbuilderintr.h
Expand Up @@ -56,7 +56,7 @@ class ANALYSIS_EXPORT QgsGraphBuilderInterface
{ }

//! get destinaltion Crs
QgsCoordinateReferenceSystem& destinationCrs()
QgsCoordinateReferenceSystem destinationCrs() const
{
return mCrs;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsdecorationgrid.cpp
Expand Up @@ -833,7 +833,7 @@ bool QgsDecorationGrid::getIntervalFromCurrentLayer( double* values )
return false;
}
QgsCoordinateReferenceSystem layerCRS = layer->crs();
const QgsCoordinateReferenceSystem& mapCRS =
QgsCoordinateReferenceSystem mapCRS =
QgisApp::instance()->mapCanvas()->mapSettings().destinationCrs();
// is this the best way to compare CRS? should we also make sure map has OTF enabled?
// TODO calculate transformed values if necessary
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsidentifyresultsdialog.h
Expand Up @@ -68,7 +68,7 @@ class APP_EXPORT QgsIdentifyResultsFeatureItem: public QTreeWidgetItem
QgsIdentifyResultsFeatureItem( const QgsFields &fields, const QgsFeature &feature, const QgsCoordinateReferenceSystem &crs, const QStringList & strings = QStringList() );
const QgsFields &fields() const { return mFields; }
const QgsFeature &feature() const { return mFeature; }
const QgsCoordinateReferenceSystem &crs() { return mCrs; }
QgsCoordinateReferenceSystem crs() const { return mCrs; }

private:
QgsFields mFields;
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgscoordinatetransform.h
Expand Up @@ -113,13 +113,13 @@ class CORE_EXPORT QgsCoordinateTransform : public QObject
* Get the QgsCoordinateReferenceSystem representation of the layer's coordinate system
* @return QgsCoordinateReferenceSystem of the layer's coordinate system
*/
const QgsCoordinateReferenceSystem& sourceCrs() const { return mSourceCRS; }
QgsCoordinateReferenceSystem sourceCrs() const { return mSourceCRS; }

/*!
* Get the QgsCoordinateReferenceSystem representation of the map canvas coordinate system
* @return QgsCoordinateReferenceSystem of the map canvas coordinate system
*/
const QgsCoordinateReferenceSystem& destCRS() const { return mDestCRS; }
QgsCoordinateReferenceSystem destCRS() const { return mDestCRS; }

/** Transform the point from Source Coordinate System to Destination Coordinate System
* If the direction is ForwardTransform then coordinates are transformed from layer CS --> map canvas CS,
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsjsonutils.cpp
Expand Up @@ -58,7 +58,7 @@ void QgsJSONExporter::setSourceCrs( const QgsCoordinateReferenceSystem& crs )
mTransform.setSourceCrs( mCrs );
}

const QgsCoordinateReferenceSystem& QgsJSONExporter::sourceCrs() const
QgsCoordinateReferenceSystem QgsJSONExporter::sourceCrs() const
{
return mCrs;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsjsonutils.h
Expand Up @@ -112,7 +112,7 @@ class CORE_EXPORT QgsJSONExporter
* correctly automatically reprojected to WGS 84, to match GeoJSON specifications.
* @see setSourceCrs()
*/
const QgsCoordinateReferenceSystem& sourceCrs() const;
QgsCoordinateReferenceSystem sourceCrs() const;

/** Sets the list of attributes to include in the JSON exports.
* @param attributes list of attribute indexes, or an empty list to include all
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsmapsettings.cpp
Expand Up @@ -291,7 +291,7 @@ void QgsMapSettings::setDestinationCrs( const QgsCoordinateReferenceSystem& crs
mDatumTransformStore.setDestinationCrs( crs );
}

const QgsCoordinateReferenceSystem& QgsMapSettings::destinationCrs() const
QgsCoordinateReferenceSystem QgsMapSettings::destinationCrs() const
{
return mDestCRS;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsmapsettings.h
Expand Up @@ -136,7 +136,7 @@ class CORE_EXPORT QgsMapSettings
//! sets destination coordinate reference system
void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
//! returns CRS of destination coordinate reference system
const QgsCoordinateReferenceSystem& destinationCrs() const;
QgsCoordinateReferenceSystem destinationCrs() const;

//! Get units of map's geographical coordinates - used for scale calculation
QGis::UnitType mapUnits() const;
Expand Down
10 changes: 5 additions & 5 deletions src/core/qgspointlocator.cpp
Expand Up @@ -608,17 +608,17 @@ class QgsPointLocator_DumpTree : public SpatialIndex::IQueryStrategy
////////////////////////////////////////////////////////////////////////////


QgsPointLocator::QgsPointLocator( QgsVectorLayer* layer, const QgsCoordinateReferenceSystem* destCRS, const QgsRectangle* extent )
QgsPointLocator::QgsPointLocator( QgsVectorLayer* layer, const QgsCoordinateReferenceSystem& destCRS, const QgsRectangle* extent )
: mStorage( nullptr )
, mRTree( nullptr )
, mIsEmptyLayer( false )
, mTransform( nullptr )
, mLayer( layer )
, mExtent( nullptr )
{
if ( destCRS )
if ( destCRS.isValid() )
{
mTransform = new QgsCoordinateTransform( layer->crs(), *destCRS );
mTransform = new QgsCoordinateTransform( layer->crs(), destCRS );
}

setExtent( extent );
Expand All @@ -639,9 +639,9 @@ QgsPointLocator::~QgsPointLocator()
delete mExtent;
}

const QgsCoordinateReferenceSystem* QgsPointLocator::destCRS() const
QgsCoordinateReferenceSystem QgsPointLocator::destCRS() const
{
return mTransform ? &mTransform->destCRS() : nullptr;
return mTransform ? mTransform->destCRS() : QgsCoordinateReferenceSystem();
}

void QgsPointLocator::setExtent( const QgsRectangle* extent )
Expand Down
12 changes: 7 additions & 5 deletions src/core/qgspointlocator.h
Expand Up @@ -22,9 +22,9 @@ class QgsVectorLayer;
#include "qgsfeature.h"
#include "qgspoint.h"
#include "qgsrectangle.h"
#include "qgscoordinatereferencesystem.h"

class QgsCoordinateTransform;
class QgsCoordinateReferenceSystem;

class QgsPointLocator_VisitorNearestVertex;
class QgsPointLocator_VisitorNearestEdge;
Expand Down Expand Up @@ -52,19 +52,21 @@ class CORE_EXPORT QgsPointLocator : public QObject
Q_OBJECT
public:
/** Construct point locator for a layer.
* @arg destCRS if not null, will do the searches on data reprojected to the given CRS
* @arg destCRS if a valid QgsCoordinateReferenceSystem is passed then the locator will
* do the searches on data reprojected to the given CRS
* @arg extent if not null, will index only a subset of the layer
*/
explicit QgsPointLocator( QgsVectorLayer* layer, const QgsCoordinateReferenceSystem* destCRS = nullptr, const QgsRectangle* extent = nullptr );
explicit QgsPointLocator( QgsVectorLayer* layer, const QgsCoordinateReferenceSystem& destCRS = QgsCoordinateReferenceSystem(),
const QgsRectangle* extent = nullptr );

~QgsPointLocator();

//! Get associated layer
//! @note added in QGIS 2.14
QgsVectorLayer* layer() const { return mLayer; }
//! Get destination CRS - may be null if not doing OTF reprojection
//! Get destination CRS - may be an invalid QgsCoordinateReferenceSystem if not doing OTF reprojection
//! @note added in QGIS 2.14
const QgsCoordinateReferenceSystem* destCRS() const;
QgsCoordinateReferenceSystem destCRS() const;
//! Get extent of the area point locator covers - if null then it caches the whole layer
//! @note added in QGIS 2.14
const QgsRectangle* extent() const { return mExtent; }
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgssnappingutils.cpp
Expand Up @@ -572,9 +572,9 @@ QString QgsSnappingUtils::dump()
return msg;
}

const QgsCoordinateReferenceSystem* QgsSnappingUtils::destCRS()
QgsCoordinateReferenceSystem QgsSnappingUtils::destCRS() const
{
return mMapSettings.hasCrsTransformEnabled() ? &mMapSettings.destinationCrs() : nullptr;
return mMapSettings.hasCrsTransformEnabled() ? mMapSettings.destinationCrs() : QgsCoordinateReferenceSystem();
}


Expand Down
4 changes: 2 additions & 2 deletions src/core/qgssnappingutils.h
Expand Up @@ -185,8 +185,8 @@ class CORE_EXPORT QgsSnappingUtils : public QObject
void onLayersWillBeRemoved( const QStringList& layerIds );

private:
//! get from map settings pointer to destination CRS - or 0 if projections are disabled
const QgsCoordinateReferenceSystem* destCRS();
//! Get destination CRS from map settings, or an invalid CRS if projections are disabled
QgsCoordinateReferenceSystem destCRS() const;

//! delete all existing locators (e.g. when destination CRS has changed and we need to reindex)
void clearAllLocators();
Expand Down
4 changes: 2 additions & 2 deletions src/server/qgsserverprojectparser.cpp
Expand Up @@ -747,7 +747,7 @@ void QgsServerProjectParser::combineExtentAndCrsOfGroupChildren( QDomElement& gr

QgsConfigParserUtils::appendCRSElementsToLayer( groupElem, doc, combinedCRSSet.toList(), supportedOutputCrsList() );

const QgsCoordinateReferenceSystem& groupCRS = projectCRS();
QgsCoordinateReferenceSystem groupCRS = projectCRS();
if ( considerMapExtent )
{
QgsRectangle mapRect = mapRectangle();
Expand Down Expand Up @@ -879,7 +879,7 @@ QgsRectangle QgsServerProjectParser::layerBoundingBoxInProjectCRS( const QDomEle
}

//get project crs
const QgsCoordinateReferenceSystem& projectCrs = projectCRS();
QgsCoordinateReferenceSystem projectCrs = projectCRS();
QgsCoordinateTransform t( layerCrs, projectCrs );

//transform
Expand Down

0 comments on commit 7d2027f

Please sign in to comment.