Skip to content
Permalink
Browse files

Very CRUDE list of most recently used projections. I love the functio…

…nality, 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
  • Loading branch information
homann
homann committed Feb 4, 2009
1 parent 87a1d3a commit 16642738bdfee7fb4965d54293836a5274f4c61d
@@ -28,6 +28,7 @@
#include <QHeaderView>
#include <QResizeEvent>
#include <QMessageBox>
#include <QSettings>
#include "qgslogger.h"

const int NAME_COLUMN = 0;
@@ -54,11 +55,35 @@ QgsProjectionSelector::QgsProjectionSelector( QWidget* parent,
lstCoordinateSystems->header()->setResizeMode( EPSG_COLUMN, QHeaderView::Stretch );
lstCoordinateSystems->header()->resizeSection( QGIS_CRS_ID_COLUMN, 0 );
lstCoordinateSystems->header()->setResizeMode( QGIS_CRS_ID_COLUMN, QHeaderView::Fixed );

// Read settings from persistent storage
QSettings settings;
mRecentProjections = settings.value("/UI/recentProjections").toStringList();

}


QgsProjectionSelector::~QgsProjectionSelector()
{}
{
// Save persistent list of projects
QSettings settings;
long crsId;

// Push current projection to front, only if set
crsId = selectedCrsId();
if ( crsId )
{
mRecentProjections.removeAll( QString::number( crsId ) );
mRecentProjections.prepend( QString::number( crsId ) );
// Prunse size of list
while ( mRecentProjections.size() > 4 )
{
mRecentProjections.removeLast();
}
// Save to file
settings.setValue( "/UI/recentProjections", mRecentProjections);
}
}


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

// Update buttons
pbnPopular1->setDisabled(true);
pbnPopular2->setDisabled(true);
pbnPopular3->setDisabled(true);
pbnPopular4->setDisabled(true);
pbnPopular1->hide();
pbnPopular2->hide();
pbnPopular3->hide();
pbnPopular4->hide();

if ( mRecentProjections.size() > 0) {
pbnPopular1->setText( getCrsIdName( mRecentProjections.at(0).toLong() ) );
pbnPopular1->setDisabled(false);
pbnPopular1->show();
}

if ( mRecentProjections.size() > 1) {
pbnPopular2->setText( getCrsIdName( mRecentProjections.at(1).toLong() ) );
pbnPopular2->setDisabled(false);
pbnPopular2->show();
}

if ( mRecentProjections.size() > 2) {
pbnPopular3->setText( getCrsIdName( mRecentProjections.at(2).toLong() ) );
pbnPopular3->setDisabled(false);
pbnPopular3->show();
}

if ( mRecentProjections.size() > 3) {
pbnPopular4->setText( getCrsIdName( mRecentProjections.at(3).toLong() ) );
pbnPopular4->setDisabled(false);
pbnPopular4->show();
}

// Pass up the inheritance heirarchy
QWidget::showEvent( theEvent );
}
@@ -235,6 +294,26 @@ void QgsProjectionSelector::applyCRSNameSelection()
}
}

QString QgsProjectionSelector::getCrsIdName( long theCrsId )
{
if (
( mProjListDone ) &&
( mUserProjListDone )
)
{
QString myCRSIDString = QString::number( theCrsId );

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

if ( nodes.count() > 0 )
{
return nodes.first()->text(0);
}
}
return QString( "" );

}

