Skip to content
Permalink
Browse files

ogr provider: increase width by one for decimal point if precision is…

… given (fixes #11755)
  • Loading branch information
jef-n committed Jun 8, 2015
1 parent bbe2e2a commit 2fcbc8bb725f45ba1d0196a95c7f21c90894a0d6
Showing with 16 additions and 3 deletions.
  1. +16 −3 src/providers/ogr/qgsogrprovider.cpp
@@ -82,6 +82,8 @@ bool QgsOgrProvider::convertField( QgsField &field, const QTextCodec &encoding )
OGRFieldType ogrType = OFTString; //default to string
int ogrWidth = field.length();
int ogrPrecision = field.precision();
if ( ogrPrecision > 0 )
ogrWidth += 1;
switch ( field.type() )
{
case QVariant::LongLong:
@@ -789,6 +791,11 @@ void QgsOgrProvider::loadFields()
}
}

int width = OGR_Fld_GetWidth( fldDef );
int prec = OGR_Fld_GetPrecision( fldDef );
if ( prec > 0 )
width -= 1;

mAttributeFields.append(
QgsField(
name,
@@ -798,8 +805,9 @@ void QgsOgrProvider::loadFields()
#else
mEncoding->toUnicode( OGR_GetFieldTypeName( ogrType ) ),
#endif
OGR_Fld_GetWidth( fldDef ),
OGR_Fld_GetPrecision( fldDef ) ) );
width, prec
)
);
}
}
}
@@ -1142,7 +1150,10 @@ bool QgsOgrProvider::addAttributes( const QList<QgsField> &attributes )
}

OGRFieldDefnH fielddefn = OGR_Fld_Create( mEncoding->fromUnicode( iter->name() ).constData(), type );
OGR_Fld_SetWidth( fielddefn, iter->length() );
int width = iter->length();
if ( iter->precision() )
width += 1;
OGR_Fld_SetWidth( fielddefn, width );
OGR_Fld_SetPrecision( fielddefn, iter->precision() );

if ( OGR_L_CreateField( ogrLayer, fielddefn, true ) != OGRERR_NONE )
@@ -2171,6 +2182,8 @@ QGISEXTERN bool createEmptyDataSource( const QString &uri,

int width = fields.size() > 1 ? fields[1].toInt() : -1;
int precision = fields.size() > 2 ? fields[2].toInt() : -1;
if ( precision > 0 )
width += 1;

OGRFieldDefnH field;
if ( fields[0] == "Real" )

0 comments on commit 2fcbc8b

Please sign in to comment.
You can’t perform that action at this time.