Skip to content

Commit

Permalink
Remove QgsCRSCache
Browse files Browse the repository at this point in the history
No longer required now that QgsCoordinateReferenceSystem
internally uses caches for CRS initialization.
  • Loading branch information
nyalldawson committed Jul 25, 2016
1 parent ac36cb5 commit bb36c60
Show file tree
Hide file tree
Showing 71 changed files with 136 additions and 656 deletions.
3 changes: 3 additions & 0 deletions doc/api_break.dox
Expand Up @@ -24,6 +24,9 @@ This page tries to maintain a list with incompatible changes that happened in pr
<li>QgsLabel and QgsLabelAttributes. Replaced by labeling based on PAL library, see QgsLabelingEngineV2.</li>
<li>QgsMapCanvasMap. It is an internal class used by map canvas.</li>
<li>QgsMapRenderer. It has been replaced by QgsMapRendererJob with subclasses and QgsMapSettings.</li>
<li>QgsCRSCache was removed. QgsCoordinateReferenceSystem now internally uses a cache for CRS creation,
so there is no longer a need for the separate cache class. Code which previously called QgsCRSCache::updateCRSCache()
should now call QgsCoordinateReferenceSystem::invalidateCache() and QgsCoordinateTransformCache::instance()->invalidateCrs( authid ).</li>
</ul>

\subsection qgis_api_break_3_0_global General changes
Expand Down
78 changes: 0 additions & 78 deletions python/core/qgscrscache.sip
Expand Up @@ -25,81 +25,3 @@ class QgsCoordinateTransformCache
QgsCoordinateTransformCache( const QgsCoordinateTransformCache& rh );
};

/** \ingroup core
* \class QgsCrsCache
* \brief Caches QgsCoordinateReferenceSystem construction, which may be expensive.
*
* QgsCRSCache maintains a cache of previously constructed coordinate systems, so that
* creating a new CRS from the cache can reuse previously calculated parameters. The
* constructors for QgsCoordinateReferenceSystem can be expensive, so it's recommended
* to use QgsCRSCache instead of directly calling the QgsCoordinateReferenceSystem
* constructors.
*/

class QgsCrsCache
{
%TypeHeaderCode
#include <qgscrscache.h>
%End

public:

//! Returns a pointer to the QgsCRSCache singleton
static QgsCrsCache* instance();

/** Returns the CRS for authid, e.g. 'EPSG:4326' (or an invalid CRS in case of error)
* @deprecated use crsByOgcWmsCrs() instead
*/
QgsCoordinateReferenceSystem crsByAuthId( const QString& authid ) /Deprecated/;

/** Returns the CRS from a given OGC WMS-format Coordinate Reference System string.
* @param ogcCrs OGR compliant CRS definition, eg "EPSG:4326"
* @returns matching CRS, or an invalid CRS if string could not be matched
* @note added in QGIS 2.16
* @see QgsCoordinateReferenceSystem::createFromOgcWmsCrs()
*/
QgsCoordinateReferenceSystem crsByOgcWmsCrs( const QString& ogcCrs ) const;

/** Returns the CRS from a given EPSG ID.
* @param epsg epsg CRS ID
* @returns matching CRS, or an invalid CRS if string could not be matched
*/
QgsCoordinateReferenceSystem crsByEpsgId( long epsg ) const;

/** Returns the CRS from a proj4 style formatted string.
* @param proj4 proj4 format string
* @returns matching CRS, or an invalid CRS if string could not be matched
* @note added in QGIS 2.16
* @see QgsCoordinateReferenceSystem::createFromProj4()
*/
QgsCoordinateReferenceSystem crsByProj4( const QString& proj4 ) const;

/** Returns the CRS from a WKT spatial ref sys definition string.
* @param wkt WKT for the desired spatial reference system.
* @returns matching CRS, or an invalid CRS if string could not be matched
* @note added in QGIS 2.16
* @see QgsCoordinateReferenceSystem::createFromWkt()
*/
QgsCoordinateReferenceSystem crsByWkt( const QString& wkt ) const;

/** Returns the CRS from a specified QGIS SRS ID.
* @param srsId internal QGIS SRS ID
* @returns matching CRS, or an invalid CRS if ID could not be found
* @note added in QGIS 2.16
* @see QgsCoordinateReferenceSystem::createFromSrsId()
*/
QgsCoordinateReferenceSystem crsBySrsId( long srsId ) const;

/** Updates the cached definition of a CRS. Should be called if the definition of a user-created
* CRS has been changed.
* @param authid CRS auth ID, eg "EPSG:4326" or "USER:100009"
*/
void updateCrsCache( const QString& authid );

protected:
QgsCrsCache();

private:

QgsCrsCache( const QgsCrsCache& other );
};
3 changes: 1 addition & 2 deletions src/app/gps/qgsgpsinformationwidget.cpp
Expand Up @@ -35,7 +35,6 @@
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
#include "qgswkbptr.h"
#include "qgscrscache.h"

