@@ -163,17 +163,9 @@ void QgsProjectionSelector::showEvent( QShowEvent * theEvent )
163163
164164 // check if a paricular projection is waiting
165165 // to be pre-selected, and if so, to select it now.
166- if ( mCRSNameSelectionPending )
166+ if ( mCRSNameSelectionPending || mCRSIDSelectionPending || mAuthIDSelectionPending )
167167 {
168- applyCRSNameSelection ();
169- }
170- if ( mCRSIDSelectionPending )
171- {
172- applyCRSIDSelection ();
173- }
174- if ( mAuthIDSelectionPending )
175- {
176- applyAuthIDSelection ();
168+ applySelection ();
177169 }
178170
179171 for ( int i = mRecentProjections .size () - 1 ; i >= 0 ; i-- )
@@ -253,7 +245,7 @@ void QgsProjectionSelector::setSelectedCrsName( QString theCRSName )
253245
254246 if ( isVisible () )
255247 {
256- applyCRSNameSelection ();
248+ applySelection ();
257249 }
258250 // else we will wait for the projection selector to
259251 // become visible (with the showEvent()) and set the
@@ -270,7 +262,7 @@ void QgsProjectionSelector::setSelectedCrsId( long theCRSID )
270262
271263 if ( isVisible () )
272264 {
273- applyCRSIDSelection ();
265+ applySelection ();
274266 }
275267 // else we will wait for the projection selector to
276268 // become visible (with the showEvent()) and set the
@@ -290,30 +282,49 @@ void QgsProjectionSelector::setSelectedAuthId( QString id )
290282 mCRSNameSelectionPending = false ; // only one type can be pending at a time
291283}
292284
293- void QgsProjectionSelector::applyCRSNameSelection ()
285+ void QgsProjectionSelector::applySelection ()
294286{
295- if (
296- mCRSNameSelectionPending &&
297- mProjListDone &&
298- mUserProjListDone
299- )
287+ if ( ! mProjListDone || ! mUserProjListDone )
288+ return ;
289+
290+ QList<QTreeWidgetItem*> nodes;
291+ if ( mCRSNameSelectionPending )
300292 {
301293 // get the srid given the wkt so we can pick the correct list item
302294 QgsDebugMsg ( " called with " + mCRSNameSelection );
303- QList<QTreeWidgetItem*> nodes = lstCoordinateSystems->findItems ( mCRSNameSelection , Qt::MatchExactly | Qt::MatchRecursive, 0 );
304-
305- if ( nodes.count () > 0 )
306- {
307- lstCoordinateSystems->setCurrentItem ( nodes.first () );
308- }
309- else // unselect the selected item to avoid confusing the user
310- {
311- lstCoordinateSystems->clearSelection ();
312- teProjection->setText ( " " );
313- }
295+ nodes = lstCoordinateSystems->findItems ( mCRSNameSelection , Qt::MatchExactly | Qt::MatchRecursive, 0 );
314296
315297 mCRSNameSelectionPending = false ;
316298 }
299+
300+ if ( mAuthIDSelectionPending )
301+ {
302+ // get the srid given the wkt so we can pick the correct list item
303+ QgsDebugMsg ( " called with " + mAuthIDSelection );
304+ nodes = lstCoordinateSystems->findItems ( mAuthIDSelection , Qt::MatchExactly | Qt::MatchRecursive, AUTHID_COLUMN );
305+
306+ mAuthIDSelectionPending = false ;
307+ }
308+
309+ if ( mCRSIDSelectionPending )
310+ {
311+ QString myCRSIDString = QString::number ( mCRSIDSelection );
312+
313+ nodes = lstCoordinateSystems->findItems ( myCRSIDString, Qt::MatchExactly | Qt::MatchRecursive, QGIS_CRS_ID_COLUMN );
314+
315+ mCRSIDSelectionPending = false ;
316+ }
317+
318+ if ( nodes.count () > 0 )
319+ {
320+ lstCoordinateSystems->setCurrentItem ( nodes.first () );
321+ lstCoordinateSystems->scrollToItem ( lstCoordinateSystems->currentItem (), QAbstractItemView::PositionAtCenter );
322+ }
323+ else // unselect the selected item to avoid confusing the user
324+ {
325+ lstCoordinateSystems->clearSelection ();
326+ teProjection->setText ( " " );
327+ }
317328}
318329
319330void QgsProjectionSelector::insertRecent ( long theCrsId )
@@ -332,51 +343,6 @@ void QgsProjectionSelector::insertRecent( long theCrsId )
332343 << nodes.first ()->text ( QGIS_CRS_ID_COLUMN ) ) );
333344}
334345
335- void QgsProjectionSelector::applyAuthIDSelection ()
336- {
337- if ( mAuthIDSelectionPending && mProjListDone && mUserProjListDone )
338- {
339- // get the srid given the wkt so we can pick the correct list item
340- QgsDebugMsg ( " called with " + mAuthIDSelection );
341- QList<QTreeWidgetItem*> nodes = lstCoordinateSystems->findItems ( mAuthIDSelection , Qt::MatchExactly | Qt::MatchRecursive, AUTHID_COLUMN );
342-
343- if ( nodes.count () > 0 )
344- {
345- lstCoordinateSystems->setCurrentItem ( nodes.first () );
346- }
347- else // unselect the selected item to avoid confusing the user
348- {
349- lstCoordinateSystems->clearSelection ();
350- teProjection->setText ( " " );
351- }
352-
353- mAuthIDSelectionPending = false ;
354- }
355- }
356-
357- void QgsProjectionSelector::applyCRSIDSelection ()
358- {
359- if ( mCRSIDSelectionPending && mProjListDone && mUserProjListDone )
360- {
361- QString myCRSIDString = QString::number ( mCRSIDSelection );
362-
363- QList<QTreeWidgetItem*> nodes = lstCoordinateSystems->findItems ( myCRSIDString, Qt::MatchExactly | Qt::MatchRecursive, QGIS_CRS_ID_COLUMN );
364-
365- if ( nodes.count () > 0 )
366- {
367- lstCoordinateSystems->setCurrentItem ( nodes.first () );
368- }
369- else // unselect the selected item to avoid confusing the user
370- {
371- lstCoordinateSystems->clearSelection ();
372- teProjection->setText ( " " );
373- }
374-
375- mCRSIDSelectionPending = false ;
376- }
377- }
378-
379-
380346// note this line just returns the projection name!
381347QString QgsProjectionSelector::selectedName ()
382348{
@@ -848,7 +814,7 @@ void QgsProjectionSelector::coordinateSystemSelected( QTreeWidgetItem * theItem
848814 QString myDescription;
849815 emit sridSelected ( QString::number ( selectedCrsId () ) );
850816 QString myProjString = selectedProj4String ();
851- lstCoordinateSystems->scrollToItem ( theItem, QAbstractItemView::PositionAtCenter );
817+ lstCoordinateSystems->scrollToItem ( theItem );
852818 teProjection->setText ( myProjString );
853819
854820 lstRecent->clearSelection ();
@@ -868,8 +834,8 @@ void QgsProjectionSelector::hideDeprecated( QTreeWidgetItem *item )
868834 item->setHidden ( cbxHideDeprecated->isChecked () );
869835 if ( item->isSelected () && item->isHidden () )
870836 {
871- teProjection->setText ( " " );
872837 item->setSelected ( false );
838+ teProjection->setText ( " " );
873839 }
874840 }
875841
0 commit comments