void QgsProjectionSelector::applyEPSGIDSelection()
{
if (
@@ -761,6 +840,24 @@ void QgsProjectionSelector::coordinateSystemSelected( QTreeWidgetItem * theItem
}
}

void QgsProjectionSelector::on_pbnPopular1_clicked()
{
setSelectedCrsId( mRecentProjections.at(0).toLong() );
}

void QgsProjectionSelector::on_pbnPopular2_clicked()
{
setSelectedCrsId( mRecentProjections.at(1).toLong() );
}
void QgsProjectionSelector::on_pbnPopular3_clicked()
{
setSelectedCrsId( mRecentProjections.at(2).toLong() );
}
void QgsProjectionSelector::on_pbnPopular4_clicked()
{
setSelectedCrsId( mRecentProjections.at(3).toLong() );
}

void QgsProjectionSelector::on_pbnFind_clicked()
{

@@ -14,6 +14,7 @@
#include <ui_qgsprojectionselectorbase.h>

#include <QSet>
#include <QStringList>

class QResizeEvent;

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

void on_pbnFind_clicked();

void on_pbnPopular1_clicked();
void on_pbnPopular2_clicked();
void on_pbnPopular3_clicked();
void on_pbnPopular4_clicked();

protected:
/** Used to ensure the projection list view is actually populated */
void showEvent( QShowEvent * theEvent );
@@ -189,6 +195,9 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
*/
long getLargestCRSIDMatch( QString theSql );

//! Returns name from CRS Id
QString getCrsIdName( long theCrsId );

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

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

//! Most recently used projections (trimmed at 25 entries)
QStringList mRecentProjections;

private slots:
/**private handler for when user selects a cs
*it will cause wktSelected and sridSelected events to be spawned
@@ -140,14 +140,14 @@ void QgsDelimitedTextPluginGui::updateFieldLists()
if ( QFile::exists( txtFilePath->text() ) )
{
QFile *file = new QFile( txtFilePath->text() );
if ( file->open( QIODevice::ReadOnly ) )
if ( file->open( QIODevice::ReadOnly | QIODevice::Text ) )
{
// clear the field lists
cmbXField->clear();
cmbYField->clear();
QTextStream stream( file );
QString line;
line = stream.readLine(); // line of text excluding '\n'
line = readLine( stream ); // line of text excluding '\n'
if ( txtDelimiter->text().length() > 0 )
{
QgsDebugMsg( QString( "Attempting to split the input line: %1 using delimiter %2" ).arg( line ).arg( txtDelimiter->text() ) );
@@ -212,13 +212,12 @@ void QgsDelimitedTextPluginGui::updateFieldLists()
txtSample->insertPlainText( line + "\n" );
// put a few more lines into the sample box
int counter = 0;
while (
( !( line = stream.readLine() ).isEmpty() ) &&
( counter < 20 )
)
line = QgsDelimitedTextPluginGui::readLine( stream );
while ( not line.isEmpty() && ( counter < 20 ) )
{
txtSample->insertPlainText( line + "\n" );
counter++;
line = QgsDelimitedTextPluginGui::readLine( stream );
}
// close the file
file->close();
@@ -265,3 +264,52 @@ void QgsDelimitedTextPluginGui::on_txtDelimiter_textChanged( const QString & tex
pbnParse->setEnabled( true );
}
}

QString QgsDelimitedTextPluginGui::readLine( QTextStream & stream )
{
QString buffer("");
QString c;

// Strip leading newlines

c = stream.read( 1 );
if ( c == NULL or c.size() == 0 )
{
// Reach end of file
return buffer;
}
while ( c == (char *)"\r" or c == (char *)"\n" )
{
c = stream.read( 1 );
if ( c == NULL or c.size() == 0 )
{
// Reach end of file
return buffer;
}
}

// First non-newline character
buffer.append( c );

c = stream.read( 1 );
if ( c == NULL or c.size() == 0 )
{
// Reach end of file
return buffer;
}

while ( not ( c == (char *)"\r" or c == (char *)"\n" ) )
{

buffer.append( c );
c = stream.read( 1 );
if ( c == NULL or c.size() == 0 )
{
// Reach end of file
return buffer;
}
}

return buffer;

}
@@ -14,6 +14,7 @@
#define PLUGINGUI_H

#include "ui_qgsdelimitedtextpluginguibase.h"
#include <QTextStream>

class QgisInterface;

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

static QString readLine( QTextStream & stream );

public slots:
void help();

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


#endif
@@ -162,6 +162,34 @@
</layout>
</widget>
</item>
<item row="3" column="0" >
<widget class="QPushButton" name="pbnPopular1">
<property name="text" >
<string>CRS ID : 100000</string>
</property>
</widget>
</item>
<item row="4" column="0" >
<widget class="QPushButton" name="pbnPopular2">
<property name="text" >
<string>CRS ID : 3344</string>
</property>
</widget>
</item>
<item row="5" column="0" >
<widget class="QPushButton" name="pbnPopular3">
<property name="text" >
<string>CRS ID : whatever</string>
</property>
</widget>
</item>
<item row="6" column="0" >
<widget class="QPushButton" name="pbnPopular4">
<property name="text" >
<string>CRS ID : whatever</string>
</property>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11" />

0 comments on commit 1664273

Please sign in to comment.
You can’t perform that action at this time.