// QWT Charting widget

Expand Down Expand Up @@ -229,7 +228,7 @@ QgsGPSInformationWidget::QgsGPSInformationWidget( QgsMapCanvas * thepCanvas, QWi
radRecenterWhenNeeded->setChecked( true );
}

mWgs84CRS = QgsCrsCache::instance()->crsByOgcWmsCrs( "EPSG:4326" );
mWgs84CRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs( "EPSG:4326" );

mBtnDebug->setVisible( mySettings.value( "/gps/showDebug", "false" ).toBool() ); // use a registry setting to control - power users/devs could set it

Expand Down
3 changes: 1 addition & 2 deletions src/app/gps/qgsgpsmarker.cpp
Expand Up @@ -18,14 +18,13 @@
#include "qgsgpsmarker.h"
#include "qgscoordinatetransform.h"
#include "qgsmapcanvas.h"
#include "qgscrscache.h"
#include "qgscsexception.h"

QgsGpsMarker::QgsGpsMarker( QgsMapCanvas* mapCanvas )
: QgsMapCanvasItem( mapCanvas )
{
mSize = 16;
mWgs84CRS = QgsCrsCache::instance()->crsByOgcWmsCrs( "EPSG:4326" );
mWgs84CRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs( "EPSG:4326" );
mSvg.load( QString( ":/images/north_arrows/gpsarrow2.svg" ) );
if ( ! mSvg.isValid() )
{
Expand Down
3 changes: 1 addition & 2 deletions src/app/ogr/qgsvectorlayersaveasdialog.cpp
Expand Up @@ -16,7 +16,6 @@
* *
***************************************************************************/
#include "qgslogger.h"
#include "qgscrscache.h"
#include "qgsvectorlayersaveasdialog.h"
#include "qgsgenericprojectionselector.h"
#include "qgsvectordataprovider.h"
Expand Down Expand Up @@ -102,7 +101,7 @@ void QgsVectorLayerSaveAsDialog::setup()
idx = 0;
}

QgsCoordinateReferenceSystem srs = QgsCrsCache::instance()->crsBySrsId( mCRS );
QgsCoordinateReferenceSystem srs = QgsCoordinateReferenceSystem::fromSrsId( mCRS );
mCrsSelector->setCrs( srs );
mCrsSelector->setLayerCrs( srs );
mCrsSelector->dialog()->setMessage( tr( "Select the coordinate reference system for the vector file. "
Expand Down
5 changes: 2 additions & 3 deletions src/app/openstreetmap/qgsosmdownloaddialog.cpp
Expand Up @@ -21,7 +21,6 @@

#include "qgis.h"
#include "qgisapp.h"
#include "qgscrscache.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
Expand Down Expand Up @@ -104,7 +103,7 @@ void QgsOSMDownloadDialog::onExtentCanvas()

if ( QgisApp::instance()->mapCanvas()->hasCrsTransformEnabled() )
{
QgsCoordinateReferenceSystem dst = QgsCrsCache::instance()->crsBySrsId( GEOCRS_ID );
QgsCoordinateReferenceSystem dst = QgsCoordinateReferenceSystem::fromSrsId( GEOCRS_ID );

QgsCoordinateTransform ct( QgisApp::instance()->mapCanvas()->mapSettings().destinationCrs(), dst );
r = ct.transformBoundingBox( r );
Expand Down Expand Up @@ -143,7 +142,7 @@ void QgsOSMDownloadDialog::onCurrentLayerChanged( int index )
if ( !layer )
return;

QgsCoordinateReferenceSystem dst = QgsCrsCache::instance()->crsBySrsId( GEOCRS_ID );
QgsCoordinateReferenceSystem dst = QgsCoordinateReferenceSystem::fromSrsId( GEOCRS_ID );

QgsCoordinateTransform ct( layer->crs(), dst );
QgsRectangle rect( ct.transformBoundingBox( layer->extent() ) );
Expand Down
11 changes: 5 additions & 6 deletions src/app/qgisapp.cpp
Expand Up @@ -127,7 +127,6 @@
#include "qgscoordinatetransform.h"
#include "qgscoordinateutils.h"
#include "qgscredentialdialog.h"
#include "qgscrscache.h"
#include "qgscursors.h"
#include "qgscustomization.h"
#include "qgscustomlayerorderwidget.h"
Expand Down Expand Up @@ -513,7 +512,7 @@ void QgisApp::validateCrs( QgsCoordinateReferenceSystem &srs )
if ( authid.isNull() )
authid = QgisApp::instance()->mapCanvas()->mapSettings().destinationCrs().authid();

QgsCoordinateReferenceSystem defaultCrs = QgsCrsCache::instance()->crsByOgcWmsCrs( authid );
QgsCoordinateReferenceSystem defaultCrs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( authid );
if ( defaultCrs.isValid() )
{
mySelector->setSelectedCrsId( defaultCrs.srsid() );
Expand Down Expand Up @@ -4413,7 +4412,7 @@ void QgisApp::fileNew( bool thePromptToSaveFlag, bool forceBlank )

// set project CRS
QString defCrs = settings.value( "/Projections/projectDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString();
QgsCoordinateReferenceSystem srs = QgsCrsCache::instance()->crsByOgcWmsCrs( defCrs );
QgsCoordinateReferenceSystem srs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( defCrs );
mMapCanvas->setDestinationCrs( srs );
// write the projections _proj string_ to project settings
prj->writeEntry( "SpatialRefSys", "/ProjectCRSProj4String", srs.toProj4() );
Expand Down Expand Up @@ -6171,7 +6170,7 @@ void QgisApp::saveAsVectorFileGeneral( QgsVectorLayer* vlayer, bool symbologyOpt
QgsWKBTypes::Type forcedGeometryType = dialog->geometryType();

QgsCoordinateTransform ct;
destCRS = QgsCrsCache::instance()->crsBySrsId( dialog->crs() );
destCRS = QgsCoordinateReferenceSystem::fromSrsId( dialog->crs() );

if ( destCRS.isValid() && destCRS != vlayer->crs() )
{
Expand Down Expand Up @@ -8469,7 +8468,7 @@ void QgisApp::setLayerCrs()
return;
}

QgsCoordinateReferenceSystem crs = QgsCrsCache::instance()->crsBySrsId( mySelector.selectedCrsId() );
QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem::fromSrsId( mySelector.selectedCrsId() );

Q_FOREACH ( QgsLayerTreeNode* node, mLayerTreeView->selectedNodes() )
{
Expand Down Expand Up @@ -8626,7 +8625,7 @@ void QgisApp::legendGroupSetCrs()
return;
}

QgsCoordinateReferenceSystem crs = QgsCrsCache::instance()->crsBySrsId( mySelector.selectedCrsId() );
QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem::fromSrsId( mySelector.selectedCrsId() );
Q_FOREACH ( QgsLayerTreeLayer* nodeLayer, currentGroup->findLayers() )
{
if ( nodeLayer->layer() )
Expand Down
3 changes: 1 addition & 2 deletions src/app/qgsbookmarks.cpp
Expand Up @@ -21,7 +21,6 @@
#include "qgsmapcanvas.h"
#include "qgsproject.h"
#include "qgsmessagelog.h"
#include "qgscrscache.h"

#include "qgslogger.h"

Expand Down Expand Up @@ -232,7 +231,7 @@ void QgsBookmarks::zoomToBookmark()
if ( srid > 0 &&
srid != QgisApp::instance()->mapCanvas()->mapSettings().destinationCrs().srsid() )
{
QgsCoordinateTransform ct( QgsCrsCache::instance()->crsBySrsId( srid ),
QgsCoordinateTransform ct( QgsCoordinateReferenceSystem::fromSrsId( srid ),
QgisApp::instance()->mapCanvas()->mapSettings().destinationCrs() );
rect = ct.transform( rect );
if ( rect.isEmpty() )
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgscustomprojectiondialog.cpp
Expand Up @@ -166,8 +166,8 @@ bool QgsCustomProjectionDialog::deleteCrs( const QString& id )
}
sqlite3_close( myDatabase );

QgsCrsCache::instance()->updateCrsCache( QString( "USER:%1" ).arg( id ) );
QgsCoordinateReferenceSystem::invalidateCache();
QgsCoordinateTransformCache::instance()->invalidateCrs( QString( "USER:%1" ).arg( id ) );

return myResult == SQLITE_OK;
}
Expand Down Expand Up @@ -292,8 +292,8 @@ bool QgsCustomProjectionDialog::saveCrs( QgsCoordinateReferenceSystem myCRS, con
existingCRSparameters[myId] = myCRS.toProj4();
existingCRSnames[myId] = myName;

QgsCrsCache::instance()->updateCrsCache( QString( "USER:%1" ).arg( myId ) );
QgsCoordinateReferenceSystem::invalidateCache();
QgsCoordinateTransformCache::instance()->invalidateCrs( QString( "USER:%1" ).arg( myId ) );

// If we have a projection acronym not in the user db previously, add it.
// This is a must, or else we can't select it from the vw_srs table.
Expand Down
3 changes: 1 addition & 2 deletions src/app/qgsdecorationnortharrow.cpp
Expand Up @@ -30,7 +30,6 @@ email : tim@linfiniti.com
#include "qgsproject.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgscrscache.h"
#include "qgscsexception.h"

// qt includes
Expand Down Expand Up @@ -231,7 +230,7 @@ bool QgsDecorationNorthArrow::calculateNorthDirection()
if ( outputCRS.isValid() && !outputCRS.isGeographic() )
{
// Use a geographic CRS to get lat/long to work out direction
QgsCoordinateReferenceSystem ourCRS = QgsCrsCache::instance()->crsByOgcWmsCrs( GEO_EPSG_CRS_AUTHID );
QgsCoordinateReferenceSystem ourCRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs( GEO_EPSG_CRS_AUTHID );
assert( ourCRS.isValid() );

QgsCoordinateTransform transform( outputCRS, ourCRS );
Expand Down
5 changes: 2 additions & 3 deletions src/app/qgsnewspatialitelayerdialog.cpp
Expand Up @@ -29,7 +29,6 @@
#include "qgscoordinatereferencesystem.h"
#include "qgsgenericprojectionselector.h"
#include "qgsslconnect.h"
#include "qgscrscache.h"

#include "qgslogger.h"

Expand Down Expand Up @@ -75,7 +74,7 @@ QgsNewSpatialiteLayerDialog::QgsNewSpatialiteLayerDialog( QWidget *parent, Qt::W
mOkButton->setEnabled( false );

// Set the SRID box to a default of WGS84
QgsCoordinateReferenceSystem srs = QgsCrsCache::instance()->crsByOgcWmsCrs( settings.value( "/Projections/layerDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString() );
QgsCoordinateReferenceSystem srs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( settings.value( "/Projections/layerDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString() );
srs.validate();
mCrsId = srs.authid();
leSRID->setText( srs.authid() + " - " + srs.description() );
Expand Down Expand Up @@ -244,7 +243,7 @@ void QgsNewSpatialiteLayerDialog::on_pbnFindSRID_clicked()

if ( mySelector->exec() )
{
QgsCoordinateReferenceSystem srs = QgsCrsCache::instance()->crsByOgcWmsCrs( mySelector->selectedAuthId() );
QgsCoordinateReferenceSystem srs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( mySelector->selectedAuthId() );
QString crsId = srs.authid();
if ( crsId != mCrsId )
{
Expand Down
5 changes: 2 additions & 3 deletions src/app/qgsoptions.cpp
Expand Up @@ -30,7 +30,6 @@
#include "qgsnetworkaccessmanager.h"
#include "qgsproject.h"
#include "qgsdualview.h"
#include "qgscrscache.h"
#include "qgsrasterlayer.h"

#include "qgsattributetablefiltermodel.h"
Expand Down Expand Up @@ -387,7 +386,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl )
radUseGlobalProjection->setChecked( true );
}
QString myLayerDefaultCrs = mSettings->value( "/Projections/layerDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString();
mLayerDefaultCrs = QgsCrsCache::instance()->crsByOgcWmsCrs( myLayerDefaultCrs );
mLayerDefaultCrs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( myLayerDefaultCrs );
leLayerGlobalCrs->setCrs( mLayerDefaultCrs );

//on the fly CRS transformation settings
Expand All @@ -406,7 +405,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl )
}

QString myDefaultCrs = mSettings->value( "/Projections/projectDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString();
mDefaultCrs = QgsCrsCache::instance()->crsByOgcWmsCrs( myDefaultCrs );
mDefaultCrs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( myDefaultCrs );
leProjectGlobalCrs->setCrs( mDefaultCrs );
leProjectGlobalCrs->setOptionVisible( QgsProjectionSelectionWidget::DefaultCrs, false );

Expand Down
9 changes: 4 additions & 5 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -25,7 +25,6 @@
#include "qgscomposer.h"
#include "qgscontexthelp.h"
#include "qgscoordinatetransform.h"
#include "qgscrscache.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayer.h"
Expand Down Expand Up @@ -129,7 +128,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
// slot triggered by setChecked() might use it.
mProjectSrsId = mMapCanvas->mapSettings().destinationCrs().srsid();

QgsCoordinateReferenceSystem srs = QgsCrsCache::instance()->crsBySrsId( mProjectSrsId );
QgsCoordinateReferenceSystem srs = QgsCoordinateReferenceSystem::fromSrsId( mProjectSrsId );
updateGuiForMapUnits( srs.mapUnits() );

QgsDebugMsg( "Read project CRSID: " + QString::number( mProjectSrsId ) );
Expand Down Expand Up @@ -774,7 +773,7 @@ void QgsProjectProperties::apply()
long myCRSID = projectionSelector->selectedCrsId();
if ( myCRSID )
{
QgsCoordinateReferenceSystem srs = QgsCrsCache::instance()->crsBySrsId( myCRSID );
QgsCoordinateReferenceSystem srs = QgsCoordinateReferenceSystem::fromSrsId( myCRSID );
mMapCanvas->setDestinationCrs( srs );
QgsDebugMsg( QString( "Selected CRS " ) + srs.description() );
// write the currently selected projections _proj string_ to project settings
Expand Down Expand Up @@ -1303,7 +1302,7 @@ void QgsProjectProperties::srIdUpdated()
if ( !isProjected() || !myCRSID )
return;

QgsCoordinateReferenceSystem srs = QgsCrsCache::instance()->crsBySrsId( myCRSID );
QgsCoordinateReferenceSystem srs = QgsCoordinateReferenceSystem::fromSrsId( myCRSID );
//set radio button to crs map unit type
Qgis::UnitType units = srs.mapUnits();

Expand Down Expand Up @@ -1396,7 +1395,7 @@ void QgsProjectProperties::on_pbnWMSSetUsedSRS_clicked()

if ( cbxProjectionEnabled->isChecked() )
{
QgsCoordinateReferenceSystem srs = QgsCrsCache::instance()->crsBySrsId( projectionSelector->selectedCrsId() );
QgsCoordinateReferenceSystem srs = QgsCoordinateReferenceSystem::fromSrsId( projectionSelector->selectedCrsId() );
crsList << srs.authid();
}

Expand Down
3 changes: 1 addition & 2 deletions src/app/qgswelcomepageitemsmodel.cpp
Expand Up @@ -16,7 +16,6 @@
#include "qgswelcomepageitemsmodel.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsmessagelog.h"
#include "qgscrscache.h"

#include <QApplication>
#include <QAbstractTextDocumentLayout>
Expand Down Expand Up @@ -150,7 +149,7 @@ QVariant QgsWelcomePageItemsModel::data( const QModelIndex& index, int role ) co
case CrsRole:
if ( mRecentProjects.at( index.row() ).crs != "" )
{
QgsCoordinateReferenceSystem crs = QgsCrsCache::instance()->crsByOgcWmsCrs( mRecentProjects.at( index.row() ).crs );
QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( mRecentProjects.at( index.row() ).crs );
return QString( "%1 (%2)" ).arg( mRecentProjects.at( index.row() ).crs, crs.description() );
}
else
Expand Down

0 comments on commit bb36c60

Please sign in to comment.