Skip to content
Permalink
Browse files

Store object instead of pointer to crs in QgsMapLayer

  • Loading branch information
nyalldawson committed May 24, 2016
1 parent fcaffa2 commit 1287f8ccbdf82f3d0465ca7293fa8e2f147f6a78
@@ -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;
@@ -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;
@@ -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 ) );
@@ -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;
@@ -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;
@@ -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;
@@ -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 );
@@ -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?
@@ -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 );
@@ -92,7 +90,6 @@ QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,

QgsMapLayer::~QgsMapLayer()
{
delete mCRS;
delete mLegend;
delete mStyleManager;
}
@@ -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;
@@ -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?
@@ -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 )
@@ -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
@@ -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 )
@@ -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 */
@@ -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 & );
@@ -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)
@@ -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;
@@ -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();
@@ -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

0 comments on commit 1287f8c

Please sign in to comment.
You can’t perform that action at this time.