Skip to content

Commit

Permalink
#5605 Support for long/longlong types
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinux committed Mar 19, 2015
1 parent 6eb1b5b commit d996966
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
Expand Up @@ -245,7 +245,7 @@ QStringList QgsDelimitedTextProvider::readCsvtFieldTypes( QString filename, QStr
// not allowed in OGR CSVT files. Also doesn't care if int and string fields have

strTypeList = strTypeList.toLower();
QRegExp reTypeList( "^(?:\\s*(\\\"?)(?:integer|real|string|date|datetime|time)(?:\\(\\d+(?:\\.\\d+)?\\))?\\1\\s*(?:,|$))+" );
QRegExp reTypeList( "^(?:\\s*(\\\"?)(?:integer|real|long|longlong|string|date|datetime|time)(?:\\(\\d+(?:\\.\\d+)?\\))?\\1\\s*(?:,|$))+" );
if ( ! reTypeList.exactMatch( strTypeList ) )
{
// Looks like this was supposed to be a CSVT file, so report bad formatted string
Expand Down Expand Up @@ -407,6 +407,7 @@ void QgsDelimitedTextProvider::scanFile( bool buildIndexes )

QList<bool> isEmpty;
QList<bool> couldBeInt;
QList<bool> couldBeLongLong;
QList<bool> couldBeDouble;

while ( true )
Expand Down Expand Up @@ -561,27 +562,28 @@ void QgsDelimitedTextProvider::scanFile( bool buildIndexes )
{

QString &value = parts[i];
if ( value.isEmpty() )
continue;

// try to convert attribute values to integer and double

while ( couldBeInt.size() <= i )
{
if ( value.isEmpty() ) {
isEmpty.append( true );
couldBeInt.append( false );
couldBeLongLong.append( false );
couldBeDouble.append( false );
continue;
}
if ( isEmpty[i] )
{
isEmpty[i] = false;
couldBeInt[i] = true;
couldBeDouble[i] = true;
}
// try to convert attribute values to integer, long and double
isEmpty.append( false );
// try all possible formats
couldBeInt.append( true );
couldBeLongLong.append( true );
couldBeDouble.append( true );
if ( couldBeInt[i] )
{
value.toInt( &couldBeInt[i] );
}

if ( couldBeLongLong[i] )
{
value.toLongLong( &couldBeLongLong[i] );
}
if ( couldBeDouble[i] )
{
if ( ! mDecimalPoint.isEmpty() )
Expand Down Expand Up @@ -620,6 +622,11 @@ void QgsDelimitedTextProvider::scanFile( bool buildIndexes )
fieldType = QVariant::Int;
typeName = "integer";
}
else if ( csvtTypes[i] == "long" || csvtTypes[i]== "longlong" )
{
fieldType = QVariant::LongLong; //QVariant doesn't support long
typeName = "longlong";
}
else if ( csvtTypes[i] == "real" )
{
fieldType = QVariant::Double;
Expand All @@ -633,6 +640,11 @@ void QgsDelimitedTextProvider::scanFile( bool buildIndexes )
fieldType = QVariant::Int;
typeName = "integer";
}
else if ( couldBeLongLong[i] )
{
fieldType = QVariant::LongLong;
typeName = "longlong";
}
else if ( couldBeDouble[i] )
{
fieldType = QVariant::Double;
Expand Down Expand Up @@ -997,12 +1009,14 @@ bool QgsDelimitedTextProvider::setSubsetString( QString subset, bool updateFeatu

if ( valid )
{

if ( mSubsetExpression ) delete mSubsetExpression;
QgsExpression * tmpSubsetExpression = mSubsetExpression;
// using a tmp pointer to avoid the pointer being dereferenced by
// a friend class after it has been freed but before it has been
// reassigned
QString previousSubset = mSubsetString;
mSubsetString = subset;
mSubsetExpression = expression;

if ( tmpSubsetExpression ) delete tmpSubsetExpression;
// Update the feature count and extents if requested

// Usage of updateFeatureCount is a bit painful, basically expect that it
Expand Down

0 comments on commit d996966

Please sign in to comment.