17#include "moc_qgsfeature.cpp" 
   42  d = 
new QgsFeaturePrivate( 
id );
 
 
   47  d = 
new QgsFeaturePrivate( 
id );
 
 
   68  if ( !( d->fid == other.d->fid
 
   69          && d->valid == other.d->valid
 
   70          && d->fields == other.d->fields
 
   71          && d->attributes == other.d->attributes
 
   72          && d->symbol == other.d->symbol ) )
 
   76  if ( d->geometry.isNull() && other.d->geometry.isNull() )
 
   78  else if ( d->geometry.isNull() || other.d->geometry.isNull() )
 
   80  else if ( !d->geometry.equals( other.d->geometry ) )
 
 
   88  return !( *
this == other );
 
 
  109  d->attributes.remove( field );
 
 
  135  return d->attributes;
 
 
  141  const int fieldSize = d->fields.size();
 
  142  const int attributeSize = d->attributes.size();
 
  143  if ( fieldSize != attributeSize )
 
  145    QgsDebugError( QStringLiteral( 
"Attribute size (%1) does not match number of fields (%2)" ).arg( attributeSize ).arg( fieldSize ) );
 
  146    return QVariantMap();
 
  149  for ( 
int i = 0; i < attributeSize; ++i )
 
  151    res[d->fields.at( i ).name()] = d->attributes.at( i );
 
 
  158  return d->attributes.size();
 
 
  164  d->attributes = attrs;
 
 
  184  if ( d->geometry.isNull() && d->valid )
 
 
  224  if ( d->valid == validity )
 
 
  233  return !d->geometry.isNull();
 
 
  239  d->attributes.resize( 0 ); 
 
  242  d->attributes.resize( fieldCount );
 
 
  247  if ( fieldCount == d->attributes.size() )
 
  251  d->attributes.resize( fieldCount );
 
 
  260  d->attributes.resize( d->attributes.size() + count );
 
 
  265  if ( idx < 0 || idx >= d->attributes.size() )
 
  272  d->attributes[idx] = value;
 
 
  286  if ( fieldIdx == -1 )
 
  290  d->attributes[fieldIdx] = value;
 
 
  298  if ( fieldIdx == -1 )
 
  302  d->attributes[fieldIdx].clear();
 
 
  308  if ( fieldIdx < 0 || fieldIdx >= d->attributes.count() )
 
  311  return d->attributes.at( fieldIdx );
 
 
  316  if ( fieldIdx < 0 || fieldIdx >= d->attributes.count() )
 
  319  return d->attributes.at( fieldIdx ).userType() == qMetaTypeId<QgsUnsetAttributeValue>();
 
 
  324  return d->symbol.get();
 
 
  329  if ( symbol == d->symbol.get() )
 
  333  d->symbol.reset( symbol );
 
 
  339  if ( fieldIdx == -1 )
 
  342  return d->attributes.at( fieldIdx );
 
 
  353  return d->fields.lookupField( fieldName );
 
 
  356static size_t qgsQStringApproximateMemoryUsage( 
const QString &str )
 
  358  return sizeof( QString ) + str.size() * 
sizeof( QChar );
 
  361static size_t qgsQVariantApproximateMemoryUsage( 
const QVariant &v )
 
  365  size_t s = 
sizeof( QVariant ) + 
sizeof( 
long long ) + 
sizeof( int );
 
  366  if ( v.userType() == QMetaType::Type::QString )
 
  368    s += qgsQStringApproximateMemoryUsage( v.toString() );
 
  370  else if ( v.userType() == QMetaType::Type::QStringList )
 
  372    for ( 
const QString &str : v.toStringList() )
 
  373      s += qgsQStringApproximateMemoryUsage( str );
 
  375  else if ( v.userType() == QMetaType::Type::QVariantList )
 
  377    for ( 
const QVariant &subV : v.toList() )
 
  378      s += qgsQVariantApproximateMemoryUsage( subV );
 
  385  size_t s = 
sizeof( *this ) + 
sizeof( *d );
 
  388  for ( 
const QVariant &attr : std::as_const( d->attributes ) )
 
  390    s += qgsQVariantApproximateMemoryUsage( attr );
 
  394  s += 
sizeof( QAtomicInt ) + 
sizeof( 
void * ); 
 
  397  s += d->geometry.wkbSize();
 
  400  s += 
sizeof( QgsFieldsPrivate );
 
  402  s += d->fields.size() * ( 
sizeof( 
QgsField )  + 
sizeof( QgsFieldPrivate ) );
 
  404  return static_cast<int>( s );
 
 
  437  in >> 
id >> attr >> geometry >> valid;
 
 
  448  const auto constAttributes = key.
attributes();
 
  449  for ( 
const QVariant &attr : constAttributes )
 
  451    hash ^= 
qHash( attr.toString() );
 
 
@ Warning
Warning message.
 
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
 
Q_INVOKABLE bool setAttribute(int field, const QVariant &attr)
Sets 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
 
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)
Clear's an attribute's value by its index.
 
QgsFeature & operator=(const QgsFeature &rhs)
 
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
 
void setFields(const QgsFields &fields, bool initAttributes=false)
Assigns 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...
 
const QgsSymbol * embeddedSymbol() const
Returns the feature's embedded symbology, or nullptr if the feature has no embedded symbol.
 
void setId(QgsFeatureId id)
Sets the feature id for this feature.
 
void setEmbeddedSymbol(QgsSymbol *symbol)
Sets the feature's embedded symbol.
 
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 isUnsetValue(int fieldIdx) const
Returns true if the attribute at the specified index is an unset value.
 
bool isValid() const
Returns the validity of this feature.
 
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
 
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
 
QVariantMap attributeMap() const
Returns the feature's attributes as a map of field name to value.
 
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.
 
Q_INVOKABLE 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::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
Adds a message to the log instance (and creates it if necessary).
 
Abstract base class for all rendered symbols.
 
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
 
#define QgsDebugError(str)