Skip to content

Commit b5465e0

Browse files
author
jef
committed
use list instead of buttons for popular/recent projections
git-svn-id: http://svn.osgeo.org/qgis/trunk@13253 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent f82574f commit b5465e0

File tree

3 files changed

+159
-147
lines changed

3 files changed

+159
-147
lines changed

src/gui/qgsprojectionselector.cpp

Lines changed: 25 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
const int NAME_COLUMN = 0;
3535
const int AUTHID_COLUMN = 1;
3636
const int QGIS_CRS_ID_COLUMN = 2;
37-
const int POPULAR_CRSES = 3;
3837

3938
QgsProjectionSelector::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

136138
void 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

144149
void 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

372336
void 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

943894
void QgsProjectionSelector::on_pbnFind_clicked()

src/gui/qgsprojectionselector.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,9 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
110110
void setOgcWmsCrsFilter( QSet<QString> crsFilter );
111111

112112
void on_pbnFind_clicked();
113+
void on_lstRecent_currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem * );
113114
void on_cbxHideDeprecated_stateChanged();
114115

115-
void on_pbnPopular1_clicked();
116-
void on_pbnPopular2_clicked();
117-
void on_pbnPopular3_clicked();
118-
void on_pbnPopular4_clicked();
119-
120116
protected:
121117
/** Used to ensure the projection list view is actually populated */
122118
void showEvent( QShowEvent * theEvent );
@@ -201,8 +197,8 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
201197
*/
202198
long getLargestCRSIDMatch( QString theSql );
203199

204-
//! Returns name from CRS Id
205-
QString getCrsIdName( long theCrsId );
200+
//! add recently used CRS
201+
void insertRecent( long theCrsId );
206202

207203
//! Has the Projection List been populated?
208204
bool mProjListDone;

0 commit comments

Comments
 (0)