Skip to content

Commit

Permalink
Store object instead of pointer to crs in QgsMapLayer
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 25, 2016
1 parent fcaffa2 commit 1287f8c
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 28 deletions.
12 changes: 6 additions & 6 deletions src/analysis/vector/qgsgeometryanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ bool QgsGeometryAnalyzer::simplify( QgsVectorLayer* layer,
}

QGis::WkbType outputType = dp->geometryType();
const QgsCoordinateReferenceSystem crs = layer->crs();
QgsCoordinateReferenceSystem crs = layer->crs();

QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), layer->fields(), outputType, &crs );
QgsFeature currentFeature;
Expand Down Expand Up @@ -163,7 +163,7 @@ bool QgsGeometryAnalyzer::centroids( QgsVectorLayer* layer, const QString& shape
}

QGis::WkbType outputType = QGis::WKBPoint;
const QgsCoordinateReferenceSystem crs = layer->crs();
QgsCoordinateReferenceSystem crs = layer->crs();

QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), layer->fields(), outputType, &crs );
QgsFeature currentFeature;
Expand Down Expand Up @@ -279,7 +279,7 @@ bool QgsGeometryAnalyzer::extent( QgsVectorLayer* layer,
}

QGis::WkbType outputType = QGis::WKBPolygon;
const QgsCoordinateReferenceSystem crs = layer->crs();
QgsCoordinateReferenceSystem crs = layer->crs();

QgsFields fields;
fields.append( QgsField( QString( "MINX" ), QVariant::Double ) );
Expand Down Expand Up @@ -389,7 +389,7 @@ bool QgsGeometryAnalyzer::convexHull( QgsVectorLayer* layer, const QString& shap
fields.append( QgsField( QString( "PERIM" ), QVariant::Double ) );

QGis::WkbType outputType = QGis::WKBPolygon;
const QgsCoordinateReferenceSystem crs = layer->crs();
QgsCoordinateReferenceSystem crs = layer->crs();

QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), fields, outputType, &crs );
QgsFeature currentFeature;
Expand Down Expand Up @@ -595,7 +595,7 @@ bool QgsGeometryAnalyzer::dissolve( QgsVectorLayer* layer, const QString& shapef
}

QGis::WkbType outputType = dp->geometryType();
const QgsCoordinateReferenceSystem crs = layer->crs();
QgsCoordinateReferenceSystem crs = layer->crs();

QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), layer->fields(), outputType, &crs );
QgsFeature currentFeature;
Expand Down Expand Up @@ -748,7 +748,7 @@ bool QgsGeometryAnalyzer::buffer( QgsVectorLayer* layer, const QString& shapefil
{
outputType = QGis::WKBMultiPolygon;
}
const QgsCoordinateReferenceSystem crs = layer->crs();
QgsCoordinateReferenceSystem crs = layer->crs();

QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), layer->fields(), outputType, &crs );
QgsFeature currentFeature;
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/vector/qgsoverlayanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bool QgsOverlayAnalyzer::intersection( QgsVectorLayer* layerA, QgsVectorLayer* l
}

