Skip to content

Commit

Permalink
fix #3624
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15523 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Mar 16, 2011
1 parent 569dd68 commit e006f04
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 102 deletions.
118 changes: 42 additions & 76 deletions src/gui/qgsprojectionselector.cpp
Expand Up @@ -163,17 +163,9 @@ void QgsProjectionSelector::showEvent( QShowEvent * theEvent )

// check if a paricular projection is waiting
// to be pre-selected, and if so, to select it now.
if ( mCRSNameSelectionPending )
if ( mCRSNameSelectionPending || mCRSIDSelectionPending || mAuthIDSelectionPending )
{
applyCRSNameSelection();
}
if ( mCRSIDSelectionPending )
{
applyCRSIDSelection();
}
if ( mAuthIDSelectionPending )
{
applyAuthIDSelection();
applySelection();
}

for ( int i = mRecentProjections.size() - 1; i >= 0; i-- )
Expand Down Expand Up @@ -253,7 +245,7 @@ void QgsProjectionSelector::setSelectedCrsName( QString theCRSName )

if ( isVisible() )
{
applyCRSNameSelection();
applySelection();
}
// else we will wait for the projection selector to
// become visible (with the showEvent()) and set the
Expand All @@ -270,7 +262,7 @@ void QgsProjectionSelector::setSelectedCrsId( long theCRSID )

if ( isVisible() )
{
applyCRSIDSelection();
applySelection();
}
// else we will wait for the projection selector to
// become visible (with the showEvent()) and set the
Expand All @@ -290,30 +282,49 @@ void QgsProjectionSelector::setSelectedAuthId( QString id )
mCRSNameSelectionPending = false; // only one type can be pending at a time
}

void QgsProjectionSelector::applyCRSNameSelection()
void QgsProjectionSelector::applySelection()
{
if (
mCRSNameSelectionPending &&
mProjListDone &&
mUserProjListDone
)
if ( !mProjListDone || !mUserProjListDone )
return;

QList<QTreeWidgetItem*> nodes;
if ( mCRSNameSelectionPending )
{
//get the srid given the wkt so we can pick the correct list item
QgsDebugMsg( "called with " + mCRSNameSelection );
QList<QTreeWidgetItem*> nodes = lstCoordinateSystems->findItems( mCRSNameSelection, Qt::MatchExactly | Qt::MatchRecursive, 0 );

if ( nodes.count() > 0 )
{
lstCoordinateSystems->setCurrentItem( nodes.first() );
}
else // unselect the selected item to avoid confusing the user
{
lstCoordinateSystems->clearSelection();
teProjection->setText( "" );
}
nodes = lstCoordinateSystems->findItems( mCRSNameSelection, Qt::MatchExactly | Qt::MatchRecursive, 0 );

mCRSNameSelectionPending = false;
}

if ( mAuthIDSelectionPending )
{
//get the srid given the wkt so we can pick the correct list item
QgsDebugMsg( "called with " + mAuthIDSelection );
nodes = lstCoordinateSystems->findItems( mAuthIDSelection, Qt::MatchExactly | Qt::MatchRecursive, AUTHID_COLUMN );

mAuthIDSelectionPending = false;
}

if ( mCRSIDSelectionPending )
{
QString myCRSIDString = QString::number( mCRSIDSelection );

nodes = lstCoordinateSystems->findItems( myCRSIDString, Qt::MatchExactly | Qt::MatchRecursive, QGIS_CRS_ID_COLUMN );

mCRSIDSelectionPending = false;
}

if ( nodes.count() > 0 )
{
lstCoordinateSystems->setCurrentItem( nodes.first() );
lstCoordinateSystems->scrollToItem( lstCoordinateSystems->currentItem(), QAbstractItemView::PositionAtCenter );
}
else // unselect the selected item to avoid confusing the user
{
lstCoordinateSystems->clearSelection();
teProjection->setText( "" );
}
}

void QgsProjectionSelector::insertRecent( long theCrsId )
Expand All @@ -332,51 +343,6 @@ void QgsProjectionSelector::insertRecent( long theCrsId )
<< nodes.first()->text( QGIS_CRS_ID_COLUMN ) ) );
}

