11
11
#include < qgsprojectionselector.h>
12
12
13
13
// standard includes
14
- #include < cassert>
15
14
#include < sqlite3.h>
16
15
17
16
// qgis includes
18
17
#include " qgis.h" // magic numbers here
19
18
#include " qgsapplication.h"
20
19
#include " qgslogger.h"
21
- #include < qgscoordinatereferencesystem.h>
20
+ #include " qgscoordinatereferencesystem.h"
22
21
23
22
// qt includes
24
- #include < QDir>
25
23
#include < QFileInfo>
26
- #include < QTextStream>
27
24
#include < QHeaderView>
28
25
#include < QResizeEvent>
29
26
#include < QMessageBox>
30
27
#include < QSettings>
31
28
32
- const int NAME_COLUMN = 0 ;
33
- const int AUTHID_COLUMN = 1 ;
34
- const int QGIS_CRS_ID_COLUMN = 2 ;
35
-
36
29
QgsProjectionSelector::QgsProjectionSelector ( QWidget* parent, const char *name, Qt::WFlags fl )
37
30
: QWidget( parent, fl )
38
31
, mProjListDone( false )
39
32
, mUserProjListDone( false )
40
33
, mRecentProjListDone( false )
41
- , mCRSNameSelectionPending( false )
42
- , mCRSIDSelectionPending( false )
43
- , mAuthIDSelectionPending( false )
34
+ , mSearchColumn( NONE )
44
35
{
45
36
Q_UNUSED ( name );
46
37
setupUi ( this );
47
- connect ( lstCoordinateSystems, SIGNAL ( currentItemChanged ( QTreeWidgetItem*, QTreeWidgetItem* ) ),
48
- this , SLOT ( coordinateSystemSelected ( QTreeWidgetItem* ) ) );
49
38
50
39
// Get the full path name to the sqlite3 spatial reference database.
51
40
mSrsDatabaseFileName = QgsApplication::srsDbFilePath ();
41
+
52
42
lstCoordinateSystems->header ()->setResizeMode ( AUTHID_COLUMN, QHeaderView::Stretch );
53
43
lstCoordinateSystems->header ()->resizeSection ( QGIS_CRS_ID_COLUMN, 0 );
54
44
lstCoordinateSystems->header ()->setResizeMode ( QGIS_CRS_ID_COLUMN, QHeaderView::Fixed );
45
+
55
46
// Hide (internal) ID column
56
47
lstCoordinateSystems->setColumnHidden ( QGIS_CRS_ID_COLUMN, true );
57
48
58
49
lstRecent->header ()->setResizeMode ( AUTHID_COLUMN, QHeaderView::Stretch );
59
50
lstRecent->header ()->resizeSection ( QGIS_CRS_ID_COLUMN, 0 );
60
51
lstRecent->header ()->setResizeMode ( QGIS_CRS_ID_COLUMN, QHeaderView::Fixed );
52
+
61
53
// Hide (internal) ID column
62
54
lstRecent->setColumnHidden ( QGIS_CRS_ID_COLUMN, true );
63
55
@@ -94,46 +86,44 @@ QgsProjectionSelector::QgsProjectionSelector( QWidget* parent, const char *name,
94
86
}
95
87
}
96
88
97
-
98
89
QgsProjectionSelector::~QgsProjectionSelector ()
99
90
{
100
- // Save persistent list of projects
101
- QSettings settings;
102
- long crsId;
103
-
104
91
// 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 )
107
101
{
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 );
117
108
118
- // Convert to EPSG and proj4, and save those values also
109
+ // Convert to EPSG and proj4, and save those values also
119
110
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 () )
123
118
{
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 ;
133
121
}
134
- settings. setValue ( " /UI/recentProjectionsProj4 " , projectionsProj4 );
135
- settings. setValue ( " /UI/recentProjectionsAuthId " , projectionsAuthId );
122
+ projectionsProj4 << crs. toProj4 ( );
123
+ projectionsAuthId << crs. authid ( );
136
124
}
125
+ settings.setValue ( " /UI/recentProjectionsProj4" , projectionsProj4 );
126
+ settings.setValue ( " /UI/recentProjectionsAuthId" , projectionsAuthId );
137
127
}
138
128
139
129
void QgsProjectionSelector::resizeEvent ( QResizeEvent * theEvent )
@@ -151,23 +141,8 @@ void QgsProjectionSelector::showEvent( QShowEvent * theEvent )
151
141
{
152
142
// ensure the projection list view is actually populated
153
143
// 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 );
171
146
172
147
if ( !mRecentProjListDone )
173
148
{
@@ -176,6 +151,9 @@ void QgsProjectionSelector::showEvent( QShowEvent * theEvent )
176
151
mRecentProjListDone = true ;
177
152
}
178
153
154
+ // apply deferred selection
155
+ applySelection ();
156
+
179
157
// Pass up the inheritance hierarchy
180
158
QWidget::showEvent ( theEvent );
181
159
}
@@ -186,9 +164,8 @@ QString QgsProjectionSelector::ogcWmsCrsFilterAsSqlExpression( QSet<QString> * c
186
164
QMap<QString, QStringList> authParts;
187
165
188
166
if ( !crsFilter )
189
- {
190
167
return sqlExpression;
191
- }
168
+
192
169
/*
193
170
Ref: WMS 1.3.0, section 6.7.3 "Layer CRS":
194
171
@@ -239,38 +216,14 @@ QString QgsProjectionSelector::ogcWmsCrsFilterAsSqlExpression( QSet<QString> * c
239
216
return sqlExpression;
240
217
}
241
218
242
-
243
219
void QgsProjectionSelector::setSelectedCrsName ( QString theCRSName )
244
220
{
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 );
257
222
}
258
223
259
-
260
224
void QgsProjectionSelector::setSelectedCrsId ( long theCRSID )
261
225
{
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 ) );
274
227
}
275
228
276
229
void QgsProjectionSelector::setSelectedEpsg ( long id )
@@ -280,53 +233,41 @@ void QgsProjectionSelector::setSelectedEpsg( long id )
280
233
281
234
void QgsProjectionSelector::setSelectedAuthId ( QString id )
282
235
{
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 );
287
237
}
288
238
289
- void QgsProjectionSelector::applySelection ()
239
+ void QgsProjectionSelector::applySelection ( int column, QString value )
290
240
{
291
241
if ( !mProjListDone || !mUserProjListDone )
292
- return ;
293
-
294
- QList<QTreeWidgetItem*> nodes;
295
- if ( mCRSNameSelectionPending )
296
242
{
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 ;
302
247
}
303
248
304
- if ( mAuthIDSelectionPending )
249
+ if ( column == NONE )
305
250
{
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 ;
311
254
}
312
255
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 ;
321
258
259
+ QList<QTreeWidgetItem*> nodes = lstCoordinateSystems->findItems ( value, Qt::MatchExactly | Qt::MatchRecursive, column );
322
260
if ( nodes.count () > 0 )
323
261
{
262
+ QgsDebugMsg ( QString ( " found %1,%2" ).arg ( column ).arg ( value ) );
324
263
lstCoordinateSystems->setCurrentItem ( nodes.first () );
325
- lstCoordinateSystems->scrollToItem ( lstCoordinateSystems->currentItem (), QAbstractItemView::PositionAtCenter );
326
264
}
327
- else // unselect the selected item to avoid confusing the user
265
+ else
328
266
{
267
+ QgsDebugMsg ( " nothing found" );
268
+ // unselect the selected item to avoid confusing the user
329
269
lstCoordinateSystems->clearSelection ();
270
+ lstRecent->clearSelection ();
330
271
teProjection->setText ( " " );
331
272
}
332
273
}
@@ -337,7 +278,6 @@ void QgsProjectionSelector::insertRecent( long theCrsId )
337
278
return ;
338
279
339
280
QList<QTreeWidgetItem*> nodes = lstCoordinateSystems->findItems ( QString::number ( theCrsId ), Qt::MatchExactly | Qt::MatchRecursive, QGIS_CRS_ID_COLUMN );
340
-
341
281
if ( nodes.count () == 0 )
342
282
return ;
343
283
@@ -352,15 +292,9 @@ QString QgsProjectionSelector::selectedName()
352
292
{
353
293
// return the selected wkt name from the list view
354
294
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;
363
296
}
297
+
364
298
// Returns the whole proj4 string for the selected projection node
365
299
QString QgsProjectionSelector::selectedProj4String ()
366
300
{
@@ -370,87 +304,64 @@ QString QgsProjectionSelector::selectedProj4String()
370
304
// system
371
305
//
372
306
// 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 " " ;
376
310
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 );
408
312
313
+ QgsDebugMsg ( " srsId = " + srsId );
314
+ QgsDebugMsg ( " USER_CRS_START_ID = " + QString::number ( USER_CRS_START_ID ) );
409
315
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
+ }
422
331
423
- QgsDebugMsg ( " Selection sql: " + sql );
332
+ QgsDebugMsg ( " db = " + databaseFileName );
424
333
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 " " ;
447
340
}
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 )
449
353
{
450
- // No node is selected, return null
451
- return QString ( " " );
354
+ projString = QString::fromUtf8 (( char * )sqlite3_column_text ( stmt, 0 ) );
452
355
}
453
356
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;
454
365
}
455
366
456
367
QString QgsProjectionSelector::getSelectedExpression ( QString expression )
@@ -460,77 +371,67 @@ QString QgsProjectionSelector::getSelectedExpression( QString expression )
460
371
// selects a top-level node rather than an actual coordinate
461
372
// system
462
373
//
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
464
376
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 )
466
386
{
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 () )
469
389
{
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 ;
529
391
}
530
392
}
393
+ else
394
+ {
395
+ databaseFileName = mSrsDatabaseFileName ;
396
+ }
531
397
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;
534
435
}
535
436
536
437
long QgsProjectionSelector::selectedEpsg ()
@@ -566,14 +467,10 @@ long QgsProjectionSelector::selectedCrsId()
566
467
{
567
468
QTreeWidgetItem* item = lstCoordinateSystems->currentItem ();
568
469
569
- if ( item != NULL && item->text ( QGIS_CRS_ID_COLUMN ).length () > 0 )
570
- {
470
+ if ( item && !item->text ( QGIS_CRS_ID_COLUMN ).isEmpty () )
571
471
return lstCoordinateSystems->currentItem ()->text ( QGIS_CRS_ID_COLUMN ).toLong ();
572
- }
573
472
else
574
- {
575
473
return 0 ;
576
- }
577
474
}
578
475
579
476
@@ -585,9 +482,11 @@ void QgsProjectionSelector::setOgcWmsCrsFilter( QSet<QString> crsFilter )
585
482
lstCoordinateSystems->clear ();
586
483
}
587
484
588
-
589
- void QgsProjectionSelector::loadUserCrsList ( QSet<QString> * crsFilter )
485
+ void QgsProjectionSelector::loadUserCrsList ( QSet<QString> *crsFilter )
590
486
{
487
+ if ( mUserProjListDone )
488
+ return ;
489
+
591
490
QgsDebugMsg ( " Fetching user projection list..." );
592
491
593
492
// convert our Coordinate Reference System filter into the SQL expression
@@ -605,64 +504,64 @@ void QgsProjectionSelector::loadUserCrsList( QSet<QString> * crsFilter )
605
504
606
505
// determine where the user proj database lives for this user. If none is found an empty
607
506
// now only will be shown
608
- QString myDatabaseFileName = QgsApplication::qgisUserDbFilePath ();
507
+ QString databaseFileName = QgsApplication::qgisUserDbFilePath ();
609
508
// first we look for ~/.qgis/qgis.db
610
509
// if it doesnt exist we copy it in from the global resources dir
611
- QFileInfo myFileInfo;
612
- myFileInfo.setFile ( myDatabaseFileName );
510
+
613
511
// return straight away if the user has not created any custom projections
614
- if ( !myFileInfo .exists ( ) )
512
+ if ( !QFileInfo ( databaseFileName ) .exists ( ) )
615
513
{
616
514
QgsDebugMsg ( " Users qgis.db not found...skipping" );
617
-
618
515
mUserProjListDone = true ;
619
516
return ;
620
517
}
621
518
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;
626
522
// 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 )
629
525
{
630
526
// XXX This will likely never happen since on open, sqlite creates the
631
527
// database if it does not exist. But we checked earlier for its existance
632
528
// and aborted in that case. This is because we may be runnig from read only
633
529
// media such as live cd and don't want to force trying to create a db.
634
- showDBMissingWarning ( myDatabaseFileName );
530
+ showDBMissingWarning ( databaseFileName );
635
531
return ;
636
532
}
637
533
638
534
// 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 );
640
536
641
- myResult = sqlite3_prepare ( myDatabase, mySql .toUtf8 (), mySql .toUtf8 ().length (), &myPreparedStatement , &myTail );
537
+ result = sqlite3_prepare ( database, sql .toUtf8 (), sql .toUtf8 ().length (), &stmt , &tail );
642
538
// XXX Need to free memory from the error msg if one is set
643
- if ( myResult == SQLITE_OK )
539
+ if ( result == SQLITE_OK )
644
540
{
645
541
QTreeWidgetItem *newItem;
646
- while ( sqlite3_step ( myPreparedStatement ) == SQLITE_ROW )
542
+ while ( sqlite3_step ( stmt ) == SQLITE_ROW )
647
543
{
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 ) ) ) );
649
545
// EpsgCrsId for user projections is not always defined in some dbases.
650
546
// It's also not written from customprojections dialog.
651
547
// 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 ) ) );
653
549
// 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 ) ) );
655
551
}
656
552
}
657
553
// close the sqlite3 statement
658
- sqlite3_finalize ( myPreparedStatement );
659
- sqlite3_close ( myDatabase );
554
+ sqlite3_finalize ( stmt );
555
+ sqlite3_close ( database );
660
556
661
557
mUserProjListDone = true ;
662
558
}
663
559
664
560
void QgsProjectionSelector::loadCrsList ( QSet<QString> *crsFilter )
665
561
{
562
+ if ( mProjListDone )
563
+ return ;
564
+
666
565
// convert our Coordinate Reference System filter into the SQL expression
667
566
QString sqlFilter = ogcWmsCrsFilterAsSqlExpression ( crsFilter );
668
567
@@ -692,74 +591,70 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> *crsFilter )
692
591
// read only filesystem because otherwise sqlite will try
693
592
// to create the db file on the fly
694
593
695
- QFileInfo myFileInfo;
696
- myFileInfo.setFile ( mSrsDatabaseFileName );
697
- if ( !myFileInfo.exists ( ) )
594
+ if ( !QFileInfo ( mSrsDatabaseFileName ).exists () )
698
595
{
699
596
mProjListDone = true ;
700
597
return ;
701
598
}
702
599
703
600
// 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 );
707
603
if ( rc )
708
604
{
709
605
// XXX This will likely never happen since on open, sqlite creates the
710
606
// database if it does not exist.
711
607
showDBMissingWarning ( mSrsDatabaseFileName );
712
- return ;
608
+ return ;
713
609
}
714
610
// prepare the sql statement
715
- const char *pzTail ;
716
- sqlite3_stmt *ppStmt ;
611
+ const char *tail ;
612
+ sqlite3_stmt *stmt ;
717
613
// get total count of records in the projection table
718
614
QString sql = " select count(*) from tbl_srs" ;
719
615
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 );
725
620
726
621
// Set up the query to retrieve the projection information needed to populate the list
727
622
// note I am giving the full field names for clarity here and in case someone
728
623
// changes the underlying view TS
729
624
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" )
730
625
.arg ( sqlFilter );
731
626
732
- rc = sqlite3_prepare ( db , sql.toUtf8 (), sql.toUtf8 ().length (), &ppStmt , &pzTail );
627
+ rc = sqlite3_prepare ( database , sql.toUtf8 (), sql.toUtf8 ().length (), &stmt , &tail );
733
628
// XXX Need to free memory from the error msg if one is set
734
629
if ( rc == SQLITE_OK )
735
630
{
736
631
QTreeWidgetItem *newItem;
737
632
// Cache some stuff to speed up creating of the list of projected
738
633
// spatial reference systems
739
634
QString previousSrsType ( " " );
740
- QTreeWidgetItem* previousSrsTypeNode = NULL ;
635
+ QTreeWidgetItem* previousSrsTypeNode = 0 ;
741
636
742
- while ( sqlite3_step ( ppStmt ) == SQLITE_ROW )
637
+ while ( sqlite3_step ( stmt ) == SQLITE_ROW )
743
638
{
744
639
// check to see if the srs is geographic
745
- int isGeo = sqlite3_column_int ( ppStmt , 3 );
640
+ int isGeo = sqlite3_column_int ( stmt , 3 );
746
641
if ( isGeo )
747
642
{
748
643
// this is a geographic coordinate system
749
644
// 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 ) ) ) );
751
646
752
647
// 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 ) ) );
754
649
755
650
// 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 ) ) );
757
652
}
758
653
else
759
654
{
760
655
// This is a projected srs
761
656
QTreeWidgetItem *node;
762
- QString srsType = QString::fromUtf8 (( char * )sqlite3_column_text ( ppStmt , 4 ) );
657
+ QString srsType = QString::fromUtf8 (( char * )sqlite3_column_text ( stmt , 4 ) );
763
658
// Find the node for this type and add the projection to it
764
659
// If the node doesn't exist, create it
765
660
if ( srsType == previousSrsType )
@@ -768,13 +663,12 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> *crsFilter )
768
663
}
769
664
else
770
665
{ // 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 );
772
667
if ( nodes.count () == 0 )
773
668
{
774
669
// the node doesn't exist -- create it
775
670
// Make in an italic font to distinguish them from real projections
776
671
node = new QTreeWidgetItem ( mProjList , QStringList ( srsType ) );
777
-
778
672
QFont fontTemp = node->font ( 0 );
779
673
fontTemp.setItalic ( true );
780
674
node->setFont ( 0 , fontTemp );
@@ -788,53 +682,77 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> *crsFilter )
788
682
previousSrsTypeNode = node;
789
683
}
790
684
// 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 ) ) ) );
792
686
// 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 ) ) );
794
688
// 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 ) ) );
796
690
// expand also parent node
797
691
newItem->parent ()->setExpanded ( true );
798
692
}
799
693
800
694
// 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 ) ) );
802
696
newItem->setHidden ( cbxHideDeprecated->isChecked () );
803
697
}
804
698
mProjList ->setExpanded ( true );
805
699
}
700
+
806
701
// close the sqlite3 statement
807
- sqlite3_finalize ( ppStmt );
702
+ sqlite3_finalize ( stmt );
808
703
// close the database
809
- sqlite3_close ( db );
704
+ sqlite3_close ( database );
810
705
811
706
mProjListDone = true ;
812
707
}
813
708
814
709
// New coordinate system selected from the list
815
- void QgsProjectionSelector::coordinateSystemSelected ( QTreeWidgetItem * theItem )
710
+ void QgsProjectionSelector::on_lstCoordinateSystems_currentItemChanged ( QTreeWidgetItem *current, QTreeWidgetItem * )
816
711
{
712
+ QgsDebugMsg ( " Entered." );
713
+ lstCoordinateSystems->scrollToItem ( current );
714
+
817
715
// If the item has children, it's not an end node in the tree, and
818
716
// hence is just a grouping thingy, not an actual CRS.
819
- if ( theItem && theItem ->childCount () == 0 )
717
+ if ( current && current ->childCount () == 0 )
820
718
{
821
719
// Found a real CRS
822
720
emit sridSelected ( QString::number ( selectedCrsId () ) );
823
- QString myProjString = selectedProj4String ();
824
- lstCoordinateSystems->scrollToItem ( theItem );
825
- teProjection->setText ( myProjString );
826
721
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
+ }
828
735
}
829
736
else
830
737
{
831
738
// 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 );
834
741
teProjection->setText ( " " );
742
+ lstRecent->clearSelection ();
835
743
}
836
744
}
837
745
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
+
838
756
void QgsProjectionSelector::hideDeprecated ( QTreeWidgetItem *item )
839
757
{
840
758
if ( item->data ( 0 , Qt::UserRole ).toBool () )
@@ -857,12 +775,6 @@ void QgsProjectionSelector::on_cbxHideDeprecated_stateChanged()
857
775
hideDeprecated ( lstCoordinateSystems->topLevelItem ( i ) );
858
776
}
859
777
860
- void QgsProjectionSelector::on_lstRecent_itemClicked ( QTreeWidgetItem * item )
861
- {
862
- setSelectedCrsId ( item->text ( QGIS_CRS_ID_COLUMN ).toLong () );
863
- item->setSelected ( true );
864
- }
865
-
866
778
void QgsProjectionSelector::on_leSearch_textChanged ( const QString & theFilterTxt )
867
779
{
868
780
// filter recent crs's
@@ -877,7 +789,7 @@ void QgsProjectionSelector::on_leSearch_textChanged( const QString & theFilterTx
877
789
{
878
790
( *itr )->setHidden ( false );
879
791
QTreeWidgetItem * parent = ( *itr )->parent ();
880
- while ( parent != NULL )
792
+ while ( parent )
881
793
{
882
794
parent->setExpanded ( true );
883
795
parent->setHidden ( false );
@@ -895,6 +807,7 @@ void QgsProjectionSelector::on_leSearch_textChanged( const QString & theFilterTx
895
807
}
896
808
++itr;
897
809
}
810
+
898
811
// filter crs's
899
812
QTreeWidgetItemIterator it ( lstCoordinateSystems );
900
813
while ( *it )
@@ -907,7 +820,7 @@ void QgsProjectionSelector::on_leSearch_textChanged( const QString & theFilterTx
907
820
{
908
821
( *it )->setHidden ( false );
909
822
QTreeWidgetItem * parent = ( *it )->parent ();
910
- while ( parent != NULL )
823
+ while ( parent )
911
824
{
912
825
parent->setExpanded ( true );
913
826
parent->setHidden ( false );
@@ -930,113 +843,104 @@ void QgsProjectionSelector::on_leSearch_textChanged( const QString & theFilterTx
930
843
931
844
long QgsProjectionSelector::getLargestCRSIDMatch ( QString theSql )
932
845
{
933
- long mySrsId = 0 ;
846
+ long srsId = 0 ;
847
+
934
848
//
935
849
// Now perform the actual search
936
850
//
937
851
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 ;
942
856
943
857
// first we search the users db as any srsid there will be definition be greater than in sys db
944
858
945
859
// 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
950
862
{
951
- myResult = sqlite3_open ( myDatabaseFileName .toUtf8 ().data (), &myDatabase );
952
- if ( myResult )
863
+ result = sqlite3_open ( databaseFileName .toUtf8 ().data (), &database );
864
+ if ( result )
953
865
{
954
866
// XXX This will likely never happen since on open, sqlite creates the
955
867
// database if it does not exist. But we checked earlier for its existance
956
868
// and aborted in that case. This is because we may be runnig from read only
957
869
// media such as live cd and don't want to force trying to create a db.
958
- showDBMissingWarning ( myDatabaseFileName );
870
+ showDBMissingWarning ( databaseFileName );
959
871
return 0 ;
960
872
}
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 )
962
877
{
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;
978
884
}
979
885
}
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
985
887
{
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
+ }
989
896
}
990
897
991
- myResult = sqlite3_prepare ( myDatabase , theSql.toUtf8 (), theSql.toUtf8 ().length (), &myPreparedStatement , &myTail );
898
+ result = sqlite3_prepare ( database , theSql.toUtf8 (), theSql.toUtf8 ().length (), &stmt , &tail );
992
899
// 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 )
994
901
{
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 ();
1004
904
}
1005
- return mySrsId;
905
+
906
+ // close the sqlite3 statement
907
+ sqlite3_finalize ( stmt );
908
+ sqlite3_close ( database );
909
+
910
+ return srsId;
1006
911
}
1007
912
1008
913
QStringList QgsProjectionSelector::authorities ()
1009
914
{
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;
1014
918
1015
- myResult = sqlite3_open ( mSrsDatabaseFileName .toUtf8 ().data (), &myDatabase );
1016
- if ( myResult )
919
+ int result = sqlite3_open ( mSrsDatabaseFileName .toUtf8 ().data (), &database );
920
+ if ( result )
1017
921
{
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 ) ) );
1019
923
// no need for assert because user db may not have been created yet
1020
924
return QStringList ();
1021
925
}
1022
926
1023
927
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 );
1025
929
1026
930
QStringList authorities;
1027
-
1028
- if ( myResult == SQLITE_OK )
931
+ if ( result == SQLITE_OK )
1029
932
{
1030
- while ( sqlite3_step ( myPreparedStatement ) == SQLITE_ROW )
933
+ while ( sqlite3_step ( stmt ) == SQLITE_ROW )
1031
934
{
1032
- authorities << QString::fromUtf8 (( char * )sqlite3_column_text ( myPreparedStatement , 0 ) );
935
+ authorities << QString::fromUtf8 (( char * )sqlite3_column_text ( stmt , 0 ) );
1033
936
}
1034
937
1035
- // close the sqlite3 statement
1036
- sqlite3_finalize ( myPreparedStatement );
1037
- sqlite3_close ( myDatabase );
1038
938
}
1039
939
940
+ // close the sqlite3 statement
941
+ sqlite3_finalize ( stmt );
942
+ sqlite3_close ( database );
943
+
1040
944
return authorities;
1041
945
}
1042
946
@@ -1051,12 +955,12 @@ QStringList QgsProjectionSelector::authorities()
1051
955
*/
1052
956
const QString QgsProjectionSelector::sqlSafeString ( const QString theSQL )
1053
957
{
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 ;
1060
964
}
1061
965
1062
966
void QgsProjectionSelector::showDBMissingWarning ( const QString theFileName )
0 commit comments