Skip to content

Commit

Permalink
Default length/precision for double/real fields
Browse files Browse the repository at this point in the history
  • Loading branch information
domi4484 committed Jul 23, 2021
1 parent 8ccf794 commit a5e81c3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/core/providers/memory/qgsmemoryprovider.cpp
Expand Up @@ -135,8 +135,8 @@ QgsMemoryProvider::QgsMemoryProvider( const QString &uri, const ProviderOptions
// If no match -> use string as type
QVariant::Type type = QVariant::String;
QVariant::Type subType = QVariant::Invalid;
QString typeName = QStringLiteral( "string" );
int length = -1;
QString typeName( QStringLiteral( "string" ) );
int length = 255;
int precision = 0;

if ( regularExpressionMatch.hasMatch() )
Expand Down Expand Up @@ -185,6 +185,13 @@ QgsMemoryProvider::QgsMemoryProvider( const QString &uri, const ProviderOptions
}
}

// Set default length/precision for double/real
if ( typeName == QLatin1String( "real" ) || typeName == QLatin1String( "double" ) )
{
length = 20;
precision = 5;
}

if ( !regularExpressionMatch.captured( 2 ).isEmpty() )
length = regularExpressionMatch.captured( 2 ).toInt();

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsfield.cpp
Expand Up @@ -312,7 +312,7 @@ QString QgsField::displayString( const QVariant &v ) const
}
}
// Default for doubles with precision
else if ( d->type == QVariant::Double && d->precision > 0 )
else if ( d->precision > 0 )
{
if ( -1 < v.toDouble() && v.toDouble() < 1 )
{
Expand Down

0 comments on commit a5e81c3

Please sign in to comment.