28
28
#include < QHeaderView>
29
29
#include < QResizeEvent>
30
30
#include < QMessageBox>
31
+ #include < QSettings>
31
32
#include " qgslogger.h"
32
33
33
34
const int NAME_COLUMN = 0 ;
@@ -54,11 +55,35 @@ QgsProjectionSelector::QgsProjectionSelector( QWidget* parent,
54
55
lstCoordinateSystems->header ()->setResizeMode ( EPSG_COLUMN, QHeaderView::Stretch );
55
56
lstCoordinateSystems->header ()->resizeSection ( QGIS_CRS_ID_COLUMN, 0 );
56
57
lstCoordinateSystems->header ()->setResizeMode ( QGIS_CRS_ID_COLUMN, QHeaderView::Fixed );
58
+
59
+ // Read settings from persistent storage
60
+ QSettings settings;
61
+ mRecentProjections = settings.value (" /UI/recentProjections" ).toStringList ();
62
+
57
63
}
58
64
59
65
60
66
QgsProjectionSelector::~QgsProjectionSelector ()
61
- {}
67
+ {
68
+ // Save persistent list of projects
69
+ QSettings settings;
70
+ long crsId;
71
+
72
+ // Push current projection to front, only if set
73
+ crsId = selectedCrsId ();
74
+ if ( crsId )
75
+ {
76
+ mRecentProjections .removeAll ( QString::number ( crsId ) );
77
+ mRecentProjections .prepend ( QString::number ( crsId ) );
78
+ // Prunse size of list
79
+ while ( mRecentProjections .size () > 4 )
80
+ {
81
+ mRecentProjections .removeLast ();
82
+ }
83
+ // Save to file
84
+ settings.setValue ( " /UI/recentProjections" , mRecentProjections );
85
+ }
86
+ }
62
87
63
88
64
89
void QgsProjectionSelector::resizeEvent ( QResizeEvent * theEvent )
@@ -99,6 +124,40 @@ void QgsProjectionSelector::showEvent( QShowEvent * theEvent )
99
124
applyEPSGIDSelection ();
100
125
}
101
126
127
+ // Update buttons
128
+ pbnPopular1->setDisabled (true );
129
+ pbnPopular2->setDisabled (true );
130
+ pbnPopular3->setDisabled (true );
131
+ pbnPopular4->setDisabled (true );
132
+ pbnPopular1->hide ();
133
+ pbnPopular2->hide ();
134
+ pbnPopular3->hide ();
135
+ pbnPopular4->hide ();
136
+
137
+ if ( mRecentProjections .size () > 0 ) {
138
+ pbnPopular1->setText ( getCrsIdName ( mRecentProjections .at (0 ).toLong () ) );
139
+ pbnPopular1->setDisabled (false );
140
+ pbnPopular1->show ();
141
+ }
142
+
143
+ if ( mRecentProjections .size () > 1 ) {
144
+ pbnPopular2->setText ( getCrsIdName ( mRecentProjections .at (1 ).toLong () ) );
145
+ pbnPopular2->setDisabled (false );
146
+ pbnPopular2->show ();
147
+ }
148
+
149
+ if ( mRecentProjections .size () > 2 ) {
150
+ pbnPopular3->setText ( getCrsIdName ( mRecentProjections .at (2 ).toLong () ) );
151
+ pbnPopular3->setDisabled (false );
152
+ pbnPopular3->show ();
153
+ }
154
+
155
+ if ( mRecentProjections .size () > 3 ) {
156
+ pbnPopular4->setText ( getCrsIdName ( mRecentProjections .at (3 ).toLong () ) );
157
+ pbnPopular4->setDisabled (false );
158
+ pbnPopular4->show ();
159
+ }
160
+
102
161
// Pass up the inheritance heirarchy
103
162
QWidget::showEvent ( theEvent );
104
163
}
@@ -235,6 +294,26 @@ void QgsProjectionSelector::applyCRSNameSelection()
235
294
}
236
295
}
237
296
297
+ QString QgsProjectionSelector::getCrsIdName ( long theCrsId )
298
+ {
299
+ if (
300
+ ( mProjListDone ) &&
301
+ ( mUserProjListDone )
302
+ )
303
+ {
304
+ QString myCRSIDString = QString::number ( theCrsId );
305
+
306
+ QList<QTreeWidgetItem*> nodes = lstCoordinateSystems->findItems ( myCRSIDString, Qt::MatchExactly | Qt::MatchRecursive, QGIS_CRS_ID_COLUMN );
307
+
308
+ if ( nodes.count () > 0 )
309
+ {
310
+ return nodes.first ()->text (0 );
311
+ }
312
+ }
313
+ return QString ( " " );
314
+
315
+ }
316
+
238
317
void QgsProjectionSelector::applyEPSGIDSelection ()
239
318
{
240
319
if (
@@ -761,6 +840,24 @@ void QgsProjectionSelector::coordinateSystemSelected( QTreeWidgetItem * theItem
761
840
}
762
841
}
763
842
843
+ void QgsProjectionSelector::on_pbnPopular1_clicked ()
844
+ {
845
+ setSelectedCrsId ( mRecentProjections .at (0 ).toLong () );
846
+ }
847
+
848
+ void QgsProjectionSelector::on_pbnPopular2_clicked ()
849
+ {
850
+ setSelectedCrsId ( mRecentProjections .at (1 ).toLong () );
851
+ }
852
+ void QgsProjectionSelector::on_pbnPopular3_clicked ()
853
+ {
854
+ setSelectedCrsId ( mRecentProjections .at (2 ).toLong () );
855
+ }
856
+ void QgsProjectionSelector::on_pbnPopular4_clicked ()
857
+ {
858
+ setSelectedCrsId ( mRecentProjections .at (3 ).toLong () );
859
+ }
860
+
764
861
void QgsProjectionSelector::on_pbnFind_clicked ()
765
862
{
766
863
0 commit comments