Skip to content

Commit c5a8ab6

Browse files
committedMay 4, 2013
Updates to compile with current master
1 parent aa93fd8 commit c5a8ab6

7 files changed

+78
-93
lines changed
 

‎src/app/qgscustomprojectiondialog.cpp

Lines changed: 44 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extern "C"
4141
#include <proj_api.h>
4242
}
4343

44+
4445
QgsCustomProjectionDialog::QgsCustomProjectionDialog( QWidget *parent, Qt::WFlags fl )
4546
: QDialog( parent, fl )
4647
{
@@ -68,8 +69,7 @@ QgsCustomProjectionDialog::QgsCustomProjectionDialog( QWidget *parent, Qt::WFlag
6869
leNameList->setCurrentItem( leNameList->topLevelItem( 0 ) );
6970
}
7071

71-
//leNameList->hideColumn(QGIS_CRS_ID_COLUMN);
72-
leNameList->header()->setResizeMode( QGIS_CRS_NAME_COLUMN, QHeaderView::Stretch );
72+
leNameList->hideColumn(QGIS_CRS_ID_COLUMN);
7373

7474
}
7575

@@ -111,7 +111,7 @@ void QgsCustomProjectionDialog::populateList()
111111
name= QString::fromUtf8( ( char* ) sqlite3_column_text( myPreparedStatement, 1 ) );
112112
parameters= QString::fromUtf8( ( char* ) sqlite3_column_text( myPreparedStatement, 2 ) );
113113

114-
crs.createFromProj4( parameters, false );
114+
crs.createFromProj4( parameters );
115115
existingCRSnames[id] = name;
116116
existingCRSparameters[id] = crs;
117117

@@ -141,7 +141,8 @@ void QgsCustomProjectionDialog::populateList()
141141
}
142142
}
143143

