Skip to content

Commit 3eb0d66

Browse files
wonder-sktimlinux
authored andcommittedMay 15, 2011

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed
 

‎src/providers/delimitedtext/qgsdelimitedtextprovider.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ QString QgsDelimitedTextProvider::readLine( QTextStream *stream )
6969

7070
QStringList QgsDelimitedTextProvider::splitLine( QString line )
7171
{
72-
QgsDebugMsg( "Attempting to split the input line: " + line + " using delimiter " + mDelimiter );
72+
QgsDebugMsgLevel( "Attempting to split the input line: " + line + " using delimiter " + mDelimiter, 3 );
7373

7474
QStringList parts;
7575
if ( mDelimiterType == "regexp" )
7676
parts = line.split( mDelimiterRegexp );
7777
else
7878
parts = line.split( mDelimiter );
7979

80-
QgsDebugMsg( "Split line into " + QString::number( parts.size() ) + " parts" );
80+
QgsDebugMsgLevel( "Split line into " + QString::number( parts.size() ) + " parts", 3 );
8181

8282
if ( mDelimiterType == "plain" )
8383
{
@@ -454,7 +454,7 @@ bool QgsDelimitedTextProvider::nextFeature( QgsFeature& feature )
454454
QString line = readLine( mStream ); // Default local 8 bit encoding
455455
if ( line.isEmpty() )
456456
continue;
457-
457+
458458
// lex the tokens from the current data line
459459
QStringList tokens = splitLine( line );
460460

@@ -528,27 +528,31 @@ bool QgsDelimitedTextProvider::nextFeature( QgsFeature& feature )
528528
i != mAttributesToFetch.end();
529529
++i )
530530
{
531-
QString &value = tokens[attributeColumns[*i]];
531+
int fieldIdx = *i;
532+
if ( fieldIdx < 0 || fieldIdx >= attributeColumns.count() )
533+
continue; // ignore non-existant fields
534+
535+
QString &value = tokens[attributeColumns[fieldIdx]];
532536
QVariant val;
533-
switch ( attributeFields[*i].type() )
537+
switch ( attributeFields[fieldIdx].type() )
534538
{
535539
case QVariant::Int:
536540
if ( !value.isEmpty() )
537541
val = QVariant( value );
538542
else
539-
val = QVariant( attributeFields[*i].type() );
543+
val = QVariant( attributeFields[fieldIdx].type() );
540544
break;
541545
case QVariant::Double:
542546
if ( !value.isEmpty() )
543547
val = QVariant( value.toDouble() );
544548
else
545-
val = QVariant( attributeFields[*i].type() );
549+
val = QVariant( attributeFields[fieldIdx].type() );
546550
break;
547551
default:
548552
val = QVariant( value );
549553
break;
550554
}
551-
feature.addAttribute( *i, val );
555+
feature.addAttribute( fieldIdx, val );
552556
}
553557

554558
// We have a good line, so return

0 commit comments

Comments
 (0)
Please sign in to comment.