00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "qgsfeature.h"
00018 #include "qgsgeometry.h"
00019 #include "qgsrectangle.h"
00020
00025 QgsFeature::QgsFeature( int id, QString typeName )
00026 : mFid( id )
00027 , mGeometry( 0 )
00028 , mOwnsGeometry( 0 )
00029 , mValid( false )
00030 , mDirty( 0 )
00031 , mTypeName( typeName )
00032 {
00033
00034 }
00035
00036 QgsFeature::QgsFeature( QgsFeature const & rhs )
00037 : mFid( rhs.mFid )
00038 , mAttributes( rhs.mAttributes )
00039 , mGeometry( 0 )
00040 , mOwnsGeometry( false )
00041 , mValid( rhs.mValid )
00042 , mDirty( rhs.mDirty )
00043 , mTypeName( rhs.mTypeName )
00044 {
00045
00046
00047 if ( rhs.mGeometry )
00048 {
00049 setGeometry( *rhs.mGeometry );
00050 }
00051 }
00052
00053
00054 QgsFeature & QgsFeature::operator=( QgsFeature const & rhs )
00055 {
00056 if ( &rhs == this )
00057 return *this;
00058
00059 mFid = rhs.mFid;
00060 mDirty = rhs.mDirty;
00061 mAttributes = rhs.mAttributes;
00062 mValid = rhs.mValid;
00063 mTypeName = rhs.mTypeName;
00064
00065
00066 if ( mGeometry && mOwnsGeometry )
00067 delete mGeometry;
00068
00069 mGeometry = 0;
00070 mOwnsGeometry = false;
00071
00072 if ( rhs.mGeometry )
00073 setGeometry( *rhs.mGeometry );
00074
00075 return *this;
00076 }
00077
00078
00079
00081 QgsFeature::~QgsFeature()
00082 {
00083
00084 if ( mOwnsGeometry && mGeometry )
00085 delete mGeometry;
00086 }
00087
00092 int QgsFeature::id() const
00093 {
00094 return mFid;
00095 }
00096
00101 const QgsAttributeMap& QgsFeature::attributeMap() const
00102 {
00103 return mAttributes;
00104 }
00105
00107 void QgsFeature::setAttributeMap( const QgsAttributeMap& attributes )
00108 {
00109 mAttributes = attributes;
00110 }
00111
00113 void QgsFeature::clearAttributeMap()
00114 {
00115 mAttributes.clear();
00116 }
00117
00121 void QgsFeature::addAttribute( int field, QVariant attr )
00122 {
00123 mAttributes.insert( field, attr );
00124 }
00125
00127 void QgsFeature::deleteAttribute( int field )
00128 {
00129 mAttributes.remove( field );
00130 }
00131
00132
00133 void QgsFeature::changeAttribute( int field, QVariant attr )
00134 {
00135 mAttributes[field] = attr;
00136 }
00137
00138 QgsGeometry *QgsFeature::geometry()
00139 {
00140 return mGeometry;
00141 }
00142
00143 QgsGeometry *QgsFeature::geometryAndOwnership()
00144 {
00145 mOwnsGeometry = false;
00146
00147 return mGeometry;
00148 }
00149
00150
00151
00154 void QgsFeature::setFeatureId( int id )
00155 {
00156 mFid = id;
00157 }
00158
00159
00160 QString QgsFeature::typeName() const
00161 {
00162 return mTypeName;
00163 }
00164
00165
00166
00169 void QgsFeature::setTypeName( QString typeName )
00170 {
00171 mTypeName = typeName;
00172 }
00173
00174
00175 void QgsFeature::setGeometry( const QgsGeometry& geom )
00176 {
00177 setGeometry( new QgsGeometry( geom ) );
00178 }
00179
00180 void QgsFeature::setGeometry( QgsGeometry* geom )
00181 {
00182
00183 if ( mOwnsGeometry && mGeometry )
00184 {
00185 delete mGeometry;
00186 mGeometry = 0;
00187 }
00188
00189 mGeometry = geom;
00190 mOwnsGeometry = true;
00191 }
00192
00195 void QgsFeature::setGeometryAndOwnership( unsigned char *geom, size_t length )
00196 {
00197 QgsGeometry *g = new QgsGeometry();
00198 g->fromWkb( geom, length );
00199 setGeometry( g );
00200 }
00201
00202
00203 bool QgsFeature::isValid() const
00204 {
00205 return mValid;
00206 }
00207
00208 void QgsFeature::setValid( bool validity )
00209 {
00210 mValid = validity;
00211 }
00212
00213 bool QgsFeature::isDirty() const
00214 {
00215 return mDirty;
00216 }
00217
00218 void QgsFeature::clean()
00219 {
00220 mDirty = false;
00221 }