Skip to content

Commit 0cc1bc7

Browse files
author
jef
committed
projection search improvements (fixes #2602)
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13185 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent de5a7e6 commit 0cc1bc7

File tree

3 files changed

+129
-84
lines changed

3 files changed

+129
-84
lines changed

src/gui/qgsprojectionselector.cpp

+62-22
Original file line numberDiff line numberDiff line change
@@ -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,

src/gui/qgsprojectionselector.h

+3
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
243243
*/
244244
void coordinateSystemSelected( QTreeWidgetItem* );
245245

246+
//! get list of authorities
247+
QStringList authorities();
248+
246249
signals:
247250
void sridSelected( QString theSRID );
248251
//! Refresh any listening canvases

src/ui/qgsprojectionselectorbase.ui

+64-62
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>428</width>
10-
<height>316</height>
9+
<width>374</width>
10+
<height>464</height>
1111
</rect>
1212
</property>
1313
<property name="sizePolicy">
@@ -31,34 +31,6 @@
3131
<property name="margin">
3232
<number>3</number>
3333
</property>
34-
<item row="0" column="0">
35-
<widget class="QTreeWidget" name="lstCoordinateSystems">
36-
<property name="alternatingRowColors">
37-
<bool>true</bool>
38-
</property>
39-
<property name="uniformRowHeights">
40-
<bool>true</bool>
41-
</property>
42-
<property name="columnCount">
43-
<number>3</number>
44-
</property>
45-
<column>
46-
<property name="text">
47-
<string>Coordinate Reference System</string>
48-
</property>
49-
</column>
50-
<column>
51-
<property name="text">
52-
<string>Authority ID</string>
53-
</property>
54-
</column>
55-
<column>
56-
<property name="text">
57-
<string>ID</string>
58-
</property>
59-
</column>
60-
</widget>
61-
</item>
6234
<item row="1" column="0">
6335
<widget class="QTextEdit" name="teProjection">
6436
<property name="sizePolicy">
@@ -93,6 +65,46 @@
9365
</property>
9466
</widget>
9567
</item>
68+
<item row="3" column="0">
69+
<widget class="QPushButton" name="pbnPopular1"/>
70+
</item>
71+
<item row="4" column="0">
72+
<widget class="QPushButton" name="pbnPopular2"/>
73+
</item>
74+
<item row="5" column="0">
75+
<widget class="QPushButton" name="pbnPopular3"/>
76+
</item>
77+
<item row="6" column="0">
78+
<widget class="QPushButton" name="pbnPopular4"/>
79+
</item>
80+
<item row="0" column="0">
81+
<widget class="QTreeWidget" name="lstCoordinateSystems">
82+
<property name="alternatingRowColors">
83+
<bool>true</bool>
84+
</property>
85+
<property name="uniformRowHeights">
86+
<bool>true</bool>
87+
</property>
88+
<property name="columnCount">
89+
<number>3</number>
90+
</property>
91+
<column>
92+
<property name="text">
93+
<string>Coordinate Reference System</string>
94+
</property>
95+
</column>
96+
<column>
97+
<property name="text">
98+
<string>Authority ID</string>
99+
</property>
100+
</column>
101+
<column>
102+
<property name="text">
103+
<string>ID</string>
104+
</property>
105+
</column>
106+
</widget>
107+
</item>
96108
<item row="2" column="0">
97109
<widget class="QGroupBox" name="groupBox">
98110
<property name="sizePolicy">
@@ -105,32 +117,34 @@
105117
<string>Search</string>
106118
</property>
107119
<layout class="QGridLayout">
120+
<item row="1" column="1">
121+
<widget class="QComboBox" name="cbxMode">
122+
<item>
123+
<property name="text">
124+
<string>ID</string>
125+
</property>
126+
</item>
127+
<item>
128+
<property name="text">
129+
<string>Name</string>
130+
</property>
131+
</item>
132+
</widget>
133+
</item>
108134
<item row="0" column="0">
109-
<widget class="QRadioButton" name="radAuthId">
135+
<widget class="QLabel" name="label">
110136
<property name="text">
111-
<string>AuthorityID</string>
112-
</property>
113-
<property name="iconSize">
114-
<size>
115-
<width>16</width>
116-
<height>10</height>
117-
</size>
118-
</property>
119-
<property name="checked">
120-
<bool>true</bool>
137+
<string>Authority</string>
121138
</property>
122139
</widget>
123140
</item>
124141
<item row="0" column="1">
125-
<widget class="QRadioButton" name="radName">
142+
<widget class="QComboBox" name="cbxAuthority"/>
143+
</item>
144+
<item row="1" column="0">
145+
<widget class="QLabel" name="label_2">
126146
<property name="text">
127-
<string>Name</string>
128-
</property>
129-
<property name="iconSize">
130-
<size>
131-
<width>16</width>
132-
<height>10</height>
133-
</size>
147+
<string>Search for</string>
134148
</property>
135149
</widget>
136150
</item>
@@ -153,7 +167,7 @@
153167
</property>
154168
</widget>
155169
</item>
156-
<item row="1" column="0" colspan="4">
170+
<item row="1" column="2" colspan="2">
157171
<widget class="QCheckBox" name="cbxHideDeprecated">
158172
<property name="text">
159173
<string>Hide deprecated CRSs</string>
@@ -163,18 +177,6 @@
163177
</layout>
164178
</widget>
165179
</item>
166-
<item row="3" column="0">
167-
<widget class="QPushButton" name="pbnPopular1"/>
168-
</item>
169-
<item row="4" column="0">
170-
<widget class="QPushButton" name="pbnPopular2"/>
171-
</item>
172-
<item row="5" column="0">
173-
<widget class="QPushButton" name="pbnPopular3"/>
174-
</item>
175-
<item row="6" column="0">
176-
<widget class="QPushButton" name="pbnPopular4"/>
177-
</item>
178180
</layout>
179181
</widget>
180182
<layoutdefault spacing="6" margin="11"/>

0 commit comments

Comments
 (0)