[QGIS Commit] r14903 - in trunk/qgis/src: core
providers/delimitedtext
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Mon Dec 13 15:23:19 EST 2010
Author: jef
Date: 2010-12-13 12:23:19 -0800 (Mon, 13 Dec 2010)
New Revision: 14903
Modified:
trunk/qgis/src/core/qgsmaplayer.cpp
trunk/qgis/src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
trunk/qgis/src/providers/delimitedtext/qgsdelimitedtextprovider.h
Log:
fix #3283
Modified: trunk/qgis/src/core/qgsmaplayer.cpp
===================================================================
--- trunk/qgis/src/core/qgsmaplayer.cpp 2010-12-13 20:10:19 UTC (rev 14902)
+++ trunk/qgis/src/core/qgsmaplayer.cpp 2010-12-13 20:23:19 UTC (rev 14903)
@@ -177,6 +177,12 @@
theURIParts[0] = QgsProject::instance()->readPath( theURIParts[0] );
mDataSource = theURIParts.join( "|" );
}
+ else if ( provider == "delimitedtext" )
+ {
+ QStringList theURIParts = mDataSource.split( "?" );
+ theURIParts[0] = QgsProject::instance()->readPath( theURIParts[0] );
+ mDataSource = theURIParts.join( "?" );
+ }
else
{
mDataSource = QgsProject::instance()->readPath( mDataSource );
@@ -301,6 +307,12 @@
theURIParts[0] = QgsProject::instance()->writePath( theURIParts[0] );
src = theURIParts.join( "|" );
}
+ else if ( vlayer && vlayer->providerType() == "delimitedtext" )
+ {
+ QStringList theURIParts = src.split( "?" );
+ theURIParts[0] = QgsProject::instance()->writePath( theURIParts[0] );
+ src = theURIParts.join( "?" );
+ }
else
{
src = QgsProject::instance()->writePath( src );
@@ -670,6 +682,11 @@
QStringList theURIParts = theURI.split( "|" );
filename = theURIParts[0];
}
+ else if ( vlayer && vlayer->providerType() == "delimitedtext" )
+ {
+ QStringList theURIParts = theURI.split( "?" );
+ filename = theURIParts[0];
+ }
else
{
filename = theURI;
Modified: trunk/qgis/src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
===================================================================
--- trunk/qgis/src/providers/delimitedtext/qgsdelimitedtextprovider.cpp 2010-12-13 20:10:19 UTC (rev 14902)
+++ trunk/qgis/src/providers/delimitedtext/qgsdelimitedtextprovider.cpp 2010-12-13 20:23:19 UTC (rev 14903)
@@ -134,13 +134,13 @@
QgsDelimitedTextProvider::QgsDelimitedTextProvider( QString uri )
: QgsVectorDataProvider( uri )
, mHasWktField( false )
- , mFirstDataLine(0)
, mFieldCount( 0 )
, mXFieldIndex( -1 ), mYFieldIndex( -1 )
, mWktFieldIndex( -1 )
, mWktHasZM( false )
, mWktZMRegexp( "\\s+(?:z|m|zm)(?=\\s*\\()", Qt::CaseInsensitive )
, mWktCrdRegexp( "(\\-?\\d+(?:\\.\\d*)?\\s+\\-?\\d+(?:\\.\\d*)?)\\s[\\s\\d\\.\\-]+" )
+ , mFirstDataLine( 0 )
, mShowInvalidLines( true )
, mWkbType( QGis::WKBNoGeometry )
{
@@ -168,9 +168,9 @@
mFileName = QUrl::fromPercentEncoding( mFileName.toUtf8() );
mDelimiter = QUrl::fromPercentEncoding( mDelimiter.toUtf8() );
mDelimiterType = QUrl::fromPercentEncoding( mDelimiterType.toUtf8() );
- wktField = QUrl::fromPercentEncoding( wktField.toUtf8() );
- xField = QUrl::fromPercentEncoding( xField.toUtf8() );
- yField = QUrl::fromPercentEncoding( yField.toUtf8() );
+ wktField = QUrl::fromPercentEncoding( wktField.toUtf8() );
+ xField = QUrl::fromPercentEncoding( xField.toUtf8() );
+ yField = QUrl::fromPercentEncoding( yField.toUtf8() );
mHasWktField = wktField != "";
@@ -281,7 +281,8 @@
}
// WKT geometry field won't be displayed in attribute tables
- if ( column == mWktFieldIndex ) continue;
+ if ( column == mWktFieldIndex )
+ continue;
QgsDebugMsg( "Adding field: " + ( field ) );
// assume that the field could be integer or double
@@ -293,20 +294,26 @@
fieldPos++;
}
}
- if ( mWktFieldIndex >= 0 ) { mXFieldIndex = -1; mYFieldIndex = -1; }
+ if ( mWktFieldIndex >= 0 )
+ {
+ mXFieldIndex = -1;
+ mYFieldIndex = -1;
+ }
QgsDebugMsg( "Field count for the delimited text file is " + QString::number( attributeFields.size() ) );
hasFields = true;
}
else // hasFields == true - field names already read
{
- if( mFirstDataLine == 0 ) mFirstDataLine = lineNumber;
+ if ( mFirstDataLine == 0 )
+ mFirstDataLine = lineNumber;
// split the line on the delimiter
QStringList parts = splitLine( line );
// Ensure that the input has at least the required number of fields (mainly to tolerate
- // missed blank strings at end of row)
- while( parts.size() < mFieldCount ) parts.append("");
+ // missed blank strings at end of row)
+ while ( parts.size() < mFieldCount )
+ parts.append( "" );
if ( mHasWktField && mWktFieldIndex >= 0 )
{
@@ -317,7 +324,8 @@
QgsGeometry *geom = 0;
try
{
- if ( ! mWktHasZM && sWkt.indexOf( mWktZMRegexp ) >= 0 ) mWktHasZM = true;
+ if ( !mWktHasZM && sWkt.indexOf( mWktZMRegexp ) >= 0 )
+ mWktHasZM = true;
if ( mWktHasZM )
{
sWkt.remove( mWktZMRegexp ).replace( mWktCrdRegexp, "\\1" );
@@ -350,10 +358,8 @@
delete geom;
}
}
-
- else if ( ! mHasWktField && mXFieldIndex >= 0 && mYFieldIndex >= 0 )
+ else if ( !mHasWktField && mXFieldIndex >= 0 && mYFieldIndex >= 0 )
{
-
// Get the x and y values, first checking to make sure they
// aren't null.
@@ -384,7 +390,8 @@
for ( int i = 0; i < attributeFields.size(); i++ )
{
QString &value = parts[attributeColumns[i]];
- if ( value.isEmpty() ) continue;
+ if ( value.isEmpty() )
+ continue;
// try to convert attribute values to integer and double
if ( couldBeInt[i] )
{
@@ -435,7 +442,7 @@
// before we do anything else, assume that there's something wrong with
// the feature
feature.setValid( false );
- while ( ! mStream->atEnd() )
+ while ( !mStream->atEnd() )
{
QString line = readLine( mStream ); // Default local 8 bit encoding
if ( line.isEmpty() )
@@ -444,7 +451,8 @@
// lex the tokens from the current data line
QStringList tokens = splitLine( line );
- while( tokens.size() < mFieldCount ) tokens.append("");
+ while ( tokens.size() < mFieldCount )
+ tokens.append( "" );
QgsGeometry *geom = 0;
@@ -453,8 +461,8 @@
try
{
QString &sWkt = tokens[mWktFieldIndex];
- // Remove Z and M coordinates if present, as currently fromWkt doesn't
- // support these.
+ // Remove Z and M coordinates if present, as currently fromWkt doesn't
+ // support these.
if ( mWktHasZM )
{
sWkt.remove( mWktZMRegexp ).replace( mWktCrdRegexp, "\\1" );
@@ -473,13 +481,13 @@
geom = 0;
}
mFid++;
- if ( ! boundsCheck( geom ) )
+ if ( !boundsCheck( geom ) )
{
delete geom;
geom = 0;
}
}
- else if ( ! mHasWktField && mXFieldIndex >= 0 && mYFieldIndex >= 0 )
+ else if ( !mHasWktField && mXFieldIndex >= 0 && mYFieldIndex >= 0 )
{
bool xOk, yOk;
double x = tokens[mXFieldIndex].toDouble( &xOk );
@@ -496,7 +504,8 @@
// If no valid geometry skip to the next line
- if ( ! geom ) continue;
+ if ( !geom )
+ continue;
// At this point the current feature values are valid
@@ -510,7 +519,6 @@
i != mAttributesToFetch.end();
++i )
{
-
QString &value = tokens[attributeColumns[*i]];
QVariant val;
switch ( attributeFields[*i].type() )
@@ -537,7 +545,7 @@
// We have a good line, so return
return true;
- } // ! textStream EOF
+ } // !mStream->atEnd()
// End of the file. If there are any lines that couldn't be
// loaded, display them now.
@@ -632,7 +640,7 @@
mFid = 0;
// Skip to first data record
mStream->seek( 0 );
- int n = mFirstDataLine-1;
+ int n = mFirstDataLine - 1;
while ( n-- > 0 )
readLine( mStream );
}
Modified: trunk/qgis/src/providers/delimitedtext/qgsdelimitedtextprovider.h
===================================================================
--- trunk/qgis/src/providers/delimitedtext/qgsdelimitedtextprovider.h 2010-12-13 20:10:19 UTC (rev 14902)
+++ trunk/qgis/src/providers/delimitedtext/qgsdelimitedtextprovider.h 2010-12-13 20:23:19 UTC (rev 14903)
@@ -222,7 +222,7 @@
long mNumberFeatures;
int mSkipLines;
- int mFirstDataLine; // Actual first line of data (accounting for blank lines)
+ int mFirstDataLine; // Actual first line of data (accounting for blank lines)
//! Storage for any lines in the file that couldn't be loaded
QStringList mInvalidLines;
More information about the QGIS-commit
mailing list