Skip to content
Permalink
Browse files

fix #1022

git-svn-id: http://svn.osgeo.org/qgis/trunk@14448 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Oct 29, 2010
1 parent 5291238 commit 4afb7293ba840b625aad74a44960c75d96801b1b
@@ -123,7 +123,7 @@ void QgsDelimitedTextPluginGui::updateFieldLists()
if ( QFile::exists( txtFilePath->text() ) )
{
QFile *file = new QFile( txtFilePath->text() );
if ( file->open( QIODevice::ReadOnly | QIODevice::Text ) )
if ( file->open( QIODevice::ReadOnly ) )
{
// clear the field lists
cmbXField->clear();
@@ -211,12 +211,12 @@ void QgsDelimitedTextPluginGui::updateFieldLists()
txtSample->insertPlainText( line + "\n" );
// put a few more lines into the sample box
int counter = 0;
line = QgsDelimitedTextPluginGui::readLine( stream );
line = readLine( stream );
while ( !line.isEmpty() && ( counter < 20 ) )
{
txtSample->insertPlainText( line + "\n" );
counter++;
line = QgsDelimitedTextPluginGui::readLine( stream );
line = readLine( stream );
}
// close the file
file->close();
@@ -259,51 +259,27 @@ void QgsDelimitedTextPluginGui::on_txtDelimiter_textChanged( const QString & tex
}
}

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

// Strip leading newlines

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

// First non-newline character
buffer.append( c );
QChar c = stream.read( 1 ).at( 0 );

c = stream.read( 1 );
if ( c == NULL || c.size() == 0 )
{
// Reach end of file
return buffer;
}
if ( c == '\r' || c == '\n' )
{
if ( buffer.isEmpty() )
{
// skip leading CR / LF
continue;
}

while ( !( c == ( char * )"\r" || c == ( char * )"\n" ) )
{
break;
}

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

return buffer;

}
@@ -44,6 +44,31 @@ static const QString TEXT_PROVIDER_KEY = "delimitedtext";
static const QString TEXT_PROVIDER_DESCRIPTION = "Delimited text data provider";


QString QgsDelimitedTextProvider::readLine( QTextStream *stream )
{
QString buffer;

while ( !stream->atEnd() )
{
QChar c = stream->read( 1 ).at( 0 );

if ( c == '\r' || c == '\n' )
{
if ( buffer.isEmpty() )
{
// skip leading CR / LF
continue;
}

break;
}

buffer.append( c );
}

return buffer;
}

QStringList QgsDelimitedTextProvider::splitLine( QString line )
{
QgsDebugMsg( "Attempting to split the input line: " + line + " using delimiter " + mDelimiter );
@@ -192,7 +217,7 @@ QgsDelimitedTextProvider::QgsDelimitedTextProvider( QString uri )
while ( !mStream->atEnd() )
{
lineNumber++;
line = mStream->readLine(); // line of text excluding '\n', default local 8 bit encoding.
line = readLine( mStream ); // line of text excluding '\n', default local 8 bit encoding.
if ( !hasFields )
{
// Get the fields from the header row and store them in the
@@ -267,7 +292,8 @@ QgsDelimitedTextProvider::QgsDelimitedTextProvider( QString uri )
mExtent.combineExtentWith( x, y );
}
else
{ // Extent for the first point is just the first point
{
// Extent for the first point is just the first point
mExtent.set( x, y, x, y );
firstPoint = false;
}
@@ -335,7 +361,7 @@ bool QgsDelimitedTextProvider::nextFeature( QgsFeature& feature )
{
double x = 0.0;
double y = 0.0;
QString line = mStream->readLine(); // Default local 8 bit encoding
QString line = readLine( mStream ); // Default local 8 bit encoding

// lex the tokens from the current data line
QStringList tokens = splitLine( line );
@@ -531,7 +557,7 @@ void QgsDelimitedTextProvider::rewind()
// Skip ahead one line since first record is always assumed to be
// the header record
mStream->seek( 0 );
mStream->readLine();
readLine( mStream );
}

bool QgsDelimitedTextProvider::isValid()
@@ -221,6 +221,6 @@ class QgsDelimitedTextProvider : public QgsVectorDataProvider

QGis::WkbType mWkbType; //can be WKBPoint or NoGeometry

QString readLine( QTextStream *stream );
QStringList splitLine( QString line );

};

0 comments on commit 4afb729

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