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 );
74 if ( d->nameToIndex.contains( field.
name() ) )
79 d->nameToIndex.insert( field.
name(), d->fields.count() - 1 );
88 d->fields.remove( fieldIdx );
89 d->nameToIndex.clear();
90 for (
int idx = 0; idx <
count(); ++idx )
92 d->nameToIndex.insert( d->fields.at( idx ).field.name(), idx );
98 for (
int i = 0; i < other.
count(); ++i )
112 return d->fields.isEmpty();
117 return d->fields.count();
122 return d->fields.count();
128 for (
int i = 0; i < d->fields.count(); ++i )
130 lst.append( d->fields[i].field.name() );
137 return i >= 0 && i < d->fields.count();
142 return d->fields[i].field;
147 return d->fields[i].field;
152 return d->fields[fieldIdx].field;
168 return d->fields[i].field;
173 if ( !
exists( fieldIdx ) )
176 return d->fields[fieldIdx].origin;
181 return d->fields[fieldIdx].originIndex;
186 return d->nameToIndex.value( fieldName, -1 );
191 return d->nameToIndex.value( fieldName, -1 );
197 for (
int i = 0; i < d->fields.count(); ++i )
198 lst.append( d->fields[i].field );
204 return d->fields == other.d->fields;
209 if ( d->fields.isEmpty() )
210 return const_iterator();
212 return const_iterator( &d->fields.first() );
217 if ( d->fields.isEmpty() )
218 return const_iterator();
220 return const_iterator( &d->fields.last() + 1 );
225 if ( d->fields.isEmpty() )
226 return const_iterator();
228 return const_iterator( &d->fields.first() );
233 if ( d->fields.isEmpty() )
234 return const_iterator();
236 return const_iterator( &d->fields.last() + 1 );
241 if ( d->fields.isEmpty() )
245 return iterator( &d->fields.first() );
250 if ( d->fields.isEmpty() )
254 return iterator( &d->fields.last() + 1 );
259 switch ( d->fields.at( fieldIdx ).field.type() )
263 case QVariant::LongLong:
264 case QVariant::ULongLong:
268 case QVariant::Double:
272 case QVariant::String:
280 case QVariant::DateTime:
301 if ( fieldName.isEmpty() )
304 for (
int idx = 0; idx <
count(); ++idx )
306 if ( d->fields[idx].field.name() == fieldName )
310 for (
int idx = 0; idx <
count(); ++idx )
312 if ( QString::compare( d->fields[idx].field.name(), fieldName, Qt::CaseInsensitive ) == 0 )
316 for (
int idx = 0; idx <
count(); ++idx )
318 QString alias = d->fields[idx].field.alias();
319 if ( !alias.isEmpty() && QString::compare( alias, fieldName, Qt::CaseInsensitive ) == 0 )
329 for (
int i = 0; i < d->fields.count(); ++i )
342 out << static_cast< quint32 >( fields.
size() );
343 for (
int i = 0; i < fields.
size(); i++ )
345 out << fields.
field( i );
355 for ( quint32 i = 0; i <
size; i++ )
int lookupField(const QString &fieldName) const
Look up field's index from the field name.
int size() const
Return number of items.
FieldOrigin fieldOrigin(int fieldIdx) const
Get field's origin (value from an enumeration)
struct QgsFields::Field Field
QgsFields()
Constructor for an empty field container.
QgsFields & operator=(const QgsFields &other)
Assignment operator.
const_iterator constEnd() const noexcept
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
QIcon iconForField(int fieldIdx) const
Returns an icon corresponding to a field index, based on the field's type and source.
bool exists(int i) const
Return if a field index is valid.
Container of fields for a vector layer.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
bool appendExpressionField(const QgsField &field, int originIndex)
Append an expression field. The field must have unique name, otherwise it is rejected (returns false)...
QStringList names() const
Returns a list with field names.
void extend(const QgsFields &other)
Extend with fields from another QgsFields container.
Field comes from the underlying data provider of the vector layer (originIndex = index in provider's ...
bool operator==(const QgsFields &other) const
QDataStream & operator<<(QDataStream &out, const QgsFields &fields)
Writes the fields to stream out. QGIS version compatibility is not guaranteed.
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
Return number of items.
It has not been specified where the field comes from.
QgsField at(int i) const
Get field at particular index (must be in range 0..N-1)
int fieldOriginIndex(int fieldIdx) const
Get field's origin index (its meaning is specific to each type of origin)
int indexFromName(const QString &fieldName) const
Get the field index from the field name.
QgsAttributeList allAttributesList() const
Utility function to get list of attribute indexes.
void clear()
Remove all fields.
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Append a field. The field must have unique name, otherwise it is rejected (returns false) ...
Encapsulate a field in an attribute table or data source.
void remove(int fieldIdx)
Remove a field with the given index.
const_iterator begin() const noexcept
Returns a const STL-style iterator pointing to the first item in the list.
QDataStream & operator>>(QDataStream &in, QgsFields &fields)
Reads fields from stream in into fields. QGIS version compatibility is not guaranteed.
const_iterator constBegin() const noexcept
Returns a const STL-style iterator pointing to the first item in the list.
int indexOf(const QString &fieldName) const
Get the field index from the field name.
QgsField operator[](int i) const
Get field at particular index (must be in range 0..N-1)
QList< QgsField > toList() const
Utility function to return a list of QgsField instances.
bool isEmpty() const
Check whether the container is empty.
QList< int > QgsAttributeList
Field is calculated from an expression.
QgsField field(int fieldIdx) const
Get field at particular index (must be in range 0..N-1)