Skip to content

Commit 3a0dbbc

Browse files
author
jef
committed
[FEATURE] allow to hide deprecated CRSes
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13125 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent e9ea885 commit 3a0dbbc

File tree

4 files changed

+91
-42
lines changed

4 files changed

+91
-42
lines changed

resources/srs.db

38 KB
Binary file not shown.

src/gui/qgsprojectionselector.cpp

+80-42
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <sqlite3.h>
1717

1818
//qgis includes
19-
#include "qgis.h" //magick numbers here
19+
#include "qgis.h" //magic numbers here
2020
#include "qgsapplication.h"
2121
#include "qgslogger.h"
2222
#include <qgscoordinatereferencesystem.h>
@@ -36,15 +36,13 @@ const int AUTHID_COLUMN = 1;
3636
const int QGIS_CRS_ID_COLUMN = 2;
3737
const int POPULAR_CRSES = 3;
3838

39-
QgsProjectionSelector::QgsProjectionSelector( QWidget* parent,
40-
const char * name,
41-
Qt::WFlags fl )
42-
: QWidget( parent, fl ),
43-
mProjListDone( FALSE ),
44-
mUserProjListDone( FALSE ),
45-
mCRSNameSelectionPending( FALSE ),
46-
mCRSIDSelectionPending( FALSE ),
47-
mAuthIDSelectionPending( FALSE )
39+
QgsProjectionSelector::QgsProjectionSelector( QWidget* parent, const char * name, Qt::WFlags fl )
40+
: QWidget( parent, fl )
41+
, mProjListDone( false )
42+
, mUserProjListDone( false )
43+
, mCRSNameSelectionPending( false )
44+
, mCRSIDSelectionPending( false )
45+
, mAuthIDSelectionPending( false )
4846
{
4947
setupUi( this );
5048
connect( lstCoordinateSystems, SIGNAL( currentItemChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ),
@@ -268,9 +266,9 @@ QString QgsProjectionSelector::ogcWmsCrsFilterAsSqlExpression( QSet<QString> * c
268266
void QgsProjectionSelector::setSelectedCrsName( QString theCRSName )
269267
{
270268
mCRSNameSelection = theCRSName;
271-
mCRSNameSelectionPending = TRUE;
272-
mCRSIDSelectionPending = FALSE; // only one type can be pending at a time
273-
mAuthIDSelectionPending = TRUE;
269+
mCRSNameSelectionPending = true;
270+
mCRSIDSelectionPending = false; // only one type can be pending at a time
271+
mAuthIDSelectionPending = true;
274272

275273
if ( isVisible() )
276274
{
@@ -285,9 +283,9 @@ void QgsProjectionSelector::setSelectedCrsName( QString theCRSName )
285283
void QgsProjectionSelector::setSelectedCrsId( long theCRSID )
286284
{
287285
mCRSIDSelection = theCRSID;
288-
mCRSIDSelectionPending = TRUE;
289-
mCRSNameSelectionPending = FALSE; // only one type can be pending at a time
290-
mAuthIDSelectionPending = FALSE;
286+
mCRSIDSelectionPending = true;
287+
mCRSNameSelectionPending = false; // only one type can be pending at a time
288+
mAuthIDSelectionPending = false;
291289

292290
if ( isVisible() )
293291
{
@@ -306,9 +304,9 @@ void QgsProjectionSelector::setSelectedEpsg( long id )
306304
void QgsProjectionSelector::setSelectedAuthId( QString id )
307305
{
308306
mAuthIDSelection = id;
309-
mCRSIDSelectionPending = FALSE;
310-
mAuthIDSelectionPending = TRUE;
311-
mCRSNameSelectionPending = FALSE; // only one type can be pending at a time
307+
mCRSIDSelectionPending = false;
308+
mAuthIDSelectionPending = true;
309+
mCRSNameSelectionPending = false; // only one type can be pending at a time
312310
}
313311

314312
void QgsProjectionSelector::applyCRSNameSelection()
@@ -334,7 +332,7 @@ void QgsProjectionSelector::applyCRSNameSelection()
334332
teProjection->setText( "" );
335333
}
336334

337-
mCRSNameSelectionPending = FALSE;
335+
mCRSNameSelectionPending = false;
338336
}
339337
}
340338

@@ -379,7 +377,7 @@ void QgsProjectionSelector::applyAuthIDSelection()
379377
teProjection->setText( "" );
380378
}
381379

382-
mAuthIDSelectionPending = FALSE;
380+
mAuthIDSelectionPending = false;
383381
}
384382
}
385383

@@ -402,7 +400,7 @@ void QgsProjectionSelector::applyCRSIDSelection()
402400
teProjection->setText( "" );
403401
}
404402

