@@ -25,11 +25,14 @@ typedef QList<int> QgsAttributeList;
25
25
26
26
class QgsExpression ;
27
27
class QgsFieldPrivate ;
28
+ class QgsFieldsPrivate ;
28
29
29
- /* * \ingroup core
30
+ /* * \class QgsField
31
+ * \ingroup core
30
32
* Encapsulate a field in an attribute table or data source.
31
33
* QgsField stores metadata about an attribute field, including name, type
32
34
* length, and if applicable, precision.
35
+ * \note QgsField objects are implicitly shared.
33
36
*/
34
37
35
38
class CORE_EXPORT QgsField
@@ -63,7 +66,7 @@ class CORE_EXPORT QgsField
63
66
QgsField& operator =( const QgsField &other );
64
67
65
68
// ! Destructor
66
- ~QgsField ();
69
+ virtual ~QgsField ();
67
70
68
71
bool operator ==( const QgsField& other ) const ;
69
72
bool operator !=( const QgsField& other ) const ;
@@ -152,13 +155,14 @@ class CORE_EXPORT QgsField
152
155
}; // class QgsField
153
156
154
157
155
- /* *
156
- \ingroup core
157
- Container of fields for a vector layer.
158
-
159
- In addition to storing a list of QgsField instances, it also:
160
- - allows quick lookups of field names to index in the list
161
- - keeps track of where the field definition comes from (vector data provider, joined layer or newly added from an editing operation)
158
+ /* * \class QgsFields
159
+ * \ingroup core
160
+ * Container of fields for a vector layer.
161
+ *
162
+ * In addition to storing a list of QgsField instances, it also:
163
+ * - allows quick lookups of field names to index in the list
164
+ *- keeps track of where the field definition comes from (vector data provider, joined layer or newly added from an editing operation)
165
+ * \note QgsFields objects are implicitly shared.
162
166
*/
163
167
class CORE_EXPORT QgsFields
164
168
{
@@ -188,6 +192,20 @@ class CORE_EXPORT QgsFields
188
192
int originIndex; // !< index specific to the origin
189
193
} Field;
190
194
195
+ /* * Constructor for an empty field container
196
+ */
197
+ QgsFields ();
198
+
199
+ /* * Copy constructor
200
+ */
201
+ QgsFields ( const QgsFields& other );
202
+
203
+ /* * Assignment operator
204
+ */
205
+ QgsFields& operator =( const QgsFields &other );
206
+
207
+ virtual ~QgsFields ();
208
+
191
209
// ! Remove all fields
192
210
void clear ();
193
211
// ! Append a field. The field must have unique name, otherwise it is rejected (returns false)
@@ -200,34 +218,34 @@ class CORE_EXPORT QgsFields
200
218
void extend ( const QgsFields& other );
201
219
202
220
// ! Check whether the container is empty
203
- inline bool isEmpty () const { return mFields . isEmpty (); }
221
+ bool isEmpty () const ;
204
222
// ! Return number of items
205
- inline int count () const { return mFields . count (); }
223
+ int count () const ;
206
224
// ! Return number of items
207
- inline int size () const { return mFields . count (); }
225
+ int size () const ;
208
226
// ! Return if a field index is valid
209
227
// ! @param i Index of the field which needs to be checked
210
228
// ! @return True if the field exists
211
- inline bool exists ( int i ) const { return i >= 0 && i < mFields . count (); }
229
+ bool exists ( int i ) const ;
212
230
213
231
// ! Get field at particular index (must be in range 0..N-1)
214
- inline const QgsField& operator []( int i ) const { return mFields [i]. field ; }
232
+ const QgsField& operator []( int i ) const ;
215
233
// ! Get field at particular index (must be in range 0..N-1)
216
- inline QgsField& operator []( int i ) { return mFields [i]. field ; }
234
+ QgsField& operator []( int i );
217
235
// ! Get field at particular index (must be in range 0..N-1)
218
- const QgsField& at ( int i ) const { return mFields [i]. field ; }
236
+ const QgsField& at ( int i ) const ;
219
237
// ! Get field at particular index (must be in range 0..N-1)
220
- const QgsField& field ( int fieldIdx ) const { return mFields [fieldIdx]. field ; }
238
+ const QgsField& field ( int fieldIdx ) const ;
221
239
// ! Get field at particular index (must be in range 0..N-1)
222
- const QgsField& field ( const QString& name ) const { return mFields [ indexFromName ( name )]. field ; }
240
+ const QgsField& field ( const QString& name ) const ;
223
241
224
242
// ! Get field's origin (value from an enumeration)
225
243
FieldOrigin fieldOrigin ( int fieldIdx ) const ;
226
244
// ! Get field's origin index (its meaning is specific to each type of origin)
227
- int fieldOriginIndex ( int fieldIdx ) const { return mFields [fieldIdx]. originIndex ; }
245
+ int fieldOriginIndex ( int fieldIdx ) const ;
228
246
229
247
// ! Look up field's index from name. Returns -1 on error
230
- int indexFromName ( const QString& name ) const { return mNameToIndex . value ( name, - 1 ); }
248
+ int indexFromName ( const QString& name ) const ;
231
249
232
250
// ! Look up field's index from name - case insensitive
233
251
// ! TODO: sort out case sensitive (indexFromName()) vs insensitive (fieldNameIndex()) calls
@@ -242,20 +260,14 @@ class CORE_EXPORT QgsFields
242
260
QList<QgsField> toList () const ;
243
261
244
262
// ! @note added in 2.6
245
- bool operator ==( const QgsFields& other ) const { return mFields == other. mFields ; }
263
+ bool operator ==( const QgsFields& other ) const ;
246
264
// ! @note added in 2.6
247
265
bool operator !=( const QgsFields& other ) const { return !( *this == other ); }
248
266
249
- protected:
250
- // ! internal storage of the container
251
- QVector<Field> mFields ;
267
+ private:
252
268
253
- // ! map for quick resolution of name to index
254
- QHash<QString, int > mNameToIndex ;
269
+ QSharedDataPointer<QgsFieldsPrivate> d;
255
270
256
271
};
257
272
258
-
259
-
260
-
261
273
#endif
0 commit comments