34
34
const int NAME_COLUMN = 0 ;
35
35
const int AUTHID_COLUMN = 1 ;
36
36
const int QGIS_CRS_ID_COLUMN = 2 ;
37
- const int POPULAR_CRSES = 3 ;
38
37
39
38
QgsProjectionSelector::QgsProjectionSelector ( QWidget* parent, const char * name, Qt::WFlags fl )
40
39
: QWidget( parent, fl )
@@ -47,21 +46,24 @@ QgsProjectionSelector::QgsProjectionSelector( QWidget* parent, const char * name
47
46
setupUi ( this );
48
47
connect ( lstCoordinateSystems, SIGNAL ( currentItemChanged ( QTreeWidgetItem*, QTreeWidgetItem* ) ),
49
48
this , SLOT ( coordinateSystemSelected ( QTreeWidgetItem* ) ) );
50
- connect ( leSearch, SIGNAL ( returnPressed () ), pbnFind, SLOT ( animateClick () ) );
51
49
52
50
// Get the full path name to the sqlite3 spatial reference database.
53
51
mSrsDatabaseFileName = QgsApplication::srsDbFilePath ();
54
52
lstCoordinateSystems->header ()->setResizeMode ( AUTHID_COLUMN, QHeaderView::Stretch );
55
53
lstCoordinateSystems->header ()->resizeSection ( QGIS_CRS_ID_COLUMN, 0 );
56
54
lstCoordinateSystems->header ()->setResizeMode ( QGIS_CRS_ID_COLUMN, QHeaderView::Fixed );
57
55
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
+
58
60
cbxAuthority->addItem ( tr ( " All" ) );
59
61
cbxAuthority->addItems ( authorities () );
60
62
61
63
// Read settings from persistent storage
62
64
QSettings settings;
63
65
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 */
65
67
/* ** This is kept now for backwards compatibility */
66
68
67
69
QStringList projectionsEpsg = settings.value ( " /UI/recentProjectionsEpsg" ).toStringList ();
@@ -135,10 +137,13 @@ QgsProjectionSelector::~QgsProjectionSelector()
135
137
136
138
void QgsProjectionSelector::resizeEvent ( QResizeEvent * theEvent )
137
139
{
138
-
139
140
lstCoordinateSystems->header ()->resizeSection ( NAME_COLUMN, theEvent->size ().width () - 240 );
140
141
lstCoordinateSystems->header ()->resizeSection ( AUTHID_COLUMN, 240 );
141
142
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 );
142
147
}
143
148
144
149
void QgsProjectionSelector::showEvent ( QShowEvent * theEvent )
@@ -171,43 +176,8 @@ void QgsProjectionSelector::showEvent( QShowEvent * theEvent )
171
176
applyAuthIDSelection ();
172
177
}
173
178
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 () );
211
181
212
182
// Pass up the inheritance hierarchy
213
183
QWidget::showEvent ( theEvent );
@@ -347,26 +317,20 @@ void QgsProjectionSelector::applyCRSNameSelection()
347
317
}
348
318
}
349
319
350
- QString QgsProjectionSelector::getCrsIdName ( long theCrsId )
320
+ void QgsProjectionSelector::insertRecent ( long theCrsId )
351
321
{
352
- QString retvalue ( " " );
353
- if ( mProjListDone && mUserProjListDone )
354
- {
355
- QString myCRSIDString = QString::number ( theCrsId );
322
+ if ( !mProjListDone || !mUserProjListDone )
323
+ return ;
356
324
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 );
358
326
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 ;
369
329
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 ) ) );
370
334
}
371
335
372
336
void QgsProjectionSelector::applyAuthIDSelection ()
@@ -889,6 +853,8 @@ void QgsProjectionSelector::coordinateSystemSelected( QTreeWidgetItem * theItem
889
853
QString myProjString = selectedProj4String ();
890
854
lstCoordinateSystems->scrollToItem ( theItem );
891
855
teProjection->setText ( myProjString );
856
+
857
+ lstRecent->clearSelection ();
892
858
}
893
859
else
894
860
{
@@ -920,24 +886,9 @@ void QgsProjectionSelector::on_cbxHideDeprecated_stateChanged()
920
886
hideDeprecated ( lstCoordinateSystems->topLevelItem ( i ) );
921
887
}
922
888
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 )
939
890
{
940
- setSelectedCrsId ( mRecentProjections . at ( 3 ).toLong () );
891
+ setSelectedCrsId ( current-> text ( QGIS_CRS_ID_COLUMN ).toLong () );
941
892
}
942
893
943
894
void QgsProjectionSelector::on_pbnFind_clicked ()
0 commit comments