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 switch ( d->fields.at( fieldIdx ).field.type() )
284 case QVariant::LongLong:
285 case QVariant::ULongLong:
289 case QVariant::Double:
293 case QVariant::String:
301 case QVariant::DateTime:
309 case QVariant::ByteArray:
326 if ( fieldName.isEmpty() )
329 for (
int idx = 0; idx <
count(); ++idx )
331 if ( d->fields[idx].field.name() == fieldName )
335 for (
int idx = 0; idx <
count(); ++idx )
337 if ( QString::compare( d->fields[idx].field.name(), fieldName, Qt::CaseInsensitive ) == 0 )
341 for (
int idx = 0; idx <
count(); ++idx )
343 QString alias = d->fields[idx].field.alias();
344 if ( !alias.isEmpty() && QString::compare( alias, fieldName, Qt::CaseInsensitive ) == 0 )
354 for (
int i = 0; i < d->fields.count(); ++i )
367 out << static_cast< quint32 >( fields.
size() );
368 for (
int i = 0; i < fields.
size(); i++ )
370 out << fields.
field( i );
380 for ( quint32 i = 0; i <
size; i++ )
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
int size() const
Returns number of items.
FieldOrigin fieldOrigin(int fieldIdx) const
Gets 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
Returns 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)
Appends 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)
Extends 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
bool rename(int fieldIdx, const QString &name)
Renames a name of field.
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
Returns number of items.
It has not been specified where the field comes from.
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
int fieldOriginIndex(int fieldIdx) const
Gets field's origin index (its meaning is specific to each type of origin)
int indexFromName(const QString &fieldName) const
Gets the field index from the field name.
QgsAttributeList allAttributesList() const
Utility function to get list of attribute indexes.
void clear()
Removes all fields.
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) ...
Encapsulate a field in an attribute table or data source.
void remove(int fieldIdx)
Removes 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
Gets the field index from the field name.
QgsField operator[](int i) const
Gets 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
Checks whether the container is empty.
QList< int > QgsAttributeList
Field is calculated from an expression.
QgsField field(int fieldIdx) const
Gets field at particular index (must be in range 0..N-1)