Skip to content

Commit 1664273

Browse files
author
homann
committed
Very CRUDE list of most recently used projections. I love the functionality, the UI could be nicer. Please do not remove, but instead improve!
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10106 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 87a1d3a commit 1664273

5 files changed

+196
-7
lines changed

src/gui/qgsprojectionselector.cpp

+98-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <QHeaderView>
2929
#include <QResizeEvent>
3030
#include <QMessageBox>
31+
#include <QSettings>
3132
#include "qgslogger.h"
3233

3334
const int NAME_COLUMN = 0;
@@ -54,11 +55,35 @@ QgsProjectionSelector::QgsProjectionSelector( QWidget* parent,
5455
lstCoordinateSystems->header()->setResizeMode( EPSG_COLUMN, QHeaderView::Stretch );
5556
lstCoordinateSystems->header()->resizeSection( QGIS_CRS_ID_COLUMN, 0 );
5657
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+
5763
}
5864

5965

6066
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+
}
6287

6388

6489
void QgsProjectionSelector::resizeEvent( QResizeEvent * theEvent )
@@ -99,6 +124,40 @@ void QgsProjectionSelector::showEvent( QShowEvent * theEvent )
99124
applyEPSGIDSelection();
100125
}
101126

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+
102161
// Pass up the inheritance heirarchy
103162
QWidget::showEvent( theEvent );
104163
}
@@ -235,6 +294,26 @@ void QgsProjectionSelector::applyCRSNameSelection()
235294
}
236295
}
237296

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+
238317
void QgsProjectionSelector::applyEPSGIDSelection()
239318
{
240319
if (
@@ -761,6 +840,24 @@ void QgsProjectionSelector::coordinateSystemSelected( QTreeWidgetItem * theItem
761840
}
762841
}
763842

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+
764861
void QgsProjectionSelector::on_pbnFind_clicked()
765862
{
766863

src/gui/qgsprojectionselector.h

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <ui_qgsprojectionselectorbase.h>
1515

1616
#include <QSet>
17+
#include <QStringList>
1718

1819
class QResizeEvent;
1920

@@ -104,6 +105,11 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
104105

105106
void on_pbnFind_clicked();
106107

108+
void on_pbnPopular1_clicked();
109+
void on_pbnPopular2_clicked();
110+
void on_pbnPopular3_clicked();
111+
void on_pbnPopular4_clicked();
112+
107113
protected:
108114
/** Used to ensure the projection list view is actually populated */
109115
void showEvent( QShowEvent * theEvent );
@@ -189,6 +195,9 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
189195
*/
190196
long getLargestCRSIDMatch( QString theSql );
191197

198+
//! Returns name from CRS Id
199+
QString getCrsIdName( long theCrsId );
200+
192201
//! Has the Projection List been populated?
193202
bool mProjListDone;
194203

@@ -216,6 +225,9 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
216225
//! The set of OGC WMS CRSs that want to be applied to this widget
217226
QSet<QString> mCrsFilter;
218227

228+
//! Most recently used projections (trimmed at 25 entries)
229+
QStringList mRecentProjections;
230+
219231
private slots:
220232
/**private handler for when user selects a cs
221233
*it will cause wktSelected and sridSelected events to be spawned

src/plugins/delimited_text/qgsdelimitedtextplugingui.cpp

+54-6
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,14 @@ void QgsDelimitedTextPluginGui::updateFieldLists()
140140
if ( QFile::exists( txtFilePath->text() ) )
141141
{
142142
QFile *file = new QFile( txtFilePath->text() );
143-
if ( file->open( QIODevice::ReadOnly ) )
143+
if ( file->open( QIODevice::ReadOnly | QIODevice::Text ) )
144144
{
145145
// clear the field lists
146146
cmbXField->clear();
147147
cmbYField->clear();
148148
QTextStream stream( file );
149149
QString line;
150-
line = stream.readLine(); // line of text excluding '\n'
150+
line = readLine( stream ); // line of text excluding '\n'
151151
if ( txtDelimiter->text().length() > 0 )
152152
{
153153
QgsDebugMsg( QString( "Attempting to split the input line: %1 using delimiter %2" ).arg( line ).arg( txtDelimiter->text() ) );
@@ -212,13 +212,12 @@ void QgsDelimitedTextPluginGui::updateFieldLists()
212212
txtSample->insertPlainText( line + "\n" );
213213
// put a few more lines into the sample box
214214
int counter = 0;
215-
while (
216-
( !( line = stream.readLine() ).isEmpty() ) &&
217-
( counter < 20 )
218-
)
215+
line = QgsDelimitedTextPluginGui::readLine( stream );
216+
while ( not line.isEmpty() && ( counter < 20 ) )
219217
{
220218
txtSample->insertPlainText( line + "\n" );
221219
counter++;
220+
line = QgsDelimitedTextPluginGui::readLine( stream );
222221
}
223222
// close the file
224223
file->close();
@@ -265,3 +264,52 @@ void QgsDelimitedTextPluginGui::on_txtDelimiter_textChanged( const QString & tex
265264
pbnParse->setEnabled( true );
266265
}
267266
}
267+
268+
QString QgsDelimitedTextPluginGui::readLine( QTextStream & stream )
269+
{
270+
QString buffer("");
271+
QString c;
272+
273+
// Strip leading newlines
274+
275+
c = stream.read( 1 );
276+
if ( c == NULL or c.size() == 0 )
277+
{
278+
// Reach end of file
279+
return buffer;
280+
}
281+
while ( c == (char *)"\r" or c == (char *)"\n" )
282+
{
283+
c = stream.read( 1 );
284+
if ( c == NULL or c.size() == 0 )
285+
{
286+
// Reach end of file
287+
return buffer;
288+
}
289+
}
290+
291+
// First non-newline character
292+
buffer.append( c );
293+
294+
c = stream.read( 1 );
295+
if ( c == NULL or c.size() == 0 )
296+
{
297+
// Reach end of file
298+
return buffer;
299+
}
300+
301+
while ( not ( c == (char *)"\r" or c == (char *)"\n" ) )
302+
{
303+
304+
buffer.append( c );
305+
c = stream.read( 1 );
306+
if ( c == NULL or c.size() == 0 )
307+
{
308+
// Reach end of file
309+
return buffer;
310+
}
311+
}
312+
313+
return buffer;
314+
315+
}

src/plugins/delimited_text/qgsdelimitedtextplugingui.h

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define PLUGINGUI_H
1515

1616
#include "ui_qgsdelimitedtextpluginguibase.h"
17+
#include <QTextStream>
1718

1819
class QgisInterface;
1920

@@ -27,6 +28,8 @@ class QgsDelimitedTextPluginGui : public QDialog, private Ui::QgsDelimitedTextPl
2728
QgsDelimitedTextPluginGui( QgisInterface * _qI, QWidget* parent = 0, Qt::WFlags fl = 0 );
2829
~QgsDelimitedTextPluginGui();
2930

31+
static QString readLine( QTextStream & stream );
32+
3033
public slots:
3134
void help();
3235

@@ -53,4 +56,5 @@ class QgsDelimitedTextPluginGui : public QDialog, private Ui::QgsDelimitedTextPl
5356
void drawVectorLayer( QString, QString, QString );
5457
};
5558

59+
5660
#endif

src/ui/qgsprojectionselectorbase.ui

+28
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,34 @@
162162
</layout>
163163
</widget>
164164
</item>
165+
<item row="3" column="0" >
166+
<widget class="QPushButton" name="pbnPopular1">
167+
<property name="text" >
168+
<string>CRS ID : 100000</string>
169+
</property>
170+
</widget>
171+
</item>
172+
<item row="4" column="0" >
173+
<widget class="QPushButton" name="pbnPopular2">
174+
<property name="text" >
175+
<string>CRS ID : 3344</string>
176+
</property>
177+
</widget>
178+
</item>
179+
<item row="5" column="0" >
180+
<widget class="QPushButton" name="pbnPopular3">
181+
<property name="text" >
182+
<string>CRS ID : whatever</string>
183+
</property>
184+
</widget>
185+
</item>
186+
<item row="6" column="0" >
187+
<widget class="QPushButton" name="pbnPopular4">
188+
<property name="text" >
189+
<string>CRS ID : whatever</string>
190+
</property>
191+
</widget>
192+
</item>
165193
</layout>
166194
</widget>
167195
<layoutdefault spacing="6" margin="11" />

0 commit comments

Comments
 (0)