Skip to content

Commit 9895141

Browse files
committed
call saveAsUserCRS after each call to createFromProj4
1 parent cc6b010 commit 9895141

7 files changed

Lines changed: 106 additions & 0 deletions

File tree

src/core/qgscoordinatereferencesystem.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@ bool QgsCoordinateReferenceSystem::createFromString( const QString theDefinition
134134
if ( reCrsStr.cap( 1 ).toLower() == "proj4" )
135135
{
136136
result = createFromProj4( reCrsStr.cap( 2 ) );
137+
//TODO: createFromProj4 used to save to the user database any new CRS
138+
// this behavior was changed in order to separate creation and saving.
139+
// Not sure if it necessary to save it here, should be checked by someone
140+
// familiar with the code (should also give a more descriptive name to the generated CRS)
141+
if( srsid() == 0 )
142+
{
143+
QString myName = QString( " * %1 (%2)" )
144+
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
145+
.arg( toProj4() );
146+
saveAsUserCRS(myName);
147+
}
137148
}
138149
else
139150
{
@@ -460,6 +471,17 @@ bool QgsCoordinateReferenceSystem::createFromWkt( QString theWkt )
460471

461472
createFromProj4( proj4src );
462473
}
474+
//TODO: createFromProj4 used to save to the user database any new CRS
475+
// this behavior was changed in order to separate creation and saving.
476+
// Not sure if it necessary to save it here, should be checked by someone
477+
// familiar with the code (should also give a more descriptive name to the generated CRS)
478+
if( mSrsId == 0 )
479+
{
480+
QString myName = QString( " * %1 (%2)" )
481+
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
482+
.arg( toProj4() );
483+
saveAsUserCRS(myName);
484+
}
463485

464486
CPLFree( proj4src );
465487

@@ -1190,6 +1212,18 @@ bool QgsCoordinateReferenceSystem::readXML( QDomNode & theNode )
11901212
//@TODO this srs needs to be validated!!!
11911213
mIsValidFlag = true; //shamelessly hard coded for now
11921214
}
1215+
//TODO: createFromProj4 used to save to the user database any new CRS
1216+
// this behavior was changed in order to separate creation and saving.
1217+
// Not sure if it necessary to save it here, should be checked by someone
1218+
// familiar with the code (should also give a more descriptive name to the generated CRS)
1219+
if( mSrsId == 0 )
1220+
{
1221+
QString myName = QString( " * %1 (%2)" )
1222+
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
1223+
.arg( toProj4() );
1224+
saveAsUserCRS(myName);
1225+
}
1226+
11931227
}
11941228
}
11951229
else

src/core/qgsdistancearea.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,18 @@ bool QgsDistanceArea::setEllipsoid( const QString& ellipsoid )
212212
QString proj4 = "+proj=longlat +ellps=" + ellipsoid + " +no_defs";
213213
QgsCoordinateReferenceSystem destCRS;
214214
destCRS.createFromProj4( proj4 );
215+
//TODO: createFromProj4 used to save to the user database any new CRS
216+
// this behavior was changed in order to separate creation and saving.
217+
// Not sure if it necessary to save it here, should be checked by someone
218+
// familiar with the code (should also give a more descriptive name to the generated CRS)
219+
if( destCRS.srsid() == 0 )
220+
{
221+
QString myName = QString( " * %1 (%2)" )
222+
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
223+
.arg( destCRS.toProj4() );
224+
destCRS.saveAsUserCRS(myName);
225+
}
226+
//
215227

216228
// set transformation from project CRS to ellipsoid coordinates
217229
mCoordTransform->setDestCRS( destCRS );

src/gui/qgsprojectionselector.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ QgsProjectionSelector::QgsProjectionSelector( QWidget* parent, const char *name,
8181
// No? Skip this entry
8282
continue;
8383
}
84+
else
85+
{
86+
//TODO: createFromProj4 used to save to the user database any new CRS
87+
// this behavior was changed in order to separate creation and saving.
88+
// Not sure if it necessary to save it here, should be checked by someone
89+
// familiar with the code (should also give a more descriptive name to the generated CRS)
90+
if( crs.srsid() == 0 )
91+
{
92+
QString myName = QString( " * %1 (%2)" )
93+
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
94+
.arg( crs.toProj4() );
95+
crs.saveAsUserCRS(myName);
96+
}
97+
}
8498
}
8599
mRecentProjections << QString::number( crs.srsid() );
86100
}

