Fix most remaining methods which return a reference to

QgsCoordinateReferenceSystem or which take a pointer to a
CRS
This commit is contained in:
Nyall Dawson 2016-07-11 16:04:50 +10:00
parent 726569c6bc
commit 7d2027faa9
19 changed files with 76 additions and 34 deletions

View File

@ -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>
@ -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>
@ -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>

View File

@ -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();

View File

@ -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,

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -56,7 +56,7 @@ class ANALYSIS_EXPORT QgsGraphBuilderInterface
{ }
//! get destinaltion Crs
QgsCoordinateReferenceSystem& destinationCrs()
QgsCoordinateReferenceSystem destinationCrs() const
{
return mCrs;
}

View File

@ -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

View File

@ -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;

View File

@ -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,

View File

@ -58,7 +58,7 @@ void QgsJSONExporter::setSourceCrs( const QgsCoordinateReferenceSystem& crs )
mTransform.setSourceCrs( mCrs );
}
const QgsCoordinateReferenceSystem& QgsJSONExporter::sourceCrs() const
QgsCoordinateReferenceSystem QgsJSONExporter::sourceCrs() const
{
return mCrs;
}

View File

@ -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

View File

@ -291,7 +291,7 @@ void QgsMapSettings::setDestinationCrs( const QgsCoordinateReferenceSystem& crs
mDatumTransformStore.setDestinationCrs( crs );
}
const QgsCoordinateReferenceSystem& QgsMapSettings::destinationCrs() const
QgsCoordinateReferenceSystem QgsMapSettings::destinationCrs() const
{
return mDestCRS;
}

View File

@ -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;

View File

@ -608,7 +608,7 @@ 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 )
@ -616,9 +616,9 @@ QgsPointLocator::QgsPointLocator( QgsVectorLayer* layer, const QgsCoordinateRefe
, mLayer( layer )
, mExtent( nullptr )
{
if ( destCRS )
if ( destCRS.isValid() )
{
mTransform = new QgsCoordinateTransform( layer->crs(), *destCRS );
mTransform = new QgsCoordinateTransform( layer->crs(), destCRS );
}
setExtent( extent );
@ -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 )

View File

@ -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;
@ -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; }

View File

@ -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();
}

View File

@ -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();

View File

@ -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();
@ -879,7 +879,7 @@ QgsRectangle QgsServerProjectParser::layerBoundingBoxInProjectCRS( const QDomEle
}
//get project crs
const QgsCoordinateReferenceSystem& projectCrs = projectCRS();
QgsCoordinateReferenceSystem projectCrs = projectCRS();
QgsCoordinateTransform t( layerCrs, projectCrs );
//transform