Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #2237 from ccrook/csv_field_name_fix
Removing unnecessary restriction on CSV provider field names
  • Loading branch information
ccrook committed Aug 6, 2015
2 parents c4ea8de + dc2de77 commit 118eea5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/providers/delimitedtext/qgsdelimitedtextfile.cpp
Expand Up @@ -52,7 +52,6 @@ QgsDelimitedTextFile::QgsDelimitedTextFile( QString url ) :
mMaxRecordNumber( -1 ),
mMaxFieldCount( 0 ),
mDefaultFieldName( "field_%1" ),
mInvalidFieldRegexp( "^\\d*(\\.\\d*)?$" ),
// field_ is optional in following regexp to simplify QgsDelimitedTextFile::fieldNumber()
mDefaultFieldRegexp( "^(?:field_)?(\\d+)$", Qt::CaseInsensitive )
{
Expand Down Expand Up @@ -429,8 +428,8 @@ void QgsDelimitedTextFile::setFieldNames( const QStringList &names )
name = name.trimmed();
if ( name.length() > mMaxNameLength ) name = name.mid( 0, mMaxNameLength );

// If the name is invalid then reset it to default name
if ( mInvalidFieldRegexp.exactMatch( name ) )
// If the name is empty then reset it to default name
if ( name.length() == 0 )
{
name = mDefaultFieldName.arg( fieldNo );
}
Expand Down
1 change: 0 additions & 1 deletion src/providers/delimitedtext/qgsdelimitedtextfile.h
Expand Up @@ -381,7 +381,6 @@ class QgsDelimitedTextFile : public QObject
int mMaxFieldCount;

QString mDefaultFieldName;
QRegExp mInvalidFieldRegexp;
QRegExp mDefaultFieldRegexp;
};

Expand Down
8 changes: 4 additions & 4 deletions tests/src/python/test_qgsdelimitedtextprovider_wanted.py
Expand Up @@ -74,8 +74,8 @@ def test_003_field_naming():
'data': u'Some data',
'field_4': u'Some info',
'data_2': u'NULL',
'field_6': u'NULL',
'field_7': u'NULL',
'28_1': u'NULL',
'24.5': u'NULL',
'field_3_1': u'NULL',
'data_1': u'NULL',
'field_10': u'NULL',
Expand All @@ -100,8 +100,8 @@ def test_004_max_fields():
'data': u'Some data',
'field_4': u'Some info',
'data_1': u'NULL',
'field_6': u'NULL',
'field_7': u'NULL',
'28_1': u'NULL',
'24.5': u'NULL',
'#fid': 2L,
'#geometry': 'None',
},
Expand Down

0 comments on commit 118eea5

Please sign in to comment.