Skip to content

Commit ebe0406

Browse files
committed
WIP
1 parent c6f678f commit ebe0406

12 files changed

+1125
-423
lines changed

src/providers/delimitedtext/qgsdelimitedtextfeatureiterator.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ bool QgsDelimitedTextFeatureIterator::nextFeature( QgsFeature& feature )
7373
if ( !geom && P->mWkbType != QGis::WKBNoGeometry )
7474
{
7575
// Already dealt with invalid lines in provider - no need to repeat
76-
// P->mInvalidLines << line;
76+
// removed code (CC 2013-04-13) ...
77+
// P->mInvalidLines << line;
78+
// In any case it may be a valid line that is excluded because of
79+
// bounds check...
7780
continue;
7881
}
7982

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

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

166-
if ( geom && geom->wkbType() != P->mWkbType )
169+
if ( geom && geom->type() != P->mGeometryType )
167170
{
168171
delete geom;
169172
geom = 0;

src/providers/delimitedtext/qgsdelimitedtextfile.cpp

+28-8
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
#include <QFile>
2323
#include <QDataStream>
2424
#include <QTextStream>
25+
#include <QTextCodec>
2526
#include <QStringList>
2627
#include <QRegExp>
2728
#include <QUrl>
2829

2930
QgsDelimitedTextFile::QgsDelimitedTextFile( QString url ) :
3031
mFileName(QString()),
32+
mEncoding("UTF-8"),
3133
mFile(0),
3234
mStream(0),
3335
mDefinitionValid(false),
@@ -74,6 +76,11 @@ bool QgsDelimitedTextFile::open()
7476
return false;
7577
}
7678
mStream = new QTextStream( mFile );
79+
if( mEncoding.isEmpty() && mEncoding != "System")
80+
{
81+
QTextCodec *codec = QTextCodec::codecForName(mEncoding.toAscii());
82+
mStream->setCodec(codec);
83+
}
7784
}
7885
return true;
7986
}
@@ -101,6 +108,12 @@ bool QgsDelimitedTextFile::setFromUrl( QUrl &url )
101108
// Extract the file name
102109
setFileName( url.toLocalFile());
103110

111+
// Extract the encoding
112+
if( url.hasQueryItem("encoding"))
113+
{
114+
mEncoding =url.queryItemValue("encoding");
115+
}
116+
104117
// The default type is csv, to be consistent with the
105118
// previous implementation (except that quoting should be handled properly)
106119

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

152165
QgsDebugMsg( "Delimited text file is: " + mFileName );
166+
QgsDebugMsg( "Encoding is: " + mEncoding);
153167
QgsDebugMsg( "Delimited file type is: " + type );
154-
QgsDebugMsg( "Delimiter is: " + delimiter );
155-
QgsDebugMsg( "Quote character is: " + quote);
156-
QgsDebugMsg( "Escape character is: " + escape);
168+
QgsDebugMsg( "Delimiter is: [" + delimiter + "]" );
169+
QgsDebugMsg( "Quote character is: [" + quote +"]");
170+
QgsDebugMsg( "Escape character is: [" + escape + "]");
157171
QgsDebugMsg( "Skip lines: " + QString::number(mSkipLines) );
158172
QgsDebugMsg( "Skip lines: " + QString(mUseHeader ? "Yes" : "No") );
159173

160-
if( type == "csv" )
161-
{
162-
setTypeCSV(delimiter,quote,escape);
163-
}
164174
// Support for previous version of plain characters
165-
else if( type == "plain" )
175+
if( type == "csv" || type == "plain" )
166176
{
167177
setTypeCSV(delimiter,quote,escape);
168178
}
@@ -184,6 +194,10 @@ bool QgsDelimitedTextFile::setFromUrl( QUrl &url )
184194
QUrl QgsDelimitedTextFile::url()
185195
{
186196
QUrl url = QUrl::fromLocalFile( mFileName );
197+
if( mEncoding != "UTF-8" )
198+
{
199+
url.addQueryItem("encoding",mEncoding);
200+
}
187201
url.addQueryItem("type",type());
188202
if( mType == DelimTypeRegexp )
189203
{
@@ -212,6 +226,12 @@ void QgsDelimitedTextFile::setFileName( QString filename )
212226
mFileName = filename;
213227
}
214228

229+
void QgsDelimitedTextFile::setEncoding( QString encoding )
230+
{
231+
resetDefinition();
232+
mEncoding = encoding;
233+
}
234+
215235
QString QgsDelimitedTextFile::type()
216236
{
217237
if( mType == DelimTypeWhitespace ) return QString("whitespace");

src/providers/delimitedtext/qgsdelimitedtextfile.h

+10
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ class QgsDelimitedTextFile
102102
return mFileName;
103103
}
104104

105+
/** Set the file encoding (defuault is UTF-8)
106+
* @param encoding the encoding to use for the fileName()
107+
*/
108+
void setEncoding( QString encoding );
109+
/** Return the file encoding
110+
* @return encoding The file encoding
111+
*/
112+
QString encoding(){ return mEncoding; }
113+
105114
/** Decode the parser settings from a url as a string
106115
* @param url The url from which the delimiter and delimiterType items are read
107116
*/
@@ -259,6 +268,7 @@ class QgsDelimitedTextFile
259268
Status (QgsDelimitedTextFile::*mParser)( QStringList &fields );
260269

261270
QString mFileName;
271+
QString mEncoding;
262272
QFile *mFile;
263273
QTextStream *mStream;
264274

0 commit comments

Comments
 (0)