Skip to content
Permalink
Browse files
projection search improvements (fixes #2602)
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13185 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Mar 28, 2010
1 parent de5a7e6 commit 0cc1bc78581243beebb4c3ce6f40344d762db198
Showing with 129 additions and 84 deletions.
  1. +62 −22 src/gui/qgsprojectionselector.cpp
  2. +3 −0 src/gui/qgsprojectionselector.h
  3. +64 −62 src/ui/qgsprojectionselectorbase.ui
@@ -55,6 +55,9 @@ QgsProjectionSelector::QgsProjectionSelector( QWidget* parent, const char * name
lstCoordinateSystems->header()->resizeSection( QGIS_CRS_ID_COLUMN, 0 );
lstCoordinateSystems->header()->setResizeMode( QGIS_CRS_ID_COLUMN, QHeaderView::Fixed );

cbxAuthority->addItem( tr( "All" ) );
cbxAuthority->addItems( authorities() );

// Read settings from persistent storage
QSettings settings;
mRecentProjections = settings.value( "/UI/recentProjections" ).toStringList();
@@ -723,7 +726,7 @@ void QgsProjectionSelector::loadUserCrsList( QSet<QString> * crsFilter )
mUserProjListDone = true;
}

void QgsProjectionSelector::loadCrsList( QSet<QString> * crsFilter )
void QgsProjectionSelector::loadCrsList( QSet<QString> *crsFilter )
{
// convert our Coordinate Reference System filter into the SQL expression
QString sqlFilter = ogcWmsCrsFilterAsSqlExpression( crsFilter );
@@ -942,39 +945,40 @@ void QgsProjectionSelector::on_pbnFind_clicked()
QgsDebugMsg( "pbnFind..." );

QString mySearchString( sqlSafeString( leSearch->text() ) );

// Set up the query to retrieve the projection information needed to populate the list
QString mySql;
if ( radAuthId->isChecked() )
QString mySql = "select srs_id from tbl_srs where ";
if ( cbxAuthority->currentIndex() > 0 )
{
mySql += QString( "auth_name='%1' AND " ).arg( cbxAuthority->currentText() );
}

if ( cbxHideDeprecated->isChecked() )
{
mySql = QString( "select srs_id from tbl_srs where upper(auth_name||':'||auth_id)='%1'" ).arg( mySearchString.toUpper() );
mySql += "not deprecated AND ";
}
else if ( radName->isChecked() ) //name search

if ( cbxMode->currentIndex() == 0 )
{
//we need to find what the largest srsid matching our query so we know whether to
//loop backto the beginning
mySql = "select srs_id from tbl_srs where upper(description) like '%" + mySearchString.toUpper() + "%'";
if ( cbxHideDeprecated->isChecked() )
mySql += " and not deprecated";
mySql += " order by srs_id desc limit 1";
long myLargestSrsId = getLargestCRSIDMatch( mySql );
mySql += QString( "auth_id='%1'" ).arg( mySearchString );
}
else
{
mySql += "upper(description) like '%" + mySearchString.toUpper() + "%' ";

long myLargestSrsId = getLargestCRSIDMatch( QString( "%1 order by srs_id desc limit 1" ).arg( mySql ) );
QgsDebugMsg( QString( "Largest CRSID%1" ).arg( myLargestSrsId ) );
//a name search is ambiguous, so we find the first srsid after the current seelcted srsid

//a name search is ambiguous, so we find the first srsid after the current selected srsid
// each time the find button is pressed. This means we can loop through all matches.
if ( myLargestSrsId <= selectedCrsId() )
{
//roll search around to the beginning
mySql = "select srs_id from tbl_srs where upper(description) like '%" + mySearchString.toUpper() + "%'";
if ( cbxHideDeprecated->isChecked() )
mySql += " and not deprecated";
mySql += " order by srs_id limit 1";
mySql = QString( "%1 order by srs_id limit 1" ).arg( mySql );
}
else
{
// search ahead of the current position
mySql = "select srs_id from tbl_srs where upper(description) like '%" + mySearchString.toUpper() + "%'";
if ( cbxHideDeprecated->isChecked() )
mySql += " and not deprecated";
mySql += " and srs_id > " + QString::number( selectedCrsId() ) + " order by srs_id limit 1";
mySql = QString( "%1 and srs_id > %2 order by srs_id limit 1" ).arg( mySql ).arg( selectedCrsId() );
}
}
QgsDebugMsg( QString( " Search sql: %1" ).arg( mySql ) );
@@ -1128,6 +1132,42 @@ long QgsProjectionSelector::getLargestCRSIDMatch( QString theSql )
}
return mySrsId;
}

