Skip to content

Commit e006f04

Browse files
author
jef
committedMar 16, 2011
fix #3624
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15523 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 569dd68 commit e006f04

File tree

2 files changed

+44
-102
lines changed

2 files changed

+44
-102
lines changed
 

‎src/gui/qgsprojectionselector.cpp

Lines changed: 42 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -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

319330
void 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!
381347
QString 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

‎src/gui/qgsprojectionselector.h

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
140140
QString ogcWmsCrsFilterAsSqlExpression( QSet<QString> * crsFilter );
141141

142142
/**
143-
* \brief does the legwork of applying the CRS Name Selection
143+
* \brief does the legwork of applying CRS Selection
144144
*
145145
* \warning This function does nothing unless getUserList() and getUserProjList()
146146
* Have already been called
@@ -149,31 +149,7 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
149149
* does not scroll the list to the selection if the widget is not visible.
150150
* Therefore you will typically want to use this in a showEvent().
151151
*/
152-
void applyCRSNameSelection();
153-
154-
/**
155-
* \brief does the legwork of applying the CRS ID Selection
156-
*
157-
* \warning This function does nothing unless getUserList() and getUserProjList()
158-
* Have already been called
159-
*
160-
* \warning This function only expands the parents of the selection and
161-
* does not scroll the list to the selection if the widget is not visible.
162-
* Therefore you will typically want to use this in a showEvent().
163-
*/
164-
void applyCRSIDSelection();
165-
166-
/**
167-
* \brief does the legwork of applying the Authority ID Selection
168-
*
169-
* \warning This function does nothing unless getUserList() and getUserProjList()
170-
* Have already been called
171-
*
172-
* \warning This function only expands the parents of the selection and
173-
* does not scroll the list to the selection if the widget is not visible.
174-
* Therefore you will typically want to use this in a showEvent().
175-
*/
176-
void applyAuthIDSelection();
152+
void applySelection();
177153

178154
/**
179155
* \brief gets an arbitrary sqlite3 expression from the selection

0 commit comments

Comments
 (0)