Skip to content

Commit b44ae22

Browse files
committedJan 29, 2012
cleanup projection selections - makes it work via keyboard again
1 parent 9a3316a commit b44ae22

File tree

2 files changed

+321
-438
lines changed

2 files changed

+321
-438
lines changed
 

‎src/gui/qgsprojectionselector.cpp

Lines changed: 312 additions & 408 deletions
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,45 @@
1111
#include <qgsprojectionselector.h>
1212

1313
//standard includes
14-
#include <cassert>
1514
#include <sqlite3.h>
1615

1716
//qgis includes
1817
#include "qgis.h" //magic numbers here
1918
#include "qgsapplication.h"
2019
#include "qgslogger.h"
21-
#include <qgscoordinatereferencesystem.h>
20+
#include "qgscoordinatereferencesystem.h"
2221

2322
//qt includes
24-
#include <QDir>
2523
#include <QFileInfo>
26-
#include <QTextStream>
2724
#include <QHeaderView>
2825
#include <QResizeEvent>
2926
#include <QMessageBox>
3027
#include <QSettings>
3128

32-
const int NAME_COLUMN = 0;
33-
const int AUTHID_COLUMN = 1;
34-
const int QGIS_CRS_ID_COLUMN = 2;
35-
3629
QgsProjectionSelector::QgsProjectionSelector( QWidget* parent, const char *name, Qt::WFlags fl )
3730
: QWidget( parent, fl )
3831
, mProjListDone( false )
3932
, mUserProjListDone( false )
4033
, mRecentProjListDone( false )
41-
, mCRSNameSelectionPending( false )
42-
, mCRSIDSelectionPending( false )
43-
, mAuthIDSelectionPending( false )
34+
, mSearchColumn( NONE )
4435
{
4536
Q_UNUSED( name );
4637
setupUi( this );
47-
connect( lstCoordinateSystems, SIGNAL( currentItemChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ),
48-
this, SLOT( coordinateSystemSelected( QTreeWidgetItem* ) ) );
4938

5039
// Get the full path name to the sqlite3 spatial reference database.
5140
mSrsDatabaseFileName = QgsApplication::srsDbFilePath();
41+
5242
lstCoordinateSystems->header()->setResizeMode( AUTHID_COLUMN, QHeaderView::Stretch );
5343
lstCoordinateSystems->header()->resizeSection( QGIS_CRS_ID_COLUMN, 0 );
5444
lstCoordinateSystems->header()->setResizeMode( QGIS_CRS_ID_COLUMN, QHeaderView::Fixed );
45+
5546
// Hide (internal) ID column
5647
lstCoordinateSystems->setColumnHidden( QGIS_CRS_ID_COLUMN, true );
5748

5849
lstRecent->header()->setResizeMode( AUTHID_COLUMN, QHeaderView::Stretch );
5950
lstRecent->header()->resizeSection( QGIS_CRS_ID_COLUMN, 0 );
6051
lstRecent->header()->setResizeMode( QGIS_CRS_ID_COLUMN, QHeaderView::Fixed );
52+
6153
// Hide (internal) ID column
6254
lstRecent->setColumnHidden( QGIS_CRS_ID_COLUMN, true );
6355

@@ -94,46 +86,44 @@ QgsProjectionSelector::QgsProjectionSelector( QWidget* parent, const char *name,
9486
}
9587
}
9688

97-
9889
QgsProjectionSelector::~QgsProjectionSelector()
9990
{
100-
// Save persistent list of projects
101-
QSettings settings;
102-
long crsId;
103-
10491
// Push current projection to front, only if set
105-
crsId = selectedCrsId();
106-
if ( crsId )
92+
long crsId = selectedCrsId();
93+
if ( crsId == 0 )
94+
return;
95+
96+
// Save persistent list of projects
97+
mRecentProjections.removeAll( QString::number( crsId ) );
98+
mRecentProjections.prepend( QString::number( crsId ) );
99+
// Prune size of list
100+
while ( mRecentProjections.size() > 8 )
107101
{
108-
mRecentProjections.removeAll( QString::number( crsId ) );
109-
mRecentProjections.prepend( QString::number( crsId ) );
110-
// Prune size of list
111-
while ( mRecentProjections.size() > 8 )
112-
{
113-
mRecentProjections.removeLast();
114-
}
115-
// Save to file *** Should be removed sometims in the future ***
116-
settings.setValue( "/UI/recentProjections", mRecentProjections );
102+
mRecentProjections.removeLast();
103+
}
104+
105+
// Save to file *** Should be removed sometims in the future ***
106+
QSettings settings;
107+
settings.setValue( "/UI/recentProjections", mRecentProjections );
117108

118-
// Convert to EPSG and proj4, and save those values also
109+
// Convert to EPSG and proj4, and save those values also
119110

120-
QStringList projectionsProj4;
121-
QStringList projectionsAuthId;
122-
for ( int i = 0; i < mRecentProjections.size(); i++ )
111+
QStringList projectionsProj4;
112+
QStringList projectionsAuthId;
113+
for ( int i = 0; i < mRecentProjections.size(); i++ )
114+
{
115+
// Create a crs from the crsId
116+
QgsCoordinateReferenceSystem crs( mRecentProjections.at( i ).toLong(), QgsCoordinateReferenceSystem::InternalCrsId );
117+
if ( ! crs.isValid() )
123118
{
124-
// Create a crs from the crsId
125-
QgsCoordinateReferenceSystem crs( mRecentProjections.at( i ).toLong(), QgsCoordinateReferenceSystem::InternalCrsId );
126-
if ( ! crs.isValid() )
127-
{
128-
// No? Skip this entry
129-
continue;
130-
}
131-
projectionsProj4 << crs.toProj4();
132-
projectionsAuthId << crs.authid();
119+
// No? Skip this entry
120+
continue;
133121
}
134-
settings.setValue( "/UI/recentProjectionsProj4", projectionsProj4 );
135-
settings.setValue( "/UI/recentProjectionsAuthId", projectionsAuthId );
122+
projectionsProj4 << crs.toProj4();
123+
projectionsAuthId << crs.authid();
136124
}
125+
settings.setValue( "/UI/recentProjectionsProj4", projectionsProj4 );
126+
settings.setValue( "/UI/recentProjectionsAuthId", projectionsAuthId );
137127
}
138128

