[QGIS Commit] r14448 - in trunk/qgis/src: plugins/delimited_text providers/delimitedtext

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Oct 29 16:59:18 EDT 2010


Author: jef
Date: 2010-10-29 13:59:18 -0700 (Fri, 29 Oct 2010)
New Revision: 14448

Modified:
   trunk/qgis/src/plugins/delimited_text/qgsdelimitedtextplugingui.cpp
   trunk/qgis/src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
   trunk/qgis/src/providers/delimitedtext/qgsdelimitedtextprovider.h
Log:
fix #1022

Modified: trunk/qgis/src/plugins/delimited_text/qgsdelimitedtextplugingui.cpp
===================================================================
--- trunk/qgis/src/plugins/delimited_text/qgsdelimitedtextplugingui.cpp	2010-10-29 19:04:12 UTC (rev 14447)
+++ trunk/qgis/src/plugins/delimited_text/qgsdelimitedtextplugingui.cpp	2010-10-29 20:59:18 UTC (rev 14448)
@@ -123,7 +123,7 @@
   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 @@
       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 @@
   }
 }
 
-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 )
+  while ( !stream.atEnd() )
   {
-    // Reach end of file
-    return buffer;
-  }
-  while ( c == ( char * )"\r" || c == ( char * )"\n" )
-  {
-    c = stream.read( 1 );
-    if ( c == NULL || c.size() == 0 )
+    QChar c = stream.read( 1 ).at( 0 );
+
+    if ( c == '\r' || c == '\n' )
     {
-      // Reach end of file
-      return buffer;
+      if ( buffer.isEmpty() )
+      {
+        // skip leading CR / LF
+        continue;
+      }
+
+      break;
     }
-  }
 
-  // First non-newline character
-  buffer.append( c );
-
-  c = stream.read( 1 );
-  if ( c == NULL || c.size() == 0 )
-  {
-    // Reach end of file
-    return buffer;
-  }
-
-  while ( !( c == ( char * )"\r" || c == ( char * )"\n" ) )
-  {
-
     buffer.append( c );
-    c = stream.read( 1 );
-    if ( c == NULL || c.size() == 0 )
-    {
-      // Reach end of file
-      return buffer;
-    }
   }
 
   return buffer;
-
 }

Modified: trunk/qgis/src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
===================================================================
--- trunk/qgis/src/providers/delimitedtext/qgsdelimitedtextprovider.cpp	2010-10-29 19:04:12 UTC (rev 14447)
+++ trunk/qgis/src/providers/delimitedtext/qgsdelimitedtextprovider.cpp	2010-10-29 20:59:18 UTC (rev 14448)
@@ -44,6 +44,31 @@
 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 @@
   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 @@
           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 @@
   {
     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 @@
   // 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()

Modified: trunk/qgis/src/providers/delimitedtext/qgsdelimitedtextprovider.h
===================================================================
--- trunk/qgis/src/providers/delimitedtext/qgsdelimitedtextprovider.h	2010-10-29 19:04:12 UTC (rev 14447)
+++ trunk/qgis/src/providers/delimitedtext/qgsdelimitedtextprovider.h	2010-10-29 20:59:18 UTC (rev 14448)
@@ -221,6 +221,6 @@
 
     QGis::WkbType mWkbType; //can be WKBPoint or NoGeometry
 
+    QString readLine( QTextStream *stream );
     QStringList splitLine( QString line );
-
 };



More information about the QGIS-commit mailing list