16
16
#include < sqlite3.h>
17
17
18
18
// qgis includes
19
- #include " qgis.h" // magick numbers here
19
+ #include " qgis.h" // magic numbers here
20
20
#include " qgsapplication.h"
21
21
#include " qgslogger.h"
22
22
#include < qgscoordinatereferencesystem.h>
@@ -36,15 +36,13 @@ const int AUTHID_COLUMN = 1;
36
36
const int QGIS_CRS_ID_COLUMN = 2 ;
37
37
const int POPULAR_CRSES = 3 ;
38
38
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 )
48
46
{
49
47
setupUi ( this );
50
48
connect ( lstCoordinateSystems, SIGNAL ( currentItemChanged ( QTreeWidgetItem*, QTreeWidgetItem* ) ),
@@ -268,9 +266,9 @@ QString QgsProjectionSelector::ogcWmsCrsFilterAsSqlExpression( QSet<QString> * c
268
266
void QgsProjectionSelector::setSelectedCrsName ( QString theCRSName )
269
267
{
270
268
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 ;
274
272
275
273
if ( isVisible () )
276
274
{
@@ -285,9 +283,9 @@ void QgsProjectionSelector::setSelectedCrsName( QString theCRSName )
285
283
void QgsProjectionSelector::setSelectedCrsId ( long theCRSID )
286
284
{
287
285
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 ;
291
289
292
290
if ( isVisible () )
293
291
{
@@ -306,9 +304,9 @@ void QgsProjectionSelector::setSelectedEpsg( long id )
306
304
void QgsProjectionSelector::setSelectedAuthId ( QString id )
307
305
{
308
306
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
312
310
}
313
311
314
312
void QgsProjectionSelector::applyCRSNameSelection ()
@@ -334,7 +332,7 @@ void QgsProjectionSelector::applyCRSNameSelection()
334
332
teProjection->setText ( " " );
335
333
}
336
334
337
- mCRSNameSelectionPending = FALSE ;
335
+ mCRSNameSelectionPending = false ;
338
336
}
339
337
}
340
338
@@ -379,7 +377,7 @@ void QgsProjectionSelector::applyAuthIDSelection()
379
377
teProjection->setText ( " " );
380
378
}
381
379
382
- mAuthIDSelectionPending = FALSE ;
380
+ mAuthIDSelectionPending = false ;
383
381
}
384
382
}
385
383
@@ -402,7 +400,7 @@ void QgsProjectionSelector::applyCRSIDSelection()
402
400
teProjection->setText ( " " );
403
401
}
404
402
405
- mCRSIDSelectionPending = FALSE ;
403
+ mCRSIDSelectionPending = false ;
406
404
}
407
405
}
408
406
@@ -654,8 +652,8 @@ void QgsProjectionSelector::loadUserCrsList( QSet<QString> * crsFilter )
654
652
mUserProjList = new QTreeWidgetItem ( lstCoordinateSystems, QStringList ( tr ( " User Defined Coordinate Systems" ) ) );
655
653
656
654
QFont fontTemp = mUserProjList ->font ( 0 );
657
- fontTemp.setItalic ( TRUE );
658
- fontTemp.setBold ( TRUE );
655
+ fontTemp.setItalic ( true );
656
+ fontTemp.setBold ( true );
659
657
mUserProjList ->setFont ( 0 , fontTemp );
660
658
mUserProjList ->setIcon ( 0 , QIcon ( QgsApplication::activeThemePath () + " user.png" ) );
661
659
@@ -671,7 +669,7 @@ void QgsProjectionSelector::loadUserCrsList( QSet<QString> * crsFilter )
671
669
{
672
670
QgsDebugMsg ( " Users qgis.db not found...skipping" );
673
671
674
- mUserProjListDone = TRUE ;
672
+ mUserProjListDone = true ;
675
673
return ;
676
674
}
677
675
@@ -714,7 +712,7 @@ void QgsProjectionSelector::loadUserCrsList( QSet<QString> * crsFilter )
714
712
sqlite3_finalize ( myPreparedStatement );
715
713
sqlite3_close ( myDatabase );
716
714
717
- mUserProjListDone = TRUE ;
715
+ mUserProjListDone = true ;
718
716
}
719
717
720
718
void QgsProjectionSelector::loadCrsList ( QSet<QString> * crsFilter )
@@ -729,17 +727,17 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> * crsFilter )
729
727
mGeoList = new QTreeWidgetItem ( lstCoordinateSystems, QStringList ( tr ( " Geographic Coordinate Systems" ) ) );
730
728
731
729
QFont fontTemp = mGeoList ->font ( 0 );
732
- fontTemp.setItalic ( TRUE );
733
- fontTemp.setBold ( TRUE );
730
+ fontTemp.setItalic ( true );
731
+ fontTemp.setBold ( true );
734
732
mGeoList ->setFont ( 0 , fontTemp );
735
733
mGeoList ->setIcon ( 0 , QIcon ( QgsApplication::activeThemePath () + " geographic.png" ) );
736
734
737
735
// Projected coordinate system node
738
736
mProjList = new QTreeWidgetItem ( lstCoordinateSystems, QStringList ( tr ( " Projected Coordinate Systems" ) ) );
739
737
740
738
fontTemp = mProjList ->font ( 0 );
741
- fontTemp.setItalic ( TRUE );
742
- fontTemp.setBold ( TRUE );
739
+ fontTemp.setItalic ( true );
740
+ fontTemp.setBold ( true );
743
741
mProjList ->setFont ( 0 , fontTemp );
744
742
mProjList ->setIcon ( 0 , QIcon ( QgsApplication::activeThemePath () + " transformed.png" ) );
745
743
@@ -752,7 +750,7 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> * crsFilter )
752
750
myFileInfo.setFile ( mSrsDatabaseFileName );
753
751
if ( !myFileInfo.exists ( ) )
754
752
{
755
- mProjListDone = TRUE ;
753
+ mProjListDone = true ;
756
754
return ;
757
755
}
758
756
@@ -782,7 +780,7 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> * crsFilter )
782
780
// Set up the query to retrieve the projection information needed to populate the list
783
781
// note I am giving the full field names for clarity here and in case someone
784
782
// 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" )
786
784
.arg ( sqlFilter );
787
785
788
786
rc = sqlite3_prepare ( db, sql.toUtf8 (), sql.toUtf8 ().length (), &ppStmt, &pzTail );
@@ -832,7 +830,7 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> * crsFilter )
832
830
node = new QTreeWidgetItem ( mProjList , QStringList ( srsType ) );
833
831
834
832
QFont fontTemp = node->font ( 0 );
835
- fontTemp.setItalic ( TRUE );
833
+ fontTemp.setItalic ( true );
836
834
node->setFont ( 0 , fontTemp );
837
835
}
838
836
else
@@ -849,7 +847,12 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> * crsFilter )
849
847
newItem->setText ( AUTHID_COLUMN, QString::fromUtf8 (( char * )sqlite3_column_text ( ppStmt, 2 ) ) );
850
848
// display the qgis srs_id (field 1) in the third column of the list view
851
849
newItem->setText ( QGIS_CRS_ID_COLUMN, QString::fromUtf8 (( char * )sqlite3_column_text ( ppStmt, 1 ) ) );
850
+
852
851
}
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 () );
853
856
}
854
857
mProjList ->setExpanded ( true );
855
858
}
@@ -858,7 +861,7 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> * crsFilter )
858
861
// close the database
859
862
sqlite3_close ( db );
860
863
861
- mProjListDone = TRUE ;
864
+ mProjListDone = true ;
862
865
}
863
866
864
867
@@ -867,7 +870,7 @@ void QgsProjectionSelector::coordinateSystemSelected( QTreeWidgetItem * theItem
867
870
{
868
871
// If the item has children, it's not an end node in the tree, and
869
872
// hence is just a grouping thingy, not an actual CRS.
870
- if ( theItem != NULL && theItem->childCount () == 0 )
873
+ if ( theItem && theItem->childCount () == 0 )
871
874
{
872
875
// Found a real CRS
873
876
QString myDescription;
@@ -879,11 +882,33 @@ void QgsProjectionSelector::coordinateSystemSelected( QTreeWidgetItem * theItem
879
882
else
880
883
{
881
884
// 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 );
883
886
teProjection->setText ( " " );
884
887
}
885
888
}
886
889
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
+
887
912
void QgsProjectionSelector::on_pbnPopular1_clicked ()
888
913
{
889
914
setSelectedCrsId ( mRecentProjections .at ( 0 ).toLong () );
@@ -893,18 +918,19 @@ void QgsProjectionSelector::on_pbnPopular2_clicked()
893
918
{
894
919
setSelectedCrsId ( mRecentProjections .at ( 1 ).toLong () );
895
920
}
921
+
896
922
void QgsProjectionSelector::on_pbnPopular3_clicked ()
897
923
{
898
924
setSelectedCrsId ( mRecentProjections .at ( 2 ).toLong () );
899
925
}
926
+
900
927
void QgsProjectionSelector::on_pbnPopular4_clicked ()
901
928
{
902
929
setSelectedCrsId ( mRecentProjections .at ( 3 ).toLong () );
903
930
}
904
931
905
932
void QgsProjectionSelector::on_pbnFind_clicked ()
906
933
{
907
-
908
934
QgsDebugMsg ( " pbnFind..." );
909
935
910
936
QString mySearchString ( sqlSafeString ( leSearch->text () ) );
@@ -918,22 +944,29 @@ void QgsProjectionSelector::on_pbnFind_clicked()
918
944
{
919
945
// we need to find what the largest srsid matching our query so we know whether to
920
946
// 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" ;
922
951
long myLargestSrsId = getLargestCRSIDMatch ( mySql );
923
952
QgsDebugMsg ( QString ( " Largest CRSID%1" ).arg ( myLargestSrsId ) );
924
953
// a name search is ambiguous, so we find the first srsid after the current seelcted srsid
925
954
// each time the find button is pressed. This means we can loop through all matches.
926
955
if ( myLargestSrsId <= selectedCrsId () )
927
956
{
928
957
// 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" ;
931
962
}
932
963
else
933
964
{
934
965
// 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" ;
937
970
}
938
971
}
939
972
QgsDebugMsg ( QString ( " Search sql: %1" ).arg ( mySql ) );
@@ -1002,8 +1035,13 @@ void QgsProjectionSelector::on_pbnFind_clicked()
1002
1035
// close the sqlite3 statement
1003
1036
sqlite3_finalize ( myPreparedStatement );
1004
1037
sqlite3_close ( myDatabase );
1038
+ return ;
1005
1039
}
1006
1040
}
1041
+
1042
+ QMessageBox::information ( this , tr ( " Find projection" ), tr ( " No matching projection found." ) );
1043
+ lstCoordinateSystems->clearSelection ();
1044
+ teProjection->setText ( " " );
1007
1045
}
1008
1046
1009
1047
long QgsProjectionSelector::getLargestCRSIDMatch ( QString theSql )
0 commit comments