QGis::WkbType outputType = dpA->geometryType();
const QgsCoordinateReferenceSystem crs = layerA->crs();
QgsCoordinateReferenceSystem crs = layerA->crs();
QgsFields fieldsA = layerA->fields();
QgsFields fieldsB = layerB->fields();
combineFieldLists( fieldsA, fieldsB );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsdecorationgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ bool QgsDecorationGrid::getIntervalFromCurrentLayer( double* values )
QMessageBox::warning( nullptr, tr( "Error" ), tr( "Invalid raster layer" ) );
return false;
}
const QgsCoordinateReferenceSystem& layerCRS = layer->crs();
QgsCoordinateReferenceSystem layerCRS = layer->crs();
const QgsCoordinateReferenceSystem& mapCRS =
QgisApp::instance()->mapCanvas()->mapSettings().destinationCrs();
// is this the best way to compare CRS? should we also make sure map has OTF enabled?
Expand Down
30 changes: 14 additions & 16 deletions src/core/qgsmaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
, mLegend( nullptr )
, mStyleManager( new QgsMapLayerStyleManager( this ) )
{
mCRS = new QgsCoordinateReferenceSystem();

// Set the display name = internal name
QgsDebugMsg( "original name: '" + mLayerOrigName + '\'' );
mLayerName = capitaliseLayerName( mLayerOrigName );
Expand Down Expand Up @@ -92,7 +90,6 @@ QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,

QgsMapLayer::~QgsMapLayer()
{
delete mCRS;
delete mLegend;
delete mStyleManager;
}
Expand Down Expand Up @@ -171,8 +168,6 @@ void QgsMapLayer::drawLabels( QgsRenderContext& rendererContext )

bool QgsMapLayer::readLayerXML( const QDomElement& layerElement )
{
QgsCoordinateReferenceSystem savedCRS;
CUSTOM_CRS_VALIDATION savedValidation;
bool layerError;

QDomNode mnl;
Expand Down Expand Up @@ -380,11 +375,14 @@ bool QgsMapLayer::readLayerXML( const QDomElement& layerElement )
mnl = layerElement.namedItem( "layername" );
mne = mnl.toElement();

QgsCoordinateReferenceSystem savedCRS;
CUSTOM_CRS_VALIDATION savedValidation;

QDomNode srsNode = layerElement.namedItem( "srs" );
mCRS->readXML( srsNode );
mCRS->setValidationHint( tr( "Specify CRS for layer %1" ).arg( mne.text() ) );
mCRS->validate();
savedCRS = *mCRS;
mCRS.readXML( srsNode );
mCRS.setValidationHint( tr( "Specify CRS for layer %1" ).arg( mne.text() ) );
mCRS.validate();
savedCRS = mCRS;

// Do not validate any projections in children, they will be overwritten anyway.
// No need to ask the user for a projections when it is overwritten, is there?
Expand All @@ -398,7 +396,7 @@ bool QgsMapLayer::readLayerXML( const QDomElement& layerElement )
// file readnig functions changed it. They will if projections is specfied in the file.
// FIXME: is this necessary?
QgsCoordinateReferenceSystem::setCustomSrsValidation( savedValidation );
*mCRS = savedCRS;
mCRS = savedCRS;

// Abort if any error in layer, such as not found.
if ( layerError )
Expand Down Expand Up @@ -768,7 +766,7 @@ bool QgsMapLayer::writeLayerXML( QDomElement& layerElement, QDomDocument& docume

// spatial reference system id
QDomElement mySrsElement = document.createElement( "srs" );
mCRS->writeXML( mySrsElement, document );
mCRS.writeXML( mySrsElement, document );
layerElement.appendChild( mySrsElement );

#if 0
Expand Down Expand Up @@ -1000,17 +998,17 @@ void QgsMapLayer::setSubLayerVisibility( const QString& name, bool vis )

const QgsCoordinateReferenceSystem& QgsMapLayer::crs() const
{
return *mCRS;
return mCRS;
}

void QgsMapLayer::setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal )
{
*mCRS = srs;
mCRS = srs;

if ( !mCRS->isValid() )
if ( !mCRS.isValid() )
{
mCRS->setValidationHint( tr( "Specify CRS for layer %1" ).arg( name() ) );
mCRS->validate();
mCRS.setValidationHint( tr( "Specify CRS for layer %1" ).arg( name() ) );
mCRS.validate();
}

if ( emitSignal )
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsmaplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
/** Returns layer's spatial reference system
@note This was introduced in QGIS 1.4
*/
//TODO QGIS 3.0 - return QgsCoordinateReferenceSystem object, not reference (since they are implicitly shared)
const QgsCoordinateReferenceSystem& crs() const;

/** Sets layer's spatial reference system */
Expand Down Expand Up @@ -764,7 +765,7 @@ class CORE_EXPORT QgsMapLayer : public QObject

/** Layer's spatial reference system.
private to make sure setCrs must be used and layerCrsChanged() is emitted */
QgsCoordinateReferenceSystem* mCRS;
QgsCoordinateReferenceSystem mCRS;

/** Private copy constructor - QgsMapLayer not copyable */
QgsMapLayer( QgsMapLayer const & );
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsmaprenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ class CORE_EXPORT QgsMapRenderer : public QObject
bool mProjectionsEnabled;

//! destination spatial reference system of the projection
// TODO QGIS 3.0 - make object, not pointer
QgsCoordinateReferenceSystem* mDestCRS;

//! stores array of layers to be rendered (identified by string)
Expand Down
4 changes: 2 additions & 2 deletions src/server/qgswcsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void QgsWCSProjectParser::wcsContentMetadata( QDomElement& parentElement, QDomDo
layerElem.appendChild( descriptionElem );

//lonLatEnvelope
const QgsCoordinateReferenceSystem& layerCrs = layer->crs();
QgsCoordinateReferenceSystem layerCrs = layer->crs();
QgsCoordinateTransform t( layerCrs, QgsCoordinateReferenceSystem( 4326 ) );
//transform
QgsRectangle BBox;
Expand Down Expand Up @@ -274,7 +274,7 @@ void QgsWCSProjectParser::describeCoverage( const QString& aCoveName, QDomElemen
layerElem.appendChild( descriptionElem );

//lonLatEnvelope
const QgsCoordinateReferenceSystem& layerCrs = rLayer->crs();
QgsCoordinateReferenceSystem layerCrs = rLayer->crs();
QgsCoordinateTransform t( layerCrs, QgsCoordinateReferenceSystem( 4326 ) );
//transform
QgsRectangle BBox = rLayer->extent();
Expand Down
2 changes: 1 addition & 1 deletion src/server/qgswmsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,7 @@ void QgsWMSProjectParser::addOWSLayers( QDomDocument &doc,
appendLayerBoundingBoxes( layerElem, doc, currentLayer->extent(), currentLayer->crs() );
*/
//get project crs
const QgsCoordinateReferenceSystem& layerCrs = currentLayer->crs();
QgsCoordinateReferenceSystem layerCrs = currentLayer->crs();
QgsCoordinateTransform t( layerCrs, projectCrs );

//transform
Expand Down

0 comments on commit 1287f8c

Please sign in to comment.