Skip to content

Commit

Permalink
More formatting standardisation
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 7, 2017
1 parent b5f64b3 commit 6143e6d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 43 deletions.
74 changes: 37 additions & 37 deletions src/app/qgscustomprojectiondialog.cpp
Expand Up @@ -68,10 +68,10 @@ QgsCustomProjectionDialog::QgsCustomProjectionDialog( QWidget *parent, Qt::Windo
}

populateList();
if ( !customCRSnames.empty() )
if ( !mCustomCRSnames.empty() )
{
leName->setText( customCRSnames[0] );
teParameters->setPlainText( customCRSparameters[0] );
leName->setText( mCustomCRSnames[0] );
teParameters->setPlainText( mCustomCRSparameters[0] );
leNameList->setCurrentItem( leNameList->topLevelItem( 0 ) );
}

Expand Down Expand Up @@ -117,8 +117,8 @@ void QgsCustomProjectionDialog::populateList()
parameters = QString::fromUtf8( ( char * ) sqlite3_column_text( preparedStatement, 2 ) );

crs.createFromProj4( parameters );
existingCRSnames[id] = name;
existingCRSparameters[id] = crs.toProj4();
mExistingCRSnames[id] = name;
mExistingCRSparameters[id] = crs.toProj4();

newItem = new QTreeWidgetItem( leNameList, QStringList() );
newItem->setText( QgisCrsNameColumn, name );
Expand All @@ -139,9 +139,9 @@ void QgsCustomProjectionDialog::populateList()
while ( *it )
{
QString id = ( *it )->text( QgisCrsIdColumn );
customCRSids.push_back( id );
customCRSnames.push_back( existingCRSnames[id] );
customCRSparameters.push_back( existingCRSparameters[id] );
mCustomCRSids.push_back( id );
mCustomCRSnames.push_back( mExistingCRSnames[id] );
mCustomCRSparameters.push_back( mExistingCRSparameters[id] );
it++;
}
}
Expand Down Expand Up @@ -293,8 +293,8 @@ bool QgsCustomProjectionDialog::saveCrs( QgsCoordinateReferenceSystem parameters
if ( result != SQLITE_OK )
return false;
}
existingCRSparameters[id] = parameters.toProj4();
existingCRSnames[id] = name;
mExistingCRSparameters[id] = parameters.toProj4();
mExistingCRSnames[id] = name;

QgsCoordinateReferenceSystem::invalidateCache();
QgsCoordinateTransformCache::instance()->invalidateCrs( QStringLiteral( "USER:%1" ).arg( id ) );
Expand All @@ -319,9 +319,9 @@ void QgsCustomProjectionDialog::pbnAdd_clicked()
newItem->setText( QgisCrsNameColumn, name );
newItem->setText( QgisCrsIdColumn, id );
newItem->setText( QgisCrsParametersColumn, parameters.toProj4() );
customCRSnames.push_back( name );
customCRSids.push_back( id );
customCRSparameters.push_back( parameters.toProj4() );
mCustomCRSnames.push_back( name );
mCustomCRSids.push_back( id );
mCustomCRSparameters.push_back( parameters.toProj4() );
leNameList->setCurrentItem( newItem );
}

Expand All @@ -334,13 +334,13 @@ void QgsCustomProjectionDialog::pbnRemove_clicked()
}
QTreeWidgetItem *item = leNameList->takeTopLevelItem( i );
delete item;
if ( !customCRSids[i].isEmpty() )
if ( !mCustomCRSids[i].isEmpty() )
{
deletedCRSs.push_back( customCRSids[i] );
mDeletedCRSs.push_back( mCustomCRSids[i] );
}
customCRSids.erase( customCRSids.begin() + i );
customCRSnames.erase( customCRSnames.begin() + i );
customCRSparameters.erase( customCRSparameters.begin() + i );
mCustomCRSids.erase( mCustomCRSids.begin() + i );
mCustomCRSnames.erase( mCustomCRSnames.begin() + i );
mCustomCRSparameters.erase( mCustomCRSparameters.begin() + i );
}