src/mapserver/qgssldparser.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,18 @@ void QgsSLDParser::setCrsForLayer( const QDomElement& layerElem, QgsMapLayer* ml
15241524
{
15251525
QgsCoordinateReferenceSystem srs;
15261526
srs.createFromProj4( projString );
1527+
//TODO: createFromProj4 used to save to the user database any new CRS
1528+
// this behavior was changed in order to separate creation and saving.
1529+
// Not sure if it necessary to save it here, should be checked by someone
1530+
// familiar with the code (should also give a more descriptive name to the generated CRS)
1531+
if( srs.srsid() == 0 )
1532+
{
1533+
QString myName = QString( " * %1 (%2)" )
1534+
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
1535+
.arg( srs.toProj4() );
1536+
srs.saveAsUserCRS(myName);
1537+
}
1538+
15271539
ml->setCrs( srs );
15281540
}
15291541
}

src/providers/grass/qgsgrassgislib.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,17 @@ int GRASS_LIB_EXPORT QgsGrassGisLib::G__gisinit( const char * version, const cha
221221
{
222222
fatal( "Cannot create CRS from QGIS_GRASS_CRS: " + crsStr );
223223
}
224+
//TODO: createFromProj4 used to save to the user database any new CRS
225+
// this behavior was changed in order to separate creation and saving.
226+
// Not sure if it necessary to save it here, should be checked by someone
227+
// familiar with the code (should also give a more descriptive name to the generated CRS)
228+
if( mCrs.srsid() == 0 )
229+
{
230+
QString myName = QString( " * %1 (%2)" )
231+
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
232+
.arg( mCrs.toProj4() );
233+
mCrs.saveAsUserCRS(myName);
234+
}
224235
}
225236
mDistanceArea.setSourceCrs( mCrs.srsid() );
226237

src/providers/spatialite/qgsspatialiteprovider.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3200,6 +3200,18 @@ QgsCoordinateReferenceSystem QgsSpatiaLiteProvider::crs()
32003200
if ( !srs.isValid() )
32013201
{
32023202
srs.createFromProj4( mProj4text );
3203+
//TODO: createFromProj4 used to save to the user database any new CRS
3204+
// this behavior was changed in order to separate creation and saving.
3205+
// Not sure if it necessary to save it here, should be checked by someone
3206+
// familiar with the code (should also give a more descriptive name to the generated CRS)
3207+
if( srs.srsid() == 0 )
3208+
{
3209+
QString myName = QString( " * %1 (%2)" )
3210+
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
3211+
.arg( srs.toProj4() );
3212+
srs.saveAsUserCRS(myName);
3213+
}
3214+
32033215
}
32043216
return srs;
32053217
}

src/providers/sqlanywhere/qgssqlanywhereprovider.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,6 +1886,17 @@ QgsSqlAnywhereProvider::checkSrs()
18861886
SaDebugMsg( "Failed to create CRS from Proj4 description. Trying WKT." );
18871887
mCrs.createFromWkt( srsWkt );
18881888
}
1889+
//TODO: createFromProj4 used to save to the user database any new CRS
1890+
// this behavior was changed in order to separate creation and saving.
1891+
// Not sure if it necessary to save it here, should be checked by someone
1892+
// familiar with the code (should also give a more descriptive name to the generated CRS)
1893+
if( mCrs.srsid() == 0 )
1894+
{
1895+
QString myName = QString( " * %1 (%2)" )
1896+
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
1897+
.arg( mCrs.toProj4() );
1898+
mCrs.saveAsUserCRS(myName);
1899+
}
18891900

18901901
return true;
18911902
} // QgsSqlAnywhereProvider::checkSrs()

0 commit comments

Comments
 (0)