144-
bool QgsCustomProjectionDialog::deleteCRS( QString id ){
144+
bool QgsCustomProjectionDialog::deleteCRS( QString id )
145+
{
145146
sqlite3 *myDatabase;
146147
const char *myTail;
147148
sqlite3_stmt *myPreparedStatement;
@@ -234,94 +235,67 @@ void QgsCustomProjectionDialog::insertProjection(QString myProjectionAcronym)
234235
sqlite3_close( myDatabase );
235236
}
236237

237-
bool QgsCustomProjectionDialog::saveCRS(QgsCoordinateReferenceSystem myParameters, QString myName, QString myId, bool newEntry)
238+
bool QgsCustomProjectionDialog::saveCRS(QgsCoordinateReferenceSystem myCRS, QString myName, QString myId, bool newEntry)
238239
{
239-
240-
if( ! myParameters.isValid() )
241-
{
242-
QMessageBox::information( this, tr( "QGIS Custom Projection" ),
243-
tr( "The proj4 projection definition for the CRS \"%1\" is not valid." ).arg( myName ) );
244-
// + tr( " Please add a proj= clause before pressing save." ) );
245-
return false;
246-
}
247-
248-
QString myProjectionAcronym = myParameters.projectionAcronym();
249-
QString myEllipsoidAcronym = myParameters.ellipsoidAcronym();
250-
251240
QString mySql;
241+
int return_id;
242+
QString myProjectionAcronym = myCRS.projectionAcronym();
243+
QString myEllipsoidAcronym = myCRS.ellipsoidAcronym();
252244
if( newEntry )
253245
{
254-
if ( existingCRSnames.size()==0 )
255-
{
256-
mySql = "insert into tbl_srs (srs_id,description,projection_acronym,ellipsoid_acronym,parameters,is_geo) values ("
257-
+ QString::number( USER_CRS_START_ID )
258-
+ "," + quotedValue( myName )
259-
+ "," + quotedValue( myProjectionAcronym )
260-
+ "," + quotedValue( myEllipsoidAcronym )
261-
+ "," + quotedValue( myParameters.toProj4() )
262-
+ ",0)"; // <-- is_geo shamelessly hard coded for now
263-
}
246+
return_id=myCRS.saveAsUserCRS(myName);
247+
if(return_id==-1)
248+
return false;
264249
else
265-
{
266-
mySql = "insert into tbl_srs (description,projection_acronym,ellipsoid_acronym,parameters,is_geo) values ("
267-
+ quotedValue( myName )
268-
+ "," + quotedValue( myProjectionAcronym )
269-
+ "," + quotedValue( myEllipsoidAcronym )
270-
+ "," + quotedValue( myParameters.toProj4() )
271-
+ ",0)"; // <-- is_geo shamelessly hard coded for now
272-
}
250+
myId = QString::number(return_id);
273251
}
274252
else
275253
{
276254
mySql = "update tbl_srs set description="
277255
+ quotedValue( myName )
278256
+ ",projection_acronym=" + quotedValue( myProjectionAcronym )
279257
+ ",ellipsoid_acronym=" + quotedValue( myEllipsoidAcronym )
280-
+ ",parameters=" + quotedValue( myParameters.toProj4() )
258+
+ ",parameters=" + quotedValue( myCRS.toProj4() )
281259
+ ",is_geo=0" // <--shamelessly hard coded for now
282260
+ " where srs_id=" + quotedValue( myId )
283261
;
284-
}
285-
QgsDebugMsg( mySql );
286-
sqlite3 *myDatabase;
287-
const char *myTail;
288-
sqlite3_stmt *myPreparedStatement;
289-
int myResult;
290-
//check if the db is available
291-
myResult = sqlite3_open( QgsApplication::qgisUserDbFilePath().toUtf8(), &myDatabase );
292-
if ( myResult != SQLITE_OK )
293-
{
294-
QgsDebugMsg( QString( "Can't open database: %1 \n please notify QGIS developers of this error \n %2 (file name) " ).arg( sqlite3_errmsg( myDatabase ) ).arg( QgsApplication::qgisUserDbFilePath() ) );
295-
// XXX This will likely never happen since on open, sqlite creates the
296-
// database if it does not exist.
297-
Q_ASSERT( myResult == SQLITE_OK );
298-
}
299-
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
300-
sqlite3_step( myPreparedStatement );
301-
// XXX Need to free memory from the error msg if one is set
302-
if ( myResult != SQLITE_OK )
303-
{
304-
QgsDebugMsg( QString( "failed to write to database in custom projection dialog: %1 [%2]" ).arg( mySql ).arg( sqlite3_errmsg( myDatabase ) ) );
305-
}
262+
QgsDebugMsg( mySql );
263+
sqlite3 *myDatabase;
264+
const char *myTail;
265+
sqlite3_stmt *myPreparedStatement;
266+
int myResult;
267+
//check if the db is available
268+
myResult = sqlite3_open( QgsApplication::qgisUserDbFilePath().toUtf8(), &myDatabase );
269+
if ( myResult != SQLITE_OK )
270+
{
271+
QgsDebugMsg( QString( "Can't open database: %1 \n please notify QGIS developers of this error \n %2 (file name) " ).arg( sqlite3_errmsg( myDatabase ) ).arg( QgsApplication::qgisUserDbFilePath() ) );
272+
// XXX This will likely never happen since on open, sqlite creates the
273+
// database if it does not exist.
274+
Q_ASSERT( myResult == SQLITE_OK );
275+
}
276+
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
277+
sqlite3_step( myPreparedStatement );
278+
// XXX Need to free memory from the error msg if one is set
279+
if ( myResult != SQLITE_OK )
280+
{
281+
QgsDebugMsg( QString( "failed to write to database in custom projection dialog: %1 [%2]" ).arg( mySql ).arg( sqlite3_errmsg( myDatabase ) ) );
282+
}
306283

307-
sqlite3_finalize( myPreparedStatement );
308-
if( newEntry )
309-
{
310-
int return_id = sqlite3_last_insert_rowid( myDatabase );
311-
myId = QString::number( return_id );
284+
sqlite3_finalize( myPreparedStatement );
285+
// close sqlite3 db
286+
sqlite3_close( myDatabase );
287+
if(myResult != SQLITE_OK)
288+
return false;
312289
}
313-
// close sqlite3 db
314-
sqlite3_close( myDatabase );
315-
316-
existingCRSparameters[myId] = myParameters;
290+
existingCRSparameters[myId] = myCRS;
317291
existingCRSnames[myId] = myName;
318292

319293
// If we have a projection acronym not in the user db previously, add it.
320294
// This is a must, or else we can't select it from the vw_srs table.
321295
// Actually, add it always and let the SQL PRIMARY KEY remove duplicates.
322296
insertProjection( myProjectionAcronym );
323297

324-
return myResult == SQLITE_OK;
298+
return true;
325299
}
326300

327301

@@ -360,7 +334,6 @@ void QgsCustomProjectionDialog::on_pbnRemove_clicked()
360334
customCRSparameters.erase( customCRSparameters.begin() + i );
361335
}
362336

