3434const int NAME_COLUMN = 0 ;
3535const int AUTHID_COLUMN = 1 ;
3636const int QGIS_CRS_ID_COLUMN = 2 ;
37- const int POPULAR_CRSES = 3 ;
3837
3938QgsProjectionSelector::QgsProjectionSelector ( QWidget* parent, const char * name, Qt::WFlags fl )
4039 : QWidget( parent, fl )
@@ -47,21 +46,24 @@ QgsProjectionSelector::QgsProjectionSelector( QWidget* parent, const char * name
4746 setupUi ( this );
4847 connect ( lstCoordinateSystems, SIGNAL ( currentItemChanged ( QTreeWidgetItem*, QTreeWidgetItem* ) ),
4948 this , SLOT ( coordinateSystemSelected ( QTreeWidgetItem* ) ) );
50- connect ( leSearch, SIGNAL ( returnPressed () ), pbnFind, SLOT ( animateClick () ) );
5149
5250 // Get the full path name to the sqlite3 spatial reference database.
5351 mSrsDatabaseFileName = QgsApplication::srsDbFilePath ();
5452 lstCoordinateSystems->header ()->setResizeMode ( AUTHID_COLUMN, QHeaderView::Stretch );
5553 lstCoordinateSystems->header ()->resizeSection ( QGIS_CRS_ID_COLUMN, 0 );
5654 lstCoordinateSystems->header ()->setResizeMode ( QGIS_CRS_ID_COLUMN, QHeaderView::Fixed );
5755
56+ lstRecent->header ()->setResizeMode ( AUTHID_COLUMN, QHeaderView::Stretch );
57+ lstRecent->header ()->resizeSection ( QGIS_CRS_ID_COLUMN, 0 );
58+ lstRecent->header ()->setResizeMode ( QGIS_CRS_ID_COLUMN, QHeaderView::Fixed );
59+
5860 cbxAuthority->addItem ( tr ( " All" ) );
5961 cbxAuthority->addItems ( authorities () );
6062
6163 // Read settings from persistent storage
6264 QSettings settings;
6365 mRecentProjections = settings.value ( " /UI/recentProjections" ).toStringList ();
64- /* ** The reading (above) of internal id from persistent storage should be removed sometims in the future */
66+ /* ** The reading (above) of internal id from persistent storage should be removed sometime in the future */
6567 /* ** This is kept now for backwards compatibility */
6668
6769 QStringList projectionsEpsg = settings.value ( " /UI/recentProjectionsEpsg" ).toStringList ();
@@ -135,10 +137,13 @@ QgsProjectionSelector::~QgsProjectionSelector()
135137
136138void QgsProjectionSelector::resizeEvent ( QResizeEvent * theEvent )
137139{
138-
139140 lstCoordinateSystems->header ()->resizeSection ( NAME_COLUMN, theEvent->size ().width () - 240 );
140141 lstCoordinateSystems->header ()->resizeSection ( AUTHID_COLUMN, 240 );
141142 lstCoordinateSystems->header ()->resizeSection ( QGIS_CRS_ID_COLUMN, 0 );
143+
144+ lstRecent->header ()->resizeSection ( NAME_COLUMN, theEvent->size ().width () - 240 );
145+ lstRecent->header ()->resizeSection ( AUTHID_COLUMN, 240 );
146+ lstRecent->header ()->resizeSection ( QGIS_CRS_ID_COLUMN, 0 );
142147}
143148
144149void QgsProjectionSelector::showEvent ( QShowEvent * theEvent )
@@ -171,43 +176,8 @@ void QgsProjectionSelector::showEvent( QShowEvent * theEvent )
171176 applyAuthIDSelection ();
172177 }
173178
174- // Update buttons
175- pbnPopular1->setDisabled ( true );
176- pbnPopular2->setDisabled ( true );
177- pbnPopular3->setDisabled ( true );
178- pbnPopular4->setDisabled ( true );
179- pbnPopular1->hide ();
180- pbnPopular2->hide ();
181- pbnPopular3->hide ();
182- pbnPopular4->hide ();
183-
184- if ( mRecentProjections .size () > 0 )
185- {
186- pbnPopular1->setText ( getCrsIdName ( mRecentProjections .at ( 0 ).toLong () ) );
187- pbnPopular1->setDisabled ( false );
188- pbnPopular1->show ();
189- }
190-
191- if ( mRecentProjections .size () > 1 )
192- {
193- pbnPopular2->setText ( getCrsIdName ( mRecentProjections .at ( 1 ).toLong () ) );
194- pbnPopular2->setDisabled ( false );
195- pbnPopular2->show ();
196- }
197-
198- if ( mRecentProjections .size () > 2 )
199- {
200- pbnPopular3->setText ( getCrsIdName ( mRecentProjections .at ( 2 ).toLong () ) );
201- pbnPopular3->setDisabled ( false );
202- pbnPopular3->show ();
203- }
204-
205- if ( mRecentProjections .size () > 3 )
206- {
207- pbnPopular4->setText ( getCrsIdName ( mRecentProjections .at ( 3 ).toLong () ) );
208- pbnPopular4->setDisabled ( false );
209- pbnPopular4->show ();
210- }
179+ for ( int i = mRecentProjections .size () - 1 ; i >= 0 ; i-- )
180+ insertRecent ( mRecentProjections .at ( i ).toLong () );
211181
212182 // Pass up the inheritance hierarchy
213183 QWidget::showEvent ( theEvent );
@@ -347,26 +317,20 @@ void QgsProjectionSelector::applyCRSNameSelection()
347317 }
348318}
349319
350- QString QgsProjectionSelector::getCrsIdName ( long theCrsId )
320+ void QgsProjectionSelector::insertRecent ( long theCrsId )
351321{
352- QString retvalue ( " " );
353- if ( mProjListDone && mUserProjListDone )
354- {
355- QString myCRSIDString = QString::number ( theCrsId );
322+ if ( !mProjListDone || !mUserProjListDone )
323+ return ;
356324
357- QList<QTreeWidgetItem*> nodes = lstCoordinateSystems->findItems ( myCRSIDString , Qt::MatchExactly | Qt::MatchRecursive, QGIS_CRS_ID_COLUMN );
325+ QList<QTreeWidgetItem*> nodes = lstCoordinateSystems->findItems ( QString::number ( theCrsId ) , Qt::MatchExactly | Qt::MatchRecursive, QGIS_CRS_ID_COLUMN );
358326
359- if ( nodes.count () > 0 )
360- {
361- retvalue = nodes.first ()->text ( NAME_COLUMN );
362- if ( nodes.first ()->text ( AUTHID_COLUMN ) != " " )
363- {
364- retvalue += " " + nodes.first ()->text ( AUTHID_COLUMN );
365- }
366- }
367- }
368- return retvalue;
327+ if ( nodes.count () == 0 )
328+ return ;
369329
330+ lstRecent->insertTopLevelItem ( 0 , new QTreeWidgetItem ( lstRecent, QStringList ()
331+ << nodes.first ()->text ( NAME_COLUMN )
332+ << nodes.first ()->text ( AUTHID_COLUMN )
333+ << nodes.first ()->text ( QGIS_CRS_ID_COLUMN ) ) );
370334}
371335
372336void QgsProjectionSelector::applyAuthIDSelection ()
@@ -889,6 +853,8 @@ void QgsProjectionSelector::coordinateSystemSelected( QTreeWidgetItem * theItem
889853 QString myProjString = selectedProj4String ();
890854 lstCoordinateSystems->scrollToItem ( theItem );
891855 teProjection->setText ( myProjString );
856+
857+ lstRecent->clearSelection ();
892858 }
893859 else
894860 {
@@ -920,24 +886,9 @@ void QgsProjectionSelector::on_cbxHideDeprecated_stateChanged()
920886 hideDeprecated ( lstCoordinateSystems->topLevelItem ( i ) );
921887}
922888
923- void QgsProjectionSelector::on_pbnPopular1_clicked ()
924- {
925- setSelectedCrsId ( mRecentProjections .at ( 0 ).toLong () );
926- }
927-
928- void QgsProjectionSelector::on_pbnPopular2_clicked ()
929- {
930- setSelectedCrsId ( mRecentProjections .at ( 1 ).toLong () );
931- }
932-
933- void QgsProjectionSelector::on_pbnPopular3_clicked ()
934- {
935- setSelectedCrsId ( mRecentProjections .at ( 2 ).toLong () );
936- }
937-
938- void QgsProjectionSelector::on_pbnPopular4_clicked ()
889+ void QgsProjectionSelector::on_lstRecent_currentItemChanged ( QTreeWidgetItem *current, QTreeWidgetItem *previous )
939890{
940- setSelectedCrsId ( mRecentProjections . at ( 3 ).toLong () );
891+ setSelectedCrsId ( current-> text ( QGIS_CRS_ID_COLUMN ).toLong () );
941892}
942893
943894void QgsProjectionSelector::on_pbnFind_clicked ()
0 commit comments