QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
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 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 )
353 const int count = d->fields.count();
355 lst.reserve(
count );
356 for (
int i = 0; i <
count; ++i )
369 out << static_cast< quint32 >( fields.
size() );
370 for (
int i = 0; i < fields.
size(); i++ )
372 out << fields.
field( i );
382 for ( quint32 i = 0; i < size; i++ )
@ OriginProvider
Field comes from the underlying data provider of the vector layer (originIndex = index in provider's ...
const_iterator begin() const noexcept
Returns a const STL-style iterator pointing to the first item in the list.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
bool isEmpty() const
Checks whether the container is empty.
int count() const
Returns number of items.
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
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.
const_iterator end() const noexcept
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list.
QDataStream & operator<<(QDataStream &out, const QgsFields &fields)
Writes the fields to stream out. QGIS version compatibility is not guaranteed.
QIcon iconForField(int fieldIdx) const
Returns an icon corresponding to a field index, based on the field's type and source.
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.
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.