@@ -163,17 +163,9 @@ void QgsProjectionSelector::showEvent( QShowEvent * theEvent )
163
163
164
164
// check if a paricular projection is waiting
165
165
// to be pre-selected, and if so, to select it now.
166
- if ( mCRSNameSelectionPending )
166
+ if ( mCRSNameSelectionPending || mCRSIDSelectionPending || mAuthIDSelectionPending )
167
167
{
168
- applyCRSNameSelection ();
169
- }
170
- if ( mCRSIDSelectionPending )
171
- {
172
- applyCRSIDSelection ();
173
- }
174
- if ( mAuthIDSelectionPending )
175
- {
176
- applyAuthIDSelection ();
168
+ applySelection ();
177
169
}
178
170
179
171
for ( int i = mRecentProjections .size () - 1 ; i >= 0 ; i-- )
@@ -253,7 +245,7 @@ void QgsProjectionSelector::setSelectedCrsName( QString theCRSName )
253
245
254
246
if ( isVisible () )
255
247
{
256
- applyCRSNameSelection ();
248
+ applySelection ();
257
249
}
258
250
// else we will wait for the projection selector to
259
251
// become visible (with the showEvent()) and set the
@@ -270,7 +262,7 @@ void QgsProjectionSelector::setSelectedCrsId( long theCRSID )
270
262
271
263
if ( isVisible () )
272
264
{
273
- applyCRSIDSelection ();
265
+ applySelection ();
274
266
}
275
267
// else we will wait for the projection selector to
276
268
// become visible (with the showEvent()) and set the
@@ -290,30 +282,49 @@ void QgsProjectionSelector::setSelectedAuthId( QString id )
290
282
mCRSNameSelectionPending = false ; // only one type can be pending at a time
291
283
}
292
284
293
- void QgsProjectionSelector::applyCRSNameSelection ()
285
+ void QgsProjectionSelector::applySelection ()
294
286
{
295
- if (
296
- mCRSNameSelectionPending &&
297
- mProjListDone &&
298
- mUserProjListDone
299
- )
287
+ if ( ! mProjListDone || ! mUserProjListDone )
288
+ return ;
289
+
290
+ QList<QTreeWidgetItem*> nodes;
291
+ if ( mCRSNameSelectionPending )
300
292
{
301
293
// get the srid given the wkt so we can pick the correct list item
302
294
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 );
314
296
315
297
mCRSNameSelectionPending = false ;
316
298
}
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
+ }
317
328
}
318
329
319
330
void QgsProjectionSelector::insertRecent ( long theCrsId )
@@ -332,51 +343,6 @@ void QgsProjectionSelector::insertRecent( long theCrsId )
332
343
<< nodes.first ()->text ( QGIS_CRS_ID_COLUMN ) ) );
333
344
}
334
345
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
-
380
346
// note this line just returns the projection name!
381
347
QString QgsProjectionSelector::selectedName ()
382
348
{
@@ -848,7 +814,7 @@ void QgsProjectionSelector::coordinateSystemSelected( QTreeWidgetItem * theItem
848
814
QString myDescription;
849
815
emit sridSelected ( QString::number ( selectedCrsId () ) );
850
816
QString myProjString = selectedProj4String ();
851
- lstCoordinateSystems->scrollToItem ( theItem, QAbstractItemView::PositionAtCenter );
817
+ lstCoordinateSystems->scrollToItem ( theItem );
852
818
teProjection->setText ( myProjString );
853
819
854
820
lstRecent->clearSelection ();
@@ -868,8 +834,8 @@ void QgsProjectionSelector::hideDeprecated( QTreeWidgetItem *item )
868
834
item->setHidden ( cbxHideDeprecated->isChecked () );
869
835
if ( item->isSelected () && item->isHidden () )
870
836
{
871
- teProjection->setText ( " " );
872
837
item->setSelected ( false );
838
+ teProjection->setText ( " " );
873
839
}
874
840
}
875
841
0 commit comments