Skip to content

Commit 2fcbc8b

Browse files
committedJun 14, 2015
ogr provider: increase width by one for decimal point if precision is given (fixes #11755)
1 parent bbe2e2a commit 2fcbc8b

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed
 

‎src/providers/ogr/qgsogrprovider.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ bool QgsOgrProvider::convertField( QgsField &field, const QTextCodec &encoding )
8282
OGRFieldType ogrType = OFTString; //default to string
8383
int ogrWidth = field.length();
8484
int ogrPrecision = field.precision();
85+
if ( ogrPrecision > 0 )
86+
ogrWidth += 1;
8587
switch ( field.type() )
8688
{
8789
case QVariant::LongLong:
@@ -789,6 +791,11 @@ void QgsOgrProvider::loadFields()
789791
}
790792
}
791793

794+
int width = OGR_Fld_GetWidth( fldDef );
795+
int prec = OGR_Fld_GetPrecision( fldDef );
796+
if ( prec > 0 )
797+
width -= 1;
798+
792799
mAttributeFields.append(
793800
QgsField(
794801
name,
@@ -798,8 +805,9 @@ void QgsOgrProvider::loadFields()
798805
#else
799806
mEncoding->toUnicode( OGR_GetFieldTypeName( ogrType ) ),
800807
#endif
801-
OGR_Fld_GetWidth( fldDef ),
802-
OGR_Fld_GetPrecision( fldDef ) ) );
808+
width, prec
809+
)
810+
);
803811
}
804812
}
805813
}
@@ -1142,7 +1150,10 @@ bool QgsOgrProvider::addAttributes( const QList<QgsField> &attributes )
11421150
}
11431151

11441152
OGRFieldDefnH fielddefn = OGR_Fld_Create( mEncoding->fromUnicode( iter->name() ).constData(), type );
1145-
OGR_Fld_SetWidth( fielddefn, iter->length() );
1153+
int width = iter->length();
1154+
if ( iter->precision() )
1155+
width += 1;
1156+
OGR_Fld_SetWidth( fielddefn, width );
11461157
OGR_Fld_SetPrecision( fielddefn, iter->precision() );
11471158

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

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.