void QgsProjectionSelector::applyAuthIDSelection()
{
if ( mAuthIDSelectionPending && mProjListDone && mUserProjListDone )
{
//get the srid given the wkt so we can pick the correct list item
QgsDebugMsg( "called with " + mAuthIDSelection );
QList<QTreeWidgetItem*> nodes = lstCoordinateSystems->findItems( mAuthIDSelection, Qt::MatchExactly | Qt::MatchRecursive, AUTHID_COLUMN );

if ( nodes.count() > 0 )
{
lstCoordinateSystems->setCurrentItem( nodes.first() );
}
else // unselect the selected item to avoid confusing the user
{
lstCoordinateSystems->clearSelection();
teProjection->setText( "" );
}

mAuthIDSelectionPending = false;
}
}

void QgsProjectionSelector::applyCRSIDSelection()
{
if ( mCRSIDSelectionPending && mProjListDone && mUserProjListDone )
{
QString myCRSIDString = QString::number( mCRSIDSelection );

QList<QTreeWidgetItem*> nodes = lstCoordinateSystems->findItems( myCRSIDString, Qt::MatchExactly | Qt::MatchRecursive, QGIS_CRS_ID_COLUMN );

if ( nodes.count() > 0 )
{
lstCoordinateSystems->setCurrentItem( nodes.first() );
}
else // unselect the selected item to avoid confusing the user
{
lstCoordinateSystems->clearSelection();
teProjection->setText( "" );
}

mCRSIDSelectionPending = false;
}
}


//note this line just returns the projection name!
QString QgsProjectionSelector::selectedName()
{
Expand Down Expand Up @@ -848,7 +814,7 @@ void QgsProjectionSelector::coordinateSystemSelected( QTreeWidgetItem * theItem
QString myDescription;
emit sridSelected( QString::number( selectedCrsId() ) );
QString myProjString = selectedProj4String();
lstCoordinateSystems->scrollToItem( theItem, QAbstractItemView::PositionAtCenter );
lstCoordinateSystems->scrollToItem( theItem );
teProjection->setText( myProjString );

lstRecent->clearSelection();
Expand All @@ -868,8 +834,8 @@ void QgsProjectionSelector::hideDeprecated( QTreeWidgetItem *item )
item->setHidden( cbxHideDeprecated->isChecked() );
if ( item->isSelected() && item->isHidden() )
{
teProjection->setText( "" );
item->setSelected( false );
teProjection->setText( "" );
}
}

Expand Down
28 changes: 2 additions & 26 deletions src/gui/qgsprojectionselector.h
Expand Up @@ -140,7 +140,7 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
QString ogcWmsCrsFilterAsSqlExpression( QSet<QString> * crsFilter );

/**
* \brief does the legwork of applying the CRS Name Selection
* \brief does the legwork of applying CRS Selection
*
* \warning This function does nothing unless getUserList() and getUserProjList()
* Have already been called
Expand All @@ -149,31 +149,7 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
* does not scroll the list to the selection if the widget is not visible.
* Therefore you will typically want to use this in a showEvent().
*/
void applyCRSNameSelection();

/**
* \brief does the legwork of applying the CRS ID Selection
*
* \warning This function does nothing unless getUserList() and getUserProjList()
* Have already been called
*
* \warning This function only expands the parents of the selection and
* does not scroll the list to the selection if the widget is not visible.
* Therefore you will typically want to use this in a showEvent().
*/
void applyCRSIDSelection();

/**
* \brief does the legwork of applying the Authority ID Selection
*
* \warning This function does nothing unless getUserList() and getUserProjList()
* Have already been called
*
* \warning This function only expands the parents of the selection and
* does not scroll the list to the selection if the widget is not visible.
* Therefore you will typically want to use this in a showEvent().
*/
void applyAuthIDSelection();
void applySelection();

/**
* \brief gets an arbitrary sqlite3 expression from the selection
Expand Down

0 comments on commit e006f04

Please sign in to comment.