Skip to content
Permalink
Browse files

WIP

  • Loading branch information
ccrook committed Apr 11, 2013
1 parent c6f678f commit ebe04068755a979c90e6d7560b51c286ae678807
@@ -73,7 +73,10 @@ bool QgsDelimitedTextFeatureIterator::nextFeature( QgsFeature& feature )
if ( !geom && P->mWkbType != QGis::WKBNoGeometry )
{
// Already dealt with invalid lines in provider - no need to repeat
// P->mInvalidLines << line;
// removed code (CC 2013-04-13) ...
// P->mInvalidLines << line;
// In any case it may be a valid line that is excluded because of
// bounds check...
continue;
}

@@ -153,7 +156,7 @@ QgsGeometry* QgsDelimitedTextFeatureIterator::loadGeometryWkt( const QStringList
// support these.
if ( P->mWktHasZM )
{
sWkt.remove( P->mWktZMRegexp ).replace( P->mWktCrdRegexp, "\\1" );
sWkt.remove( P->WktZMRegexp ).replace( P->WktCrdRegexp, "\\1" );
}

geom = QgsGeometry::fromWkt( sWkt );
@@ -163,7 +166,7 @@ QgsGeometry* QgsDelimitedTextFeatureIterator::loadGeometryWkt( const QStringList
geom = 0;
}

if ( geom && geom->wkbType() != P->mWkbType )
if ( geom && geom->type() != P->mGeometryType )
{
delete geom;
geom = 0;
@@ -22,12 +22,14 @@
#include <QFile>
#include <QDataStream>
#include <QTextStream>
#include <QTextCodec>
#include <QStringList>
#include <QRegExp>
#include <QUrl>

QgsDelimitedTextFile::QgsDelimitedTextFile( QString url ) :
mFileName(QString()),
mEncoding("UTF-8"),
mFile(0),
mStream(0),
mDefinitionValid(false),
@@ -74,6 +76,11 @@ bool QgsDelimitedTextFile::open()
return false;
}
mStream = new QTextStream( mFile );
if( mEncoding.isEmpty() && mEncoding != "System")
{
QTextCodec *codec = QTextCodec::codecForName(mEncoding.toAscii());
mStream->setCodec(codec);
}
}
return true;
}
@@ -101,6 +108,12 @@ bool QgsDelimitedTextFile::setFromUrl( QUrl &url )
// Extract the file name
setFileName( url.toLocalFile());

// Extract the encoding
if( url.hasQueryItem("encoding"))
{
mEncoding =url.queryItemValue("encoding");
}

// The default type is csv, to be consistent with the
// previous implementation (except that quoting should be handled properly)

@@ -150,19 +163,16 @@ bool QgsDelimitedTextFile::setFromUrl( QUrl &url )
}

QgsDebugMsg( "Delimited text file is: " + mFileName );
QgsDebugMsg( "Encoding is: " + mEncoding);
QgsDebugMsg( "Delimited file type is: " + type );
QgsDebugMsg( "Delimiter is: " + delimiter );
QgsDebugMsg( "Quote character is: " + quote);
QgsDebugMsg( "Escape character is: " + escape);
QgsDebugMsg( "Delimiter is: [" + delimiter + "]" );
QgsDebugMsg( "Quote character is: [" + quote +"]");
QgsDebugMsg( "Escape character is: [" + escape + "]");
QgsDebugMsg( "Skip lines: " + QString::number(mSkipLines) );
QgsDebugMsg( "Skip lines: " + QString(mUseHeader ? "Yes" : "No") );

if( type == "csv" )
{
setTypeCSV(delimiter,quote,escape);
}
// Support for previous version of plain characters
else if( type == "plain" )
if( type == "csv" || type == "plain" )
{
setTypeCSV(delimiter,quote,escape);
}
@@ -184,6 +194,10 @@ bool QgsDelimitedTextFile::setFromUrl( QUrl &url )
QUrl QgsDelimitedTextFile::url()
{
QUrl url = QUrl::fromLocalFile( mFileName );
if( mEncoding != "UTF-8" )
{
url.addQueryItem("encoding",mEncoding);
}
url.addQueryItem("type",type());
if( mType == DelimTypeRegexp )
{
@@ -212,6 +226,12 @@ void QgsDelimitedTextFile::setFileName( QString filename )
mFileName = filename;
}

void QgsDelimitedTextFile::setEncoding( QString encoding )
{
resetDefinition();
mEncoding = encoding;
}

QString QgsDelimitedTextFile::type()
{
if( mType == DelimTypeWhitespace ) return QString("whitespace");
@@ -102,6 +102,15 @@ class QgsDelimitedTextFile
return mFileName;
}

/** Set the file encoding (defuault is UTF-8)
* @param encoding the encoding to use for the fileName()
*/
void setEncoding( QString encoding );
/** Return the file encoding
* @return encoding The file encoding
*/
QString encoding(){ return mEncoding; }

/** Decode the parser settings from a url as a string
* @param url The url from which the delimiter and delimiterType items are read
*/
@@ -259,6 +268,7 @@ class QgsDelimitedTextFile
Status (QgsDelimitedTextFile::*mParser)( QStringList &fields );

QString mFileName;
QString mEncoding;
QFile *mFile;
QTextStream *mStream;

0 comments on commit ebe0406

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