363-
364337
void QgsCustomProjectionDialog::on_leNameList_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem * previous )
365338
{
366339
//Store the modifications made to the current element before moving on
@@ -369,7 +342,7 @@ void QgsCustomProjectionDialog::on_leNameList_currentItemChanged( QTreeWidgetIte
369342
{
370343
previousIndex = leNameList->indexOfTopLevelItem( previous );
371344
customCRSnames[previousIndex] = leName->text();
372-
customCRSparameters[previousIndex].createFromProj4( teParameters->toPlainText(), false);
345+
customCRSparameters[previousIndex].createFromProj4( teParameters->toPlainText() );
373346
previous->setText( QGIS_CRS_NAME_COLUMN, leName->text() );
374347
previous->setText( QGIS_CRS_PARAMETERS_COLUMN, teParameters->toPlainText() );
375348
}
@@ -418,7 +391,7 @@ void QgsCustomProjectionDialog::on_buttonBox_accepted()
418391
if(i != -1)
419392
{
420393
customCRSnames[i] = leName->text();
421-
customCRSparameters[i].createFromProj4( teParameters->toPlainText(), false );
394+
customCRSparameters[i].createFromProj4( teParameters->toPlainText() );
422395
}
423396

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

‎src/app/qgscustomprojectiondialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class QgsCustomProjectionDialog : public QDialog, private Ui::QgsCustomProjectio
3636
QgsCustomProjectionDialog( QWidget *parent = 0, Qt::WFlags fl = 0 );
3737
~QgsCustomProjectionDialog();
3838

39-
public slots:
39+
public slots:
4040
void on_pbnCalculate_clicked();
4141
void on_pbnAdd_clicked();
4242
void on_pbnRemove_clicked();

‎src/core/qgscoordinatereferencesystem.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <QRegExp>
2828
#include <QTextStream>
2929
#include <QFile>
30+
#include <QSettings>
3031

3132
#include "qgsapplication.h"
3233
#include "qgscrscache.h"
@@ -494,7 +495,7 @@ bool QgsCoordinateReferenceSystem::isValid() const
494495
return mIsValidFlag;
495496
}
496497

497-
bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String, bool save )
498+
bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String )
498499
{
499500
//
500501
// Examples:
@@ -1472,8 +1473,28 @@ bool QgsCoordinateReferenceSystem::saveAsUserCRS( QString name )
14721473

14731474
QgsMessageLog::logMessage( QObject::tr( "Saved user CRS [%1]" ).arg( toProj4() ), QObject::tr( "CRS" ) );
14741475

1475-
// XXX Need to free memory from the error msg if one is set
1476-
return myResult == SQLITE_OK;
1476+
int return_id;
1477+
if(myResult == SQLITE_OK)
1478+
{
1479+
return_id = sqlite3_last_insert_rowid( myDatabase );
1480+
setInternalId(return_id);
1481+
1482+
//We add the just created user CRS to the list of recently used CRS
1483+
QSettings settings;
1484+
//QStringList recentProjections = settings.value( "/UI/recentProjections" ).toStringList();
1485+
QStringList projectionsProj4 = settings.value( "/UI/recentProjectionsProj4" ).toStringList();
1486+
QStringList projectionsAuthId = settings.value( "/UI/recentProjectionsAuthId" ).toStringList();
1487+
//recentProjections.append();
1488+
//settings.setValue( "/UI/recentProjections", recentProjections );
1489+
projectionsProj4.append(toProj4());
1490+
projectionsAuthId.append(authid());
1491+
settings.setValue( "/UI/recentProjectionsProj4", projectionsProj4 );
1492+
settings.setValue( "/UI/recentProjectionsAuthId", projectionsAuthId );
1493+
1494+
}
1495+
else
1496+
return_id = -1;
1497+
return return_id;
14771498
}
14781499

