@@ -121,35 +121,43 @@ class QgsFields
121
121
%End
122
122
public:
123
123
124
- enum FieldOrigin { OriginUnknown, OriginProvider, OriginJoin, OriginEdit };
125
-
124
+ enum FieldOrigin
125
+ {
126
+ OriginUnknown, //!< it has not been specified where the field comes from
127
+ OriginProvider, //!< field comes from the underlying data provider of the vector layer (originIndex = index in provider's fields)
128
+ OriginJoin, //!< field comes from a joined layer (originIndex / 1000 = index of the join, originIndex % 1000 = index within the join)
129
+ OriginEdit //!< field has been temporarily added in editing mode (originIndex = index in the list of added attributes)
130
+ };
131
+
132
+ //! Remove all fields
126
133
void clear();
127
- void append( const QgsField& field, FieldOrigin origin = OriginProvider, int originIndex = -1 );
134
+ //! Append a field. The field must have unique name, otherwise it is rejected (returns false)
135
+ bool append( const QgsField& field, FieldOrigin origin = OriginProvider, int originIndex = -1 );
136
+ //! Remove a field with the given index
128
137
void remove( int fieldIdx );
138
+ //! Extend with fields from another QgsFields container
139
+ void extend( const QgsFields& other );
129
140
141
+ //! Check whether the container is empty
130
142
bool isEmpty() const;
143
+ //! Return number of items
144
+ int count() const;
131
145
// __len__ annotation since sip 4.10.3
132
146
//int count() const /__len__/;
133
- int count() const;
134
147
int __len__() const;
135
148
%MethodCode
136
149
sipRes = sipCpp->count();
137
150
%End
151
+ //! Return number of items
138
152
int size() const;
139
- //const QgsField& operator[](int i) const;
140
- //QgsField& operator[](int i);
141
- const QgsField& at(int i) const;
142
- QList<QgsField> toList() const;
143
-
144
- const QgsField& field( int fieldIdx ) const;
145
- const QgsField& field( const QString& name ) const;
146
- FieldOrigin fieldOrigin( int fieldIdx ) const;
147
- int fieldOriginIndex( int fieldIdx ) const;
148
-
149
- int indexFromName( const QString& name ) const;
150
- void extend( const QgsFields& other );
151
-
152
-
153
+ //! Return if a field index is valid
154
+ //! @param i Index of the field which needs to be checked
155
+ //! @return True if the field exists
156
+ bool exists( int i ) const;
157
+
158
+ //! Get field at particular index (must be in range 0..N-1)
159
+ //inline const QgsField& operator[]( int i ) const;
160
+ //! Get field at particular index (must be in range 0..N-1)
153
161
QgsField& operator[](int i) /Factory/;
154
162
%MethodCode
155
163
SIP_SSIZE_T idx = sipConvertFromSequenceIndex(a0, sipCpp->count());
@@ -159,6 +167,23 @@ class QgsFields
159
167
sipRes = new QgsField(sipCpp->operator[](idx));
160
168
161
169
%End
170
+ //! Get field at particular index (must be in range 0..N-1)
171
+ const QgsField& at( int i ) const;
172
+ //! Get field at particular index (must be in range 0..N-1)
173
+ const QgsField& field( int fieldIdx ) const;
174
+ //! Get field at particular index (must be in range 0..N-1)
175
+ const QgsField& field( const QString& name ) const;
176
+
177
+ //! Get field's origin (value from an enumeration)
178
+ FieldOrigin fieldOrigin( int fieldIdx ) const;
179
+ //! Get field's origin index (its meaning is specific to each type of origin)
180
+ int fieldOriginIndex( int fieldIdx ) const;
181
+
182
+ //! Look up field's index from name. Returns -1 on error
183
+ int indexFromName( const QString& name ) const;
184
+
185
+ //! Utility function to return a list of QgsField instances
186
+ QList<QgsField> toList() const;
162
187
163
188
/* SIP_PYOBJECT __getitem__(int key);
164
189
%MethodCode
0 commit comments