Skip to content
Permalink
Browse files

Fix return type for QgsCoordinateReferenceSystem::saveAsUserCrs

  • Loading branch information
nyalldawson committed Nov 13, 2017
1 parent 82644fb commit e0b2c27c0732eaea960b561ca5a9be06102cb17b
@@ -636,11 +636,12 @@ Returns whether this CRS is correctly initialized and usable
%End


bool saveAsUserCrs( const QString &name );
long saveAsUserCrs( const QString &name );
%Docstring
Save the proj4-string as a custom CRS
:return: bool true if success else false
:rtype: bool
Save the proj4-string as a custom CRS.

Returns the new CRS srsid(), or -1 if the CRS could not be saved.
:rtype: long
%End

QString geographicCrsAuthId() const;
@@ -1637,12 +1637,12 @@ QString QgsCoordinateReferenceSystem::validationHint()
/// Copied from QgsCustomProjectionDialog ///
/// Please refactor into SQL handler !!! ///

bool QgsCoordinateReferenceSystem::saveAsUserCrs( const QString &name )
long QgsCoordinateReferenceSystem::saveAsUserCrs( const QString &name )
{
if ( !d->mIsValid )
{
QgsDebugMsgLevel( "Can't save an invalid CRS!", 4 );
return false;
return -1;
}

QString mySql;
@@ -1691,13 +1691,13 @@ bool QgsCoordinateReferenceSystem::saveAsUserCrs( const QString &name )
}
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );

qint64 return_id;
qint64 returnId;
if ( myResult == SQLITE_OK && sqlite3_step( myPreparedStatement ) == SQLITE_DONE )
{
QgsMessageLog::logMessage( QObject::tr( "Saved user CRS [%1]" ).arg( toProj4() ), QObject::tr( "CRS" ) );

return_id = sqlite3_last_insert_rowid( myDatabase );
setInternalId( return_id );
returnId = sqlite3_last_insert_rowid( myDatabase );
setInternalId( returnId );

//We add the just created user CRS to the list of recently used CRS
QgsSettings settings;
@@ -1713,8 +1713,8 @@ bool QgsCoordinateReferenceSystem::saveAsUserCrs( const QString &name )

}
else
return_id = -1;
return return_id;
returnId = -1;
return returnId;
}

long QgsCoordinateReferenceSystem::getRecordCount()
@@ -613,10 +613,11 @@ class CORE_EXPORT QgsCoordinateReferenceSystem


/**
* Save the proj4-string as a custom CRS
* \returns bool true if success else false
* Save the proj4-string as a custom CRS.
*
* Returns the new CRS srsid(), or -1 if the CRS could not be saved.
*/
bool saveAsUserCrs( const QString &name );
long saveAsUserCrs( const QString &name );

//! Returns auth id of related geographic CRS
QString geographicCrsAuthId() const;
@@ -76,6 +76,7 @@ class TestQgsCoordinateReferenceSystem: public QObject
void validSrsIds();
void asVariant();
void bounds();
void saveAsUserCrs();

private:
void debugPrint( QgsCoordinateReferenceSystem &crs );
@@ -86,20 +87,30 @@ class TestQgsCoordinateReferenceSystem: public QObject
QStringList myProj4Strings;
QStringList myTOWGS84Strings;
QStringList myAuthIdStrings;
QString mTempFolder;
QString testESRIWkt( int i, QgsCoordinateReferenceSystem &crs );
};


void TestQgsCoordinateReferenceSystem::initTestCase()
{
// we start from a clean profile - we don't want to mess with user custom srses
// create temporary folder
QString subPath = QUuid::createUuid().toString().remove( '-' ).remove( '{' ).remove( '}' );
mTempFolder = QDir::tempPath() + '/' + subPath;
if ( !QDir( mTempFolder ).exists() )
QDir().mkpath( mTempFolder );

//
// Runs once before any tests are run
//
// init QGIS's paths - true means that all path will be inited from prefix
QgsApplication::init();
QgsApplication::init( mTempFolder );
QgsApplication::initQgis();
QgsApplication::showSettings();

QgsDebugMsg( QString( "Custom srs database: %1" ).arg( QgsApplication::qgisUserDatabaseFilePath() ) );

qDebug() << "GEOPROJ4 constant: " << GEOPROJ4;
qDebug() << "GDAL version (build): " << GDAL_RELEASE_NAME;
qDebug() << "GDAL version (runtime): " << GDALVersionInfo( "RELEASE_NAME" );
@@ -799,5 +810,17 @@ void TestQgsCoordinateReferenceSystem::bounds()
QGSCOMPARENEAR( bounds.yMaximum(), 90.00000, 0.0001 );
}

void TestQgsCoordinateReferenceSystem::saveAsUserCrs()
{
QString madeUpProjection = QStringLiteral( "+proj=aea +lat_1=20 +lat_2=-23 +lat_0=4 +lon_0=29 +x_0=10 +y_0=3 +datum=WGS84 +units=m +no_defs" );
QgsCoordinateReferenceSystem userCrs = QgsCoordinateReferenceSystem::fromProj4( madeUpProjection );
QVERIFY( userCrs.isValid() );
QCOMPARE( userCrs.toProj4(), madeUpProjection );
QCOMPARE( userCrs.srsid(), 0L ); // not saved to database yet

long newId = userCrs.saveAsUserCrs( QStringLiteral( "babies first projection" ) );
QCOMPARE( newId, static_cast< long >( USER_CRS_START_ID ) );
}

QGSTEST_MAIN( TestQgsCoordinateReferenceSystem )
#include "testqgscoordinatereferencesystem.moc"

0 comments on commit e0b2c27

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