14791500
long QgsCoordinateReferenceSystem::getRecordCount()

‎src/core/qgscoordinatereferencesystem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
134134
* in the parameters member. The reason for this is so that we
135135
* can easily present the user with 'natural language' representation
136136
* of the projection and ellipsoid by looking them up in the srs.bs sqlite
137-
* database. Also having the ellpse and proj elements stripped out
137+
* database. Also having the ellipse and proj elements stripped out
138138
* is helpful to speed up globbing queries (see below).
139139
*
140140
* We try to match the proj string to and srsid using the following logic:
@@ -154,7 +154,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
154154
* @param theProjString A proj4 format string
155155
* @return bool TRUE if success else false
156156
*/
157-
bool createFromProj4( const QString theProjString, bool save=true );
157+
bool createFromProj4( const QString theProjString );
158158

159159
/*! Set up this srs from a string definition, by default a WKT definition. Otherwise
160160
* the string defines a authority, followed by a colon, followed by the definition.

‎src/gui/qgsprojectionselector.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,10 @@ QgsProjectionSelector::QgsProjectionSelector( QWidget* parent, const char *name,
8181
// No? Skip this entry
8282
continue;
8383
}
84-
else
84+
//If the CRS can be created but do not correspond to a CRS in the database, skip it (for example a deleted custom CRS)
85+
if ( crs.srsid() == 0 )
8586
{
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-
}
87+
continue;
9788
}
9889
}
9990
mRecentProjections << QString::number( crs.srsid() );
@@ -277,7 +268,7 @@ void QgsProjectionSelector::applySelection( int column, QString value )
277268
}
278269
else
279270
{
280-
QgsDebugMsg( "nothing found" );
271+
QgsDebugMsg( QString("nothing found for %1,%2" ).arg( column ).arg( value ) );
281272
// unselect the selected item to avoid confusing the user
282273
lstCoordinateSystems->clearSelection();
283274
lstRecent->clearSelection();

‎src/providers/wcs/qgswcsprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ void QgsWcsProvider::readBlock( int bandNo, QgsRectangle const & viewExtent, in
556556
// It may happen (Geoserver) that if requested BBOX is larger than coverage
557557
// extent, the returned data cover intersection of requested BBOX and coverage
558558
// extent scaled to requested WIDTH/HEIGHT => check extent
559-
// Unfortunately if received raster does not hac CRS, the extent is raster size
559+
// Unfortunately if the received raster does not have a CRS, the extent is the raster size
560560
// and in that case it cannot be used to verify extent
561561
QgsCoordinateReferenceSystem cacheCrs;
562562
if ( !cacheCrs.createFromWkt( GDALGetProjectionRef( mCachedGdalDataset ) ) &&

‎src/ui/qgsprojectionselectorbase.ui

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>574</width>
10-
<height>390</height>
9+
<width>820</width>
10+
<height>591</height>
1111
</rect>
1212
</property>
1313
<property name="sizePolicy">

0 commit comments

Comments
 (0)
Please sign in to comment.