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 )
288 return iconForFieldType( d->fields.at( fieldIdx ).field.type(), d->fields.at( fieldIdx ).field.subType() );
291 return iconForFieldType( d->fields.at( fieldIdx ).field.type(), d->fields.at( fieldIdx ).field.subType() );
302 case QVariant::LongLong:
303 case QVariant::ULongLong:
305 case QVariant::Double:
307 case QVariant::String:
311 case QVariant::DateTime:
315 case QVariant::ByteArray:
323 case QVariant::LongLong:
324 case QVariant::ULongLong:
326 case QVariant::Double:
328 case QVariant::String:
334 case QVariant::StringList:
351 if ( fieldName.isEmpty() )
354 for (
int idx = 0; idx <
count(); ++idx )
356 if ( d->fields[idx].field.name() == fieldName )
360 for (
int idx = 0; idx <
count(); ++idx )
362 if ( QString::compare( d->fields[idx].field.name(), fieldName, Qt::CaseInsensitive ) == 0 )
366 for (
int idx = 0; idx <
count(); ++idx )
368 const QString alias = d->fields[idx].field.alias();
369 if ( !alias.isEmpty() && QString::compare( alias, fieldName, Qt::CaseInsensitive ) == 0 )
378 const int count = d->fields.count();
380 lst.reserve(
count );
381 for (
int i = 0; i <
count; ++i )
394 out << static_cast< quint32 >( fields.
size() );
395 for (
int i = 0; i < fields.
size(); i++ )
397 out << fields.
field( i );
407 for ( quint32 i = 0; i < size; i++ )
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.
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.
struct QgsFields::Field Field
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...
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)
int indexFromName(const QString &fieldName) const
Gets the field index from the field name.
static QIcon iconForFieldType(QVariant::Type type, QVariant::Type subType=QVariant::Type::Invalid)
Returns an icon corresponding to a field type.
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.
@ OriginExpression
Field is calculated from an expression.
@ OriginUnknown
It has not been specified where the field comes from.
@ OriginJoin
Field comes from a joined layer (originIndex / 1000 = index of the join, originIndex % 1000 = index w...
@ OriginProvider
Field comes from the underlying data provider of the vector layer (originIndex = index in provider's ...
int count() const
Returns number of items.
const_iterator begin() const noexcept
Returns a const STL-style iterator pointing to the first item in the list.
FieldOrigin fieldOrigin(int fieldIdx) const
Returns the field's origin (value from an enumeration).
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.
bool exists(int i) const
Returns if a field index is valid.
bool isEmpty() const
Checks whether the container is empty.
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).
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.
QStringList names() const
Returns a list with field names.
const_iterator constBegin() const noexcept
Returns a const STL-style iterator pointing to the first item in the list.
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.