405-
mCRSIDSelectionPending = FALSE;
403+
mCRSIDSelectionPending = false;
406404
}
407405
}
408406

@@ -654,8 +652,8 @@ void QgsProjectionSelector::loadUserCrsList( QSet<QString> * crsFilter )
654652
mUserProjList = new QTreeWidgetItem( lstCoordinateSystems, QStringList( tr( "User Defined Coordinate Systems" ) ) );
655653

656654
QFont fontTemp = mUserProjList->font( 0 );
657-
fontTemp.setItalic( TRUE );
658-
fontTemp.setBold( TRUE );
655+
fontTemp.setItalic( true );
656+
fontTemp.setBold( true );
659657
mUserProjList->setFont( 0, fontTemp );
660658
mUserProjList->setIcon( 0, QIcon( QgsApplication::activeThemePath() + "user.png" ) );
661659

@@ -671,7 +669,7 @@ void QgsProjectionSelector::loadUserCrsList( QSet<QString> * crsFilter )
671669
{
672670
QgsDebugMsg( "Users qgis.db not found...skipping" );
673671

674-
mUserProjListDone = TRUE;
672+
mUserProjListDone = true;
675673
return;
676674
}
677675

@@ -714,7 +712,7 @@ void QgsProjectionSelector::loadUserCrsList( QSet<QString> * crsFilter )
714712
sqlite3_finalize( myPreparedStatement );
715713
sqlite3_close( myDatabase );
716714

717-
mUserProjListDone = TRUE;
715+
mUserProjListDone = true;
718716
}
719717

720718
void QgsProjectionSelector::loadCrsList( QSet<QString> * crsFilter )
@@ -729,17 +727,17 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> * crsFilter )
729727
mGeoList = new QTreeWidgetItem( lstCoordinateSystems, QStringList( tr( "Geographic Coordinate Systems" ) ) );
730728

731729
QFont fontTemp = mGeoList->font( 0 );
732-
fontTemp.setItalic( TRUE );
733-
fontTemp.setBold( TRUE );
730+
fontTemp.setItalic( true );
731+
fontTemp.setBold( true );
734732
mGeoList->setFont( 0, fontTemp );
735733
mGeoList->setIcon( 0, QIcon( QgsApplication::activeThemePath() + "geographic.png" ) );
736734

737735
// Projected coordinate system node
738736
mProjList = new QTreeWidgetItem( lstCoordinateSystems, QStringList( tr( "Projected Coordinate Systems" ) ) );
739737

740738
fontTemp = mProjList->font( 0 );
741-
fontTemp.setItalic( TRUE );
742-
fontTemp.setBold( TRUE );
739+
fontTemp.setItalic( true );
740+
fontTemp.setBold( true );
743741
mProjList->setFont( 0, fontTemp );
744742
mProjList->setIcon( 0, QIcon( QgsApplication::activeThemePath() + "transformed.png" ) );
745743

@@ -752,7 +750,7 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> * crsFilter )
752750
myFileInfo.setFile( mSrsDatabaseFileName );
753751
if ( !myFileInfo.exists( ) )
754752
{
755-
mProjListDone = TRUE;
753+
mProjListDone = true;
756754
return;
757755
}
758756

@@ -782,7 +780,7 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> * crsFilter )
782780
// Set up the query to retrieve the projection information needed to populate the list
783781
//note I am giving the full field names for clarity here and in case someone
784782
//changes the underlying view TS
785-
sql = QString( "select description, srs_id, auth_id, is_geo, name, parameters from vw_srs where %1 order by name,description" )
783+
sql = QString( "select description, srs_id, auth_name||':'||auth_id, is_geo, name, parameters, deprecated from vw_srs where %1 order by name,description" )
786784
.arg( sqlFilter );
787785

