@@ -69,15 +69,15 @@ QString QgsDelimitedTextProvider::readLine( QTextStream *stream )
69
69
70
70
QStringList QgsDelimitedTextProvider::splitLine ( QString line )
71
71
{
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 );
73
73
74
74
QStringList parts;
75
75
if ( mDelimiterType == " regexp" )
76
76
parts = line.split ( mDelimiterRegexp );
77
77
else
78
78
parts = line.split ( mDelimiter );
79
79
80
- QgsDebugMsg ( " Split line into " + QString::number ( parts.size () ) + " parts" );
80
+ QgsDebugMsgLevel ( " Split line into " + QString::number ( parts.size () ) + " parts" , 3 );
81
81
82
82
if ( mDelimiterType == " plain" )
83
83
{
@@ -454,7 +454,7 @@ bool QgsDelimitedTextProvider::nextFeature( QgsFeature& feature )
454
454
QString line = readLine ( mStream ); // Default local 8 bit encoding
455
455
if ( line.isEmpty () )
456
456
continue ;
457
-
457
+
458
458
// lex the tokens from the current data line
459
459
QStringList tokens = splitLine ( line );
460
460
@@ -528,27 +528,31 @@ bool QgsDelimitedTextProvider::nextFeature( QgsFeature& feature )
528
528
i != mAttributesToFetch .end ();
529
529
++i )
530
530
{
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]];
532
536
QVariant val;
533
- switch ( attributeFields[*i ].type () )
537
+ switch ( attributeFields[fieldIdx ].type () )
534
538
{
535
539
case QVariant::Int:
536
540
if ( !value.isEmpty () )
537
541
val = QVariant ( value );
538
542
else
539
- val = QVariant ( attributeFields[*i ].type () );
543
+ val = QVariant ( attributeFields[fieldIdx ].type () );
540
544
break ;
541
545
case QVariant::Double:
542
546
if ( !value.isEmpty () )
543
547
val = QVariant ( value.toDouble () );
544
548
else
545
- val = QVariant ( attributeFields[*i ].type () );
549
+ val = QVariant ( attributeFields[fieldIdx ].type () );
546
550
break ;
547
551
default :
548
552
val = QVariant ( value );
549
553
break ;
550
554
}
551
- feature.addAttribute ( *i , val );
555
+ feature.addAttribute ( fieldIdx , val );
552
556
}
553
557
554
558
// We have a good line, so return
0 commit comments