139129
void QgsProjectionSelector::resizeEvent( QResizeEvent * theEvent )
@@ -151,23 +141,8 @@ void QgsProjectionSelector::showEvent( QShowEvent * theEvent )
151141
{
152142
// ensure the projection list view is actually populated
153143
// before we show this widget
154-
155-
if ( !mProjListDone )
156-
{
157-
loadCrsList( &mCrsFilter );
158-
}
159-
160-
if ( !mUserProjListDone )
161-
{
162-
loadUserCrsList( &mCrsFilter );
163-
}
164-
165-
// check if a paricular projection is waiting
166-
// to be pre-selected, and if so, to select it now.
167-
if ( mCRSNameSelectionPending || mCRSIDSelectionPending || mAuthIDSelectionPending )
168-
{
169-
applySelection();
170-
}
144+
loadCrsList( &mCrsFilter );
145+
loadUserCrsList( &mCrsFilter );
171146

172147
if ( !mRecentProjListDone )
173148
{
@@ -176,6 +151,9 @@ void QgsProjectionSelector::showEvent( QShowEvent * theEvent )
176151
mRecentProjListDone = true;
177152
}
178153

154+
// apply deferred selection
155+
applySelection();
156+
179157
// Pass up the inheritance hierarchy
180158
QWidget::showEvent( theEvent );
181159
}
@@ -186,9 +164,8 @@ QString QgsProjectionSelector::ogcWmsCrsFilterAsSqlExpression( QSet<QString> * c
186164
QMap<QString, QStringList> authParts;
187165

188166
if ( !crsFilter )
189-
{
190167
return sqlExpression;
191-
}
168+
192169
/*
193170
Ref: WMS 1.3.0, section 6.7.3 "Layer CRS":
194171
@@ -239,38 +216,14 @@ QString QgsProjectionSelector::ogcWmsCrsFilterAsSqlExpression( QSet<QString> * c
239216
return sqlExpression;
240217
}
241218

242-
243219
void QgsProjectionSelector::setSelectedCrsName( QString theCRSName )
244220
{
245-
mCRSNameSelection = theCRSName;
246-
mCRSNameSelectionPending = true;
247-
mCRSIDSelectionPending = false; // only one type can be pending at a time
248-
mAuthIDSelectionPending = true;
249-
250-
if ( isVisible() )
251-
{
252-
applySelection();
253-
}
254-
// else we will wait for the projection selector to
255-
// become visible (with the showEvent()) and set the
256-
// selection there
221+
applySelection( NAME_COLUMN, theCRSName );
257222
}
258223

259-
260224
void QgsProjectionSelector::setSelectedCrsId( long theCRSID )
261225
{
262-
mCRSIDSelection = theCRSID;
263-
mCRSIDSelectionPending = true;
264-
mCRSNameSelectionPending = false; // only one type can be pending at a time
265-
mAuthIDSelectionPending = false;
266-
267-
if ( isVisible() )
268-
{
269-
applySelection();
270-
}
271-
// else we will wait for the projection selector to
272-
// become visible (with the showEvent()) and set the
273-
// selection there
226+
applySelection( QGIS_CRS_ID_COLUMN, QString::number( theCRSID ) );
274227
}
275228

276229
void QgsProjectionSelector::setSelectedEpsg( long id )
@@ -280,53 +233,41 @@ void QgsProjectionSelector::setSelectedEpsg( long id )
280233

281234
void QgsProjectionSelector::setSelectedAuthId( QString id )
282235
{
283-
mAuthIDSelection = id;
284-
mCRSIDSelectionPending = false;
285-
mAuthIDSelectionPending = true;
286-
mCRSNameSelectionPending = false; // only one type can be pending at a time
236+
applySelection( AUTHID_COLUMN, id );
287237
}
288238

289-
void QgsProjectionSelector::applySelection()
239+
void QgsProjectionSelector::applySelection( int column, QString value )
290240
{
291241
if ( !mProjListDone || !mUserProjListDone )
292-
return;
293-
294-
QList<QTreeWidgetItem*> nodes;
295-
if ( mCRSNameSelectionPending )
296242
{
297-
//get the srid given the wkt so we can pick the correct list item
298-
QgsDebugMsg( "called with " + mCRSNameSelection );
299-
nodes = lstCoordinateSystems->findItems( mCRSNameSelection, Qt::MatchExactly | Qt::MatchRecursive, 0 );
300-
301-
mCRSNameSelectionPending = false;
243+
// defer selection until loaded
244+
mSearchColumn = column;
245+
mSearchValue = value;
246+
return;
302247
}
303248

304-
if ( mAuthIDSelectionPending )
249+
if ( column == NONE )
305250
{
306-
//get the srid given the wkt so we can pick the correct list item
307-
QgsDebugMsg( "called with " + mAuthIDSelection );
308-
nodes = lstCoordinateSystems->findItems( mAuthIDSelection, Qt::MatchExactly | Qt::MatchRecursive, AUTHID_COLUMN );
309-
310-
mAuthIDSelectionPending = false;
251+
// invoked deferred selection
252+
column = mSearchColumn;
253+
value = mSearchValue;
311254
}
312255

313-
if ( mCRSIDSelectionPending )
314-
{
315-
QString myCRSIDString = QString::number( mCRSIDSelection );
316-
317-
nodes = lstCoordinateSystems->findItems( myCRSIDString, Qt::MatchExactly | Qt::MatchRecursive, QGIS_CRS_ID_COLUMN );
318-
319-
mCRSIDSelectionPending = false;
320-
}
256+
if ( column == NONE )
257+
return;
321258

259+
QList<QTreeWidgetItem*> nodes = lstCoordinateSystems->findItems( value, Qt::MatchExactly | Qt::MatchRecursive, column );
322260
if ( nodes.count() > 0 )
323261
{
262+
QgsDebugMsg( QString( "found %1,%2" ).arg( column ).arg( value ) );
324263
lstCoordinateSystems->setCurrentItem( nodes.first() );
325-
lstCoordinateSystems->scrollToItem( lstCoordinateSystems->currentItem(), QAbstractItemView::PositionAtCenter );
326264
}
327-
else // unselect the selected item to avoid confusing the user
265+
else
328266
{
267+
QgsDebugMsg( "nothing found" );
268+
// unselect the selected item to avoid confusing the user
329269
lstCoordinateSystems->clearSelection();
270+
lstRecent->clearSelection();
330271
teProjection->setText( "" );
331272
}
332273
}
@@ -337,7 +278,6 @@ void QgsProjectionSelector::insertRecent( long theCrsId )
337278
return;
338279

339280
QList<QTreeWidgetItem*> nodes = lstCoordinateSystems->findItems( QString::number( theCrsId ), Qt::MatchExactly | Qt::MatchRecursive, QGIS_CRS_ID_COLUMN );
340-
341281
if ( nodes.count() == 0 )
342282
return;
343283

@@ -352,15 +292,9 @@ QString QgsProjectionSelector::selectedName()
352292
{
353293
// return the selected wkt name from the list view
354294
QTreeWidgetItem *lvi = lstCoordinateSystems->currentItem();
355-
if ( lvi )
356-
{
357-
return lvi->text( 0 );
358-
}
359-
else
360-
{
361-
return QString::null;
362-
}
295+
return lvi ? lvi->text( NAME_COLUMN ) : QString::null;
363296
}
297+
364298
// Returns the whole proj4 string for the selected projection node
365299
QString QgsProjectionSelector::selectedProj4String()
366300
{
@@ -370,87 +304,64 @@ QString QgsProjectionSelector::selectedProj4String()
370304
// system
371305
//
372306
// Get the selected node
373-
QTreeWidgetItem *myItem = lstCoordinateSystems->currentItem();
374-
if ( myItem )
375-
{
307+
QTreeWidgetItem *item = lstCoordinateSystems->currentItem();
308+
if ( !item || item->text( QGIS_CRS_ID_COLUMN ).isEmpty() )
309+
return "";
376310

377-
if ( myItem->text( QGIS_CRS_ID_COLUMN ).length() > 0 )
378-
{
379-
QString myDatabaseFileName;
380-
QString mySrsId = myItem->text( QGIS_CRS_ID_COLUMN );
381-
382-
QgsDebugMsg( "mySrsId = " + mySrsId );
383-
QgsDebugMsg( "USER_CRS_START_ID = " + QString::number( USER_CRS_START_ID ) );
384-
//
385-
// Determine if this is a user projection or a system on
386-
// user projection defs all have srs_id >= 100000
387-
//
388-
if ( mySrsId.toLong() >= USER_CRS_START_ID )
389-
{
390-
myDatabaseFileName = QgsApplication::qgisUserDbFilePath();
391-
QFileInfo myFileInfo;
392-
myFileInfo.setFile( myDatabaseFileName );
393-
if ( !myFileInfo.exists( ) ) //its unlikely that this condition will ever be reached
394-
{
395-
QgsDebugMsg( "users qgis.db not found" );
396-
return QString( "" );
397-
}
398-
else
399-
{
400-
QgsDebugMsg( "users qgis.db found" );
401-
}
402-
}
403-
else //must be a system projection then
404-
{
405-
myDatabaseFileName = mSrsDatabaseFileName;
406-
}
407-
QgsDebugMsg( "db = " + myDatabaseFileName );
311+
QString srsId = item->text( QGIS_CRS_ID_COLUMN );
408312

313+
QgsDebugMsg( "srsId = " + srsId );
314+
QgsDebugMsg( "USER_CRS_START_ID = " + QString::number( USER_CRS_START_ID ) );
409315

410-
sqlite3 *db;
411-
int rc;
412-
rc = sqlite3_open( myDatabaseFileName.toUtf8().data(), &db );
413-
if ( rc )
414-
{
415-
showDBMissingWarning( myDatabaseFileName );
416-
return QString( "" );
417-
}
418-
// prepare the sql statement
419-
const char *pzTail;
420-
sqlite3_stmt *ppStmt;
421-
QString sql = QString( "select parameters from tbl_srs where srs_id = %1" ).arg( mySrsId );
316+
//
317+
// Determine if this is a user projection or a system on
318+
// user projection defs all have srs_id >= 100000
319+
//
320+
QString databaseFileName;
321+
if ( srsId.toLong() >= USER_CRS_START_ID )
322+
{
323+
databaseFileName = QgsApplication::qgisUserDbFilePath();
324+
if ( !QFileInfo( databaseFileName ).exists() ) //its unlikely that this condition will ever be reached
325+
return QString( "" );
326+
}
327+
else //must be a system projection then
328+
{
329+
databaseFileName = mSrsDatabaseFileName;
330+
}
422331

423-
QgsDebugMsg( "Selection sql: " + sql );
332+
QgsDebugMsg( "db = " + databaseFileName );
424333

425-
rc = sqlite3_prepare( db, sql.toUtf8(), sql.toUtf8().length(), &ppStmt, &pzTail );
426-
// XXX Need to free memory from the error msg if one is set
427-
QString myProjString;
428-
if ( rc == SQLITE_OK )
429-
{
430-
if ( sqlite3_step( ppStmt ) == SQLITE_ROW )
431-
{
432-
myProjString = QString::fromUtf8(( char * )sqlite3_column_text( ppStmt, 0 ) );
433-
}
434-
}
435-
// close the statement
436-
sqlite3_finalize( ppStmt );
437-
// close the database
438-
sqlite3_close( db );
439-
assert( myProjString.length() > 0 );
440-
return myProjString;
441-
}
442-
else
443-
{
444-
// No node is selected, return null
445-
return QString( "" );
446-
}
334+
sqlite3 *database;
335+
int rc = sqlite3_open( databaseFileName.toUtf8().data(), &database );
336+
if ( rc )
337+
{
338+
showDBMissingWarning( databaseFileName );
339+
return "";
447340
}
448-
else
341+
342+
// prepare the sql statement
343+
const char *tail;
344+
sqlite3_stmt *stmt;
345+
QString sql = QString( "select parameters from tbl_srs where srs_id=%1" ).arg( srsId );
346+
347+
QgsDebugMsg( "Selection sql: " + sql );
348+
349+
rc = sqlite3_prepare( database, sql.toUtf8(), sql.toUtf8().length(), &stmt, &tail );
350+
// XXX Need to free memory from the error msg if one is set
351+
QString projString;
352+
if ( rc == SQLITE_OK && sqlite3_step( stmt ) == SQLITE_ROW )
449353
{
450-
// No node is selected, return null
451-
return QString( "" );
354+
projString = QString::fromUtf8(( char * )sqlite3_column_text( stmt, 0 ) );
452355
}
453356

357+
// close the statement
358+
sqlite3_finalize( stmt );
359+
// close the database
360+
sqlite3_close( database );
361+
362+
Q_ASSERT( !projString.isEmpty() );
363+
364+
return projString;
454365
}
455366

456367
QString QgsProjectionSelector::getSelectedExpression( QString expression )
@@ -460,77 +371,67 @@ QString QgsProjectionSelector::getSelectedExpression( QString expression )
460371
// selects a top-level node rather than an actual coordinate
461372
// system
462373
//
463-
// Get the selected node
374+
// Get the selected node and make sure it is a srs andx
375+
// not a top-level projection node
464376
QTreeWidgetItem *lvi = lstCoordinateSystems->currentItem();
465-
if ( lvi )
377+
if ( !lvi || lvi->text( QGIS_CRS_ID_COLUMN ).isEmpty() )
378+
return 0;
379+
380+
//
381+
// Determine if this is a user projection or a system on
382+
// user projection defs all have srs_id >= 100000
383+
//
384+
QString databaseFileName;
385+
if ( lvi->text( QGIS_CRS_ID_COLUMN ).toLong() >= USER_CRS_START_ID )
466386
{
467-
// Make sure the selected node is a srs and not a top-level projection node
468-
if ( lvi->text( QGIS_CRS_ID_COLUMN ).length() > 0 )
387+
databaseFileName = QgsApplication::qgisUserDbFilePath();
388+
if ( !QFileInfo( databaseFileName ).exists() )
469389
{
470-
QString myDatabaseFileName;
471-
//
472-
// Determine if this is a user projection or a system on
473-
// user projection defs all have srs_id >= 100000
474-
//
475-
if ( lvi->text( QGIS_CRS_ID_COLUMN ).toLong() >= USER_CRS_START_ID )
476-
{
477-
myDatabaseFileName = QgsApplication::qgisUserDbFilePath();
478-
QFileInfo myFileInfo;
479-
myFileInfo.setFile( myDatabaseFileName );
480-
if ( !myFileInfo.exists( ) )
481-
{
482-
QgsDebugMsg( " Projection selector : users qgis.db not found" );
483-
return 0;
484-
}
485-
}
486-
else //must be a system projection then
487-
{
488-
myDatabaseFileName = mSrsDatabaseFileName;
489-
}
490-
//
491-
// set up the database
492-
// XXX We could probabaly hold the database open for the life of this object,
493-
// assuming that it will never be used anywhere else. Given the low overhead,
494-
// opening it each time seems to be a reasonable approach at this time.
495-
sqlite3 *db;
496-
int rc;
497-
rc = sqlite3_open( myDatabaseFileName.toUtf8().data(), &db );
498-
if ( rc )
499-
{
500-
showDBMissingWarning( myDatabaseFileName );
501-
return 0;
502-
}
503-
// prepare the sql statement
504-
const char *pzTail;
505-
sqlite3_stmt *ppStmt;
506-
QString sql = QString( "select %1 from tbl_srs where srs_id=%2" )
507-
.arg( expression )
508-
.arg( lvi->text( QGIS_CRS_ID_COLUMN ) );
509-
510-
QgsDebugMsg( QString( "Finding selected attribute using : %1" ).arg( sql ) );
511-
rc = sqlite3_prepare( db, sql.toUtf8(), sql.toUtf8().length(), &ppStmt, &pzTail );
512-
// XXX Need to free memory from the error msg if one is set
513-
QString myAttributeValue;
514-
if ( rc == SQLITE_OK )
515-
{
516-
// get the first row of the result set
517-
if ( sqlite3_step( ppStmt ) == SQLITE_ROW )
518-
{
519-
// get the attribute
520-
myAttributeValue = QString::fromUtf8(( char * )sqlite3_column_text( ppStmt, 0 ) );
521-
}
522-
}
523-
// close the statement
524-
sqlite3_finalize( ppStmt );
525-
// close the database
526-
sqlite3_close( db );
527-
// return the srs
528-
return myAttributeValue;
390+
return 0;
529391
}
530392
}
393+
else
394+
{
395+
databaseFileName = mSrsDatabaseFileName;
396+
}
531397

532-
// No node is selected, return null
533-
return 0;
398+
//
399+
// set up the database
400+
// XXX We could probabaly hold the database open for the life of this object,
401+
// assuming that it will never be used anywhere else. Given the low overhead,
402+
// opening it each time seems to be a reasonable approach at this time.
403+
sqlite3 *database;
404+
int rc = sqlite3_open( databaseFileName.toUtf8().data(), &database );
405+
if ( rc )
406+
{
407+
showDBMissingWarning( databaseFileName );
408+
return 0;
409+
}
410+
411+
// prepare the sql statement
412+
const char *tail;
413+
sqlite3_stmt *stmt;
414+
QString sql = QString( "select %1 from tbl_srs where srs_id=%2" )
415+
.arg( expression )
416+
.arg( lvi->text( QGIS_CRS_ID_COLUMN ) );
417+
418+
QgsDebugMsg( QString( "Finding selected attribute using : %1" ).arg( sql ) );
419+
rc = sqlite3_prepare( database, sql.toUtf8(), sql.toUtf8().length(), &stmt, &tail );
420+
// XXX Need to free memory from the error msg if one is set
421+
QString attributeValue;
422+
if ( rc == SQLITE_OK && sqlite3_step( stmt ) == SQLITE_ROW )
423+
{
424+
// get the first row of the result set
425+
attributeValue = QString::fromUtf8(( char * )sqlite3_column_text( stmt, 0 ) );
426+
}
427+
428+
// close the statement
429+
sqlite3_finalize( stmt );
430+
// close the database
431+
sqlite3_close( database );
432+
433+
// return the srs
434+
return attributeValue;
534435
}
535436

536437
long QgsProjectionSelector::selectedEpsg()
@@ -566,14 +467,10 @@ long QgsProjectionSelector::selectedCrsId()
566467
{
567468
QTreeWidgetItem* item = lstCoordinateSystems->currentItem();
568469

569-
if ( item != NULL && item->text( QGIS_CRS_ID_COLUMN ).length() > 0 )
570-
{
470+
if ( item && !item->text( QGIS_CRS_ID_COLUMN ).isEmpty() )
571471
return lstCoordinateSystems->currentItem()->text( QGIS_CRS_ID_COLUMN ).toLong();
572-
}
573472
else
574-
{
575473
return 0;
576-
}
577474
}
578475

579476

@@ -585,9 +482,11 @@ void QgsProjectionSelector::setOgcWmsCrsFilter( QSet<QString> crsFilter )
585482
lstCoordinateSystems->clear();
586483
}
587484

588-
589-
void QgsProjectionSelector::loadUserCrsList( QSet<QString> * crsFilter )
485+
void QgsProjectionSelector::loadUserCrsList( QSet<QString> *crsFilter )
590486
{
487+
if ( mUserProjListDone )
488+
return;
489+
591490
QgsDebugMsg( "Fetching user projection list..." );
592491

593492
// convert our Coordinate Reference System filter into the SQL expression
@@ -605,64 +504,64 @@ void QgsProjectionSelector::loadUserCrsList( QSet<QString> * crsFilter )
605504

606505
//determine where the user proj database lives for this user. If none is found an empty
607506
//now only will be shown
608-
QString myDatabaseFileName = QgsApplication::qgisUserDbFilePath();
507+
QString databaseFileName = QgsApplication::qgisUserDbFilePath();
609508
// first we look for ~/.qgis/qgis.db
610509
// if it doesnt exist we copy it in from the global resources dir
611-
QFileInfo myFileInfo;
612-
myFileInfo.setFile( myDatabaseFileName );
510+
613511
//return straight away if the user has not created any custom projections
614-
if ( !myFileInfo.exists( ) )
512+
if ( !QFileInfo( databaseFileName ).exists( ) )
615513
{
616514
QgsDebugMsg( "Users qgis.db not found...skipping" );
617-
618515
mUserProjListDone = true;
619516
return;
620517
}
621518

622-
sqlite3 *myDatabase;
623-
const char *myTail;
624-
sqlite3_stmt *myPreparedStatement;
625-
int myResult;
519+
sqlite3 *database;
520+
const char *tail;
521+
sqlite3_stmt *stmt;
626522
//check the db is available
627-
myResult = sqlite3_open( QString( myDatabaseFileName ).toUtf8().data(), &myDatabase );
628-
if ( myResult )
523+
int result = sqlite3_open( databaseFileName.toUtf8().constData(), &database );
524+
if ( result )
629525
{
630526
// XXX This will likely never happen since on open, sqlite creates the
631527
// database if it does not exist. But we checked earlier for its existance
632528
// and aborted in that case. This is because we may be runnig from read only
633529
// media such as live cd and don't want to force trying to create a db.
634-
showDBMissingWarning( myDatabaseFileName );
530+
showDBMissingWarning( databaseFileName );
635531
return;
636532
}
637533

638534
// Set up the query to retrieve the projection information needed to populate the list
639-
QString mySql = QString( "select description, srs_id from vw_srs where %1" ).arg( sqlFilter );
535+
QString sql = QString( "select description, srs_id from vw_srs where %1" ).arg( sqlFilter );
640536

641-
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
537+
result = sqlite3_prepare( database, sql.toUtf8(), sql.toUtf8().length(), &stmt, &tail );
642538
// XXX Need to free memory from the error msg if one is set
643-
if ( myResult == SQLITE_OK )
539+
if ( result == SQLITE_OK )
644540
{
645541
QTreeWidgetItem *newItem;
646-
while ( sqlite3_step( myPreparedStatement ) == SQLITE_ROW )
542+
while ( sqlite3_step( stmt ) == SQLITE_ROW )
647543
{
648-
newItem = new QTreeWidgetItem( mUserProjList, QStringList( QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 0 ) ) ) );
544+
newItem = new QTreeWidgetItem( mUserProjList, QStringList( QString::fromUtf8(( char * )sqlite3_column_text( stmt, 0 ) ) ) );
649545
// EpsgCrsId for user projections is not always defined in some dbases.
650546
// It's also not written from customprojections dialog.
651547
// display the epsg (field 2) in the second column of the list view
652-
// newItem->setText( EPSG_COLUMN, QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 2 ) ) );
548+
// newItem->setText( EPSG_COLUMN, QString::fromUtf8(( char * )sqlite3_column_text( stmt, 2 ) ) );
653549
// display the qgis srs_id (field 1) in the third column of the list view
654-
newItem->setText( QGIS_CRS_ID_COLUMN, QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 1 ) ) );
550+
newItem->setText( QGIS_CRS_ID_COLUMN, QString::fromUtf8(( char * )sqlite3_column_text( stmt, 1 ) ) );
655551
}
656552
}
657553
// close the sqlite3 statement
658-
sqlite3_finalize( myPreparedStatement );
659-
sqlite3_close( myDatabase );
554+
sqlite3_finalize( stmt );
555+
sqlite3_close( database );
660556

661557
mUserProjListDone = true;
662558
}
663559

664560
void QgsProjectionSelector::loadCrsList( QSet<QString> *crsFilter )
665561
{
562+
if ( mProjListDone )
563+
return;
564+
666565
// convert our Coordinate Reference System filter into the SQL expression
667566
QString sqlFilter = ogcWmsCrsFilterAsSqlExpression( crsFilter );
668567

@@ -692,74 +591,70 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> *crsFilter )
692591
//read only filesystem because otherwise sqlite will try
693592
//to create the db file on the fly
694593

695-
QFileInfo myFileInfo;
696-
myFileInfo.setFile( mSrsDatabaseFileName );
697-
if ( !myFileInfo.exists( ) )
594+
if ( !QFileInfo( mSrsDatabaseFileName ).exists() )
698595
{
699596
mProjListDone = true;
700597
return;
701598
}
702599

703600
// open the database containing the spatial reference data
704-
sqlite3 *db;
705-
int rc;
706-
rc = sqlite3_open( mSrsDatabaseFileName.toUtf8().data(), &db );
601+
sqlite3 *database;
602+
int rc = sqlite3_open( mSrsDatabaseFileName.toUtf8().data(), &database );
707603
if ( rc )
708604
{
709605
// XXX This will likely never happen since on open, sqlite creates the
710606
// database if it does not exist.
711607
showDBMissingWarning( mSrsDatabaseFileName );
712-
return ;
608+
return;
713609
}
714610
// prepare the sql statement
715-
const char *pzTail;
716-
sqlite3_stmt *ppStmt;
611+
const char *tail;
612+
sqlite3_stmt *stmt;
717613
// get total count of records in the projection table
718614
QString sql = "select count(*) from tbl_srs";
719615

720-
rc = sqlite3_prepare( db, sql.toUtf8(), sql.toUtf8().length(), &ppStmt, &pzTail );
721-
assert( rc == SQLITE_OK );
722-
sqlite3_step( ppStmt );
723-
724-
sqlite3_finalize( ppStmt );
616+
rc = sqlite3_prepare( database, sql.toUtf8(), sql.toUtf8().length(), &stmt, &tail );
617+
Q_ASSERT( rc == SQLITE_OK );
618+
sqlite3_step( stmt );
619+
sqlite3_finalize( stmt );
725620

726621
// Set up the query to retrieve the projection information needed to populate the list
727622
//note I am giving the full field names for clarity here and in case someone
728623
//changes the underlying view TS
729624
sql = QString( "select description, srs_id, upper(auth_name||':'||auth_id), is_geo, name, parameters, deprecated from vw_srs where %1 order by name,description" )
730625
.arg( sqlFilter );
731626

732-
rc = sqlite3_prepare( db, sql.toUtf8(), sql.toUtf8().length(), &ppStmt, &pzTail );
627+
rc = sqlite3_prepare( database, sql.toUtf8(), sql.toUtf8().length(), &stmt, &tail );
733628
// XXX Need to free memory from the error msg if one is set
734629
if ( rc == SQLITE_OK )
735630
{
736631
QTreeWidgetItem *newItem;
737632
// Cache some stuff to speed up creating of the list of projected
738633
// spatial reference systems
739634
QString previousSrsType( "" );
740-
QTreeWidgetItem* previousSrsTypeNode = NULL;
635+
QTreeWidgetItem* previousSrsTypeNode = 0;
741636

742-
while ( sqlite3_step( ppStmt ) == SQLITE_ROW )
637+
while ( sqlite3_step( stmt ) == SQLITE_ROW )
743638
{
744639
// check to see if the srs is geographic
745-
int isGeo = sqlite3_column_int( ppStmt, 3 );
640+
int isGeo = sqlite3_column_int( stmt, 3 );
746641
if ( isGeo )
747642
{
748643
// this is a geographic coordinate system
749644
// Add it to the tree (field 0)
750-
newItem = new QTreeWidgetItem( mGeoList, QStringList( QString::fromUtf8(( char * )sqlite3_column_text( ppStmt, 0 ) ) ) );
645+
newItem = new QTreeWidgetItem( mGeoList, QStringList( QString::fromUtf8(( char * )sqlite3_column_text( stmt, 0 ) ) ) );
751646

752647
// display the authority name (field 2) in the second column of the list view
753-
newItem->setText( AUTHID_COLUMN, QString::fromUtf8(( char * )sqlite3_column_text( ppStmt, 2 ) ) );
648+
newItem->setText( AUTHID_COLUMN, QString::fromUtf8(( char * )sqlite3_column_text( stmt, 2 ) ) );
754649

755650
// display the qgis srs_id (field 1) in the third column of the list view
756-
newItem->setText( QGIS_CRS_ID_COLUMN, QString::fromUtf8(( char * )sqlite3_column_text( ppStmt, 1 ) ) );
651+
newItem->setText( QGIS_CRS_ID_COLUMN, QString::fromUtf8(( char * )sqlite3_column_text( stmt, 1 ) ) );
757652
}
758653
else
759654
{
760655
// This is a projected srs
761656
QTreeWidgetItem *node;
762-
QString srsType = QString::fromUtf8(( char* )sqlite3_column_text( ppStmt, 4 ) );
657+
QString srsType = QString::fromUtf8(( char* )sqlite3_column_text( stmt, 4 ) );
763658
// Find the node for this type and add the projection to it
764659
// If the node doesn't exist, create it
765660
if ( srsType == previousSrsType )
@@ -768,13 +663,12 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> *crsFilter )
768663
}
769664
else
770665
{ // Different from last one, need to search
771-
QList<QTreeWidgetItem*> nodes = lstCoordinateSystems->findItems( srsType, Qt::MatchExactly | Qt::MatchRecursive, 0 );
666+
QList<QTreeWidgetItem*> nodes = lstCoordinateSystems->findItems( srsType, Qt::MatchExactly | Qt::MatchRecursive, NAME_COLUMN );
772667
if ( nodes.count() == 0 )
773668
{
774669
// the node doesn't exist -- create it
775670
// Make in an italic font to distinguish them from real projections
776671
node = new QTreeWidgetItem( mProjList, QStringList( srsType ) );
777-
778672
QFont fontTemp = node->font( 0 );
779673
fontTemp.setItalic( true );
780674
node->setFont( 0, fontTemp );
@@ -788,53 +682,77 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> *crsFilter )
788682
previousSrsTypeNode = node;
789683
}
790684
// add the item, setting the projection name in the first column of the list view
791-
newItem = new QTreeWidgetItem( node, QStringList( QString::fromUtf8(( char * )sqlite3_column_text( ppStmt, 0 ) ) ) );
685+
newItem = new QTreeWidgetItem( node, QStringList( QString::fromUtf8(( char * )sqlite3_column_text( stmt, 0 ) ) ) );
792686
// display the authority id (field 2) in the second column of the list view
793-
newItem->setText( AUTHID_COLUMN, QString::fromUtf8(( char * )sqlite3_column_text( ppStmt, 2 ) ) );
687+
newItem->setText( AUTHID_COLUMN, QString::fromUtf8(( char * )sqlite3_column_text( stmt, 2 ) ) );
794688
// display the qgis srs_id (field 1) in the third column of the list view
795-
newItem->setText( QGIS_CRS_ID_COLUMN, QString::fromUtf8(( char * )sqlite3_column_text( ppStmt, 1 ) ) );
689+
newItem->setText( QGIS_CRS_ID_COLUMN, QString::fromUtf8(( char * )sqlite3_column_text( stmt, 1 ) ) );
796690
// expand also parent node
797691
newItem->parent()->setExpanded( true );
798692
}
799693

800694
// display the qgis deprecated in the user data of the item
801-
newItem->setData( 0, Qt::UserRole, QString::fromUtf8(( char * )sqlite3_column_text( ppStmt, 6 ) ) );
695+
newItem->setData( 0, Qt::UserRole, QString::fromUtf8(( char * )sqlite3_column_text( stmt, 6 ) ) );
802696
newItem->setHidden( cbxHideDeprecated->isChecked() );
803697
}
804698
mProjList->setExpanded( true );
805699
}
700+
806701
// close the sqlite3 statement
807-
sqlite3_finalize( ppStmt );
702+
sqlite3_finalize( stmt );
808703
// close the database
809-
sqlite3_close( db );
704+
sqlite3_close( database );
810705

811706
mProjListDone = true;
812707
}
813708

814709
// New coordinate system selected from the list
815-
void QgsProjectionSelector::coordinateSystemSelected( QTreeWidgetItem * theItem )
710+
void QgsProjectionSelector::on_lstCoordinateSystems_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem * )
816711
{
712+
QgsDebugMsg( "Entered." );
713+
lstCoordinateSystems->scrollToItem( current );
714+
817715
// If the item has children, it's not an end node in the tree, and
818716
// hence is just a grouping thingy, not an actual CRS.
819-
if ( theItem && theItem->childCount() == 0 )
717+
if ( current && current->childCount() == 0 )
820718
{
821719
// Found a real CRS
822720
emit sridSelected( QString::number( selectedCrsId() ) );
823-
QString myProjString = selectedProj4String();
824-
lstCoordinateSystems->scrollToItem( theItem );
825-
teProjection->setText( myProjString );
826721

827-
lstRecent->clearSelection();
722+
teProjection->setText( selectedProj4String() );
723+
724+
QList<QTreeWidgetItem*> nodes = lstRecent->findItems( current->text( QGIS_CRS_ID_COLUMN ), Qt::MatchExactly, QGIS_CRS_ID_COLUMN );
725+
if ( nodes.count() > 0 )
726+
{
727+
QgsDebugMsg( QString( "found srs %1 in recent" ).arg( current->text( QGIS_CRS_ID_COLUMN ) ) );
728+
lstRecent->setCurrentItem( nodes.first() );
729+
}
730+
else
731+
{
732+
QgsDebugMsg( QString( "srs %1 not recent" ).arg( current->text( QGIS_CRS_ID_COLUMN ) ) );
733+
lstRecent->clearSelection();
734+
}
828735
}
829736
else
830737
{
831738
// Not an CRS - remove the highlight so the user doesn't get too confused
832-
if ( theItem )
833-
theItem->setSelected( false );
739+
if ( current )
740+
current->setSelected( false );
834741
teProjection->setText( "" );
742+
lstRecent->clearSelection();
835743
}
836744
}
837745

746+
void QgsProjectionSelector::on_lstRecent_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem * )
747+
{
748+
QgsDebugMsg( "Entered." );
749+
lstRecent->scrollToItem( current );
750+
751+
QList<QTreeWidgetItem*> nodes = lstCoordinateSystems->findItems( current->text( QGIS_CRS_ID_COLUMN ), Qt::MatchExactly | Qt::MatchRecursive, QGIS_CRS_ID_COLUMN );
752+
if ( nodes.count() > 0 )
753+
lstCoordinateSystems->setCurrentItem( nodes.first() );
754+
}
755+
838756
void QgsProjectionSelector::hideDeprecated( QTreeWidgetItem *item )
839757
{
840758
if ( item->data( 0, Qt::UserRole ).toBool() )
@@ -857,12 +775,6 @@ void QgsProjectionSelector::on_cbxHideDeprecated_stateChanged()
857775
hideDeprecated( lstCoordinateSystems->topLevelItem( i ) );
858776
}
859777

860-
void QgsProjectionSelector::on_lstRecent_itemClicked( QTreeWidgetItem * item )
861-
{
862-
setSelectedCrsId( item->text( QGIS_CRS_ID_COLUMN ).toLong() );
863-
item->setSelected( true );
864-
}
865-
866778
void QgsProjectionSelector::on_leSearch_textChanged( const QString & theFilterTxt )
867779
{
868780
// filter recent crs's
@@ -877,7 +789,7 @@ void QgsProjectionSelector::on_leSearch_textChanged( const QString & theFilterTx
877789
{
878790
( *itr )->setHidden( false );
879791
QTreeWidgetItem * parent = ( *itr )->parent();
880-
while ( parent != NULL )
792+
while ( parent )
881793
{
882794
parent->setExpanded( true );
883795
parent->setHidden( false );
@@ -895,6 +807,7 @@ void QgsProjectionSelector::on_leSearch_textChanged( const QString & theFilterTx
895807
}
896808
++itr;
897809
}
810+
898811
// filter crs's
899812
QTreeWidgetItemIterator it( lstCoordinateSystems );
900813
while ( *it )
@@ -907,7 +820,7 @@ void QgsProjectionSelector::on_leSearch_textChanged( const QString & theFilterTx
907820
{
908821
( *it )->setHidden( false );
909822
QTreeWidgetItem * parent = ( *it )->parent();
910-
while ( parent != NULL )
823+
while ( parent )
911824
{
912825
parent->setExpanded( true );
913826
parent->setHidden( false );
@@ -930,113 +843,104 @@ void QgsProjectionSelector::on_leSearch_textChanged( const QString & theFilterTx
930843

931844
long QgsProjectionSelector::getLargestCRSIDMatch( QString theSql )
932845
{
933-
long mySrsId = 0;
846+
long srsId = 0;
847+
934848
//
935849
// Now perform the actual search
936850
//
937851

938-
sqlite3 *myDatabase;
939-
const char *myTail;
940-
sqlite3_stmt *myPreparedStatement;
941-
int myResult;
852+
sqlite3 *database;
853+
const char *tail;
854+
sqlite3_stmt *stmt;
855+
int result;
942856

943857
// first we search the users db as any srsid there will be definition be greater than in sys db
944858

945859
//check the db is available
946-
QString myDatabaseFileName = QgsApplication::qgisUserDbFilePath();
947-
QFileInfo myFileInfo;
948-
myFileInfo.setFile( myDatabaseFileName );
949-
if ( myFileInfo.exists( ) ) //only bother trying to open if the file exists
860+
QString databaseFileName = QgsApplication::qgisUserDbFilePath();
861+
if ( QFileInfo( databaseFileName ).exists() ) //only bother trying to open if the file exists
950862
{
951-
myResult = sqlite3_open( myDatabaseFileName.toUtf8().data(), &myDatabase );
952-
if ( myResult )
863+
result = sqlite3_open( databaseFileName.toUtf8().data(), &database );
864+
if ( result )
953865
{
954866
// XXX This will likely never happen since on open, sqlite creates the
955867
// database if it does not exist. But we checked earlier for its existance
956868
// and aborted in that case. This is because we may be runnig from read only
957869
// media such as live cd and don't want to force trying to create a db.
958-
showDBMissingWarning( myDatabaseFileName );
870+
showDBMissingWarning( databaseFileName );
959871
return 0;
960872
}
961-
else
873+
874+
result = sqlite3_prepare( database, theSql.toUtf8(), theSql.toUtf8().length(), &stmt, &tail );
875+
// XXX Need to free memory from the error msg if one is set
876+
if ( result == SQLITE_OK && sqlite3_step( stmt ) == SQLITE_ROW )
962877
{
963-
myResult = sqlite3_prepare( myDatabase, theSql.toUtf8(), theSql.toUtf8().length(), &myPreparedStatement, &myTail );
964-
// XXX Need to free memory from the error msg if one is set
965-
if ( myResult == SQLITE_OK )
966-
{
967-
myResult = sqlite3_step( myPreparedStatement );
968-
if ( myResult == SQLITE_ROW )
969-
{
970-
QString mySrsIdString = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 0 ) );
971-
mySrsId = mySrsIdString.toLong();
972-
// close the sqlite3 statement
973-
sqlite3_finalize( myPreparedStatement );
974-
sqlite3_close( myDatabase );
975-
return mySrsId;
976-
}
977-
}
878+
QString srsIdString = QString::fromUtf8(( char * )sqlite3_column_text( stmt, 0 ) );
879+
srsId = srsIdString.toLong();
880+
// close the sqlite3 statement
881+
sqlite3_finalize( stmt );
882+
sqlite3_close( database );
883+
return srsId;
978884
}
979885
}
980-
981-
//only bother looking in srs.db if it wasnt found above
982-
983-
myResult = sqlite3_open( mSrsDatabaseFileName.toUtf8().data(), &myDatabase );
984-
if ( myResult )
886+
else
985887
{
986-
QgsDebugMsg( QString( "Can't open * user * database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
987-
//no need for assert because user db may not have been created yet
988-
return 0;
888+
//only bother looking in srs.db if it wasnt found above
889+
result = sqlite3_open( mSrsDatabaseFileName.toUtf8().data(), &database );
890+
if ( result )
891+
{
892+
QgsDebugMsg( QString( "Can't open * user * database: %1" ).arg( sqlite3_errmsg( database ) ) );
893+
//no need for assert because user db may not have been created yet
894+
return 0;
895+
}
989896
}
990897

991-
myResult = sqlite3_prepare( myDatabase, theSql.toUtf8(), theSql.toUtf8().length(), &myPreparedStatement, &myTail );
898+
result = sqlite3_prepare( database, theSql.toUtf8(), theSql.toUtf8().length(), &stmt, &tail );
992899
// XXX Need to free memory from the error msg if one is set
993-
if ( myResult == SQLITE_OK )
900+
if ( result == SQLITE_OK && sqlite3_step( stmt ) == SQLITE_ROW )
994901
{
995-
myResult = sqlite3_step( myPreparedStatement );
996-
if ( myResult == SQLITE_ROW )
997-
{
998-
QString mySrsIdString = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 0 ) );
999-
mySrsId = mySrsIdString.toLong();
1000-
// close the sqlite3 statement
1001-
sqlite3_finalize( myPreparedStatement );
1002-
sqlite3_close( myDatabase );
1003-
}
902+
QString srsIdString = QString::fromUtf8(( char * )sqlite3_column_text( stmt, 0 ) );
903+
srsId = srsIdString.toLong();
1004904
}
1005-
return mySrsId;
905+
906+
// close the sqlite3 statement
907+
sqlite3_finalize( stmt );
908+
sqlite3_close( database );
909+
910+
return srsId;
1006911
}
1007912

1008913
QStringList QgsProjectionSelector::authorities()
1009914
{
1010-
sqlite3 *myDatabase;
1011-
const char *myTail;
1012-
sqlite3_stmt *myPreparedStatement;
1013-
int myResult;
915+
sqlite3 *database;
916+
const char *tail;
917+
sqlite3_stmt *stmt;
1014918

1015-
myResult = sqlite3_open( mSrsDatabaseFileName.toUtf8().data(), &myDatabase );
1016-
if ( myResult )
919+
int result = sqlite3_open( mSrsDatabaseFileName.toUtf8().data(), &database );
920+
if ( result )
1017921
{
1018-
QgsDebugMsg( QString( "Can't open * user * database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
922+
QgsDebugMsg( QString( "Can't open * user * database: %1" ).arg( sqlite3_errmsg( database ) ) );
1019923
//no need for assert because user db may not have been created yet
1020924
return QStringList();
1021925
}
1022926

1023927
QString theSql = "select distinct auth_name from tbl_srs";
1024-
myResult = sqlite3_prepare( myDatabase, theSql.toUtf8(), theSql.toUtf8().length(), &myPreparedStatement, &myTail );
928+
result = sqlite3_prepare( database, theSql.toUtf8(), theSql.toUtf8().length(), &stmt, &tail );
1025929

1026930
QStringList authorities;
1027-
1028-
if ( myResult == SQLITE_OK )
931+
if ( result == SQLITE_OK )
1029932
{
1030-
while ( sqlite3_step( myPreparedStatement ) == SQLITE_ROW )
933+
while ( sqlite3_step( stmt ) == SQLITE_ROW )
1031934
{
1032-
authorities << QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 0 ) );
935+
authorities << QString::fromUtf8(( char * )sqlite3_column_text( stmt, 0 ) );
1033936
}
1034937

1035-
// close the sqlite3 statement
1036-
sqlite3_finalize( myPreparedStatement );
1037-
sqlite3_close( myDatabase );
1038938
}
1039939

940+
// close the sqlite3 statement
941+
sqlite3_finalize( stmt );
942+
sqlite3_close( database );
943+
1040944
return authorities;
1041945
}
1042946

@@ -1051,12 +955,12 @@ QStringList QgsProjectionSelector::authorities()
1051955
*/
1052956
const QString QgsProjectionSelector::sqlSafeString( const QString theSQL )
1053957
{
1054-
QString myRetval = theSQL;
1055-
myRetval.replace( "\\", "\\\\" );
1056-
myRetval.replace( '\"', "\\\"" );
1057-
myRetval.replace( "\'", "\\'" );
1058-
myRetval.replace( "%", "\\%" );
1059-
return myRetval;
958+
QString retval = theSQL;
959+
retval.replace( "\\", "\\\\" );
960+
retval.replace( '\"', "\\\"" );
961+
retval.replace( "\'", "\\'" );
962+
retval.replace( "%", "\\%" );
963+
return retval;
1060964
}
1061965

1062966
void QgsProjectionSelector::showDBMissingWarning( const QString theFileName )

‎src/gui/qgsprojectionselector.h

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
2929
{
3030
Q_OBJECT
3131
public:
32-
QgsProjectionSelector( QWidget* parent,
33-
const char * name = "",
34-
Qt::WFlags fl = 0 );
32+
QgsProjectionSelector( QWidget* parent, const char *name = "", Qt::WFlags fl = 0 );
3533

3634
~QgsProjectionSelector();
3735

@@ -44,7 +42,7 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
4442
*
4543
* \todo Should this be public?
4644
*/
47-
void loadUserCrsList( QSet<QString> * crsFilter = 0 );
45+
void loadUserCrsList( QSet<QString> *crsFilter = 0 );
4846

4947
/**
5048
* \brief Populate the proj tree view with system projection names...
@@ -55,8 +53,7 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
5553
*
5654
* \todo Should this be public?
5755
*/
58-
void loadCrsList( QSet<QString> * crsFilter = 0 );
59-
56+
void loadCrsList( QSet<QString> *crsFilter = 0 );
6057

6158
/*!
6259
* \brief Make the string safe for use in SQL statements.
@@ -113,7 +110,8 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
113110
* \warning This function's behaviour is undefined if it is called after the widget is shown.
114111
*/
115112
void setOgcWmsCrsFilter( QSet<QString> crsFilter );
116-
void on_lstRecent_itemClicked( QTreeWidgetItem * );
113+
void on_lstCoordinateSystems_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem *prev );
114+
void on_lstRecent_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem *prev );
117115
void on_cbxHideDeprecated_stateChanged();
118116
void on_leSearch_textChanged( const QString & );
119117