788786
rc = sqlite3_prepare( db, sql.toUtf8(), sql.toUtf8().length(), &ppStmt, &pzTail );
@@ -832,7 +830,7 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> * crsFilter )
832830
node = new QTreeWidgetItem( mProjList, QStringList( srsType ) );
833831

834832
QFont fontTemp = node->font( 0 );
835-
fontTemp.setItalic( TRUE );
833+
fontTemp.setItalic( true );
836834
node->setFont( 0, fontTemp );
837835
}
838836
else
@@ -849,7 +847,12 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> * crsFilter )
849847
newItem->setText( AUTHID_COLUMN, QString::fromUtf8(( char * )sqlite3_column_text( ppStmt, 2 ) ) );
850848
// display the qgis srs_id (field 1) in the third column of the list view
851849
newItem->setText( QGIS_CRS_ID_COLUMN, QString::fromUtf8(( char * )sqlite3_column_text( ppStmt, 1 ) ) );
850+
852851
}
852+
853+
// display the qgis deprecated in the user data of the item
854+
newItem->setData( 0, Qt::UserRole, QString::fromUtf8(( char * )sqlite3_column_text( ppStmt, 6 ) ) );
855+
newItem->setHidden( cbxHideDeprecated->isChecked() );
853856
}
854857
mProjList->setExpanded( true );
855858
}
@@ -858,7 +861,7 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> * crsFilter )
858861
// close the database
859862
sqlite3_close( db );
860863

861-
mProjListDone = TRUE;
864+
mProjListDone = true;
862865
}
863866

864867

