31  d = 
new QgsFieldsPrivate();
 
 
   51  d->nameToIndex.clear();
 
 
   62  if ( d->nameToIndex.contains( 
field.
name() ) )
 
   66    originIndex = d->fields.count();
 
   67  d->fields.append( 
Field( 
field, origin, originIndex ) );
 
   69  d->nameToIndex.insert( 
field.
name(), d->fields.count() - 1 );
 
 
   81  if ( d->nameToIndex.contains( name ) )
 
   84  const QString oldName = d->fields[ fieldIdx ].field.name();
 
   85  d->fields[ fieldIdx ].field.setName( name );
 
   86  d->nameToIndex.remove( oldName );
 
   87  d->nameToIndex.insert( name, fieldIdx );
 
 
   93  if ( d->nameToIndex.contains( 
field.
name() ) )
 
   98  d->nameToIndex.insert( 
field.
name(), d->fields.count() - 1 );
 
 
  104  if ( !
exists( fieldIdx ) )
 
  107  d->fields.remove( fieldIdx );
 
  108  d->nameToIndex.clear();
 
  109  for ( 
int idx = 0; idx < 
count(); ++idx )
 
  111    d->nameToIndex.insert( d->fields.at( idx ).field.name(), idx );
 
 
  117  for ( 
int i = 0; i < other.
count(); ++i )
 
 
  131  return d->fields.isEmpty();
 
 
  136  return d->fields.count();
 
 
  141  return d->fields.count();
 
 
  147  for ( 
int i = 0; i < d->fields.count(); ++i )
 
  149    lst.append( d->fields[i].field.name() );
 
 
  156  return i >= 0 && i < d->fields.count();
 
 
  161  return d->fields[i].field;
 
 
  166  return d->fields[i].field;
 
 
  171  return d->fields[fieldIdx].field;
 
 
  187  return d->fields[i].field;
 
 
  192  if ( !
exists( fieldIdx ) )
 
  195  return d->fields[fieldIdx].origin;
 
 
  200  return d->fields[fieldIdx].originIndex;
 
 
  205  return d->nameToIndex.value( fieldName, -1 );
 
 
  210  return d->nameToIndex.value( fieldName, -1 );
 
 
  216  for ( 
int i = 0; i < d->fields.count(); ++i )
 
  217    lst.append( d->fields[i].field );
 
 
  223  return d->fields == other.d->fields;
 
 
  228  if ( d->fields.isEmpty() )
 
  229    return const_iterator();
 
  231  return const_iterator( &d->fields.first() );
 
 
  236  if ( d->fields.isEmpty() )
 
  237    return const_iterator();
 
  239  return const_iterator( &d->fields.last() + 1 );
 
 
  244  if ( d->fields.isEmpty() )
 
  245    return const_iterator();
 
  247  return const_iterator( &d->fields.first() );
 
 
  252  if ( d->fields.isEmpty() )
 
  253    return const_iterator();
 
  255  return const_iterator( &d->fields.last() + 1 );
 
 
  260  if ( d->fields.isEmpty() )
 
  264  return iterator( &d->fields.first() );
 
 
  269  if ( d->fields.isEmpty() )
 
  273  return iterator( &d->fields.last() + 1 );
 
 
  278  if ( considerOrigin )
 
  289        return iconForFieldType( d->fields.at( fieldIdx ).field.type(), d->fields.at( fieldIdx ).field.subType(), d->fields.at( fieldIdx ).field.typeName() );
 
  292  return iconForFieldType( d->fields.at( fieldIdx ).field.type(), d->fields.at( fieldIdx ).field.subType(), d->fields.at( fieldIdx ).field.typeName() );
 
 
  299    case QMetaType::Type::Bool:
 
  301    case QMetaType::Type::Int:
 
  302    case QMetaType::Type::UInt:
 
  303    case QMetaType::Type::LongLong:
 
  304    case QMetaType::Type::ULongLong:
 
  306    case QMetaType::Type::Double:
 
  308    case QMetaType::Type::QString:
 
  310    case QMetaType::Type::QDate:
 
  312    case QMetaType::Type::QDateTime:
 
  314    case QMetaType::Type::QTime:
 
  316    case QMetaType::Type::QByteArray:
 
  318    case QMetaType::Type::QVariantList:
 
  322        case QMetaType::Type::Int:
 
  323        case QMetaType::Type::UInt:
 
  324        case QMetaType::Type::LongLong:
 
  325        case QMetaType::Type::ULongLong:
 
  327        case QMetaType::Type::Double:
 
  329        case QMetaType::Type::QString:
 
  335    case QMetaType::Type::QStringList:
 
  337    case QMetaType::Type::QVariantMap:
 
  339    case QMetaType::Type::User:
 
  340      if ( typeString.compare( QLatin1String( 
"geometry" ) ) == 0 )
 
 
  367  if ( fieldName.isEmpty() ) 
 
  370  for ( 
int idx = 0; idx < 
count(); ++idx )
 
  372    if ( d->fields[idx].field.name() == fieldName )
 
  376  for ( 
int idx = 0; idx < 
count(); ++idx )
 
  378    if ( QString::compare( d->fields[idx].field.name(), fieldName, Qt::CaseInsensitive ) == 0 )
 
  382  for ( 
int idx = 0; idx < 
count(); ++idx )
 
  384    const QString alias = d->fields[idx].field.alias();
 
  385    if ( !alias.isEmpty() && QString::compare( alias, fieldName, Qt::CaseInsensitive ) == 0 )
 
 
  394  const int count = d->fields.count();
 
  396  lst.reserve( 
count );
 
  397  for ( 
int i = 0; i < 
count; ++i )
 
 
  410  out << static_cast< quint32 >( fields.
size() );
 
  411  for ( 
int i = 0; i < fields.
size(); i++ )
 
  413    out << fields.
