Skip to content
Permalink
Browse files

Fix for ticket #815 (broken delimited text layer loading for plain text

delimiters)


git-svn-id: http://svn.osgeo.org/qgis/trunk@7452 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m
g_j_m committed Nov 18, 2007
1 parent f4a505d commit 834c38b9a8b8920db017eb722756f23d7a1cef76
Showing with 15 additions and 13 deletions.
  1. +15 −13 src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
@@ -60,14 +60,16 @@ QgsDelimitedTextProvider::QgsDelimitedTextProvider(QString uri)
// get the individual parameters and assign values
QStringList temp = parameters.grep("delimiter=");
mDelimiter = temp.size()? temp[0].mid(temp[0].find("=") + 1) : "";
temp = parameters.grep("delimiterType=");
mDelimiterType = temp.size()? temp[0].mid(temp[0].find("=") + 1) : "";
temp = parameters.grep("xField=");
QString xField = temp.size()? temp[0].mid(temp[0].find("=") + 1) : "";
temp = parameters.grep("yField=");
QString yField = temp.size()? temp[0].mid(temp[0].find("=") + 1) : "";
// Decode the parts of the uri. Good if someone entered '=' as a delimiter, for instance.
mFileName = QUrl::fromPercentEncoding(mFileName.toUtf8());
mDelimiter = QUrl::fromPercentEncoding(mDelimiter.toUtf8());
mDelimiterType = QUrl::fromPercentEncoding(mDelimiter.toUtf8());
mDelimiterType = QUrl::fromPercentEncoding(mDelimiterType.toUtf8());
xField = QUrl::fromPercentEncoding(xField.toUtf8());
yField = QUrl::fromPercentEncoding(yField.toUtf8());

@@ -79,10 +81,10 @@ QgsDelimitedTextProvider::QgsDelimitedTextProvider(QString uri)
QgsDebugMsg("yField is: " + yField);

// if delimiter contains some special characters, convert them
if (mDelimiterType == "plain")
mDelimiter.replace("\\t", "\t"); // replace "\t" with a real tabulator
else
if (mDelimiterType == "regexp")
mDelimiterRegexp = QRegExp(mDelimiter);
else
mDelimiter.replace("\\t", "\t"); // replace "\t" with a real tabulator

// Set the selection rectangle to null
mSelectionRectangle = QgsRect();
@@ -138,10 +140,10 @@ QgsDelimitedTextProvider::QgsDelimitedTextProvider(QString uri)
QgsDebugMsg("Attempting to split the input line: " + line + " using delimiter " + mDelimiter);

QStringList fieldList;
if (mDelimiterType == "plain")
fieldList = QStringList::split(mDelimiter, line, true);
else
if (mDelimiterType == "regexp")
fieldList = line.split(mDelimiterRegexp);
else
fieldList = line.split(mDelimiter);
QgsDebugMsg("Split line into " + QString::number(fieldList.size()) + " parts");

// We don't know anything about a text based field other
@@ -184,10 +186,10 @@ QgsDelimitedTextProvider::QgsDelimitedTextProvider(QString uri)

// split the line on the delimiter
QStringList parts;
if (mDelimiterType == "plain")
parts = QStringList::split(mDelimiter, line, true);
else
if (mDelimiterType == "regexp")
parts = line.split(mDelimiterRegexp);
else
parts = line.split(mDelimiter);

// Skip malformed lines silently. Report line number with getNextFeature()
if (attributeFields.size() != parts.size())
@@ -292,10 +294,10 @@ bool QgsDelimitedTextProvider::getNextFeature(QgsFeature& feature)

// lex the tokens from the current data line
QStringList tokens;
if (mDelimiterType == "plain")
tokens = QStringList::split(mDelimiter, line, true);
else
if (mDelimiterType == "regexp")
tokens = line.split(mDelimiterRegexp);
else
tokens = line.split(mDelimiter);

bool xOk = false;
bool yOk = false;

0 comments on commit 834c38b

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