void QgsCustomProjectionDialog::leNameList_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem *previous )
Expand All @@ -350,15 +350,15 @@ void QgsCustomProjectionDialog::leNameList_currentItemChanged( QTreeWidgetItem *
if ( previous )
{
previousIndex = leNameList->indexOfTopLevelItem( previous );
customCRSnames[previousIndex] = leName->text();
customCRSparameters[previousIndex] = teParameters->toPlainText();
mCustomCRSnames[previousIndex] = leName->text();
mCustomCRSparameters[previousIndex] = teParameters->toPlainText();
previous->setText( QgisCrsNameColumn, leName->text() );
previous->setText( QgisCrsParametersColumn, teParameters->toPlainText() );
}
if ( current )
{
currentIndex = leNameList->indexOfTopLevelItem( current );
leName->setText( customCRSnames[currentIndex] );
leName->setText( mCustomCRSnames[currentIndex] );
teParameters->setPlainText( current->text( QgisCrsParametersColumn ) );
}
else
Expand All @@ -381,7 +381,7 @@ void QgsCustomProjectionDialog::pbnCopyCRS_clicked()
pbnAdd_clicked();
}
teParameters->setPlainText( srs.toProj4() );
customCRSparameters[leNameList->currentIndex().row()] = srs.toProj4();
mCustomCRSparameters[leNameList->currentIndex().row()] = srs.toProj4();
leNameList->currentItem()->setText( QgisCrsParametersColumn, srs.toProj4() );

}
Expand All @@ -394,53 +394,53 @@ void QgsCustomProjectionDialog::buttonBox_accepted()
int i = leNameList->currentIndex().row();
if ( i != -1 )
{
customCRSnames[i] = leName->text();
customCRSparameters[i] = teParameters->toPlainText();
mCustomCRSnames[i] = leName->text();
mCustomCRSparameters[i] = teParameters->toPlainText();
}

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

//Check if all CRS are valid:
QgsCoordinateReferenceSystem CRS;
for ( int i = 0; i < customCRSids.size(); ++i )
for ( int i = 0; i < mCustomCRSids.size(); ++i )
{
CRS.createFromProj4( customCRSparameters[i] );
CRS.createFromProj4( mCustomCRSparameters[i] );
if ( !CRS.isValid() )
{
QMessageBox::information( this, tr( "QGIS Custom Projection" ),
tr( "The proj4 definition of '%1' is not valid." ).arg( customCRSnames[i] ) );
tr( "The proj4 definition of '%1' is not valid." ).arg( mCustomCRSnames[i] ) );
return;
}
}
//Modify the CRS changed:
bool save_success = true;
for ( int i = 0; i < customCRSids.size(); ++i )
for ( int i = 0; i < mCustomCRSids.size(); ++i )
{
CRS.createFromProj4( customCRSparameters[i] );
CRS.createFromProj4( mCustomCRSparameters[i] );
//Test if we just added this CRS (if it has no existing ID)
if ( !customCRSids[i].isEmpty() )
if ( !mCustomCRSids[i].isEmpty() )
{
save_success &= saveCrs( CRS, customCRSnames[i], QLatin1String( "" ), true );
save_success &= saveCrs( CRS, mCustomCRSnames[i], QLatin1String( "" ), true );
}
else
{
if ( existingCRSnames[customCRSids[i]] != customCRSnames[i] || existingCRSparameters[customCRSids[i]] != customCRSparameters[i] )
if ( mExistingCRSnames[mCustomCRSids[i]] != mCustomCRSnames[i] || mExistingCRSparameters[mCustomCRSids[i]] != mCustomCRSparameters[i] )
{
save_success &= saveCrs( CRS, customCRSnames[i], customCRSids[i], false );
save_success &= saveCrs( CRS, mCustomCRSnames[i], mCustomCRSids[i], false );
}
}
if ( ! save_success )
{
QgsDebugMsg( QString( "Error when saving CRS '%1'" ).arg( customCRSnames[i] ) );
QgsDebugMsg( QString( "Error when saving CRS '%1'" ).arg( mCustomCRSnames[i] ) );
}
}
QgsDebugMsg( "We remove the deleted CRS." );
for ( int i = 0; i < deletedCRSs.size(); ++i )
for ( int i = 0; i < mDeletedCRSs.size(); ++i )
{
save_success &= deleteCrs( deletedCRSs[i] );
save_success &= deleteCrs( mDeletedCRSs[i] );
if ( ! save_success )
{
QgsDebugMsg( QString( "Problem for layer '%1'" ).arg( customCRSparameters[i] ) );
QgsDebugMsg( QString( "Problem for layer '%1'" ).arg( mCustomCRSparameters[i] ) );
}
}
if ( save_success )
Expand Down
12 changes: 6 additions & 6 deletions src/app/qgscustomprojectiondialog.h
Expand Up @@ -54,16 +54,16 @@ class APP_EXPORT QgsCustomProjectionDialog : public QDialog, private Ui::QgsCust
void showHelp();

//These two QMap store the values as they are on the database when loading
QMap <QString, QString> existingCRSparameters;
QMap <QString, QString> existingCRSnames;
QMap <QString, QString> mExistingCRSparameters;
QMap <QString, QString> mExistingCRSnames;

//These three list store the value updated with the current modifications
QStringList customCRSnames;
QStringList customCRSids;
QStringList customCRSparameters;
QStringList mCustomCRSnames;
QStringList mCustomCRSids;
QStringList mCustomCRSparameters;

//vector saving the CRS to be deleted
QStringList deletedCRSs;
QStringList mDeletedCRSs;

//Columns in the tree widget
enum Columns { QgisCrsNameColumn, QgisCrsIdColumn, QgisCrsParametersColumn };
Expand Down

0 comments on commit 6143e6d

Please sign in to comment.