24 #include <QDataStream>
28 d =
new QgsFeaturePrivate(
id );
33 d =
new QgsFeaturePrivate(
id );
61 d->attributes.remove( field );
78 d->ownsGeometry =
false;
99 if ( attrs == d->attributes )
103 d->attributes = attrs;
118 QgsFeaturePrivate* old_d = d.
data();
119 bool ownedGeom = d->ownsGeometry;
123 d->ownsGeometry =
false;
127 if ( old_d != d.
data() )
129 old_d->ownsGeometry = ownedGeom;
131 else if ( ownedGeom )
137 d->ownsGeometry =
true;
166 return &( d->fields );
177 if ( d->valid == validity )
187 d->attributes.resize( fieldCount );
189 for (
int i = 0; i < fieldCount; ++i, ++ptr )
196 if ( idx < 0 || idx >= d->attributes.size() )
203 d->attributes[idx] = value;
210 if ( fieldIdx == -1 )
214 d->attributes[fieldIdx] = value;
221 if ( fieldIdx == -1 )
225 d->attributes[fieldIdx].clear();
231 if ( fieldIdx < 0 || fieldIdx >= d->attributes.count() )
234 return d->attributes.at( fieldIdx );
241 if ( fieldIdx == -1 )
244 return d->attributes.at( fieldIdx );
249 return d->fields.fieldNameIndex( fieldName );
275 in >>
id >> attr >> *geometry >> valid;
QgsFeatureId id() const
Get the feature ID for this feature.
bool isValid() const
Returns the validity of this feature.
int fieldNameIndex(const QString &fieldName) const
Utility method to get attribute index from name.
virtual ~QgsFeature()
Destructor.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
bool setAttribute(int field, const QVariant &attr)
Set an attribute's value by field index.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QString tr(const char *sourceText, const char *disambiguation, int n)
QDataStream & operator>>(QDataStream &in, QgsFeature &feature)
Reads a feature from stream in into feature.
void setGeometry(const QgsGeometry &geom)
Set this feature's geometry from another QgsGeometry object.
void deleteAttribute(int field)
Deletes an attribute and its value.
void setFeatureId(QgsFeatureId id)
Sets the feature ID for this feature.
QgsAttributes attributes() const
Returns the feature's attributes.
QDataStream & operator<<(QDataStream &out, const QgsFeature &feature)
Writes the feature to stream out.
void initAttributes(int fieldCount)
Initialize this feature with the given number of fields.
const QgsFields * fields() const
Returns the field map associated with the feature.
static void logMessage(const QString &message, const QString &tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
QgsFeature & operator=(QgsFeature const &rhs)
Assignment operator.
Q_DECL_DEPRECATED void setFields(const QgsFields *fields, bool initAttributes=false)
Assign a field map with the feature to allow attribute access by attribute name.
QgsFeature(QgsFeatureId id=QgsFeatureId())
Constructor for QgsFeature.
QgsGeometry * geometry()
Get the geometry object associated with this feature.
void setValid(bool validity)
Sets the validity of the feature.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
void fromWkb(unsigned char *wkb, size_t length)
Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer's length...
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
Q_DECL_DEPRECATED QgsGeometry * geometryAndOwnership()
Get the geometry object associated with this feature, and transfer ownership of the geometry to the c...
void setGeometryAndOwnership(unsigned char *geom, size_t length)
Set this feature's geometry from WKB.