Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrook committed Apr 11, 2013
1 parent c6f678f commit ebe0406
Show file tree
Hide file tree
Showing 12 changed files with 1,125 additions and 423 deletions.
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 );
Expand All @@ -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;
Expand Down
36 changes: 28 additions & 8 deletions src/providers/delimitedtext/qgsdelimitedtextfile.cpp
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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);
}
Expand All @@ -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 )
{
Expand Down Expand Up @@ -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");
Expand Down
10 changes: 10 additions & 0 deletions src/providers/delimitedtext/qgsdelimitedtextfile.h
Expand Up @@ -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
*/
Expand Down Expand Up @@ -259,6 +268,7 @@ class QgsDelimitedTextFile
Status (QgsDelimitedTextFile::*mParser)( QStringList &fields );

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

Expand Down

0 comments on commit ebe0406

Please sign in to comment.