field( i );
 
 
  423  for ( quint32 i = 0; i < size; i++ )
 
 
@ Provider
Field originates from the underlying data provider of the vector layer.
 
@ Unknown
The field origin has not been specified.
 
@ Expression
Field is calculated from an expression.
 
@ Join
Field originates from a joined layer.
 
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
 
Encapsulate a field in an attribute table or data source.
 
Container of fields for a vector layer.
 
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
 
void extend(const QgsFields &other)
Extends with fields from another QgsFields container.
 
const_iterator constEnd() const noexcept
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list.
 
QList< QgsField > toList() const
Utility function to return a list of QgsField instances.
 
QgsAttributeList allAttributesList() const
Utility function to get list of attribute indexes.
 
bool operator==(const QgsFields &other) const
 
bool appendExpressionField(const QgsField &field, int originIndex)
Appends an expression field. The field must have unique name, otherwise it is rejected (returns false...
 
Q_INVOKABLE int indexFromName(const QString &fieldName) const
Gets the field index from the field name.
 
Q_INVOKABLE int indexOf(const QString &fieldName) const
Gets the field index from the field name.
 
void remove(int fieldIdx)
Removes the field with the given index.
 
const_iterator begin() const noexcept
Returns a const STL-style iterator pointing to the first item in the list.
 
static QIcon iconForFieldType(QMetaType::Type type, QMetaType::Type subType=QMetaType::Type::UnknownType, const QString &typeString=QString())
Returns an icon corresponding to a field type.
 
QgsField field(int fieldIdx) const
Returns the field at particular index (must be in range 0..N-1).
 
QgsFields & operator=(const QgsFields &other)
Assignment operator.
 
QgsField operator[](int i) const
Gets field at particular index (must be in range 0..N-1)
 
QgsFields()
Constructor for an empty field container.
 
Qgis::FieldOrigin fieldOrigin(int fieldIdx) const
Returns the field's origin (value from an enumeration).
 
Q_INVOKABLE bool exists(int i) const
Returns if a field index is valid.
 
int size() const
Returns number of items.
 
void clear()
Removes all fields.
 
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
 
int fieldOriginIndex(int fieldIdx) const
Returns the field's origin index (its meaning is specific to each type of origin).
 
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
 
QIcon iconForField(int fieldIdx, bool considerOrigin=false) const
Returns an icon corresponding to a field index, based on the field's type and source.
 
const_iterator end() const noexcept
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list.
 
bool rename(int fieldIdx, const QString &name)
Renames a name of field.
 
const_iterator constBegin() const noexcept
Returns a const STL-style iterator pointing to the first item in the list.
 
static QMetaType::Type variantTypeToMetaType(QVariant::Type variantType)
Converts a QVariant::Type to a QMetaType::Type.
 
QList< int > QgsAttributeList
 
QDataStream & operator>>(QDataStream &in, QgsFields &fields)
Reads fields from stream in into fields. QGIS version compatibility is not guaranteed.
 
QDataStream & operator<<(QDataStream &out, const QgsFields &fields)
Writes the fields to stream out. QGIS version compatibility is not guaranteed.