|
QGIS API Documentation
master-6164ace
|
00001 /*************************************************************************** 00002 qgsfield.cpp - Describes a field in a layer or table 00003 -------------------------------------- 00004 Date : 01-Jan-2004 00005 Copyright : (C) 2004 by Gary E.Sherman 00006 email : sherman at mrcc.com 00007 00008 *************************************************************************** 00009 * * 00010 * This program is free software; you can redistribute it and/or modify * 00011 * it under the terms of the GNU General Public License as published by * 00012 * the Free Software Foundation; either version 2 of the License, or * 00013 * (at your option) any later version. * 00014 * * 00015 ***************************************************************************/ 00016 00017 #include "qgsfield.h" 00018 00019 /* 00020 QgsField::QgsField(QString nam, QString typ, int len, int prec, bool num, 00021 QString comment) 00022 :mName(nam), mType(typ), mLength(len), mPrecision(prec), mNumeric(num), 00023 mComment(comment) 00024 { 00025 // This function used to lower case the field name since some stores 00026 // use upper case (eg. shapefiles), but that caused problems with 00027 // attribute actions getting confused between uppercase and 00028 // lowercase versions of the attribute names, so just leave the 00029 // names how they are now. 00030 }*/ 00031 00032 QgsField::QgsField( QString name, QVariant::Type type, QString typeName, int len, int prec, QString comment ) 00033 : mName( name ), mType( type ), mTypeName( typeName ), 00034 mLength( len ), mPrecision( prec ), mComment( comment ) 00035 { 00036 } 00037 00038 00039 QgsField::~QgsField() 00040 { 00041 } 00042 00043 bool QgsField::operator==( const QgsField& other ) const 00044 { 00045 return (( mName == other.mName ) && ( mType == other.mType ) 00046 && ( mLength == other.mLength ) && ( mPrecision == other.mPrecision ) ); 00047 } 00048 00049 bool QgsField::operator!=( const QgsField& other ) const 00050 { 00051 return !( *this == other ); 00052 } 00053 00054 00055 const QString & QgsField::name() const 00056 { 00057 return mName; 00058 } 00059 00060 QVariant::Type QgsField::type() const 00061 { 00062 return mType; 00063 } 00064 00065 const QString & QgsField::typeName() const 00066 { 00067 return mTypeName; 00068 } 00069 00070 int QgsField::length() const 00071 { 00072 return mLength; 00073 } 00074 00075 int QgsField::precision() const 00076 { 00077 return mPrecision; 00078 } 00079 00080 const QString & QgsField::comment() const 00081 { 00082 return mComment; 00083 } 00084 00085 void QgsField::setName( const QString & nam ) 00086 { 00087 mName = nam; 00088 } 00089 00090 void QgsField::setType( QVariant::Type type ) 00091 { 00092 mType = type; 00093 } 00094 00095 void QgsField::setTypeName( const QString & typeName ) 00096 { 00097 mTypeName = typeName; 00098 } 00099 00100 void QgsField::setLength( int len ) 00101 { 00102 mLength = len; 00103 } 00104 void QgsField::setPrecision( int prec ) 00105 { 00106 mPrecision = prec; 00107 } 00108 00109 void QgsField::setComment( const QString & comment ) 00110 { 00111 mComment = comment; 00112 } 00113 00114 QString QgsField::displayString( const QVariant& v ) const 00115 { 00116 switch ( mType ) 00117 { 00118 case QVariant::Double: 00119 if ( mPrecision > 0 ) 00120 { 00121 return QString::number( v.toDouble(), 'f', mPrecision ); 00122 } 00123 default: 00124 return v.toString(); 00125 } 00126 }