Skip to content
Permalink
Browse files

Avoid unnecessary duplicate detachments in QgsCoordinateReferenceSystem

In all these code paths a detach had already just occurrred

(cherry picked from commit 9fafde4)
  • Loading branch information
nyalldawson committed Jan 21, 2020
1 parent d5eb523 commit 15938150dd51fe6ac4c9acff76da54b92bae9523
Showing with 10 additions and 116 deletions.
  1. +10 −67 src/core/qgscoordinatereferencesystem.cpp
  2. +0 −49 src/core/qgscoordinatereferencesystem.h
@@ -464,8 +464,6 @@ bool QgsCoordinateReferenceSystem::createFromOgcWmsCrs( const QString &crs )
wmsCrs.compare( QLatin1String( "OGC:CRS84" ), Qt::CaseInsensitive ) == 0 )
{
createFromOgcWmsCrs( QStringLiteral( "EPSG:4326" ) );

d.detach();
d->mAxisInverted = false;
d->mAxisInvertedDirty = false;

@@ -490,8 +488,6 @@ void QgsCoordinateReferenceSystem::validate()
if ( d->mIsValid || !sCustomSrsValidation )
return;

d.detach();

// try to validate using custom validation routines
if ( sCustomSrsValidation )
sCustomSrsValidation( *this );
@@ -1460,30 +1456,6 @@ QgsRectangle QgsCoordinateReferenceSystem::bounds() const
#endif
}


// Mutators -----------------------------------


void QgsCoordinateReferenceSystem::setInternalId( long srsId )
{
d.detach();
d->mSrsId = srsId;
}
void QgsCoordinateReferenceSystem::setAuthId( const QString &authId )
{
d.detach();
d->mAuthId = authId;
}
void QgsCoordinateReferenceSystem::setSrid( long srid )
{
d.detach();
d->mSRID = srid;
}
void QgsCoordinateReferenceSystem::setDescription( const QString &description )
{
d.detach();
d->mDescription = description;
}
void QgsCoordinateReferenceSystem::setProjString( const QString &proj4String )
{
d.detach();
@@ -1679,30 +1651,8 @@ bool QgsCoordinateReferenceSystem::setWktString( const QString &wkt, bool allowP
return d->mIsValid;
}

void QgsCoordinateReferenceSystem::setGeographicFlag( bool geoFlag )
{
d.detach();
d->mIsGeographic = geoFlag;
}
void QgsCoordinateReferenceSystem::setEpsg( long epsg )
{
d.detach();
d->mAuthId = QStringLiteral( "EPSG:%1" ).arg( epsg );
}
void QgsCoordinateReferenceSystem::setProjectionAcronym( const QString &projectionAcronym )
{
d.detach();
d->mProjectionAcronym = projectionAcronym;
}
void QgsCoordinateReferenceSystem::setEllipsoidAcronym( const QString &ellipsoidAcronym )
{
d.detach();
d->mEllipsoidAcronym = ellipsoidAcronym;
}

void QgsCoordinateReferenceSystem::setMapUnits()
{
d.detach();
if ( !d->mIsValid )
{
d->mMapUnits = QgsUnitTypes::DistanceUnknownUnit;
@@ -2033,32 +1983,25 @@ bool QgsCoordinateReferenceSystem::readXml( const QDomNode &node )
setProjString( node.toElement().text() );

node = srsNode.namedItem( QStringLiteral( "srsid" ) );
setInternalId( node.toElement().text().toLong() );
d->mSrsId = node.toElement().text().toLong();

node = srsNode.namedItem( QStringLiteral( "srid" ) );
setSrid( node.toElement().text().toLong() );
d->mSRID = node.toElement().text().toLong();

node = srsNode.namedItem( QStringLiteral( "authid" ) );
setAuthId( node.toElement().text() );
d->mAuthId = node.toElement().text();

node = srsNode.namedItem( QStringLiteral( "description" ) );
setDescription( node.toElement().text() );
d->mDescription = node.toElement().text();

node = srsNode.namedItem( QStringLiteral( "projectionacronym" ) );
setProjectionAcronym( node.toElement().text() );
d->mProjectionAcronym = node.toElement().text();

node = srsNode.namedItem( QStringLiteral( "ellipsoidacronym" ) );
setEllipsoidAcronym( node.toElement().text() );
d->mEllipsoidAcronym = node.toElement().text();

node = srsNode.namedItem( QStringLiteral( "geographicflag" ) );
if ( node.toElement().text().compare( QLatin1String( "true" ) ) )
{
setGeographicFlag( true );
}
else
{
setGeographicFlag( false );
}
d->mIsGeographic = node.toElement().text().compare( QLatin1String( "true" ) );

//make sure the map units have been set
setMapUnits();
@@ -2315,10 +2258,10 @@ long QgsCoordinateReferenceSystem::saveAsUserCrs( const QString &name, Format na
QgsMessageLog::logMessage( QObject::tr( "Saved user CRS [%1]" ).arg( toProj() ), QObject::tr( "CRS" ) );

returnId = sqlite3_last_insert_rowid( database.get() );
setInternalId( returnId );
d->mSrsId = returnId;
if ( authid().isEmpty() )
setAuthId( QStringLiteral( "USER:%1" ).arg( returnId ) );
setDescription( name );
d->mAuthId = QStringLiteral( "USER:%1" ).arg( returnId );
d->mDescription = name;
}

invalidateCache();
@@ -836,24 +836,6 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
*/
static QString projFromSrsId( int srsId );

/**
* Set the QGIS SrsId
* \param srsId The internal sqlite3 srs.db primary key for this CRS
*/
void setInternalId( long srsId );

/**
* Set the PostGIS srid
* \param srid The PostGIS spatial_ref_sys key for this CRS
*/
void setSrid( long srid );

/**
* Set the Description
* \param description A textual description of the CRS.
*/
void setDescription( const QString &description );

/**
* Set the Proj string.
* \param projString Proj format specifies
@@ -866,37 +848,6 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
*/
bool setWktString( const QString &wkt, bool allowProjFallback = true );

/**
* Set this Geographic? flag
* \param geoFlag Whether this is a geographic or projected coordinate system
*/
void setGeographicFlag( bool geoFlag );

/**
* Set the EpsgCrsId identifier for this CRS
* \param epsg the EPSG identifier for this CRS (defaults to 0)
*/
void setEpsg( long epsg );

/**
* Set the authority identifier for this CRS
* \param theID the authority identifier for this CRS (defaults to 0)
*/
void setAuthId( const QString &theID );

/**
* Set the projection acronym
* \param projectionAcronym the acronym (must be a valid Proj projection acronym)
*/
void setProjectionAcronym( const QString &projectionAcronym );

/**
* Set the ellipsoid acronym
* \param ellipsoidAcronym the acronym (must be a valid Proj ellipsoid acronym or
* authority:code identifier on Proj version 6+ builds)
*/
void setEllipsoidAcronym( const QString &ellipsoidAcronym );

/**
* Print the description if debugging
*/

0 comments on commit 1593815

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