QStringList QgsProjectionSelector::authorities()
{
sqlite3 *myDatabase;
const char *myTail;
sqlite3_stmt *myPreparedStatement;
int myResult;

myResult = sqlite3_open( mSrsDatabaseFileName.toUtf8().data(), &myDatabase );
if ( myResult )
{
QgsDebugMsg( QString( "Can't open * user * database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
//no need for assert because user db may not have been created yet
return QStringList();
}

QString theSql = "select distinct auth_name from tbl_srs";
myResult = sqlite3_prepare( myDatabase, theSql.toUtf8(), theSql.toUtf8().length(), &myPreparedStatement, &myTail );

QStringList authorities;

if ( myResult == SQLITE_OK )
{
while ( sqlite3_step( myPreparedStatement ) == SQLITE_ROW )
{
authorities << QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 0 ) );
}

// close the sqlite3 statement
sqlite3_finalize( myPreparedStatement );
sqlite3_close( myDatabase );
}

return authorities;
}

/*!
* \brief Make the string safe for use in SQL statements.
* This involves escaping single quotes, double quotes, backslashes,
@@ -243,6 +243,9 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
*/
void coordinateSystemSelected( QTreeWidgetItem* );

//! get list of authorities
QStringList authorities();

signals:
void sridSelected( QString theSRID );
//! Refresh any listening canvases
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>428</width>
<height>316</height>
<width>374</width>
<height>464</height>
</rect>
</property>
<property name="sizePolicy">
@@ -31,34 +31,6 @@
<property name="margin">
<number>3</number>
</property>
<item row="0" column="0">
<widget class="QTreeWidget" name="lstCoordinateSystems">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="uniformRowHeights">
<bool>true</bool>
</property>
<property name="columnCount">
<number>3</number>
</property>
<column>
<property name="text">
<string>Coordinate Reference System</string>
</property>
</column>
<column>
<property name="text">
<string>Authority ID</string>
</property>
</column>
<column>
<property name="text">
<string>ID</string>
</property>
</column>
</widget>
</item>
<item row="1" column="0">
<widget class="QTextEdit" name="teProjection">
<property name="sizePolicy">
@@ -93,6 +65,46 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="pbnPopular1"/>
</item>
<item row="4" column="0">
<widget class="QPushButton" name="pbnPopular2"/>
</item>
<item row="5" column="0">
<widget class="QPushButton" name="pbnPopular3"/>
</item>
<item row="6" column="0">
<widget class="QPushButton" name="pbnPopular4"/>
</item>
<item row="0" column="0">
<widget class="QTreeWidget" name="lstCoordinateSystems">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="uniformRowHeights">
<bool>true</bool>
</property>
<property name="columnCount">
<number>3</number>
</property>
<column>
<property name="text">
<string>Coordinate Reference System</string>
</property>
</column>
<column>
<property name="text">
<string>Authority ID</string>
</property>
</column>
<column>
<property name="text">
<string>ID</string>
</property>
</column>
</widget>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
@@ -105,32 +117,34 @@
<string>Search</string>
</property>
<layout class="QGridLayout">
<item row="1" column="1">
<widget class="QComboBox" name="cbxMode">
<item>
<property name="text">
<string>ID</string>
</property>
</item>
<item>
<property name="text">
<string>Name</string>
</property>
</item>
</widget>
</item>
<item row="0" column="0">
<widget class="QRadioButton" name="radAuthId">
<widget class="QLabel" name="label">
<property name="text">
<string>AuthorityID</string>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>10</height>
</size>
</property>
<property name="checked">
<bool>true</bool>
<string>Authority</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QRadioButton" name="radName">
<widget class="QComboBox" name="cbxAuthority"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Name</string>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>10</height>
</size>
<string>Search for</string>
</property>
</widget>
</item>
@@ -153,7 +167,7 @@
</property>
</widget>
</item>
<item row="1" column="0" colspan="4">
<item row="1" column="2" colspan="2">
<widget class="QCheckBox" name="cbxHideDeprecated">
<property name="text">
<string>Hide deprecated CRSs</string>
@@ -163,18 +177,6 @@
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="pbnPopular1"/>
</item>
<item row="4" column="0">
<widget class="QPushButton" name="pbnPopular2"/>
</item>
<item row="5" column="0">
<widget class="QPushButton" name="pbnPopular3"/>
</item>
<item row="6" column="0">
<widget class="QPushButton" name="pbnPopular4"/>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>

0 comments on commit 0cc1bc7

Please sign in to comment.