@@ -55,6 +55,9 @@ QgsProjectionSelector::QgsProjectionSelector( QWidget* parent, const char * name
5555 lstCoordinateSystems->header ()->resizeSection ( QGIS_CRS_ID_COLUMN, 0 );
5656 lstCoordinateSystems->header ()->setResizeMode ( QGIS_CRS_ID_COLUMN, QHeaderView::Fixed );
5757
58+ cbxAuthority->addItem ( tr ( " All" ) );
59+ cbxAuthority->addItems ( authorities () );
60+
5861 // Read settings from persistent storage
5962 QSettings settings;
6063 mRecentProjections = settings.value ( " /UI/recentProjections" ).toStringList ();
@@ -723,7 +726,7 @@ void QgsProjectionSelector::loadUserCrsList( QSet<QString> * crsFilter )
723726 mUserProjListDone = true ;
724727}
725728
726- void QgsProjectionSelector::loadCrsList ( QSet<QString> * crsFilter )
729+ void QgsProjectionSelector::loadCrsList ( QSet<QString> *crsFilter )
727730{
728731 // convert our Coordinate Reference System filter into the SQL expression
729732 QString sqlFilter = ogcWmsCrsFilterAsSqlExpression ( crsFilter );
@@ -942,39 +945,40 @@ void QgsProjectionSelector::on_pbnFind_clicked()
942945 QgsDebugMsg ( " pbnFind..." );
943946
944947 QString mySearchString ( sqlSafeString ( leSearch->text () ) );
948+
945949 // Set up the query to retrieve the projection information needed to populate the list
946- QString mySql;
947- if ( radAuthId->isChecked () )
950+ QString mySql = " select srs_id from tbl_srs where " ;
951+ if ( cbxAuthority->currentIndex () > 0 )
952+ {
953+ mySql += QString ( " auth_name='%1' AND " ).arg ( cbxAuthority->currentText () );
954+ }
955+
956+ if ( cbxHideDeprecated->isChecked () )
948957 {
949- mySql = QString ( " select srs_id from tbl_srs where upper(auth_name||':'||auth_id)='%1' " ). arg ( mySearchString. toUpper () ) ;
958+ mySql += " not deprecated AND " ;
950959 }
951- else if ( radName->isChecked () ) // name search
960+
961+ if ( cbxMode->currentIndex () == 0 )
952962 {
953- // we need to find what the largest srsid matching our query so we know whether to
954- // loop backto the beginning
955- mySql = " select srs_id from tbl_srs where upper(description) like '% " + mySearchString. toUpper () + " %' " ;
956- if ( cbxHideDeprecated-> isChecked () )
957- mySql += " and not deprecated " ;
958- mySql += " order by srs_id desc limit 1 " ;
959- long myLargestSrsId = getLargestCRSIDMatch ( mySql );
963+ mySql += QString ( " auth_id='%1' " ). arg ( mySearchString );
964+ }
965+ else
966+ {
967+ mySql += " upper(description) like '% " + mySearchString. toUpper () + " %' " ;
968+
969+ long myLargestSrsId = getLargestCRSIDMatch ( QString ( " %1 order by srs_id desc limit 1 " ). arg ( mySql ) );
960970 QgsDebugMsg ( QString ( " Largest CRSID%1" ).arg ( myLargestSrsId ) );
961- // a name search is ambiguous, so we find the first srsid after the current seelcted srsid
971+
972+ // a name search is ambiguous, so we find the first srsid after the current selected srsid
962973 // each time the find button is pressed. This means we can loop through all matches.
963974 if ( myLargestSrsId <= selectedCrsId () )
964975 {
965- // roll search around to the beginning
966- mySql = " select srs_id from tbl_srs where upper(description) like '%" + mySearchString.toUpper () + " %'" ;
967- if ( cbxHideDeprecated->isChecked () )
968- mySql += " and not deprecated" ;
969- mySql += " order by srs_id limit 1" ;
976+ mySql = QString ( " %1 order by srs_id limit 1" ).arg ( mySql );
970977 }
971978 else
972979 {
973980 // search ahead of the current position
974- mySql = " select srs_id from tbl_srs where upper(description) like '%" + mySearchString.toUpper () + " %'" ;
975- if ( cbxHideDeprecated->isChecked () )
976- mySql += " and not deprecated" ;
977- mySql += " and srs_id > " + QString::number ( selectedCrsId () ) + " order by srs_id limit 1" ;
981+ mySql = QString ( " %1 and srs_id > %2 order by srs_id limit 1" ).arg ( mySql ).arg ( selectedCrsId () );
978982 }
979983 }
980984 QgsDebugMsg ( QString ( " Search sql: %1" ).arg ( mySql ) );
@@ -1128,6 +1132,42 @@ long QgsProjectionSelector::getLargestCRSIDMatch( QString theSql )
11281132 }
11291133 return mySrsId;
11301134}
1135+
1136+ QStringList QgsProjectionSelector::authorities ()
1137+ {
1138+ sqlite3 *myDatabase;
1139+ const char *myTail;
1140+ sqlite3_stmt *myPreparedStatement;
1141+ int myResult;
1142+
1143+ myResult = sqlite3_open ( mSrsDatabaseFileName .toUtf8 ().data (), &myDatabase );
1144+ if ( myResult )
1145+ {
1146+ QgsDebugMsg ( QString ( " Can't open * user * database: %1" ).arg ( sqlite3_errmsg ( myDatabase ) ) );
1147+ // no need for assert because user db may not have been created yet
1148+ return QStringList ();
1149+ }
1150+
1151+ QString theSql = " select distinct auth_name from tbl_srs" ;
1152+ myResult = sqlite3_prepare ( myDatabase, theSql.toUtf8 (), theSql.toUtf8 ().length (), &myPreparedStatement, &myTail );
1153+
1154+ QStringList authorities;
1155+
1156+ if ( myResult == SQLITE_OK )
1157+ {
1158+ while ( sqlite3_step ( myPreparedStatement ) == SQLITE_ROW )
1159+ {
1160+ authorities << QString::fromUtf8 (( char * )sqlite3_column_text ( myPreparedStatement, 0 ) );
1161+ }
1162+
1163+ // close the sqlite3 statement
1164+ sqlite3_finalize ( myPreparedStatement );
1165+ sqlite3_close ( myDatabase );
1166+ }
1167+
1168+ return authorities;
1169+ }
1170+
11311171/* !
11321172* \brief Make the string safe for use in SQL statements.
11331173* This involves escaping single quotes, double quotes, backslashes,
0 commit comments