@@ -867,7 +870,7 @@ void QgsProjectionSelector::coordinateSystemSelected( QTreeWidgetItem * theItem
867870
{
868871
// If the item has children, it's not an end node in the tree, and
869872
// hence is just a grouping thingy, not an actual CRS.
870-
if ( theItem != NULL && theItem->childCount() == 0 )
873+
if ( theItem && theItem->childCount() == 0 )
871874
{
872875
// Found a real CRS
873876
QString myDescription;
@@ -879,11 +882,33 @@ void QgsProjectionSelector::coordinateSystemSelected( QTreeWidgetItem * theItem
879882
else
880883
{
881884
// Not an CRS - remove the highlight so the user doesn't get too confused
882-
lstCoordinateSystems->setItemSelected( theItem, FALSE ); // TODO - make this work.
885+
theItem->setSelected( false );
883886
teProjection->setText( "" );
884887
}
885888
}
886889

890+
void QgsProjectionSelector::hideDeprecated( QTreeWidgetItem *item )
891+
{
892+
if( item->data( 0, Qt::UserRole ).toBool() )
893+
{
894+
item->setHidden( cbxHideDeprecated->isChecked() );
895+
if( item->isSelected() && item->isHidden() )
896+
{
897+
teProjection->setText( "" );
898+
item->setSelected( false );
899+
}
900+
}
901+
902+
for( int i=0; i < item->childCount(); i++ )
903+
hideDeprecated( item->child(i) );
904+
}
905+
906+
void QgsProjectionSelector::on_cbxHideDeprecated_stateChanged()
907+
{
908+
for( int i = 0; i<lstCoordinateSystems->topLevelItemCount(); i++ )
909+
hideDeprecated( lstCoordinateSystems->topLevelItem(i) );
910+
}
911+
887912
void QgsProjectionSelector::on_pbnPopular1_clicked()
888913
{
889914
setSelectedCrsId( mRecentProjections.at( 0 ).toLong() );
@@ -893,18 +918,19 @@ void QgsProjectionSelector::on_pbnPopular2_clicked()
893918
{
894919
setSelectedCrsId( mRecentProjections.at( 1 ).toLong() );
895920
}
921+
896922
void QgsProjectionSelector::on_pbnPopular3_clicked()
897923
{
898924
setSelectedCrsId( mRecentProjections.at( 2 ).toLong() );
899925
}
926+
900927
void QgsProjectionSelector::on_pbnPopular4_clicked()
901928
{
902929
setSelectedCrsId( mRecentProjections.at( 3 ).toLong() );
903930
}
904931

905932
void QgsProjectionSelector::on_pbnFind_clicked()
906933
{
907-
908934
QgsDebugMsg( "pbnFind..." );
909935

910936
QString mySearchString( sqlSafeString( leSearch->text() ) );
@@ -918,22 +944,29 @@ void QgsProjectionSelector::on_pbnFind_clicked()
918944
{
919945
//we need to find what the largest srsid matching our query so we know whether to
920946
//loop backto the beginning
921-
mySql = "select srs_id from tbl_srs where description like '%" + mySearchString + "%' order by srs_id desc limit 1";
947+
mySql = "select srs_id from tbl_srs where description like '%" + mySearchString + "%'";
948+
if( cbxHideDeprecated->isChecked() )
949+
mySql += " and not deprecated";
950+
mySql += " order by srs_id desc limit 1";
922951
long myLargestSrsId = getLargestCRSIDMatch( mySql );
923952
QgsDebugMsg( QString( "Largest CRSID%1" ).arg( myLargestSrsId ) );
924953
//a name search is ambiguous, so we find the first srsid after the current seelcted srsid
925954
// each time the find button is pressed. This means we can loop through all matches.
926955
if ( myLargestSrsId <= selectedCrsId() )
927956
{
928957
//roll search around to the beginning
929-
mySql = "select srs_id from tbl_srs where description like '%" + mySearchString + "%'" +
930-
" order by srs_id limit 1";
958+
mySql = "select srs_id from tbl_srs where description like '%" + mySearchString + "%'";
959+
if( cbxHideDeprecated->isChecked() )
960+
mySql += " and not deprecated";
961+
mySql += " order by srs_id limit 1";
931962
}
932963
else
933964
{
934965
// search ahead of the current position
935-
mySql = "select srs_id from tbl_srs where description like '%" + mySearchString + "%'" +
936-
" and srs_id > " + QString::number( selectedCrsId() ) + " order by srs_id limit 1";
966+
mySql = "select srs_id from tbl_srs where description like '%" + mySearchString + "%'";
967+
if( cbxHideDeprecated->isChecked() )
968+
mySql += " and not deprecated";
969+
mySql += " and srs_id > " + QString::number( selectedCrsId() ) + " order by srs_id limit 1";
937970
}
938971
}
939972
QgsDebugMsg( QString( " Search sql: %1" ).arg( mySql ) );
@@ -1002,8 +1035,13 @@ void QgsProjectionSelector::on_pbnFind_clicked()
10021035
// close the sqlite3 statement
10031036
sqlite3_finalize( myPreparedStatement );
10041037
sqlite3_close( myDatabase );
1038+
return;
10051039
}
10061040
}
1041+
1042+
QMessageBox::information( this, tr( "Find projection" ), tr( "No matching projection found." ) );
1043+
lstCoordinateSystems->clearSelection();
1044+
teProjection->setText( "" );
10071045
}
10081046

10091047
long QgsProjectionSelector::getLargestCRSIDMatch( QString theSql )

src/gui/qgsprojectionselector.h

+4
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
110110
void setOgcWmsCrsFilter( QSet<QString> crsFilter );
111111

112112
void on_pbnFind_clicked();
113+
void on_cbxHideDeprecated_stateChanged();
113114

114115
void on_pbnPopular1_clicked();
115116
void on_pbnPopular2_clicked();
@@ -233,6 +234,9 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
233234
//! Most recently used projections (trimmed at 25 entries)
234235
QStringList mRecentProjections;
235236

237+
//! hide deprecated CRSes
238+
void hideDeprecated( QTreeWidgetItem *item );
239+
236240
private slots:
237241
/**private handler for when user selects a cs
238242
*it will cause wktSelected and sridSelected events to be spawned

src/ui/qgsprojectionselectorbase.ui

+7
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@
153153
</property>
154154
</widget>
155155
</item>
156+
<item row="1" column="0" colspan="4">
157+
<widget class="QCheckBox" name="cbxHideDeprecated">
158+
<property name="text">
159+
<string>Hide deprecated CRSs</string>
160+
</property>
161+
</widget>
162+
</item>
156163
</layout>
157164
</widget>
158165
</item>

0 commit comments

Comments
 (0)