QgsField::displayString() consider configurable NULL representation

This commit is contained in:
Juergen E. Fischer 2014-04-25 12:32:28 +02:00
parent b548ac8c5c
commit ea98608461

View File

@ -16,22 +16,25 @@
#include "qgsfield.h" #include "qgsfield.h"
/* #include <QSettings>
QgsField::QgsField(QString nam, QString typ, int len, int prec, bool num,
QString comment) #if 0
:mName(nam), mType(typ), mLength(len), mPrecision(prec), mNumeric(num), QgsField::QgsField( QString nam, QString typ, int len, int prec, bool num,
mComment(comment) QString comment )
: mName( nam ), mType( typ ), mLength( len ), mPrecision( prec ), mNumeric( num )
, mComment( comment )
{ {
// This function used to lower case the field name since some stores // This function used to lower case the field name since some stores
// use upper case (eg. shapefiles), but that caused problems with // use upper case (eg. shapefiles), but that caused problems with
// attribute actions getting confused between uppercase and // attribute actions getting confused between uppercase and
// lowercase versions of the attribute names, so just leave the // lowercase versions of the attribute names, so just leave the
// names how they are now. // names how they are now.
}*/ }
#endif
QgsField::QgsField( QString name, QVariant::Type type, QString typeName, int len, int prec, QString comment ) QgsField::QgsField( QString name, QVariant::Type type, QString typeName, int len, int prec, QString comment )
: mName( name ), mType( type ), mTypeName( typeName ), : mName( name ), mType( type ), mTypeName( typeName )
mLength( len ), mPrecision( prec ), mComment( comment ) , mLength( len ), mPrecision( prec ), mComment( comment )
{ {
} }
@ -113,16 +116,16 @@ void QgsField::setComment( const QString & comment )
QString QgsField::displayString( const QVariant& v ) const QString QgsField::displayString( const QVariant& v ) const
{ {
switch ( mType ) if ( v.isNull() )
{ {
case QVariant::Double: QSettings settings;
if ( mPrecision > 0 ) return settings.value( "qgis/nullValue", "NULL" ).toString();
{
return QString::number( v.toDouble(), 'f', mPrecision );
}
default:
return v.toString();
} }
if ( mType == QVariant::Double && mPrecision > 0 )
return QString::number( v.toDouble(), 'f', mPrecision );
return v.toString();
} }