26 #include <QDataStream>
41 d =
new QgsFeaturePrivate(
id );
46 d =
new QgsFeaturePrivate(
id );
67 if ( d->fid == other.d->fid
68 && d->valid == other.d->valid
69 && d->fields == other.d->fields
70 && d->attributes == other.d->attributes
71 && d->geometry.equals( other.d->geometry ) )
79 return !( *
this == other );
100 d->attributes.remove(
field );
126 return d->attributes;
131 return d->attributes.size();
136 if ( attrs == d->attributes )
140 d->attributes = attrs;
197 if ( d->valid == validity )
206 return !d->geometry.isNull();
212 d->attributes.resize( 0 );
215 d->attributes.resize( fieldCount );
220 if ( fieldCount == d->attributes.size() )
224 d->attributes.resize( fieldCount );
233 d->attributes.resize( d->attributes.size() + count );
238 if ( idx < 0 || idx >= d->attributes.size() )
245 d->attributes[idx] = value;
259 if ( fieldIdx == -1 )
263 d->attributes[fieldIdx] = value;
271 if ( fieldIdx == -1 )
275 d->attributes[fieldIdx].clear();
281 if ( fieldIdx < 0 || fieldIdx >= d->attributes.count() )
284 return d->attributes.at( fieldIdx );
290 if ( fieldIdx == -1 )
293 return d->attributes.at( fieldIdx );
304 return d->fields.lookupField( fieldName );
307 static size_t qgsQStringApproximateMemoryUsage(
const QString &str )
309 return sizeof( QString ) + str.size() *
sizeof( QChar );
312 static size_t qgsQVariantApproximateMemoryUsage(
const QVariant &v )
316 size_t s =
sizeof( QVariant ) +
sizeof(
long long ) +
sizeof( int );
317 if ( v.type() == QVariant::String )
319 s += qgsQStringApproximateMemoryUsage( v.toString() );
321 else if ( v.type() == QVariant::StringList )
323 for (
const QString &str : v.toStringList() )
324 s += qgsQStringApproximateMemoryUsage( str );
326 else if ( v.type() == QVariant::List )
328 for (
const QVariant &subV : v.toList() )
329 s += qgsQVariantApproximateMemoryUsage( subV );
336 size_t s =
sizeof( *this ) +
sizeof( *d );
339 for (
const QVariant &attr : qgis::as_const( d->attributes ) )
341 s += qgsQVariantApproximateMemoryUsage( attr );
345 s +=
sizeof( QAtomicInt ) +
sizeof(
void * );
348 s += d->geometry.wkbSize();
351 s +=
sizeof( QgsFieldsPrivate );
353 s += d->fields.size() * (
sizeof(
QgsField ) +
sizeof( QgsFieldPrivate ) );
355 return static_cast<int>( s );
388 in >>
id >> attr >> geometry >> valid;
399 const auto constAttributes = key.
attributes();
400 for (
const QVariant &attr : constAttributes )
402 hash ^=
qHash( attr.toString() );
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool setAttribute(int field, const QVariant &attr)
Set an attribute's value by field index.
void resizeAttributes(int fieldCount)
Resizes the attributes attached to this feature to the given number of fields.
bool operator!=(const QgsFeature &other) const
Compares two features.
int fieldNameIndex(const QString &fieldName) const
Utility method to get attribute index from name.
void initAttributes(int fieldCount)
Initialize this feature with the given number of fields.
void deleteAttribute(int field)
Deletes an attribute and its value.
QgsFeature & operator=(const QgsFeature &rhs)
Assignment operator.
int approximateMemoryUsage() const
Returns the approximate RAM usage of the feature, in bytes.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
bool operator==(const QgsFeature &other) const
Compares two features.
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=FID_NULL)
Constructor for QgsFeature.
int attributeCount() const
Returns the number of attributes attached to the feature.
void padAttributes(int count)
Resizes the attributes attached to this feature by appending the specified count of NULL values to th...
void setId(QgsFeatureId id)
Sets the feature ID for this feature.
void clearGeometry()
Removes any geometry associated with the feature.
void setValid(bool validity)
Sets the validity of the feature.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
bool isValid() const
Returns the validity of this feature.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
QString asWkt(int precision=17) const
Exports the geometry to WKT.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
uint qHash(const QgsFeature &key, uint seed)
QDataStream & operator<<(QDataStream &out, const QgsFeature &feature)
Writes the feature to stream out. QGIS version compatibility is not guaranteed.
QDataStream & operator>>(QDataStream &in, QgsFeature &feature)
Reads a feature from stream in into feature. QGIS version compatibility is not guaranteed.
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features