Skip to content

Commit 6e3e89b

Browse files
committedMay 4, 2013
do not use QgsCoordinateReferenceSystem internally
1 parent 60b4369 commit 6e3e89b

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed
 

‎src/app/qgscustomprojectiondialog.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ QgsCustomProjectionDialog::QgsCustomProjectionDialog( QWidget *parent, Qt::WFlag
6565
if( !customCRSnames.empty() )
6666
{
6767
leName->setText( customCRSnames[0] );
68-
teParameters->setPlainText( customCRSparameters[0].toProj4() );
68+
teParameters->setPlainText( customCRSparameters[0] );
6969
leNameList->setCurrentItem( leNameList->topLevelItem( 0 ) );
7070
}
7171

@@ -113,7 +113,7 @@ void QgsCustomProjectionDialog::populateList()
113113

114114
crs.createFromProj4( parameters );
115115
existingCRSnames[id] = name;
116-
existingCRSparameters[id] = crs;
116+
existingCRSparameters[id] = crs.toProj4();
117117

118118
newItem = new QTreeWidgetItem( leNameList, QStringList( ) );
119119
newItem->setText( QGIS_CRS_NAME_COLUMN, name );
@@ -241,6 +241,7 @@ bool QgsCustomProjectionDialog::saveCRS(QgsCoordinateReferenceSystem myCRS, QStr
241241
int return_id;
242242
QString myProjectionAcronym = myCRS.projectionAcronym();
243243
QString myEllipsoidAcronym = myCRS.ellipsoidAcronym();
244+
QgsDebugMsg( QString("Saving a CRS:%1, %2, %3").arg(myName).arg(myCRS.toProj4()).arg(newEntry) );
244245
if( newEntry )
245246
{
246247
return_id=myCRS.saveAsUserCRS(myName);
@@ -287,7 +288,7 @@ bool QgsCustomProjectionDialog::saveCRS(QgsCoordinateReferenceSystem myCRS, QStr
287288
if(myResult != SQLITE_OK)
288289
return false;
289290
}
290-
existingCRSparameters[myId] = myCRS;
291+
existingCRSparameters[myId] = myCRS.toProj4();
291292
existingCRSnames[myId] = myName;
292293

293294
// If we have a projection acronym not in the user db previously, add it.
@@ -312,7 +313,7 @@ void QgsCustomProjectionDialog::on_pbnAdd_clicked()
312313
newItem->setText( QGIS_CRS_PARAMETERS_COLUMN, parameters.toProj4());
313314
customCRSnames.push_back( name );
314315
customCRSids.push_back ( id);
315-
customCRSparameters.push_back( parameters );
316+
customCRSparameters.push_back( parameters.toProj4() );
316317
leNameList->setCurrentItem( newItem );
317318
}
318319

@@ -342,7 +343,7 @@ void QgsCustomProjectionDialog::on_leNameList_currentItemChanged( QTreeWidgetIte
342343
{
343344
previousIndex = leNameList->indexOfTopLevelItem( previous );
344345
customCRSnames[previousIndex] = leName->text();
345-
customCRSparameters[previousIndex].createFromProj4( teParameters->toPlainText() );
346+
customCRSparameters[previousIndex] = teParameters->toPlainText();
346347
previous->setText( QGIS_CRS_NAME_COLUMN, leName->text() );
347348
previous->setText( QGIS_CRS_PARAMETERS_COLUMN, teParameters->toPlainText() );
348349
}
@@ -376,7 +377,7 @@ void QgsCustomProjectionDialog::on_pbnCopyCRS_clicked()
376377
on_pbnAdd_clicked();
377378
}
378379
teParameters->setPlainText( srs.toProj4() );
379-
customCRSparameters[leNameList->currentIndex().row()].createFromProj4( srs.toProj4() );
380+
customCRSparameters[leNameList->currentIndex().row()] = srs.toProj4();
380381
leNameList->currentItem()->setText( QGIS_CRS_PARAMETERS_COLUMN, srs.toProj4() );
381382

382383
}
@@ -391,35 +392,38 @@ void QgsCustomProjectionDialog::on_buttonBox_accepted()
391392
if(i != -1)
392393
{
393394
customCRSnames[i] = leName->text();
394-
customCRSparameters[i].createFromProj4( teParameters->toPlainText() );
395+
customCRSparameters[i] = teParameters->toPlainText();
395396
}
396397

397398
QgsDebugMsg( "We save the modified CRS." );
398399

399400
//Check if all CRS are valid:
401+
QgsCoordinateReferenceSystem CRS;
400402
for( size_t i = 0; i < customCRSids.size(); ++i )
401403
{
402-
if( customCRSparameters[i].isValid()==false )
404+
CRS.createFromProj4(customCRSparameters[i]);
405+
if( CRS.isValid()==false )
403406
{
404407
QMessageBox::information( this, tr( "QGIS Custom Projection" ),
405408
tr( "The proj4 definition of '%1' is not valid." ).arg(customCRSnames[i]) );
406409
return;
407410
}
408411
}
409412
//Modify the CRS changed:
410-
bool save_success;
413+
bool save_success=true;
411414
for( size_t i = 0; i < customCRSids.size(); ++i )
412415
{
416+
CRS.createFromProj4(customCRSparameters[i]);
413417
//Test if we just added this CRS (if it has no existing ID)
414418
if( customCRSids[i] == "" )
415419
{
416-
save_success = save_success && saveCRS( customCRSparameters[i],customCRSnames[i], "", true);
420+
save_success = save_success && saveCRS( CRS,customCRSnames[i], "", true);
417421
}
418422
else
419423
{
420-
if ( existingCRSnames[customCRSids[i]]!=customCRSnames[i] || existingCRSparameters[customCRSids[i]].toProj4() != customCRSparameters[i].toProj4() )
424+
if ( existingCRSnames[customCRSids[i]]!=customCRSnames[i] || existingCRSparameters[customCRSids[i]] != customCRSparameters[i] )
421425
{
422-
save_success = save_success && saveCRS(customCRSparameters[i], customCRSnames[i], customCRSids[i], false );
426+
save_success = save_success && saveCRS(CRS, customCRSnames[i], customCRSids[i], false );
423427
}
424428
}
425429
if( ! save_success )
@@ -433,7 +437,7 @@ void QgsCustomProjectionDialog::on_buttonBox_accepted()
433437
save_success=save_success && deleteCRS( deletedCRSs[i] );
434438
if( ! save_success )
435439
{
436-
QgsDebugMsg( QString( "Problem for layer %1" ).arg( customCRSparameters[i].toProj4() ));
440+
QgsDebugMsg( QString( "Problem for layer '%1'" ).arg( customCRSparameters[i] ));
437441
}
438442
}
439443
if( save_success )

‎src/app/qgscustomprojectiondialog.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ class QgsCustomProjectionDialog : public QDialog, private Ui::QgsCustomProjectio
5555
bool saveCRS( QgsCoordinateReferenceSystem myParameters, QString myName, QString myId, bool newEntry );
5656
void insertProjection( QString myProjectionAcronym );
5757

58-
//These two QMap store the value as it is on the database when loading
59-
QMap <QString, QgsCoordinateReferenceSystem> existingCRSparameters;
58+
//These two QMap store the values as they are on the database when loading
59+
QMap <QString, QString> existingCRSparameters;
6060
QMap <QString, QString> existingCRSnames;
6161

6262
//These three vectors store the value updated with the current modifications
6363
std::vector<QString> customCRSnames;
6464
std::vector<QString> customCRSids;
65-
std::vector<QgsCoordinateReferenceSystem> customCRSparameters;
65+
std::vector<QString> customCRSparameters;
6666

6767
//vector saving the CRS to be deleted
6868
std::vector<QString> deletedCRSs;

0 commit comments

Comments
 (0)
Please sign in to comment.