@@ -55,6 +55,9 @@ QgsProjectionSelector::QgsProjectionSelector( QWidget* parent, const char * name
55
55
lstCoordinateSystems->header ()->resizeSection ( QGIS_CRS_ID_COLUMN, 0 );
56
56
lstCoordinateSystems->header ()->setResizeMode ( QGIS_CRS_ID_COLUMN, QHeaderView::Fixed );
57
57
58
+ cbxAuthority->addItem ( tr ( " All" ) );
59
+ cbxAuthority->addItems ( authorities () );
60
+
58
61
// Read settings from persistent storage
59
62
QSettings settings;
60
63
mRecentProjections = settings.value ( " /UI/recentProjections" ).toStringList ();
@@ -723,7 +726,7 @@ void QgsProjectionSelector::loadUserCrsList( QSet<QString> * crsFilter )
723
726
mUserProjListDone = true ;
724
727
}
725
728
726
- void QgsProjectionSelector::loadCrsList ( QSet<QString> * crsFilter )
729
+ void QgsProjectionSelector::loadCrsList ( QSet<QString> *crsFilter )
727
730
{
728
731
// convert our Coordinate Reference System filter into the SQL expression
729
732
QString sqlFilter = ogcWmsCrsFilterAsSqlExpression ( crsFilter );
@@ -942,39 +945,40 @@ void QgsProjectionSelector::on_pbnFind_clicked()
942
945
QgsDebugMsg ( " pbnFind..." );
943
946
944
947
QString mySearchString ( sqlSafeString ( leSearch->text () ) );
948
+
945
949
// 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 () )
948
957
{
949
- mySql = QString ( " select srs_id from tbl_srs where upper(auth_name||':'||auth_id)='%1' " ). arg ( mySearchString. toUpper () ) ;
958
+ mySql += " not deprecated AND " ;
950
959
}
951
- else if ( radName->isChecked () ) // name search
960
+
961
+ if ( cbxMode->currentIndex () == 0 )
952
962
{
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 ) );
960
970
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
962
973
// each time the find button is pressed. This means we can loop through all matches.
963
974
if ( myLargestSrsId <= selectedCrsId () )
964
975
{
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 );
970
977
}
971
978
else
972
979
{
973
980
// 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 () );
978
982
}
979
983
}
980
984
QgsDebugMsg ( QString ( " Search sql: %1" ).arg ( mySql ) );
@@ -1128,6 +1132,42 @@ long QgsProjectionSelector::getLargestCRSIDMatch( QString theSql )
1128
1132
}
1129
1133
return mySrsId;
1130
1134
}
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
+
1131
1171
/* !
1132
1172
* \brief Make the string safe for use in SQL statements.
1133
1173
* This involves escaping single quotes, double quotes, backslashes,
0 commit comments