@@ -148,7 +146,7 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
148146
* does not scroll the list to the selection if the widget is not visible.
149147
* Therefore you will typically want to use this in a showEvent().
150148
*/
151-
void applySelection();
149+
void applySelection( int column = NONE, QString value = QString::null );
152150

153151
/**
154152
* \brief gets an arbitrary sqlite3 expression from the selection
@@ -189,23 +187,9 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
189187
//! Has the Recent Projection List been populated?
190188
bool mRecentProjListDone;
191189

192-
//! Is there a pending selection to be made by CRS Name?
193-
bool mCRSNameSelectionPending;
194-
195-
//! Is there a pending selection to be made by CRS ID?
196-
bool mCRSIDSelectionPending;
197-
198-
//! Is there a pending selection to be made by Authority ID?
199-
bool mAuthIDSelectionPending;
200-
201-
//! The CRS Name that wants to be selected on this widget
202-
QString mCRSNameSelection;
203-
204-
//! The CRS ID that wants to be selected on this widget
205-
long mCRSIDSelection;
206-
207-
//! The Authority ID that wants to be selected on this widget
208-
QString mAuthIDSelection;
190+
enum columns { NAME_COLUMN, AUTHID_COLUMN, QGIS_CRS_ID_COLUMN, NONE };
191+
int mSearchColumn;
192+
QString mSearchValue;
209193

210194
//! The set of OGC WMS CRSs that want to be applied to this widget
211195
QSet<QString> mCrsFilter;
@@ -217,11 +201,6 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
217201
void hideDeprecated( QTreeWidgetItem *item );
218202

219203
private slots:
220-
/**private handler for when user selects a cs
221-
*it will cause wktSelected and sridSelected events to be spawned
222-
*/
223-
void coordinateSystemSelected( QTreeWidgetItem* );
224-
225204
//! get list of authorities
226205
QStringList authorities();
227206

0 commit comments

Comments
 (0)
Please sign in to comment.