Skip to content

Commit

Permalink
Avoid unnecessary duplicate detachments in QgsCoordinateReferenceSystem
Browse files Browse the repository at this point in the history
In all these code paths a detach had already just occurrred
  • Loading branch information
nyalldawson committed Jan 22, 2020
1 parent e90fb88 commit 2ca3ca6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 116 deletions.
77 changes: 10 additions & 67 deletions src/core/qgscoordinatereferencesystem.cpp
Expand Up @@ -467,8 +467,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;

Expand All @@ -493,8 +491,6 @@ void QgsCoordinateReferenceSystem::validate()
if ( d->mIsValid || !sCustomSrsValidation )
return;

d.detach();

// try to validate using custom validation routines
if ( sCustomSrsValidation )
sCustomSrsValidation( *this );
Expand Down Expand Up @@ -1463,30 +1459,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();
Expand Down Expand Up @@ -1682,30 +1654,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;
Expand Down Expand Up @@ -2036,32 +1986,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();
Expand Down Expand Up @@ -2318,10 +2261,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();
Expand Down
49 changes: 0 additions & 49 deletions src/core/qgscoordinatereferencesystem.h
Expand Up @@ -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
Expand All @@ -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
*/
Expand Down

0 comments on commit 2ca3ca6

Please sign in to comment.