Skip to content

Commit

Permalink
Fix bad logic in custom projections dialog (fixes #17258)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 7, 2017
1 parent 108de77 commit c8a62c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions src/app/qgscustomprojectiondialog.cpp
Expand Up @@ -339,8 +339,9 @@ void QgsCustomProjectionDialog::insertProjection( const QString &projectionAcro
}
}

bool QgsCustomProjectionDialog::saveCrs( QgsCoordinateReferenceSystem parameters, const QString &name, QString id, bool newEntry )
bool QgsCustomProjectionDialog::saveCrs( QgsCoordinateReferenceSystem parameters, const QString &name, const QString &existingId, bool newEntry )
{
QString id = existingId;
QString sql;
int returnId;
QString projectionAcronym = parameters.projectionAcronym();
Expand Down Expand Up @@ -504,37 +505,37 @@ void QgsCustomProjectionDialog::buttonBox_accepted()
}
}
//Modify the CRS changed:
bool save_success = true;
bool saveSuccess = true;
for ( int i = 0; i < mCustomCRSids.size(); ++i )
{
CRS.createFromProj4( mCustomCRSparameters[i] );
//Test if we just added this CRS (if it has no existing ID)
if ( !mCustomCRSids[i].isEmpty() )
if ( mCustomCRSids[i].isEmpty() )
{
save_success &= saveCrs( CRS, mCustomCRSnames[i], QLatin1String( "" ), true );
saveSuccess &= saveCrs( CRS, mCustomCRSnames[i], QString(), true );
}
else
{
if ( mExistingCRSnames[mCustomCRSids[i]] != mCustomCRSnames[i] || mExistingCRSparameters[mCustomCRSids[i]] != mCustomCRSparameters[i] )
{
save_success &= saveCrs( CRS, mCustomCRSnames[i], mCustomCRSids[i], false );
saveSuccess &= saveCrs( CRS, mCustomCRSnames[i], mCustomCRSids[i], false );
}
}
if ( ! save_success )
if ( ! saveSuccess )
{
QgsDebugMsg( QString( "Error when saving CRS '%1'" ).arg( mCustomCRSnames[i] ) );
}
}
QgsDebugMsg( "We remove the deleted CRS." );
for ( int i = 0; i < mDeletedCRSs.size(); ++i )
{
save_success &= deleteCrs( mDeletedCRSs[i] );
if ( ! save_success )
saveSuccess &= deleteCrs( mDeletedCRSs[i] );
if ( ! saveSuccess )
{
QgsDebugMsg( QString( "Problem for layer '%1'" ).arg( mCustomCRSparameters[i] ) );
}
}
if ( save_success )
if ( saveSuccess )
{
accept();
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgscustomprojectiondialog.h
Expand Up @@ -49,7 +49,7 @@ class APP_EXPORT QgsCustomProjectionDialog : public QDialog, private Ui::QgsCust
void populateList();
QString quotedValue( QString value );
bool deleteCrs( const QString &id );
bool saveCrs( QgsCoordinateReferenceSystem parameters, const QString &name, QString id, bool newEntry );
bool saveCrs( QgsCoordinateReferenceSystem parameters, const QString &name, const QString &id, bool newEntry );
void insertProjection( const QString &projectionAcronym );
void showHelp();

Expand Down

0 comments on commit c8a62c5

Please sign in to comment.