QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
30 d =
new QgsFieldsPrivate();
50 d->nameToIndex.clear();
61 if ( d->nameToIndex.contains(
field.
name() ) )
65 originIndex = d->fields.count();
66 d->fields.append(
Field(
field, origin, originIndex ) );
68 d->nameToIndex.insert(
field.
name(), d->fields.count() - 1 );
80 if ( d->nameToIndex.contains( name ) )
83 const QString oldName = d->fields[ fieldIdx ].field.name();
84 d->fields[ fieldIdx ].field.setName( name );
85 d->nameToIndex.remove( oldName );
86 d->nameToIndex.insert( name, fieldIdx );
92 if ( d->nameToIndex.contains(
field.
name() ) )
97 d->nameToIndex.insert(
field.
name(), d->fields.count() - 1 );
103 if ( !
exists( fieldIdx ) )
106 d->fields.remove( fieldIdx );
107 d->nameToIndex.clear();
108 for (
int idx = 0; idx <
count(); ++idx )
110 d->nameToIndex.insert( d->fields.at( idx ).field.name(), idx );
116 for (
int i = 0; i < other.
count(); ++i )
130 return d->fields.isEmpty();
135 return d->fields.count();
140 return d->fields.count();
146 for (
int i = 0; i < d->fields.count(); ++i )
148 lst.append( d->fields[i].field.name() );
155 return i >= 0 && i < d->fields.count();
160 return d->fields[i].field;
165 return d->fields[i].field;
170 return d->fields[fieldIdx].field;
186 return d->fields[i].field;
191 if ( !
exists( fieldIdx ) )
194 return d->fields[fieldIdx].origin;
199 return d->fields[fieldIdx].originIndex;
204 return d->nameToIndex.value( fieldName, -1 );
209 return d->nameToIndex.value( fieldName, -1 );
215 for (
int i = 0; i < d->fields.count(); ++i )
216 lst.append( d->fields[i].field );
222 return d->fields == other.d->fields;
227 if ( d->fields.isEmpty() )
228 return const_iterator();
230 return const_iterator( &d->fields.first() );
235 if ( d->fields.isEmpty() )
236 return const_iterator();
238 return const_iterator( &d->fields.last() + 1 );
243 if ( d->fields.isEmpty() )
244 return const_iterator();
246 return const_iterator( &d->fields.first() );
251 if ( d->fields.isEmpty() )
252 return const_iterator();
254 return const_iterator( &d->fields.last() + 1 );
259 if ( d->fields.isEmpty() )
263 return iterator( &d->fields.first() );
268 if ( d->fields.isEmpty() )
272 return iterator( &d->fields.last() + 1 );
277 if ( considerOrigin )
304 case QVariant::LongLong:
305 case QVariant::ULongLong:
309 case QVariant::Double:
313 case QVariant::String:
321 case QVariant::DateTime:
329 case QVariant::ByteArray:
346 if ( fieldName.isEmpty() )
349 for (
int idx = 0; idx <
count(); ++idx )
351 if ( d->fields[idx].field.name() == fieldName )
355 for (
int idx = 0; idx <
count(); ++idx )
357 if ( QString::compare( d->fields[idx].field.name(), fieldName, Qt::CaseInsensitive ) == 0 )
361 for (
int idx = 0; idx <
count(); ++idx )
363 QString alias = d->fields[idx].field.alias();
364 if ( !alias.isEmpty() && QString::compare( alias, fieldName, Qt::CaseInsensitive ) == 0 )
373 const int count = d->fields.count();
375 lst.reserve(
count );
376 for (
int i = 0; i <
count; ++i )
389 out << static_cast< quint32 >( fields.
size() );
390 for (
int i = 0; i < fields.
size(); i++ )
392 out << fields.
field( i );
402 for ( quint32 i = 0; i < size; i++ )
@ OriginProvider
Field comes from the underlying data provider of the vector layer (originIndex = index in provider's ...
QIcon iconForField(int fieldIdx, bool considerOrigin=false) const
Returns an icon corresponding to a field index, based on the field's type and source.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
bool isEmpty() const
Checks whether the container is empty.
const_iterator end() const noexcept
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list.
int count() const
Returns number of items.
Container of fields for a vector layer.
static QIcon iconForFieldType(const QVariant::Type &type)
Returns an icon corresponding to a field type.
QgsFields & operator=(const QgsFields &other)
Assignment operator.
const_iterator constBegin() const noexcept
Returns a const STL-style iterator pointing to the first item in the list.
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false)
QList< int > QgsAttributeList
QgsField operator[](int i) const
Gets field at particular index (must be in range 0..N-1)
struct QgsFields::Field Field
const_iterator begin() const noexcept
Returns a const STL-style iterator pointing to the first item in the list.
QList< QgsField > toList() const
Utility function to return a list of QgsField instances.
QgsFields()
Constructor for an empty field container.
bool exists(int i) const
Returns if a field index is valid.
@ OriginUnknown
It has not been specified where the field comes from.
int size() const
Returns number of items.
FieldOrigin fieldOrigin(int fieldIdx) const
Gets field's origin (value from an enumeration)
bool operator==(const QgsFields &other) const
QgsField field(int fieldIdx) const
Gets field at particular index (must be in range 0..N-1)
QgsAttributeList allAttributesList() const
Utility function to get list of attribute indexes.
QDataStream & operator<<(QDataStream &out, const QgsFields &fields)
Writes the fields to stream out. QGIS version compatibility is not guaranteed.
QDataStream & operator>>(QDataStream &in, QgsFields &fields)
Reads fields from stream in into fields. QGIS version compatibility is not guaranteed.
@ OriginExpression
Field is calculated from an expression.
void clear()
Removes all fields.
int fieldOriginIndex(int fieldIdx) const
Gets field's origin index (its meaning is specific to each type of origin)
bool rename(int fieldIdx, const QString &name)
Renames a name of field.
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
const_iterator constEnd() const noexcept
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list.
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
void remove(int fieldIdx)
Removes a field with the given index.
bool appendExpressionField(const QgsField &field, int originIndex)
Appends an expression field. The field must have unique name, otherwise it is rejected (returns false...
int indexFromName(const QString &fieldName) const
Gets the field index from the field name.
@ OriginJoin
Field comes from a joined layer (originIndex / 1000 = index of the join, originIndex % 1000 = index w...
QStringList names() const
Returns a list with field names.
int indexOf(const QString &fieldName) const
Gets the field index from the field name.
void extend(const QgsFields &other)
Extends with fields from another QgsFields container.
Encapsulate a field in an attribute table or data source.