Branch data Line data Source code
1 : :
2 : : /***************************************************************************
3 : : -------------------
4 : : begin : Oct 29, 2003
5 : : copyright : (C) 2003 by Gary E.Sherman
6 : : email : sherman at mrcc.com
7 : : ***************************************************************************/
8 : :
9 : : /***************************************************************************
10 : : * *
11 : : * This program is free software; you can redistribute it and/or modify *
12 : : * it under the terms of the GNU General Public License as published by *
13 : : * the Free Software Foundation; either version 2 of the License, or *
14 : : * (at your option) any later version. *
15 : : * *
16 : : ***************************************************************************/
17 : :
18 : : #ifndef QGSVECTORLAYER_H
19 : : #define QGSVECTORLAYER_H
20 : :
21 : :
22 : : #include "qgis_core.h"
23 : : #include <QMap>
24 : : #include <QSet>
25 : : #include <QList>
26 : : #include <QStringList>
27 : : #include <QFont>
28 : : #include <QMutex>
29 : :
30 : : #include "qgis.h"
31 : : #include "qgsmaplayer.h"
32 : : #include "qgsfeature.h"
33 : : #include "qgsfeaturerequest.h"
34 : : #include "qgsfeaturesource.h"
35 : : #include "qgsfields.h"
36 : : #include "qgsvectordataprovider.h"
37 : : #include "qgsvectorsimplifymethod.h"
38 : : #include "qgsvectorlayerserverproperties.h"
39 : : #include "qgseditformconfig.h"
40 : : #include "qgsattributetableconfig.h"
41 : : #include "qgsaggregatecalculator.h"
42 : : #include "qgsfeatureiterator.h"
43 : : #include "qgsexpressioncontextgenerator.h"
44 : : #include "qgsexpressioncontextscopegenerator.h"
45 : : #include "qgsexpressioncontext.h"
46 : :
47 : : class QPainter;
48 : : class QImage;
49 : :
50 : : class QgsAbstractGeometrySimplifier;
51 : : class QgsActionManager;
52 : : class QgsConditionalLayerStyles;
53 : : class QgsCurve;
54 : : class QgsDiagramLayerSettings;
55 : : class QgsDiagramRenderer;
56 : : class QgsEditorWidgetWrapper;
57 : : class QgsExpressionFieldBuffer;
58 : : class QgsFeatureRenderer;
59 : : class QgsGeometry;
60 : : class QgsGeometryVertexIndex;
61 : : class QgsMapToPixel;
62 : : class QgsRectangle;
63 : : class QgsRectangle;
64 : : class QgsRelation;
65 : : class QgsWeakRelation;
66 : : class QgsRelationManager;
67 : : class QgsSingleSymbolRenderer;
68 : : class QgsStoredExpressionManager;
69 : : class QgsSymbol;
70 : : class QgsVectorLayerJoinInfo;
71 : : class QgsVectorLayerEditBuffer;
72 : : class QgsVectorLayerJoinBuffer;
73 : : class QgsVectorLayerFeatureCounter;
74 : : class QgsAbstractVectorLayerLabeling;
75 : : class QgsPalLayerSettings;
76 : : class QgsPoint;
77 : : class QgsFeedback;
78 : : class QgsAuxiliaryStorage;
79 : : class QgsAuxiliaryLayer;
80 : : class QgsGeometryOptions;
81 : : class QgsStyleEntityVisitorInterface;
82 : : class QgsVectorLayerTemporalProperties;
83 : : class QgsFeatureRendererGenerator;
84 : :
85 : : typedef QList<int> QgsAttributeList;
86 : : typedef QSet<int> QgsAttributeIds;
87 : :
88 : : // TODO QGIS4: Remove virtual from non-inherited methods (like isModified)
89 : :
90 : : /**
91 : : * \ingroup core
92 : : * \brief Represents a vector layer which manages a vector based data sets.
93 : : *
94 : : * The QgsVectorLayer is instantiated by specifying the name of a data provider,
95 : : * such as postgres or wfs, and url defining the specific data set to connect to.
96 : : * The vector layer constructor in turn instantiates a QgsVectorDataProvider subclass
97 : : * corresponding to the provider type, and passes it the url. The data provider
98 : : * connects to the data source.
99 : : *
100 : : * The QgsVectorLayer provides a common interface to the different data types. It also
101 : : * manages editing transactions by buffering layer edits until they are written to the
102 : : * underlying QgsVectorDataProvider. Before edits can be made a call to startEditing()
103 : : * is required. Any edits made to a QgsVectorLayer are then held in memory only, and
104 : : * are not written to the underlying QgsVectorDataProvider until a call to commitChanges()
105 : : * is made. Buffered edits can be rolled back and discarded without altering the
106 : : * underlying provider by calling rollBack().
107 : : *
108 : : * Sample usage of the QgsVectorLayer class:
109 : : *
110 : : * \code{.py}
111 : : * uri = "point?crs=epsg:4326&field=id:integer"
112 : : * scratchLayer = QgsVectorLayer(uri, "Scratch point layer", "memory")
113 : : * \endcode
114 : : *
115 : : * The main data providers supported by QGIS are listed below.
116 : : *
117 : : * \section providers Vector data providers
118 : : *
119 : : * \subsection memory Memory data providerType (memory)
120 : : *
121 : : * The memory data provider is used to construct in memory data, for example scratch
122 : : * data or data generated from spatial operations such as contouring. There is no
123 : : * inherent persistent storage of the data. The data source uri is constructed. The
124 : : * url specifies the geometry type ("point", "linestring", "polygon",
125 : : * "multipoint","multilinestring","multipolygon"), optionally followed by url parameters
126 : : * as follows:
127 : : *
128 : : * - crs=definition
129 : : * Defines the coordinate reference system to use for the layer.
130 : : * definition is any string accepted by QgsCoordinateReferenceSystem::createFromString()
131 : : * - index=yes
132 : : * Specifies that the layer will be constructed with a spatial index
133 : : * - field=name:type(length,precision)
134 : : * Defines an attribute of the layer. Multiple field parameters can be added
135 : : * to the data provider definition. type is one of "integer", "double", "string".
136 : : *
137 : : * An example url is "Point?crs=epsg:4326&field=id:integer&field=name:string(20)&index=yes"
138 : : *
139 : : * Since QGIS 3.4 when closing a project, the application shows a warning about potential data
140 : : * loss if there are any non-empty memory layers present. If your memory layer should not
141 : : * trigger such warning, it is possible to suppress that by setting the following custom variable:
142 : : *
143 : : * \code{.py}
144 : : * layer.setCustomProperty("skipMemoryLayersCheck", 1)
145 : : * \endcode
146 : : *
147 : : *
148 : : * \subsection ogr OGR data provider (ogr)
149 : : *
150 : : * Accesses data using the OGR drivers (https://gdal.org/drivers/vector/index.html). The url
151 : : * is the OGR connection string. A wide variety of data formats can be accessed using this
152 : : * driver, including file based formats used by many GIS systems, database formats, and
153 : : * web services. Some of these formats are also supported by custom data providers listed
154 : : * below.
155 : : *
156 : : * \subsection spatialite SpatiaLite data provider (spatialite)
157 : : *
158 : : * Access data in a SpatiaLite database. The url defines the connection parameters, table,
159 : : * geometry column, and other attributes. The url can be constructed using the
160 : : * QgsDataSourceUri class.
161 : : *
162 : : * \subsection postgres PostgreSQL data provider (postgres)
163 : : *
164 : : * Connects to a PostgreSQL database. The url defines the connection parameters, table,
165 : : * geometry column, and other attributes. The url can be constructed using the
166 : : * QgsDataSourceUri class.
167 : : *
168 : : * \subsection mssql Microsoft SQL server data provider (mssql)
169 : : *
170 : : * Connects to a Microsoft SQL server database. The url defines the connection parameters, table,
171 : : * geometry column, and other attributes. The url can be constructed using the
172 : : * QgsDataSourceUri class.
173 : : *
174 : : * \subsection wfs WFS (web feature service) data provider (wfs)
175 : : *
176 : : * Used to access data provided by a web feature service.
177 : : *
178 : : * The url can be a HTTP url to a WFS server (legacy, e.g. http://foobar/wfs?TYPENAME=xxx&SRSNAME=yyy[&FILTER=zzz]), or,
179 : : * starting with QGIS 2.16, a URI constructed using the QgsDataSourceUri class with the following parameters :
180 : : *
181 : : * - url=string (mandatory): HTTP url to a WFS server endpoint. e.g http://foobar/wfs
182 : : * - typename=string (mandatory): WFS typename
183 : : * - srsname=string (recommended): SRS like 'EPSG:XXXX'
184 : : * - username=string
185 : : * - password=string
186 : : * - authcfg=string
187 : : * - version=auto/1.0.0/1.1.0/2.0.0
188 : : * - sql=string: full SELECT SQL statement with optional WHERE, ORDER BY and possibly with JOIN if supported on server
189 : : * - filter=string: QGIS expression or OGC/FES filter
190 : : * - restrictToRequestBBOX=1: to download only features in the view extent (or more generally
191 : : * in the bounding box of the feature iterator)
192 : : * - pageSize=number: number of features to retrieve in a single request (WFS 2)
193 : : * - maxNumFeatures=number: maximum number of features to retrieve (possibly across several multiple paging requests)
194 : : * - IgnoreAxisOrientation=1: to ignore EPSG axis order for WFS 1.1 or 2.0
195 : : * - InvertAxisOrientation=1: to invert axis order
196 : : * - hideDownloadProgressDialog=1: to hide the download progress dialog
197 : : *
198 : : * The ‘FILTER’ query string parameter can be used to filter
199 : : * the WFS feature type. The ‘FILTER’ key value can either be a QGIS expression
200 : : * or an OGC XML filter. If the value is set to a QGIS expression the driver will
201 : : * turn it into OGC XML filter before passing it to the WFS server. Beware the
202 : : * QGIS expression filter only supports” =, !=, <, >, <=, >=, AND, OR, NOT, LIKE, IS NULL”
203 : : * attribute operators, “BBOX, Disjoint, Intersects, Touches, Crosses, Contains, Overlaps, Within”
204 : : * spatial binary operators and the QGIS local “geomFromWKT, geomFromGML”
205 : : * geometry constructor functions.
206 : : *
207 : : * \subsection oapif OGC API - Features data provider (oapif)
208 : : *
209 : : * Used to access data provided by a OGC API - Features server.
210 : : *
211 : : * The URI should be constructed using the QgsDataSourceUri class with the following parameters:
212 : : *
213 : : * - url=string (mandatory): HTTP url to a OGC API - Features landing page.
214 : : * - typename=string (mandatory): Collection id
215 : : * - username=string
216 : : * - password=string
217 : : * - authcfg=string
218 : : * - filter=string: QGIS expression (only datetime filtering is forwarded to the server)
219 : : * - restrictToRequestBBOX=1: to download only features in the view extent (or more generally
220 : : * in the bounding box of the feature iterator)
221 : : * - pageSize=number: number of features to retrieve in a single request
222 : : * - maxNumFeatures=number: maximum number of features to retrieve (possibly across several multiple paging requests)
223 : : * - hideDownloadProgressDialog=1: to hide the download progress dialog.
224 : : *
225 : : * Also note:
226 : : *
227 : : * - You can use various functions available in the QGIS Expression list,
228 : : * however the function must exist server side and have the same name and arguments to work.
229 : : * - Use the special $geometry parameter to provide the layer geometry column as input
230 : : * into the spatial binary operators e.g intersects($geometry, geomFromWKT('POINT (5 6)'))
231 : : *
232 : : * \subsection delimitedtext Delimited text file data provider (delimitedtext)
233 : : *
234 : : * Accesses data in a delimited text file, for example CSV files generated by
235 : : * spreadsheets. The contents of the file are split into columns based on specified
236 : : * delimiter characters. Each record may be represented spatially either by an
237 : : * X and Y coordinate column, or by a WKT (well known text) formatted columns.
238 : : *
239 : : * The url defines the filename, the formatting options (how the
240 : : * text in the file is divided into data fields, and which fields contain the
241 : : * X,Y coordinates or WKT text definition. The options are specified as url query
242 : : * items.
243 : : *
244 : : * At its simplest the url can just be the filename, in which case it will be loaded
245 : : * as a CSV formatted file.
246 : : *
247 : : * The url may include the following items:
248 : : *
249 : : * - encoding=UTF-8
250 : : *
251 : : * Defines the character encoding in the file. The default is UTF-8. To use
252 : : * the default encoding for the operating system use "System".
253 : : *
254 : : * - type=(csv|regexp|whitespace|plain)
255 : : *
256 : : * Defines the algorithm used to split records into columns. Records are
257 : : * defined by new lines, except for csv format files for which quoted fields
258 : : * may span multiple records. The default type is csv.
259 : : *
260 : : * - "csv" splits the file based on three sets of characters:
261 : : * delimiter characters, quote characters,
262 : : * and escape characters. Delimiter characters mark the end
263 : : * of a field. Quote characters enclose a field which can contain
264 : : * delimiter characters, and newlines. Escape characters cause the
265 : : * following character to be treated literally (including delimiter,
266 : : * quote, and newline characters). Escape and quote characters must
267 : : * be different from delimiter characters. Escape characters that are
268 : : * also quote characters are treated specially - they can only
269 : : * escape themselves within quotes. Elsewhere they are treated as
270 : : * quote characters. The defaults for delimiter, quote, and escape
271 : : * are ',', '"', '"'.
272 : : * - "regexp" splits each record using a regular expression (see QRegExp
273 : : * documentation for details).
274 : : * - "whitespace" splits each record based on whitespace (on or more whitespace
275 : : * characters. Leading whitespace in the record is ignored.
276 : : * - "plain" is provided for backwards compatibility. It is equivalent to
277 : : * CSV except that the default quote characters are single and double quotes,
278 : : * and there is no escape characters.
279 : : * - delimiter=characters
280 : : *
281 : : * Defines the delimiter characters used for csv and plain type files, or the
282 : : * regular expression for regexp type files. It is a literal string of characters
283 : : * except that "\t" may be used to represent a tab character.
284 : : *
285 : : * - quote=characters
286 : : *
287 : : * Defines the characters that are used as quote characters for csv and plain type
288 : : * files.
289 : : *
290 : : * - escape=characters
291 : : *
292 : : * Defines the characters used to escape delimiter, quote, and newline characters.
293 : : *
294 : : * - skipLines=n
295 : : *
296 : : * Defines the number of lines to ignore at the beginning of the file (default 0)
297 : : *
298 : : * - useHeader=(yes|no)
299 : : *
300 : : * Defines whether the first record in the file (after skipped lines) contains
301 : : * column names (default yes)
302 : : *
303 : : * - trimFields=(yes|no)
304 : : *
305 : : * If yes then leading and trailing whitespace will be removed from fields
306 : : *
307 : : * - skipEmptyFields=(yes|no)
308 : : *
309 : : * If yes then empty fields will be discarded (equivalent to concatenating consecutive
310 : : * delimiters)
311 : : *
312 : : * - maxFields=#
313 : : *
314 : : * Specifies the maximum number of fields to load for each record. Additional
315 : : * fields will be discarded. Default is 0 - load all fields.
316 : : *
317 : : * - decimalPoint=c
318 : : *
319 : : * Defines a character that is used as a decimal point in the numeric columns
320 : : * The default is '.'.
321 : : *
322 : : * - xField=column yField=column
323 : : *
324 : : * Defines the name of the columns holding the x and y coordinates for XY point geometries.
325 : : * If the useHeader is no (ie there are no column names), then this is the column
326 : : * number (with the first column as 1).
327 : : *
328 : : * - xyDms=(yes|no)
329 : : *
330 : : * If yes then the X and Y coordinates are interpreted as
331 : : * degrees/minutes/seconds format (fairly permissively),
332 : : * or degree/minutes format.
333 : : *
334 : : * - wktField=column
335 : : *
336 : : * Defines the name of the columns holding the WKT geometry definition for WKT geometries.
337 : : * If the useHeader is no (ie there are no column names), then this is the column
338 : : * number (with the first column as 1).
339 : : *
340 : : * - geomType=(point|line|polygon|none)
341 : : *
342 : : * Defines the geometry type for WKT type geometries. QGIS will only display one
343 : : * type of geometry for the layer - any others will be ignored when the file is
344 : : * loaded. By default the provider uses the type of the first geometry in the file.
345 : : * Use geomType to override this type.
346 : : *
347 : : * geomType can also be set to none, in which case the layer is loaded without
348 : : * geometries.
349 : : *
350 : : * - subset=expression
351 : : *
352 : : * Defines an expression that will identify a subset of records to display
353 : : *
354 : : * - crs=crsstring
355 : : *
356 : : * Defines the coordinate reference system used for the layer. This can be
357 : : * any string accepted by QgsCoordinateReferenceSystem::createFromString()
358 : : *
359 : : * - subsetIndex=(yes|no)
360 : : *
361 : : * Determines whether the provider generates an index to improve the efficiency
362 : : * of subsets. The default is yes
363 : : *
364 : : * - spatialIndex=(yes|no)
365 : : *
366 : : * Determines whether the provider generates a spatial index. The default is no.
367 : : *
368 : : * - watchFile=(yes|no)
369 : : *
370 : : * Defines whether the file will be monitored for changes. The default is
371 : : * to monitor for changes.
372 : : *
373 : : * - quiet
374 : : *
375 : : * Errors encountered loading the file will not be reported in a user dialog if
376 : : * quiet is included (They will still be shown in the output log).
377 : : *
378 : : * \subsection gpx GPX data provider (gpx)
379 : : *
380 : : * Provider reads tracks, routes, and waypoints from a GPX file. The url
381 : : * defines the name of the file, and the type of data to retrieve from it
382 : : * ("track", "route", or "waypoint").
383 : : *
384 : : * An example url is "/home/user/data/holiday.gpx?type=route"
385 : : *
386 : : * \subsection grass Grass data provider (grass)
387 : : *
388 : : * Provider to display vector data in a GRASS GIS layer.
389 : : *
390 : : * \see QgsVectorLayerUtils()
391 : : */
392 : : class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionContextGenerator, public QgsExpressionContextScopeGenerator, public QgsFeatureSink, public QgsFeatureSource
393 : : {
394 : 0 : Q_OBJECT
395 : :
396 : : Q_PROPERTY( QString subsetString READ subsetString WRITE setSubsetString NOTIFY subsetStringChanged )
397 : : Q_PROPERTY( QString displayExpression READ displayExpression WRITE setDisplayExpression NOTIFY displayExpressionChanged )
398 : : Q_PROPERTY( QString mapTipTemplate READ mapTipTemplate WRITE setMapTipTemplate NOTIFY mapTipTemplateChanged )
399 : : Q_PROPERTY( QgsEditFormConfig editFormConfig READ editFormConfig WRITE setEditFormConfig NOTIFY editFormConfigChanged )
400 : : Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged )
401 : : Q_PROPERTY( bool supportsEditing READ supportsEditing NOTIFY supportsEditingChanged )
402 : :
403 : : public:
404 : :
405 : : //! Result of an edit operation
406 : : enum EditResult
407 : : {
408 : : Success = 0, //!< Edit operation was successful
409 : : EmptyGeometry = 1, //!< Edit operation resulted in an empty geometry
410 : : EditFailed = 2, //!< Edit operation failed
411 : : FetchFeatureFailed = 3, //!< Unable to fetch requested feature
412 : : InvalidLayer = 4, //!< Edit failed due to invalid layer
413 : : };
414 : : Q_ENUM( EditResult )
415 : :
416 : : //! Selection behavior
417 : : enum SelectBehavior
418 : : {
419 : : SetSelection, //!< Set selection, removing any existing selection
420 : : AddToSelection, //!< Add selection to current selection
421 : : IntersectSelection, //!< Modify current selection to include only select features which match
422 : : RemoveFromSelection, //!< Remove from current selection
423 : : };
424 : : Q_ENUM( SelectBehavior )
425 : :
426 : : /**
427 : : * Setting options for loading vector layers.
428 : : * \since QGIS 3.0
429 : : */
430 : 78 : struct LayerOptions
431 : : {
432 : :
433 : : /**
434 : : * Constructor for LayerOptions.
435 : : */
436 : 78 : explicit LayerOptions( bool loadDefaultStyle = true,
437 : : bool readExtentFromXml = false )
438 : 78 : : loadDefaultStyle( loadDefaultStyle )
439 : 78 : , readExtentFromXml( readExtentFromXml )
440 : 78 : {}
441 : :
442 : : /**
443 : : * Constructor for LayerOptions.
444 : : * \since QGIS 3.8
445 : : */
446 : 0 : explicit LayerOptions( const QgsCoordinateTransformContext &transformContext,
447 : : bool loadDefaultStyle = true,
448 : : bool readExtentFromXml = false
449 : : )
450 : 0 : : loadDefaultStyle( loadDefaultStyle )
451 : 0 : , readExtentFromXml( readExtentFromXml )
452 : 0 : , transformContext( transformContext )
453 : 0 : {}
454 : :
455 : : //! Set to TRUE if the default layer style should be loaded
456 : : bool loadDefaultStyle = true;
457 : :
458 : : /**
459 : : * If TRUE, the layer extent will be read from XML (i.e. stored in the
460 : : * project file). If FALSE, the extent will be determined by the provider on layer load.
461 : : */
462 : : bool readExtentFromXml = false;
463 : :
464 : : /**
465 : : * Coordinate transform context
466 : : * \since QGIS 3.8
467 : : */
468 : 78 : QgsCoordinateTransformContext transformContext = QgsCoordinateTransformContext();
469 : :
470 : : /**
471 : : * Fallback geometry type.
472 : : *
473 : : * This may be set for layers where the geometry type is known in advance, and where
474 : : * the layer path may not be initially resolvable. (E.g. layers with a URI pointing
475 : : * to a non-existent file). It is only ever used if the layer cannot be resolved,
476 : : * otherwise the actual layer geometry type will be detected and used for the layer.
477 : : *
478 : : * \see fallbackCrs
479 : : * \since QGIS 3.8
480 : : */
481 : 78 : QgsWkbTypes::Type fallbackWkbType = QgsWkbTypes::Unknown;
482 : :
483 : : /**
484 : : * Fallback layer coordinate reference system.
485 : : *
486 : : * This may be set for layers where the coordinate reference system is known in advance, and where
487 : : * the layer path may not be initially resolvable. (E.g. layers with a URI pointing
488 : : * to a non-existent file). It is only ever used if the layer cannot be resolved,
489 : : * otherwise the actual layer CRS will be detected and used for the layer.
490 : : *
491 : : * \see fallbackWkbType
492 : : * \since QGIS 3.8
493 : : */
494 : : QgsCoordinateReferenceSystem fallbackCrs;
495 : :
496 : : /**
497 : : * Controls whether the layer is allowed to have an invalid/unknown CRS.
498 : : *
499 : : * If TRUE, then no validation will be performed on the layer's CRS and the layer
500 : : * layer's crs() may be invalid() (i.e. the layer will have no georeferencing available
501 : : * and will be treated as having purely numerical coordinates).
502 : : *
503 : : * If FALSE (the default), the layer's CRS will be validated using QgsCoordinateReferenceSystem::validate(),
504 : : * which may cause a blocking, user-facing dialog asking users to manually select the correct CRS for the
505 : : * layer.
506 : : *
507 : : * \since QGIS 3.10
508 : : */
509 : 78 : bool skipCrsValidation = false;
510 : :
511 : : };
512 : :
513 : : /**
514 : : * Context for cascade delete features
515 : : * \since QGIS 3.14
516 : : */
517 : : struct CORE_EXPORT DeleteContext
518 : : {
519 : :
520 : : /**
521 : : * Constructor for DeleteContext.
522 : : */
523 : : explicit DeleteContext( bool cascade = false, QgsProject *project = nullptr ): cascade( cascade ), project( project ) {}
524 : :
525 : : /**
526 : : * Returns a list of all layers affected by the delete operation.
527 : : *
528 : : * If \a includeAuxiliaryLayers is FALSE then auxiliary layers will not be included in the
529 : : * returned list.
530 : : */
531 : : QList<QgsVectorLayer *> handledLayers( bool includeAuxiliaryLayers = true ) const;
532 : :
533 : : /**
534 : : * Returns a list of feature IDs from the specified \a layer affected by the delete operation.
535 : : */
536 : : QgsFeatureIds handledFeatures( QgsVectorLayer *layer ) const;
537 : :
538 : : QMap<QgsVectorLayer *, QgsFeatureIds> mHandledFeatures SIP_SKIP;
539 : : bool cascade;
540 : : QgsProject *project;
541 : : };
542 : :
543 : : /**
544 : : * Constructor - creates a vector layer
545 : : *
546 : : * The QgsVectorLayer is constructed by instantiating a data provider. The provider
547 : : * interprets the supplied path (url) of the data source to connect to and access the
548 : : * data.
549 : : *
550 : : * \param path The path or url of the parameter. Typically this encodes
551 : : * parameters used by the data provider as url query items.
552 : : * \param baseName The name used to represent the layer in the legend
553 : : * \param providerLib The name of the data provider, e.g., "memory", "postgres"
554 : : * \param options layer load options
555 : : */
556 : : explicit QgsVectorLayer( const QString &path = QString(), const QString &baseName = QString(),
557 : : const QString &providerLib = "ogr", const QgsVectorLayer::LayerOptions &options = QgsVectorLayer::LayerOptions() );
558 : :
559 : : ~QgsVectorLayer() override;
560 : :
561 : : //! QgsVectorLayer cannot be copied.
562 : : QgsVectorLayer( const QgsVectorLayer &rhs ) = delete;
563 : : //! QgsVectorLayer cannot be copied.
564 : : QgsVectorLayer &operator=( QgsVectorLayer const &rhs ) = delete;
565 : :
566 : : #ifdef SIP_RUN
567 : : SIP_PYOBJECT __repr__();
568 : : % MethodCode
569 : : QString str = QStringLiteral( "<QgsVectorLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
570 : : sipRes = PyUnicode_FromString( str.toUtf8().constData() );
571 : : % End
572 : : #endif
573 : :
574 : : /**
575 : : * Returns a new instance equivalent to this one. A new provider is
576 : : * created for the same data source and renderers for features and diagrams
577 : : * are cloned too. Moreover, each attributes (transparency, extent, selected
578 : : * features and so on) are identical.
579 : : * \returns a new layer instance
580 : : * \since QGIS 3.0
581 : : */
582 : : QgsVectorLayer *clone() const override SIP_FACTORY;
583 : :
584 : : /**
585 : : * Returns the permanent storage type for this layer as a friendly name.
586 : : * This is obtained from the data provider and does not follow any standard.
587 : : */
588 : : QString storageType() const;
589 : :
590 : : /**
591 : : * Capabilities for this layer, comma separated and translated.
592 : : */
593 : : QString capabilitiesString() const;
594 : :
595 : : /**
596 : : * Returns a description for this layer as defined in the data provider.
597 : : */
598 : : QString dataComment() const;
599 : :
600 : : /**
601 : : * This is a shorthand for accessing the displayExpression if it is a simple field.
602 : : * If the displayExpression is more complex than a simple field, a null string will
603 : : * be returned.
604 : : *
605 : : * \see displayExpression
606 : : */
607 : : QString displayField() const;
608 : :
609 : : /**
610 : : * Set the preview expression, used to create a human readable preview string.
611 : : * Used e.g. in the attribute table feature list. Uses QgsExpression.
612 : : *
613 : : * \param displayExpression The expression which will be used to preview features
614 : : * for this layer
615 : : */
616 : : void setDisplayExpression( const QString &displayExpression );
617 : :
618 : : /**
619 : : * Returns the preview expression, used to create a human readable preview string.
620 : : * Uses QgsExpression
621 : : *
622 : : * \returns The expression which will be used to preview features for this layer
623 : : */
624 : : QString displayExpression() const;
625 : :
626 : : QgsVectorDataProvider *dataProvider() FINAL;
627 : : const QgsVectorDataProvider *dataProvider() const FINAL SIP_SKIP;
628 : :
629 : : /**
630 : : * Returns temporal properties associated with the vector layer.
631 : : */
632 : : QgsMapLayerTemporalProperties *temporalProperties() override;
633 : :
634 : : /**
635 : : * Sets the text \a encoding of the data provider.
636 : : *
637 : : * An empty \a encoding string indicates that the provider should automatically
638 : : * select the most appropriate encoding.
639 : : *
640 : : * \warning Support for setting the provider encoding depends on the underlying data
641 : : * provider. Check dataProvider().capabilities() for the QgsVectorDataProvider::SelectEncoding
642 : : * capability in order to determine if the provider supports this ability.
643 : : */
644 : : void setProviderEncoding( const QString &encoding );
645 : :
646 : : //! Setup the coordinate system transformation for the layer
647 : : void setCoordinateSystem();
648 : :
649 : : /**
650 : : * Joins another vector layer to this layer
651 : : * \param joinInfo join object containing join layer id, target and source field
652 : : * \note since 2.6 returns bool indicating whether the join can be added
653 : : */
654 : : bool addJoin( const QgsVectorLayerJoinInfo &joinInfo );
655 : :
656 : : /**
657 : : * Removes a vector layer join
658 : : * \returns TRUE if join was found and successfully removed
659 : : */
660 : : bool removeJoin( const QString &joinLayerId );
661 : :
662 : : /**
663 : : * Returns the join buffer object.
664 : : * \since QGIS 2.14.7
665 : : */
666 : 0 : QgsVectorLayerJoinBuffer *joinBuffer() { return mJoinBuffer; }
667 : :
668 : : /**
669 : : * Returns a const pointer on join buffer object.
670 : : * \since QGIS 3.10
671 : : */
672 : 0 : const QgsVectorLayerJoinBuffer *joinBuffer() const { return mJoinBuffer; } SIP_SKIP;
673 : :
674 : : const QList<QgsVectorLayerJoinInfo> vectorJoins() const;
675 : :
676 : : /**
677 : : * Sets the list of dependencies.
678 : : * \see dependencies()
679 : : *
680 : : * \param layers set of QgsMapLayerDependency. Only user-defined dependencies will be added
681 : : * \returns FALSE if a dependency cycle has been detected
682 : : * \since QGIS 3.0
683 : : */
684 : : bool setDependencies( const QSet<QgsMapLayerDependency> &layers ) FINAL;
685 : :
686 : : /**
687 : : * Gets the list of dependencies. This includes data dependencies set by the user (\see setDataDependencies)
688 : : * as well as dependencies given by the provider
689 : : *
690 : : * \returns a set of QgsMapLayerDependency
691 : : * \since QGIS 3.0
692 : : */
693 : : QSet<QgsMapLayerDependency> dependencies() const FINAL;
694 : :
695 : : /**
696 : : * Add a new field which is calculated by the expression specified
697 : : *
698 : : * \param exp The expression which calculates the field
699 : : * \param fld The field to calculate
700 : : *
701 : : * \returns The index of the new field
702 : : *
703 : : * \since QGIS 2.9
704 : : */
705 : : int addExpressionField( const QString &exp, const QgsField &fld );
706 : :
707 : : /**
708 : : * Removes an expression field
709 : : *
710 : : * \param index The index of the field
711 : : *
712 : : * \since QGIS 2.6
713 : : */
714 : : void removeExpressionField( int index );
715 : :
716 : : /**
717 : : * Returns the expression used for a given expression field
718 : : *
719 : : * \param index An index of an epxression based (virtual) field
720 : : *
721 : : * \returns The expression for the field at index
722 : : *
723 : : * \since QGIS 2.9
724 : : */
725 : : QString expressionField( int index ) const;
726 : :
727 : : /**
728 : : * Changes the expression used to define an expression based (virtual) field
729 : : *
730 : : * \param index The index of the expression to change
731 : : *
732 : : * \param exp The new expression to set
733 : : *
734 : : * \since QGIS 2.9
735 : : */
736 : : void updateExpressionField( int index, const QString &exp );
737 : :
738 : : /**
739 : : * Returns all layer actions defined on this layer.
740 : : *
741 : : * The pointer which is returned directly points to the actions object
742 : : * which is used by the layer, so any changes are immediately applied.
743 : : */
744 : 0 : QgsActionManager *actions() { return mActions; }
745 : :
746 : : /**
747 : : * Returns all layer actions defined on this layer.
748 : : *
749 : : * The pointer which is returned is const.
750 : : */
751 : 0 : const QgsActionManager *actions() const SIP_SKIP { return mActions; }
752 : :
753 : : /**
754 : : * Returns QGIS Server Properties of the vector layer
755 : : * \since QGIS 3.10
756 : : */
757 : : QgsVectorLayerServerProperties *serverProperties() const { return mServerProperties.get(); }
758 : :
759 : : /**
760 : : * Returns the number of features that are selected in this layer.
761 : : *
762 : : * \see selectedFeatureIds()
763 : : */
764 : : int selectedFeatureCount() const;
765 : :
766 : : /**
767 : : * Selects features found within the search rectangle (in layer's coordinates)
768 : : * \param rect search rectangle
769 : : * \param behavior selection type, allows adding to current selection, removing
770 : : * from selection, etc.
771 : : * \see invertSelectionInRectangle(QgsRectangle & rect)
772 : : * \see selectByExpression()
773 : : * \see selectByIds()
774 : : */
775 : : Q_INVOKABLE void selectByRect( QgsRectangle &rect, QgsVectorLayer::SelectBehavior behavior = QgsVectorLayer::SetSelection );
776 : :
777 : : /**
778 : : * Selects matching features using an expression.
779 : : * \param expression expression to evaluate to select features
780 : : * \param behavior selection type, allows adding to current selection, removing
781 : : * from selection, etc.
782 : : * \see selectByRect()
783 : : * \see selectByIds()
784 : : * \since QGIS 2.16
785 : : */
786 : : Q_INVOKABLE void selectByExpression( const QString &expression, QgsVectorLayer::SelectBehavior behavior = QgsVectorLayer::SetSelection );
787 : :
788 : : /**
789 : : * Selects matching features using a list of feature IDs. Will emit the
790 : : * selectionChanged() signal with the clearAndSelect flag set.
791 : : * \param ids feature IDs to select
792 : : * \param behavior selection type, allows adding to current selection, removing
793 : : * from selection, etc.
794 : : * \see selectByRect()
795 : : * \see selectByExpression()
796 : : * \since QGIS 2.16
797 : : */
798 : : Q_INVOKABLE void selectByIds( const QgsFeatureIds &ids, QgsVectorLayer::SelectBehavior behavior = QgsVectorLayer::SetSelection );
799 : :
800 : : /**
801 : : * Modifies the current selection on this layer
802 : : *
803 : : * \param selectIds Select these ids
804 : : * \param deselectIds Deselect these ids
805 : : *
806 : : * \see selectByIds
807 : : * \see deselect(const QgsFeatureIds&)
808 : : * \see deselect(const QgsFeatureId)
809 : : * \see selectByExpression()
810 : : */
811 : : Q_INVOKABLE void modifySelection( const QgsFeatureIds &selectIds, const QgsFeatureIds &deselectIds );
812 : :
813 : : //! Selects not selected features and deselects selected ones
814 : : Q_INVOKABLE void invertSelection();
815 : :
816 : : //! Select all the features
817 : : Q_INVOKABLE void selectAll();
818 : :
819 : : /**
820 : : * Inverts selection of features found within the search rectangle (in layer's coordinates)
821 : : *
822 : : * \param rect The rectangle in which the selection of features will be inverted
823 : : *
824 : : * \see invertSelection()
825 : : */
826 : : Q_INVOKABLE void invertSelectionInRectangle( QgsRectangle &rect );
827 : :
828 : : /**
829 : : * Returns a copy of the user-selected features.
830 : : *
831 : : * \warning Calling this method triggers a request for all attributes and geometry for the selected features.
832 : : * Consider using the much more efficient selectedFeatureIds() or selectedFeatureCount() if you do not
833 : : * require access to the feature attributes or geometry.
834 : : *
835 : : * \returns A list of QgsFeature
836 : : *
837 : : * \see selectedFeatureIds()
838 : : * \see getSelectedFeatures() which is more memory friendly when handling large selections
839 : : */
840 : : Q_INVOKABLE QgsFeatureList selectedFeatures() const;
841 : :
842 : : /**
843 : : * Returns an iterator of the selected features.
844 : : *
845 : : * \param request You may specify a request, e.g. to limit the set of requested attributes.
846 : : * Any filter on the request will be discarded.
847 : : *
848 : : * \returns Iterator over the selected features
849 : : *
850 : : * \warning Calling this method returns an iterator for all attributes and geometry for the selected features.
851 : : * Consider using the much more efficient selectedFeatureIds() or selectedFeatureCount() if you do not
852 : : * require access to the feature attributes or geometry.
853 : : *
854 : : * \see selectedFeatureIds()
855 : : * \see selectedFeatures()
856 : : */
857 : : QgsFeatureIterator getSelectedFeatures( QgsFeatureRequest request = QgsFeatureRequest() ) const;
858 : :
859 : : /**
860 : : * Returns a list of the selected features IDs in this layer.
861 : : *
862 : : * \see selectedFeatures()
863 : : * \see selectedFeatureCount()
864 : : * \see selectByIds()
865 : : */
866 : : Q_INVOKABLE const QgsFeatureIds &selectedFeatureIds() const;
867 : :
868 : : //! Returns the bounding box of the selected features. If there is no selection, QgsRectangle(0,0,0,0) is returned
869 : : Q_INVOKABLE QgsRectangle boundingBoxOfSelected() const;
870 : :
871 : : /**
872 : : * Returns whether the layer contains labels which are enabled and should be drawn.
873 : : * \returns TRUE if layer contains enabled labels
874 : : *
875 : : * \see setLabelsEnabled()
876 : : * \since QGIS 2.9
877 : : */
878 : : bool labelsEnabled() const;
879 : :
880 : : /**
881 : : * Sets whether labels should be \a enabled for the layer.
882 : : *
883 : : * \note Labels will only be rendered if labelsEnabled() is TRUE and a labeling
884 : : * object is returned by labeling().
885 : : *
886 : : * \see labelsEnabled()
887 : : * \see labeling()
888 : : */
889 : : void setLabelsEnabled( bool enabled );
890 : :
891 : : /**
892 : : * Returns whether the layer contains diagrams which are enabled and should be drawn.
893 : : * \returns TRUE if layer contains enabled diagrams
894 : : * \since QGIS 2.9
895 : : */
896 : : bool diagramsEnabled() const;
897 : :
898 : : //! Sets diagram rendering object (takes ownership)
899 : : void setDiagramRenderer( QgsDiagramRenderer *r SIP_TRANSFER );
900 : 0 : const QgsDiagramRenderer *diagramRenderer() const { return mDiagramRenderer; }
901 : :
902 : : void setDiagramLayerSettings( const QgsDiagramLayerSettings &s );
903 : 0 : const QgsDiagramLayerSettings *diagramLayerSettings() const { return mDiagramLayerSettings; }
904 : :
905 : : /**
906 : : * Returns the feature renderer used for rendering the features in the layer in 2D
907 : : * map views.
908 : : *
909 : : * \see setRenderer()
910 : : */
911 : 78 : QgsFeatureRenderer *renderer() { return mRenderer; }
912 : :
913 : : /**
914 : : * Returns the feature renderer used for rendering the features in the layer in 2D
915 : : * map views.
916 : : *
917 : : * \see setRenderer()
918 : : * \note not available in Python bindings
919 : : */
920 : 0 : const QgsFeatureRenderer *renderer() const SIP_SKIP { return mRenderer; }
921 : :
922 : : /**
923 : : * Sets the feature renderer which will be invoked to represent this layer in 2D map views.
924 : : * Ownership is transferred.
925 : : *
926 : : * \see renderer()
927 : : */
928 : : void setRenderer( QgsFeatureRenderer *r SIP_TRANSFER );
929 : :
930 : : /**
931 : : * Adds a new feature renderer \a generator to the layer.
932 : : *
933 : : * Ownership of \a generator is transferred to the layer.
934 : : *
935 : : * \see removeFeatureRendererGenerator()
936 : : * \see featureRendererGenerators()
937 : : * \since QGIS 3.18
938 : : */
939 : : void addFeatureRendererGenerator( QgsFeatureRendererGenerator *generator SIP_TRANSFER );
940 : :
941 : : /**
942 : : * Removes the feature renderer with matching \a id from the layer.
943 : : *
944 : : * The corresponding generator will be deleted.
945 : : *
946 : : * \see addFeatureRendererGenerator()
947 : : * \see featureRendererGenerators()
948 : : * \since QGIS 3.18
949 : : */
950 : : void removeFeatureRendererGenerator( const QString &id );
951 : :
952 : : /**
953 : : * Returns a list of the feature renderer generators owned by the layer.
954 : : *
955 : : * \see addFeatureRendererGenerator()
956 : : * \see removeFeatureRendererGenerator()
957 : : * \since QGIS 3.18
958 : : */
959 : : QList< const QgsFeatureRendererGenerator * > featureRendererGenerators() const;
960 : :
961 : : //! Returns point, line or polygon
962 : : Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const;
963 : :
964 : : //! Returns the WKBType or WKBUnknown in case of error
965 : : Q_INVOKABLE QgsWkbTypes::Type wkbType() const FINAL;
966 : :
967 : : QgsCoordinateReferenceSystem sourceCrs() const FINAL;
968 : : QString sourceName() const FINAL;
969 : :
970 : : /**
971 : : * Reads vector layer specific state from project file Dom node.
972 : : * \note Called by QgsMapLayer::readXml().
973 : : */
974 : : bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) FINAL;
975 : :
976 : : /**
977 : : * Writes vector layer specific state to project file Dom node.
978 : : * \note Called by QgsMapLayer::writeXml().
979 : : */
980 : : bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const FINAL;
981 : :
982 : : QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const FINAL;
983 : : QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const FINAL;
984 : :
985 : : /**
986 : : * Resolves references to other layers (kept as layer IDs after reading XML) into layer objects.
987 : : * \since QGIS 3.0
988 : : */
989 : : void resolveReferences( QgsProject *project ) FINAL;
990 : :
991 : : /**
992 : : * Saves named and sld style of the layer to the style table in the db.
993 : : * \param name Style name
994 : : * \param description A description of the style
995 : : * \param useAsDefault Set to TRUE if style should be used as the default style for the layer
996 : : * \param uiFileContent
997 : : * \param msgError will be set to a descriptive error message if any occurs
998 : : */
999 : : virtual void saveStyleToDatabase( const QString &name, const QString &description,
1000 : : bool useAsDefault, const QString &uiFileContent,
1001 : : QString &msgError SIP_OUT );
1002 : :
1003 : : /**
1004 : : * Lists all the style in db split into related to the layer and not related to
1005 : : * \param ids the list in which will be stored the style db ids
1006 : : * \param names the list in which will be stored the style names
1007 : : * \param descriptions the list in which will be stored the style descriptions
1008 : : * \param msgError will be set to a descriptive error message if any occurs
1009 : : * \returns the number of styles related to current layer (-1 on not implemented)
1010 : : * \note Since QGIS 3.2 Styles related to the layer are ordered with the default style first then by update time for Postgres, MySQL and Spatialite.
1011 : : */
1012 : : virtual int listStylesInDatabase( QStringList &ids SIP_OUT, QStringList &names SIP_OUT,
1013 : : QStringList &descriptions SIP_OUT, QString &msgError SIP_OUT );
1014 : :
1015 : : /**
1016 : : * Returns the named style corresponding to style id provided
1017 : : */
1018 : : virtual QString getStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
1019 : :
1020 : : /**
1021 : : * Deletes a style from the database
1022 : : * \param styleId the provider's layer_styles table id of the style to delete
1023 : : * \param msgError will be set to a descriptive error message if any occurs
1024 : : * \returns TRUE in case of success
1025 : : * \since QGIS 3.0
1026 : : */
1027 : : virtual bool deleteStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
1028 : :
1029 : : /**
1030 : : * Loads a named style from file/local db/datasource db
1031 : : * \param theURI the URI of the style or the URI of the layer
1032 : : * \param resultFlag will be set to TRUE if a named style is correctly loaded
1033 : : * \param loadFromLocalDb if TRUE forces to load from local db instead of datasource one
1034 : : * \param categories the style categories to be loaded.
1035 : : */
1036 : : virtual QString loadNamedStyle( const QString &theURI, bool &resultFlag SIP_OUT, bool loadFromLocalDb,
1037 : : QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
1038 : :
1039 : : /**
1040 : : * Calls loadNamedStyle( theURI, resultFlag, FALSE );
1041 : : * Retained for backward compatibility
1042 : : */
1043 : : QString loadNamedStyle( const QString &theURI, bool &resultFlag SIP_OUT,
1044 : : QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) FINAL;
1045 : :
1046 : : /**
1047 : : * Loads the auxiliary layer for this vector layer. If there's no
1048 : : * corresponding table in the database, then nothing happens and FALSE is
1049 : : * returned. The key is optional because if this layer has been read from
1050 : : * a XML document, then the key read in this document is used by default.
1051 : : *
1052 : : * \param storage The auxiliary storage where to look for the table
1053 : : * \param key The key to use for joining.
1054 : : *
1055 : : * \returns TRUE if the auxiliary layer is well loaded, FALSE otherwise
1056 : : *
1057 : : * \since QGIS 3.0
1058 : : */
1059 : : bool loadAuxiliaryLayer( const QgsAuxiliaryStorage &storage, const QString &key = QString() );
1060 : :
1061 : : /**
1062 : : * Sets the current auxiliary layer. The auxiliary layer is automatically
1063 : : * put in editable mode and fields are updated. Moreover, a join is created
1064 : : * between the current layer and the auxiliary layer. Ownership is
1065 : : * transferred.
1066 : : *
1067 : : *
1068 : : * \since QGIS 3.0
1069 : : */
1070 : : void setAuxiliaryLayer( QgsAuxiliaryLayer *layer SIP_TRANSFER = nullptr );
1071 : :
1072 : : /**
1073 : : * Returns the current auxiliary layer.
1074 : : *
1075 : : * \since QGIS 3.0
1076 : : */
1077 : : QgsAuxiliaryLayer *auxiliaryLayer();
1078 : :
1079 : : /**
1080 : : * Returns the current const auxiliary layer.
1081 : : *
1082 : : * \since QGIS 3.0
1083 : : */
1084 : : const QgsAuxiliaryLayer *auxiliaryLayer() const SIP_SKIP;
1085 : :
1086 : : bool readSymbology( const QDomNode &layerNode, QString &errorMessage,
1087 : : QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) FINAL;
1088 : : bool readStyle( const QDomNode &node, QString &errorMessage,
1089 : : QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) FINAL;
1090 : : bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
1091 : : const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const FINAL;
1092 : : bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
1093 : : const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const FINAL;
1094 : :
1095 : : /**
1096 : : * Writes the symbology of the layer into the document provided in SLD 1.1 format
1097 : : * \param node the node that will have the style element added to it.
1098 : : * \param doc the document that will have the QDomNode added.
1099 : : * \param errorMessage reference to string that will be updated with any error messages
1100 : : * \param props a open ended set of properties that can drive/inform the SLD encoding
1101 : : * \returns TRUE in case of success
1102 : : */
1103 : : bool writeSld( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QVariantMap &props = QVariantMap() ) const;
1104 : :
1105 : : bool readSld( const QDomNode &node, QString &errorMessage ) FINAL;
1106 : :
1107 : : /**
1108 : : * Number of features rendered with specified legend key. Features must be first
1109 : : * calculated by countSymbolFeatures()
1110 : : * \returns number of features rendered by symbol or -1 if failed or counts are not available
1111 : : */
1112 : : long featureCount( const QString &legendKey ) const;
1113 : :
1114 : : /**
1115 : : * Ids of features rendered with specified legend key. Features must be first
1116 : : * calculated by countSymbolFeatures()
1117 : : * \returns Ids of features rendered by symbol or -1 if failed or Ids are not available
1118 : : * \since QGIS 3.10
1119 : : */
1120 : : QgsFeatureIds symbolFeatureIds( const QString &legendKey ) const;
1121 : :
1122 : : /**
1123 : : * Determines if this vector layer has features.
1124 : : *
1125 : : * \warning when a layer is editable and some features
1126 : : * have been deleted, this will return
1127 : : * QgsFeatureSource::FeatureAvailability::FeaturesMayBeAvailable
1128 : : * to avoid a potentially expensive call to the dataprovider.
1129 : : *
1130 : : * \since QGIS 3.4
1131 : : */
1132 : : FeatureAvailability hasFeatures() const FINAL;
1133 : :
1134 : : /**
1135 : : * Update the data source of the layer. The layer's renderer and legend will be preserved only
1136 : : * if the geometry type of the new data source matches the current geometry type of the layer.
1137 : : * \param dataSource new layer data source
1138 : : * \param baseName base name of the layer
1139 : : * \param provider provider string
1140 : : * \param loadDefaultStyleFlag set to TRUE to reset the layer's style to the default for the
1141 : : * data source
1142 : : * \since QGIS 2.10
1143 : : * \deprecated Use version with ProviderOptions argument instead
1144 : : */
1145 : : Q_DECL_DEPRECATED void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag = false ) SIP_DEPRECATED;
1146 : :
1147 : : /**
1148 : : * Updates the data source of the layer. The layer's renderer and legend will be preserved only
1149 : : * if the geometry type of the new data source matches the current geometry type of the layer.
1150 : : * \param dataSource new layer data source
1151 : : * \param baseName base name of the layer
1152 : : * \param provider provider string
1153 : : * \param options provider options
1154 : : * \param loadDefaultStyleFlag set to TRUE to reset the layer's style to the default for the
1155 : : * data source
1156 : : * \see dataSourceChanged()
1157 : : * \since QGIS 3.2
1158 : : */
1159 : : void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false ) override;
1160 : :
1161 : : QString loadDefaultStyle( bool &resultFlag SIP_OUT ) FINAL;
1162 : :
1163 : : /**
1164 : : * Count features for symbols.
1165 : : * The method will return the feature counter task. You will need to
1166 : : * connect to the symbolFeatureCountMapChanged() signal to be
1167 : : * notified when the freshly updated feature counts are ready.
1168 : : *
1169 : : * \param storeSymbolFids If TRUE will gather the feature ids (fids) per symbol, otherwise only the count. Default FALSE.
1170 : : * \note If the count features for symbols has been already done a
1171 : : * NULLPTR is returned. If you need to wait for the results,
1172 : : * you can call waitForFinished() on the feature counter.
1173 : : *
1174 : : * \since This is asynchronous since QGIS 3.0
1175 : : */
1176 : : QgsVectorLayerFeatureCounter *countSymbolFeatures( bool storeSymbolFids = false );
1177 : :
1178 : : /**
1179 : : * Sets the string (typically sql) used to define a subset of the layer
1180 : : * \param subset The subset string. This may be the where clause of a sql statement
1181 : : * or other definition string specific to the underlying dataprovider
1182 : : * and data store.
1183 : : * \returns TRUE, when setting the subset string was successful, FALSE otherwise
1184 : : */
1185 : : virtual bool setSubsetString( const QString &subset );
1186 : :
1187 : : /**
1188 : : * Returns the string (typically sql) used to define a subset of the layer.
1189 : : * \returns The subset string or null QString if not implemented by the provider
1190 : : */
1191 : : virtual QString subsetString() const;
1192 : :
1193 : : /**
1194 : : * Queries the layer for features specified in request.
1195 : : * \param request feature request describing parameters of features to return
1196 : : * \returns iterator for matching features from provider
1197 : : */
1198 : : QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const FINAL;
1199 : :
1200 : : /**
1201 : : * Queries the layer for features matching a given expression.
1202 : : */
1203 : : inline QgsFeatureIterator getFeatures( const QString &expression )
1204 : : {
1205 : : return getFeatures( QgsFeatureRequest( expression ) );
1206 : : }
1207 : :
1208 : : /**
1209 : : * Queries the layer for the feature with the given id.
1210 : : * If there is no such feature, the returned feature will be invalid.
1211 : : */
1212 : 1 : inline QgsFeature getFeature( QgsFeatureId fid ) const
1213 : : {
1214 : 1 : QgsFeature feature;
1215 : 1 : getFeatures( QgsFeatureRequest( fid ) ).nextFeature( feature );
1216 : 1 : return feature;
1217 : 1 : }
1218 : :
1219 : : /**
1220 : : * Queries the layer for the geometry at the given id.
1221 : : * If there is no such feature, the returned geometry will be invalid.
1222 : : */
1223 : : QgsGeometry getGeometry( QgsFeatureId fid ) const;
1224 : :
1225 : : /**
1226 : : * Queries the layer for the features with the given ids.
1227 : : */
1228 : : inline QgsFeatureIterator getFeatures( const QgsFeatureIds &fids )
1229 : : {
1230 : : return getFeatures( QgsFeatureRequest( fids ) );
1231 : : }
1232 : :
1233 : : /**
1234 : : * Queries the layer for the features which intersect the specified rectangle.
1235 : : */
1236 : : inline QgsFeatureIterator getFeatures( const QgsRectangle &rectangle )
1237 : : {
1238 : : return getFeatures( QgsFeatureRequest( rectangle ) );
1239 : : }
1240 : :
1241 : : bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) FINAL;
1242 : :
1243 : : /**
1244 : : * Updates an existing \a feature in the layer, replacing the attributes and geometry for the feature
1245 : : * with matching QgsFeature::id() with the attributes and geometry from \a feature.
1246 : : * Changes are not immediately committed to the layer.
1247 : : *
1248 : : * If \a skipDefaultValue is set to TRUE, default field values will not
1249 : : * be updated. This can be used to override default field value expressions.
1250 : : *
1251 : : * Returns TRUE if the feature's attribute was successfully changed.
1252 : : *
1253 : : * \note Calls to updateFeature() are only valid for layers in which edits have been enabled
1254 : : * by a call to startEditing(). Changes made to features using this method are not committed
1255 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1256 : : * changes can be discarded by calling rollBack().
1257 : : *
1258 : : * \warning This method needs to query the underlying data provider to fetch the feature
1259 : : * with matching QgsFeature::id() on every call. Depending on the underlying data source this
1260 : : * can be slow to execute. Consider using the more efficient changeAttributeValue() or
1261 : : * changeGeometry() methods instead.
1262 : : *
1263 : : * \see startEditing()
1264 : : * \see commitChanges()
1265 : : * \see changeGeometry()
1266 : : * \see changeAttributeValue()
1267 : : */
1268 : : bool updateFeature( QgsFeature &feature, bool skipDefaultValues = false );
1269 : :
1270 : : /**
1271 : : * Inserts a new vertex before the given vertex number,
1272 : : * in the given ring, item (first number is index 0), and feature.
1273 : : *
1274 : : * Not meaningful for Point geometries
1275 : : *
1276 : : * \note Calls to insertVertex() are only valid for layers in which edits have been enabled
1277 : : * by a call to startEditing(). Changes made to features using this method are not committed
1278 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1279 : : * changes can be discarded by calling rollBack().
1280 : : */
1281 : : bool insertVertex( double x, double y, QgsFeatureId atFeatureId, int beforeVertex );
1282 : :
1283 : : /**
1284 : : * Inserts a new vertex before the given vertex number,
1285 : : * in the given ring, item (first number is index 0), and feature.
1286 : : *
1287 : : * Not meaningful for Point geometries
1288 : : *
1289 : : * \note Calls to insertVertex() are only valid for layers in which edits have been enabled
1290 : : * by a call to startEditing(). Changes made to features using this method are not committed
1291 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1292 : : * changes can be discarded by calling rollBack().
1293 : : */
1294 : : bool insertVertex( const QgsPoint &point, QgsFeatureId atFeatureId, int beforeVertex );
1295 : :
1296 : : /**
1297 : : * Moves the vertex at the given position number,
1298 : : * ring and item (first number is index 0), and feature
1299 : : * to the given coordinates.
1300 : : *
1301 : : * \note Calls to moveVertex() are only valid for layers in which edits have been enabled
1302 : : * by a call to startEditing(). Changes made to features using this method are not committed
1303 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1304 : : * changes can be discarded by calling rollBack().
1305 : : */
1306 : : bool moveVertex( double x, double y, QgsFeatureId atFeatureId, int atVertex );
1307 : :
1308 : : /**
1309 : : * Moves the vertex at the given position number,
1310 : : * ring and item (first number is index 0), and feature
1311 : : * to the given coordinates.
1312 : : * \note available in Python as moveVertexV2
1313 : : * \note Calls to moveVertex() are only valid for layers in which edits have been enabled
1314 : : * by a call to startEditing(). Changes made to features using this method are not committed
1315 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1316 : : * changes can be discarded by calling rollBack().
1317 : : */
1318 : : bool moveVertex( const QgsPoint &p, QgsFeatureId atFeatureId, int atVertex ) SIP_PYNAME( moveVertexV2 );
1319 : :
1320 : : /**
1321 : : * Deletes a vertex from a feature.
1322 : : * \param featureId ID of feature to remove vertex from
1323 : : * \param vertex index of vertex to delete
1324 : : * \note Calls to deleteVertex() are only valid for layers in which edits have been enabled
1325 : : * by a call to startEditing(). Changes made to features using this method are not committed
1326 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1327 : : * changes can be discarded by calling rollBack().
1328 : : * \since QGIS 2.14
1329 : : */
1330 : : EditResult deleteVertex( QgsFeatureId featureId, int vertex );
1331 : :
1332 : : /**
1333 : : * Deletes the selected features
1334 : : * \param deletedCount The number of successfully deleted features
1335 : : * \param context The chain of features who will be deleted for feedback and to avoid endless recursions
1336 : : *
1337 : : * \returns TRUE in case of success and FALSE otherwise
1338 : : */
1339 : : Q_INVOKABLE bool deleteSelectedFeatures( int *deletedCount = nullptr, DeleteContext *context = nullptr );
1340 : :
1341 : : /**
1342 : : * Adds a ring to polygon/multipolygon features
1343 : : * \param ring ring to add
1344 : : * \param featureId if specified, feature ID for feature ring was added to will be stored in this parameter
1345 : : * \returns QgsGeometry::OperationResult
1346 : : *
1347 : : * - Success
1348 : : * - LayerNotEditable
1349 : : * - AddRingNotInExistingFeature
1350 : : * - InvalidInputGeometryType
1351 : : * - AddRingNotClosed
1352 : : * - AddRingNotValid
1353 : : * - AddRingCrossesExistingRings
1354 : : *
1355 : : * \note Calls to addRing() are only valid for layers in which edits have been enabled
1356 : : * by a call to startEditing(). Changes made to features using this method are not committed
1357 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1358 : : * changes can be discarded by calling rollBack().
1359 : : * \deprecated since QGIS 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.
1360 : : */
1361 : : Q_DECL_DEPRECATED QgsGeometry::OperationResult addRing( const QVector<QgsPointXY> &ring, QgsFeatureId *featureId = nullptr ) SIP_DEPRECATED;
1362 : :
1363 : :
1364 : : /**
1365 : : * Adds a ring to polygon/multipolygon features
1366 : : * \param ring ring to add
1367 : : * \param featureId if specified, feature ID for feature ring was added to will be stored in this parameter
1368 : : * \returns QgsGeometry::OperationResult
1369 : : *
1370 : : * - Success
1371 : : * - LayerNotEditable
1372 : : * - AddRingNotInExistingFeature
1373 : : * - InvalidInputGeometryType
1374 : : * - AddRingNotClosed
1375 : : * - AddRingNotValid
1376 : : * - AddRingCrossesExistingRings
1377 : : *
1378 : : * \note Calls to addRing() are only valid for layers in which edits have been enabled
1379 : : * by a call to startEditing(). Changes made to features using this method are not committed
1380 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1381 : : * changes can be discarded by calling rollBack().
1382 : : */
1383 : : Q_INVOKABLE QgsGeometry::OperationResult addRing( const QgsPointSequence &ring, QgsFeatureId *featureId = nullptr );
1384 : :
1385 : : /**
1386 : : * Adds a ring to polygon/multipolygon features (takes ownership)
1387 : : * \param ring ring to add
1388 : : * \param featureId if specified, feature ID for feature ring was added to will be stored in this parameter
1389 : : * \returns QgsGeometry::OperationResult
1390 : : *
1391 : : * - Success
1392 : : * - LayerNotEditable
1393 : : * - AddRingNotInExistingFeature
1394 : : * - InvalidInputGeometryType
1395 : : * - AddRingNotClosed
1396 : : * - AddRingNotValid
1397 : : * - AddRingCrossesExistingRings
1398 : : *
1399 : : * \note available in Python as addCurvedRing
1400 : : * \note Calls to addRing() are only valid for layers in which edits have been enabled
1401 : : * by a call to startEditing(). Changes made to features using this method are not committed
1402 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1403 : : * changes can be discarded by calling rollBack().
1404 : : */
1405 : : Q_INVOKABLE QgsGeometry::OperationResult addRing( QgsCurve *ring SIP_TRANSFER, QgsFeatureId *featureId = nullptr ) SIP_PYNAME( addCurvedRing );
1406 : :
1407 : : /**
1408 : : * Adds a new part polygon to a multipart feature
1409 : : * \returns QgsGeometry::OperationResult
1410 : : *
1411 : : * - Success
1412 : : * - LayerNotEditable
1413 : : * - SelectionIsEmpty
1414 : : * - SelectionIsGreaterThanOne
1415 : : * - AddPartSelectedGeometryNotFound
1416 : : * - AddPartNotMultiGeometry
1417 : : * - InvalidBaseGeometry
1418 : : * - InvalidInputGeometryType
1419 : : *
1420 : : * \note Calls to addPart() are only valid for layers in which edits have been enabled
1421 : : * by a call to startEditing(). Changes made to features using this method are not committed
1422 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1423 : : * changes can be discarded by calling rollBack().
1424 : : * \deprecated since QGIS 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.
1425 : : */
1426 : : Q_DECL_DEPRECATED QgsGeometry::OperationResult addPart( const QList<QgsPointXY> &ring ) SIP_DEPRECATED;
1427 : :
1428 : : #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1429 : :
1430 : : /**
1431 : : * Adds a new part polygon to a multipart feature
1432 : : * \returns QgsGeometry::OperationResult
1433 : : *
1434 : : * - Success
1435 : : * - LayerNotEditable
1436 : : * - SelectionIsEmpty
1437 : : * - SelectionIsGreaterThanOne
1438 : : * - AddPartSelectedGeometryNotFound
1439 : : * - AddPartNotMultiGeometry
1440 : : * - InvalidBaseGeometry
1441 : : * - InvalidInputGeometryType
1442 : : *
1443 : : * \note available in Python bindings as addPartV2
1444 : : * \note Calls to addPart() are only valid for layers in which edits have been enabled
1445 : : * by a call to startEditing(). Changes made to features using this method are not committed
1446 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1447 : : * changes can be discarded by calling rollBack().
1448 : : * \deprecated since QGIS 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.
1449 : : */
1450 : : Q_DECL_DEPRECATED QgsGeometry::OperationResult addPart( const QVector<QgsPointXY> &ring ) SIP_PYNAME( addPartV2 ) SIP_DEPRECATED;
1451 : : #endif
1452 : :
1453 : : /**
1454 : : * Adds a new part polygon to a multipart feature
1455 : : * \returns QgsGeometry::OperationResult
1456 : : *
1457 : : * - Success
1458 : : * - LayerNotEditable
1459 : : * - SelectionIsEmpty
1460 : : * - SelectionIsGreaterThanOne
1461 : : * - AddPartSelectedGeometryNotFound
1462 : : * - AddPartNotMultiGeometry
1463 : : * - InvalidBaseGeometry
1464 : : * - InvalidInputGeometryType
1465 : : *
1466 : : * \note available in Python bindings as addPartV2
1467 : : * \note Calls to addPart() are only valid for layers in which edits have been enabled
1468 : : * by a call to startEditing(). Changes made to features using this method are not committed
1469 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1470 : : * changes can be discarded by calling rollBack().
1471 : : */
1472 : : Q_INVOKABLE QgsGeometry::OperationResult addPart( const QgsPointSequence &ring ) SIP_PYNAME( addPartV2 );
1473 : :
1474 : : /**
1475 : : * \note available in Python as addCurvedPart
1476 : : * \note Calls to addPart() are only valid for layers in which edits have been enabled
1477 : : * by a call to startEditing(). Changes made to features using this method are not committed
1478 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1479 : : * changes can be discarded by calling rollBack().
1480 : : */
1481 : : Q_INVOKABLE QgsGeometry::OperationResult addPart( QgsCurve *ring SIP_TRANSFER ) SIP_PYNAME( addCurvedPart );
1482 : :
1483 : : /**
1484 : : * Translates feature by dx, dy
1485 : : * \param featureId id of the feature to translate
1486 : : * \param dx translation of x-coordinate
1487 : : * \param dy translation of y-coordinate
1488 : : * \returns 0 in case of success
1489 : : * \note Calls to translateFeature() are only valid for layers in which edits have been enabled
1490 : : * by a call to startEditing(). Changes made to features using this method are not committed
1491 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1492 : : * changes can be discarded by calling rollBack().
1493 : : */
1494 : : Q_INVOKABLE int translateFeature( QgsFeatureId featureId, double dx, double dy );
1495 : :
1496 : : /**
1497 : : * Splits parts cut by the given line
1498 : : * \param splitLine line that splits the layer features
1499 : : * \param topologicalEditing TRUE if topological editing is enabled
1500 : : * \returns QgsGeometry::OperationResult
1501 : : *
1502 : : * - Success
1503 : : * - NothingHappened
1504 : : * - LayerNotEditable
1505 : : * - InvalidInputGeometryType
1506 : : * - InvalidBaseGeometry
1507 : : * - GeometryEngineError
1508 : : * - SplitCannotSplitPoint
1509 : : *
1510 : : * \note Calls to splitParts() are only valid for layers in which edits have been enabled
1511 : : * by a call to startEditing(). Changes made to features using this method are not committed
1512 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1513 : : * changes can be discarded by calling rollBack().
1514 : : * \deprecated since QGIS 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.
1515 : : */
1516 : : Q_DECL_DEPRECATED QgsGeometry::OperationResult splitParts( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false ) SIP_DEPRECATED;
1517 : :
1518 : : /**
1519 : : * Splits parts cut by the given line
1520 : : * \param splitLine line that splits the layer features
1521 : : * \param topologicalEditing TRUE if topological editing is enabled
1522 : : * \returns QgsGeometry::OperationResult
1523 : : *
1524 : : * - Success
1525 : : * - NothingHappened
1526 : : * - LayerNotEditable
1527 : : * - InvalidInputGeometryType
1528 : : * - InvalidBaseGeometry
1529 : : * - GeometryEngineError
1530 : : * - SplitCannotSplitPoint
1531 : : *
1532 : : * \note Calls to splitParts() are only valid for layers in which edits have been enabled
1533 : : * by a call to startEditing(). Changes made to features using this method are not committed
1534 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1535 : : * changes can be discarded by calling rollBack().
1536 : : */
1537 : : Q_INVOKABLE QgsGeometry::OperationResult splitParts( const QgsPointSequence &splitLine, bool topologicalEditing = false );
1538 : :
1539 : : /**
1540 : : * Splits features cut by the given line
1541 : : * \param splitLine line that splits the layer features
1542 : : * \param topologicalEditing TRUE if topological editing is enabled
1543 : : * \returns QgsGeometry::OperationResult
1544 : : *
1545 : : * - Success
1546 : : * - NothingHappened
1547 : : * - LayerNotEditable
1548 : : * - InvalidInputGeometryType
1549 : : * - InvalidBaseGeometry
1550 : : * - GeometryEngineError
1551 : : * - SplitCannotSplitPoint
1552 : : *
1553 : : * \note Calls to splitFeatures() are only valid for layers in which edits have been enabled
1554 : : * by a call to startEditing(). Changes made to features using this method are not committed
1555 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1556 : : * changes can be discarded by calling rollBack().
1557 : : * \deprecated since QGIS 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.
1558 : : */
1559 : : Q_DECL_DEPRECATED QgsGeometry::OperationResult splitFeatures( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false ) SIP_DEPRECATED;
1560 : :
1561 : : /**
1562 : : * Splits features cut by the given line
1563 : : * \param splitLine line that splits the layer features
1564 : : * \param topologicalEditing TRUE if topological editing is enabled
1565 : : * \returns QgsGeometry::OperationResult
1566 : : *
1567 : : * - Success
1568 : : * - NothingHappened
1569 : : * - LayerNotEditable
1570 : : * - InvalidInputGeometryType
1571 : : * - InvalidBaseGeometry
1572 : : * - GeometryEngineError
1573 : : * - SplitCannotSplitPoint
1574 : : *
1575 : : * \note Calls to splitFeatures() are only valid for layers in which edits have been enabled
1576 : : * by a call to startEditing(). Changes made to features using this method are not committed
1577 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1578 : : * changes can be discarded by calling rollBack().
1579 : : */
1580 : : Q_INVOKABLE QgsGeometry::OperationResult splitFeatures( const QgsPointSequence &splitLine, bool topologicalEditing = false );
1581 : :
1582 : : /**
1583 : : * Splits features cut by the given curve
1584 : : * \param curve curve that splits the layer features
1585 : : * \param[out] topologyTestPoints topological points to be tested against other layers
1586 : : * \param preserveCircular whether circular strings are preserved after splitting
1587 : : * \param topologicalEditing TRUE if topological editing is enabled
1588 : : * \returns QgsGeometry::OperationResult
1589 : : *
1590 : : * - Success
1591 : : * - NothingHappened
1592 : : * - LayerNotEditable
1593 : : * - InvalidInputGeometryType
1594 : : * - InvalidBaseGeometry
1595 : : * - GeometryEngineError
1596 : : * - SplitCannotSplitPoint
1597 : : *
1598 : : * \note Calls to splitFeatures() are only valid for layers in which edits have been enabled
1599 : : * by a call to startEditing(). Changes made to features using this method are not committed
1600 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1601 : : * changes can be discarded by calling rollBack().
1602 : : * \since QGIS 3.16
1603 : : */
1604 : : Q_INVOKABLE QgsGeometry::OperationResult splitFeatures( const QgsCurve *curve, QgsPointSequence &topologyTestPoints SIP_OUT, bool preserveCircular = false, bool topologicalEditing = false );
1605 : :
1606 : : /**
1607 : : * Adds topological points for every vertex of the geometry.
1608 : : * \param geom the geometry where each vertex is added to segments of other features
1609 : : * \returns 0 in case of success
1610 : : * \note geom is not going to be modified by the function
1611 : : * \note Calls to addTopologicalPoints() are only valid for layers in which edits have been enabled
1612 : : * by a call to startEditing(). Changes made to features using this method are not committed
1613 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1614 : : * changes can be discarded by calling rollBack().
1615 : : */
1616 : : int addTopologicalPoints( const QgsGeometry &geom );
1617 : :
1618 : : /**
1619 : : * Adds a vertex to segments which intersect point \a p but don't
1620 : : * already have a vertex there. If a feature already has a vertex at position \a p,
1621 : : * no additional vertex is inserted. This method is useful for topological
1622 : : * editing.
1623 : : * \param p position of the vertex
1624 : : * \returns 0 in case of success
1625 : : * \note Calls to addTopologicalPoints() are only valid for layers in which edits have been enabled
1626 : : * by a call to startEditing(). Changes made to features using this method are not committed
1627 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1628 : : * changes can be discarded by calling rollBack().
1629 : : * \deprecated since QGIS 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.
1630 : : */
1631 : : Q_DECL_DEPRECATED int addTopologicalPoints( const QgsPointXY &p ) SIP_DEPRECATED;
1632 : :
1633 : : /**
1634 : : * Adds a vertex to segments which intersect point \a p but don't
1635 : : * already have a vertex there. If a feature already has a vertex at position \a p,
1636 : : * no additional vertex is inserted. This method is useful for topological
1637 : : * editing.
1638 : : * \param p position of the vertex
1639 : : * \returns 0 in case of success
1640 : : * \note Calls to addTopologicalPoints() are only valid for layers in which edits have been enabled
1641 : : * by a call to startEditing(). Changes made to features using this method are not committed
1642 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1643 : : * changes can be discarded by calling rollBack().
1644 : : * \since 3.10
1645 : : */
1646 : : int addTopologicalPoints( const QgsPoint &p );
1647 : :
1648 : : /**
1649 : : * Adds a vertex to segments which intersect any of the points \a p but don't
1650 : : * already have a vertex there. If a feature already has a vertex at position \a p,
1651 : : * no additional vertex is inserted. This method is useful for topological
1652 : : * editing.
1653 : : * \param ps point sequence of the vertices
1654 : : * \returns 0 in case of success
1655 : : * \note Calls to addTopologicalPoints() are only valid for layers in which edits have been enabled
1656 : : * by a call to startEditing(). Changes made to features using this method are not committed
1657 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1658 : : * changes can be discarded by calling rollBack().
1659 : : * \since 3.16
1660 : : */
1661 : : int addTopologicalPoints( const QgsPointSequence &ps );
1662 : :
1663 : : /**
1664 : : * Access to const labeling configuration. May be NULLPTR if labeling is not used.
1665 : : * \note Labels will only be rendered if labelsEnabled() returns TRUE.
1666 : : * \see labelsEnabled()
1667 : : * \since QGIS 3.0
1668 : : */
1669 : 0 : const QgsAbstractVectorLayerLabeling *labeling() const SIP_SKIP { return mLabeling; }
1670 : :
1671 : : /**
1672 : : * Access to labeling configuration. May be NULLPTR if labeling is not used.
1673 : : * \note Labels will only be rendered if labelsEnabled() returns TRUE.
1674 : : * \see labelsEnabled()
1675 : : * \since QGIS 3.0
1676 : : */
1677 : 0 : QgsAbstractVectorLayerLabeling *labeling() { return mLabeling; }
1678 : :
1679 : : /**
1680 : : * Sets labeling configuration. Takes ownership of the object.
1681 : : * \since QGIS 3.0
1682 : : */
1683 : : void setLabeling( QgsAbstractVectorLayerLabeling *labeling SIP_TRANSFER );
1684 : :
1685 : : //! Returns TRUE if the provider is in editing mode
1686 : : bool isEditable() const FINAL;
1687 : :
1688 : : //! Returns TRUE if this is a geometry layer and FALSE in case of NoGeometry (table only) or UnknownGeometry
1689 : : bool isSpatial() const FINAL;
1690 : :
1691 : : //! Returns TRUE if the provider has been modified since the last commit
1692 : : virtual bool isModified() const;
1693 : :
1694 : : /**
1695 : : * Returns TRUE if the field comes from the auxiliary layer,
1696 : : * FALSE otherwise.
1697 : : *
1698 : : * \since QGIS 3.0
1699 : : */
1700 : : bool isAuxiliaryField( int index, int &srcIndex ) const;
1701 : :
1702 : : //! Synchronises with changes in the datasource
1703 : : void reload() FINAL;
1704 : :
1705 : : /**
1706 : : * Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context
1707 : : * \since QGIS 2.4
1708 : : */
1709 : : QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) FINAL SIP_FACTORY;
1710 : :
1711 : : QgsRectangle extent() const FINAL;
1712 : : QgsRectangle sourceExtent() const FINAL;
1713 : :
1714 : : /**
1715 : : * Returns the list of fields of this layer.
1716 : : * This also includes fields which have not yet been saved to the provider.
1717 : : *
1718 : : * \returns A list of fields
1719 : : */
1720 : : QgsFields fields() const FINAL;
1721 : :
1722 : : /**
1723 : : * Returns list of attribute indexes. i.e. a list from 0 ... fieldCount()
1724 : : */
1725 : 0 : inline QgsAttributeList attributeList() const { return mFields.allAttributesList(); }
1726 : :
1727 : : /**
1728 : : * Returns the list of attributes which make up the layer's primary keys.
1729 : : */
1730 : : QgsAttributeList primaryKeyAttributes() const;
1731 : :
1732 : : /**
1733 : : * Returns feature count including changes which have not yet been committed
1734 : : * If you need only the count of committed features call this method on this layer's provider.
1735 : : * \returns the number of features on this layer or -1 if unknown.
1736 : : */
1737 : : long featureCount() const FINAL;
1738 : :
1739 : : /**
1740 : : * Makes layer read-only (editing disabled) or not
1741 : : * \returns FALSE if the layer is in editing yet
1742 : : */
1743 : : bool setReadOnly( bool readonly = true );
1744 : :
1745 : : /**
1746 : : * Returns whether the layer supports editing or not
1747 : : * \return FALSE if the layer is read only or the data provider has no editing capabilities
1748 : : * \since QGIS 3.18
1749 : : */
1750 : : bool supportsEditing();
1751 : :
1752 : : /**
1753 : : * Changes a feature's \a geometry within the layer's edit buffer
1754 : : * (but does not immediately commit the changes). The \a fid argument
1755 : : * specifies the ID of the feature to be changed.
1756 : : *
1757 : : * If \a skipDefaultValue is set to TRUE, default field values will not
1758 : : * be updated. This can be used to override default field value expressions.
1759 : : *
1760 : : * \returns TRUE if the feature's geometry was successfully changed.
1761 : : *
1762 : : * \note Calls to changeGeometry() are only valid for layers in which edits have been enabled
1763 : : * by a call to startEditing(). Changes made to features using this method are not committed
1764 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1765 : : * changes can be discarded by calling rollBack().
1766 : : *
1767 : : * \see startEditing()
1768 : : * \see commitChanges()
1769 : : * \see changeAttributeValue()
1770 : : * \see updateFeature()
1771 : : */
1772 : : bool changeGeometry( QgsFeatureId fid, QgsGeometry &geometry, bool skipDefaultValue = false );
1773 : :
1774 : : /**
1775 : : * Changes an attribute value for a feature (but does not immediately commit the changes).
1776 : : * The \a fid argument specifies the ID of the feature to be changed.
1777 : : *
1778 : : * The \a field argument must specify a valid field index for the layer (where an index of 0
1779 : : * corresponds to the first field).
1780 : : *
1781 : : * The new value to be assigned to the field is given by \a newValue.
1782 : : *
1783 : : * If a valid QVariant is specified for \a oldValue, it will be used as the field value in the
1784 : : * case of an undo operation corresponding to this attribute value change. If an invalid
1785 : : * QVariant is used (the default behavior), then the feature's current value will be automatically
1786 : : * retrieved and used. Note that this involves a feature request to the underlying data provider,
1787 : : * so it is more efficient to explicitly pass an \a oldValue if it is already available.
1788 : : *
1789 : : * If \a skipDefaultValues is set to TRUE, default field values will not
1790 : : * be updated. This can be used to override default field value expressions.
1791 : : *
1792 : : * \returns TRUE if the feature's attribute was successfully changed.
1793 : : *
1794 : : * \note Calls to changeAttributeValue() are only valid for layers in which edits have been enabled
1795 : : * by a call to startEditing(). Changes made to features using this method are not committed
1796 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1797 : : * changes can be discarded by calling rollBack().
1798 : : *
1799 : : * \see startEditing()
1800 : : * \see commitChanges()
1801 : : * \see changeGeometry()
1802 : : * \see updateFeature()
1803 : : */
1804 : : bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant(), bool skipDefaultValues = false );
1805 : :
1806 : : /**
1807 : : * Changes attributes' values for a feature (but does not immediately
1808 : : * commit the changes).
1809 : : * The \a fid argument specifies the ID of the feature to be changed.
1810 : : *
1811 : : * The new values to be assigned to the fields are given by \a newValues.
1812 : : *
1813 : : * If a valid QVariant is specified for a field in \a oldValues, it will be
1814 : : * used as the field value in the case of an undo operation corresponding
1815 : : * to this attribute value change. If an invalid QVariant is used (the
1816 : : * default behavior), then the feature's current value will be
1817 : : * automatically retrieved and used. Note that this involves a feature
1818 : : * request to the underlying data provider, so it is more efficient to
1819 : : * explicitly pass an oldValue if it is already available.
1820 : : *
1821 : : * If \a skipDefaultValues is set to TRUE, default field values will not
1822 : : * be updated. This can be used to override default field value
1823 : : * expressions.
1824 : : *
1825 : : * \returns TRUE if feature's attributes was successfully changed.
1826 : : *
1827 : : * \note Calls to changeAttributeValues() are only valid for layers in
1828 : : * which edits have been enabled by a call to startEditing(). Changes made
1829 : : * to features using this method are not committed to the underlying data
1830 : : * provider until a commitChanges() call is made. Any uncommitted changes
1831 : : * can be discarded by calling rollBack().
1832 : : *
1833 : : * \see startEditing()
1834 : : * \see commitChanges()
1835 : : * \see changeGeometry()
1836 : : * \see updateFeature()
1837 : : * \see changeAttributeValue()
1838 : : *
1839 : : * \since QGIS 3.0
1840 : : */
1841 : : bool changeAttributeValues( QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues = QgsAttributeMap(), bool skipDefaultValues = false );
1842 : :
1843 : : /**
1844 : : * Add an attribute field (but does not commit it)
1845 : : * returns TRUE if the field was added
1846 : : *
1847 : : * \note Calls to addAttribute() are only valid for layers in which edits have been enabled
1848 : : * by a call to startEditing(). Changes made to features using this method are not committed
1849 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1850 : : * changes can be discarded by calling rollBack().
1851 : : */
1852 : : bool addAttribute( const QgsField &field );
1853 : :
1854 : : /**
1855 : : * Sets an alias (a display name) for attributes to display in dialogs
1856 : : *
1857 : : * \since QGIS 3.0
1858 : : */
1859 : : void setFieldAlias( int index, const QString &aliasString );
1860 : :
1861 : : /**
1862 : : * Removes an alias (a display name) for attributes to display in dialogs
1863 : : *
1864 : : * \since QGIS 3.0
1865 : : */
1866 : : void removeFieldAlias( int index );
1867 : :
1868 : : /**
1869 : : * Renames an attribute field (but does not commit it).
1870 : : * \param index attribute index
1871 : : * \param newName new name of field
1872 : : * \note Calls to renameAttribute() are only valid for layers in which edits have been enabled
1873 : : * by a call to startEditing(). Changes made to features using this method are not committed
1874 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1875 : : * changes can be discarded by calling rollBack().
1876 : : * \since QGIS 2.16
1877 : : */
1878 : : bool renameAttribute( int index, const QString &newName );
1879 : :
1880 : : /**
1881 : : * Returns the alias of an attribute name or a null string if there is no alias.
1882 : : *
1883 : : * \see {attributeDisplayName( int attributeIndex )} which returns the field name
1884 : : * if no alias is defined.
1885 : : */
1886 : : QString attributeAlias( int index ) const;
1887 : :
1888 : : //! Convenience function that returns the attribute alias if defined or the field name else
1889 : : QString attributeDisplayName( int index ) const;
1890 : :
1891 : : //! Returns a map of field name to attribute alias
1892 : : QgsStringMap attributeAliases() const;
1893 : :
1894 : : /**
1895 : : * A set of attributes that are not advertised in WMS requests with QGIS server.
1896 : : * \deprecated since QGIS 3.16, use fields().configurationFlags() instead
1897 : : */
1898 : : Q_DECL_DEPRECATED QSet<QString> excludeAttributesWms() const SIP_DEPRECATED;
1899 : :
1900 : : /**
1901 : : * A set of attributes that are not advertised in WMS requests with QGIS server.
1902 : : * \deprecated since QGIS 3.16, use setFieldConfigurationFlag instead
1903 : : */
1904 : : Q_DECL_DEPRECATED void setExcludeAttributesWms( const QSet<QString> &att ) SIP_DEPRECATED;
1905 : :
1906 : : /**
1907 : : * A set of attributes that are not advertised in WFS requests with QGIS server.
1908 : : * \deprecated since QGIS 3.16, use fields().configurationFlags() instead
1909 : : */
1910 : : Q_DECL_DEPRECATED QSet<QString> excludeAttributesWfs() const SIP_DEPRECATED;
1911 : :
1912 : : /**
1913 : : * A set of attributes that are not advertised in WFS requests with QGIS server.
1914 : : * \deprecated since QGIS 3.16, use setFieldConfigurationFlag instead
1915 : : */
1916 : : Q_DECL_DEPRECATED void setExcludeAttributesWfs( const QSet<QString> &att ) SIP_DEPRECATED;
1917 : :
1918 : : /**
1919 : : * Deletes an attribute field (but does not commit it).
1920 : : *
1921 : : * \note Calls to deleteAttribute() are only valid for layers in which edits have been enabled
1922 : : * by a call to startEditing(). Changes made to features using this method are not committed
1923 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1924 : : * changes can be discarded by calling rollBack().
1925 : : */
1926 : : virtual bool deleteAttribute( int attr );
1927 : :
1928 : : /**
1929 : : * Deletes a list of attribute fields (but does not commit it)
1930 : : *
1931 : : * \param attrs the indices of the attributes to delete
1932 : : * \returns TRUE if at least one attribute has been deleted
1933 : : *
1934 : : */
1935 : : bool deleteAttributes( const QList<int> &attrs );
1936 : :
1937 : : bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) FINAL;
1938 : :
1939 : : /**
1940 : : * Deletes a feature from the layer (but does not commit it).
1941 : : * \param fid The feature id to delete
1942 : : * \param context The chain of features who will be deleted for feedback and to avoid endless recursions
1943 : : *
1944 : : * \note Calls to deleteFeature() are only valid for layers in which edits have been enabled
1945 : : * by a call to startEditing(). Changes made to features using this method are not committed
1946 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1947 : : * changes can be discarded by calling rollBack().
1948 : : */
1949 : : bool deleteFeature( QgsFeatureId fid, DeleteContext *context = nullptr );
1950 : :
1951 : : /**
1952 : : * Deletes a set of features from the layer (but does not commit it)
1953 : : * \param fids The feature ids to delete
1954 : : * \param context The chain of features who will be deleted for feedback and to avoid endless recursions
1955 : : *
1956 : : * \returns FALSE if the layer is not in edit mode or does not support deleting
1957 : : * in case of an active transaction depends on the provider implementation
1958 : : *
1959 : : * \note Calls to deleteFeatures() are only valid for layers in which edits have been enabled
1960 : : * by a call to startEditing(). Changes made to features using this method are not committed
1961 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1962 : : * changes can be discarded by calling rollBack().
1963 : : */
1964 : : bool deleteFeatures( const QgsFeatureIds &fids, DeleteContext *context = nullptr );
1965 : :
1966 : : /**
1967 : : * Attempts to commit to the underlying data provider any buffered changes made since the
1968 : : * last to call to startEditing().
1969 : : *
1970 : : * Returns the result of the attempt. If a commit fails (i.e. FALSE is returned), the
1971 : : * in-memory changes are left untouched and are not discarded. This allows editing to
1972 : : * continue if the commit failed on e.g. a disallowed value in a Postgres
1973 : : * database - the user can re-edit and try again.
1974 : : *
1975 : : * The commits occur in distinct stages,
1976 : : * (add attributes, add features, change attribute values, change
1977 : : * geometries, delete features, delete attributes)
1978 : : * so if a stage fails, it can be difficult to roll back cleanly.
1979 : : * Therefore any error message returned by commitErrors() also includes which stage failed so
1980 : : * that the user has some chance of repairing the damage cleanly.
1981 : : *
1982 : : * By setting \a stopEditing to FALSE, the layer will stay in editing mode.
1983 : : * Otherwise the layer editing mode will be disabled if the commit is successful.
1984 : : *
1985 : : * \see startEditing()
1986 : : * \see commitErrors()
1987 : : * \see rollBack()
1988 : : */
1989 : : Q_INVOKABLE bool commitChanges( bool stopEditing = true );
1990 : :
1991 : : /**
1992 : : * Returns a list containing any error messages generated when attempting
1993 : : * to commit changes to the layer.
1994 : : * \see commitChanges()
1995 : : */
1996 : : QStringList commitErrors() const;
1997 : :
1998 : : /**
1999 : : * Stops a current editing operation and discards any uncommitted edits.
2000 : : *
2001 : : * If \a deleteBuffer is TRUE the editing buffer will be completely deleted (the default
2002 : : * behavior).
2003 : : *
2004 : : * \see startEditing()
2005 : : * \see commitChanges()
2006 : : */
2007 : : Q_INVOKABLE bool rollBack( bool deleteBuffer = true );
2008 : :
2009 : : /**
2010 : : * Returns the layer's relations, where the foreign key is on this layer.
2011 : : *
2012 : : * \param idx Only get relations, where idx forms part of the foreign key
2013 : : * \returns A list of relations
2014 : : */
2015 : : QList<QgsRelation> referencingRelations( int idx ) const;
2016 : :
2017 : : /**
2018 : : * Returns the layer's weak relations as specified in the layer's style.
2019 : : * \returns A list of weak relations
2020 : : * \note not available in Python bindings
2021 : : * \since QGIS 3.12
2022 : : */
2023 : : QList<QgsWeakRelation> weakRelations( ) const SIP_SKIP;
2024 : :
2025 : :
2026 : : //! Buffer with uncommitted editing operations. Only valid after editing has been turned on.
2027 : 0 : Q_INVOKABLE QgsVectorLayerEditBuffer *editBuffer() { return mEditBuffer; }
2028 : :
2029 : : /**
2030 : : * Buffer with uncommitted editing operations. Only valid after editing has been turned on.
2031 : : * \note not available in Python bindings
2032 : : */
2033 : 223 : const QgsVectorLayerEditBuffer *editBuffer() const SIP_SKIP { return mEditBuffer; }
2034 : :
2035 : : /**
2036 : : * Create edit command for undo/redo operations
2037 : : * \param text text which is to be displayed in undo window
2038 : : */
2039 : : void beginEditCommand( const QString &text );
2040 : :
2041 : : //! Finish edit command and add it to undo/redo stack
2042 : : void endEditCommand();
2043 : :
2044 : : //! Destroy active command and reverts all changes in it
2045 : : void destroyEditCommand();
2046 : :
2047 : : //! Editing vertex markers
2048 : : enum VertexMarkerType
2049 : : {
2050 : : SemiTransparentCircle,
2051 : : Cross,
2052 : : NoMarker
2053 : : };
2054 : :
2055 : : /**
2056 : : * Draws a vertex symbol at (screen) coordinates x, y. (Useful to assist vertex editing.)
2057 : : * \deprecated Use the equivalent QgsSymbolLayerUtils::drawVertexMarker function instead
2058 : : */
2059 : : Q_DECL_DEPRECATED static void drawVertexMarker( double x, double y, QPainter &p, QgsVectorLayer::VertexMarkerType type, int vertexSize );
2060 : :
2061 : : /**
2062 : : * Will regenerate the `fields` property of this layer by obtaining all fields
2063 : : * from the dataProvider, joined fields and virtual fields. It will also
2064 : : * take any changes made to default values into consideration.
2065 : : *
2066 : : * \note Unless the fields on the provider have directly been modified, there is
2067 : : * no reason to call this method.
2068 : : */
2069 : : void updateFields();
2070 : :
2071 : : /**
2072 : : * Returns the calculated default value for the specified field index. The default
2073 : : * value may be taken from a client side default value expression (see setDefaultValueDefinition())
2074 : : * or taken from the underlying data provider.
2075 : : * \param index field index
2076 : : * \param feature optional feature to use for default value evaluation. If passed,
2077 : : * then properties from the feature (such as geometry) can be used when calculating
2078 : : * the default value.
2079 : : * \param context optional expression context to evaluate expressions again. If not
2080 : : * specified, a default context will be created
2081 : : * \returns calculated default value
2082 : : * \see setDefaultValueDefinition()
2083 : : * \since QGIS 3.0
2084 : : */
2085 : : QVariant defaultValue( int index, const QgsFeature &feature = QgsFeature(),
2086 : : QgsExpressionContext *context = nullptr ) const;
2087 : :
2088 : : /**
2089 : : * Sets the definition of the expression to use when calculating the default value for a field.
2090 : : * \param index field index
2091 : : * \param definition default value definition to use and evaluate
2092 : : * when calculating default values for field. Pass
2093 : : * an empty expression to clear the default.
2094 : : *
2095 : : * \see defaultValue()
2096 : : * \see defaultValueDefinition()
2097 : : * \since QGIS 3.0
2098 : : */
2099 : : void setDefaultValueDefinition( int index, const QgsDefaultValue &definition );
2100 : :
2101 : : /**
2102 : : * Returns the definition of the expression used when calculating the default value for a field.
2103 : : * \param index field index
2104 : : * \returns definition of the default value with the expression evaluated
2105 : : * when calculating default values for field, or definition with an
2106 : : * empty string if no default is set
2107 : : * \see defaultValue()
2108 : : * \see setDefaultValueDefinition()
2109 : : * \since QGIS 3.0
2110 : : */
2111 : : QgsDefaultValue defaultValueDefinition( int index ) const;
2112 : :
2113 : : /**
2114 : : * Returns any constraints which are present for a specified
2115 : : * field index. These constraints may be inherited from the layer's data provider
2116 : : * or may be set manually on the vector layer from within QGIS.
2117 : : * \see setFieldConstraint()
2118 : : * \since QGIS 3.0
2119 : : */
2120 : : QgsFieldConstraints::Constraints fieldConstraints( int fieldIndex ) const;
2121 : :
2122 : : /**
2123 : : * Returns a map of constraint with their strength for a specific field of the layer.
2124 : : * \param fieldIndex field index
2125 : : * \since QGIS 3.0
2126 : : */
2127 : : QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength> fieldConstraintsAndStrength( int fieldIndex ) const;
2128 : :
2129 : : /**
2130 : : * Sets a constraint for a specified field index. Any constraints inherited from the layer's
2131 : : * data provider will be kept intact and cannot be modified. Ie, calling this method only allows for new
2132 : : * constraints to be added on top of the existing provider constraints.
2133 : : * \see fieldConstraints()
2134 : : * \see removeFieldConstraint()
2135 : : * \since QGIS 3.0
2136 : : */
2137 : : void setFieldConstraint( int index, QgsFieldConstraints::Constraint constraint, QgsFieldConstraints::ConstraintStrength strength = QgsFieldConstraints::ConstraintStrengthHard );
2138 : :
2139 : : /**
2140 : : * Removes a constraint for a specified field index. Any constraints inherited from the layer's
2141 : : * data provider will be kept intact and cannot be removed.
2142 : : * \see fieldConstraints()
2143 : : * \see setFieldConstraint()
2144 : : * \since QGIS 3.0
2145 : : */
2146 : : void removeFieldConstraint( int index, QgsFieldConstraints::Constraint constraint );
2147 : :
2148 : : /**
2149 : : * Returns the constraint expression for for a specified field index, if set.
2150 : : * \see fieldConstraints()
2151 : : * \see constraintDescription()
2152 : : * \see setConstraintExpression()
2153 : : * \since QGIS 3.0
2154 : : */
2155 : : QString constraintExpression( int index ) const;
2156 : :
2157 : : /**
2158 : : * Returns the descriptive name for the constraint expression for a specified field index.
2159 : : * \see fieldConstraints()
2160 : : * \see constraintExpression()
2161 : : * \see setConstraintExpression()
2162 : : * \since QGIS 3.0
2163 : : */
2164 : : QString constraintDescription( int index ) const;
2165 : :
2166 : : /**
2167 : : * Sets the constraint expression for the specified field index. An optional descriptive name for the constraint
2168 : : * can also be set. Setting an empty expression will clear any existing expression constraint.
2169 : : * \see constraintExpression()
2170 : : * \see constraintDescription()
2171 : : * \see fieldConstraints()
2172 : : * \since QGIS 3.0
2173 : : */
2174 : : void setConstraintExpression( int index, const QString &expression, const QString &description = QString() );
2175 : :
2176 : : /**
2177 : : * Sets the configuration flags of the field at given index
2178 : : * \see QgsField::ConfigurationFlag
2179 : : * \since QGIS 3.16
2180 : : */
2181 : : void setFieldConfigurationFlags( int index, QgsField::ConfigurationFlags flags ) SIP_SKIP;
2182 : :
2183 : : /**
2184 : : * Sets the given configuration \a flag for the field at given \a index to be \a active or not.
2185 : : * \since QGIS 3.16
2186 : : */
2187 : : void setFieldConfigurationFlag( int index, QgsField::ConfigurationFlag flag, bool active ) SIP_SKIP;
2188 : :
2189 : : /**
2190 : : * Returns the configuration flags of the field at given index
2191 : : * \see QgsField::ConfigurationFlag
2192 : : * \since QGIS 3.16
2193 : : */
2194 : : QgsField::ConfigurationFlags fieldConfigurationFlags( int index ) const SIP_SKIP;
2195 : :
2196 : : /**
2197 : : * \copydoc editorWidgetSetup
2198 : : */
2199 : : void setEditorWidgetSetup( int index, const QgsEditorWidgetSetup &setup );
2200 : :
2201 : : /**
2202 : : * The editor widget setup defines which QgsFieldFormatter and editor widget will be used
2203 : : * for the field at `index`.
2204 : : *
2205 : : * \since QGIS 3.0
2206 : : */
2207 : : QgsEditorWidgetSetup editorWidgetSetup( int index ) const;
2208 : :
2209 : : /**
2210 : : * Calculates a list of unique values contained within an attribute in the layer. Note that
2211 : : * in some circumstances when unsaved changes are present for the layer then the returned list
2212 : : * may contain outdated values (for instance when the attribute value in a saved feature has
2213 : : * been changed inside the edit buffer then the previous saved value will be included in the
2214 : : * returned list).
2215 : : * \param fieldIndex column index for attribute
2216 : : * \param limit maximum number of values to return (or -1 if unlimited)
2217 : : * \see minimumValue()
2218 : : * \see maximumValue()
2219 : : */
2220 : : QSet<QVariant> uniqueValues( int fieldIndex, int limit = -1 ) const FINAL;
2221 : :
2222 : : /**
2223 : : * Returns unique string values of an attribute which contain a specified subset string. Subset
2224 : : * matching is done in a case-insensitive manner. Note that
2225 : : * in some circumstances when unsaved changes are present for the layer then the returned list
2226 : : * may contain outdated values (for instance when the attribute value in a saved feature has
2227 : : * been changed inside the edit buffer then the previous saved value will be included in the
2228 : : * returned list).
2229 : : * \param index column index for attribute
2230 : : * \param substring substring to match (case insensitive)
2231 : : * \param limit maxmum number of the values to return, or -1 to return all unique values
2232 : : * \param feedback optional feedback object for canceling request
2233 : : * \returns list of unique strings containing substring
2234 : : */
2235 : : QStringList uniqueStringsMatching( int index, const QString &substring, int limit = -1,
2236 : : QgsFeedback *feedback = nullptr ) const;
2237 : :
2238 : : /**
2239 : : * Returns the minimum value for an attribute column or an invalid variant in case of error.
2240 : : *
2241 : : * \note In some circumstances when unsaved changes are present for the layer then the
2242 : : * returned value may be outdated (for instance when the attribute value in a saved feature has
2243 : : * been changed inside the edit buffer then the previous saved value may be returned as the minimum).
2244 : : *
2245 : : * \note If both the minimum and maximum value are required it is more efficient to call minimumAndMaximumValue()
2246 : : * instead of separate calls to minimumValue() and maximumValue().
2247 : : *
2248 : : * \see maximumValue()
2249 : : * \see minimumAndMaximumValue()
2250 : : * \see uniqueValues()
2251 : : */
2252 : : QVariant minimumValue( int index ) const FINAL;
2253 : :
2254 : : /**
2255 : : * Returns the maximum value for an attribute column or an invalid variant in case of error.
2256 : : *
2257 : : * \note In some circumstances when unsaved changes are present for the layer then the
2258 : : * returned value may be outdated (for instance when the attribute value in a saved feature has
2259 : : * been changed inside the edit buffer then the previous saved value may be returned as the maximum).
2260 : : *
2261 : : * \note If both the minimum and maximum value are required it is more efficient to call minimumAndMaximumValue()
2262 : : * instead of separate calls to minimumValue() and maximumValue().
2263 : : *
2264 : : * \see minimumValue()
2265 : : * \see minimumAndMaximumValue()
2266 : : * \see uniqueValues()
2267 : : */
2268 : : QVariant maximumValue( int index ) const FINAL;
2269 : :
2270 : :
2271 : : /**
2272 : : * Calculates both the minimum and maximum value for an attribute column.
2273 : : *
2274 : : * This is more efficient then calling both minimumValue() and maximumValue() when both the minimum
2275 : : * and maximum values are required.
2276 : : *
2277 : : * \param index index of field to calculate minimum and maximum value for.
2278 : : * \param minimum will be set to minimum attribute value or an invalid variant in case of error.
2279 : : * \param maximum will be set to maximum attribute value or an invalid variant in case of error.
2280 : : *
2281 : : * \note In some circumstances when unsaved changes are present for the layer then the
2282 : : * calculated values may be outdated (for instance when the attribute value in a saved feature has
2283 : : * been changed inside the edit buffer then the previous saved value may be returned as the maximum).
2284 : : *
2285 : : * \see minimumValue()
2286 : : * \see maximumValue()
2287 : : *
2288 : : * \since QGIS 3.20
2289 : : */
2290 : : void minimumAndMaximumValue( int index, QVariant &minimum SIP_OUT, QVariant &maximum SIP_OUT ) const;
2291 : :
2292 : : /**
2293 : : * Calculates an aggregated value from the layer's features.
2294 : : * Currently any filtering expression provided will override filters in the FeatureRequest.
2295 : : * \param aggregate aggregate to calculate
2296 : : * \param fieldOrExpression source field or expression to use as basis for aggregated values.
2297 : : * \param parameters parameters controlling aggregate calculation
2298 : : * \param context expression context for expressions and filters
2299 : : * \param ok if specified, will be set to TRUE if aggregate calculation was successful
2300 : : * \param fids list of fids to filter, otherwise will use all fids
2301 : : * \returns calculated aggregate value
2302 : : * \since QGIS 2.16
2303 : : */
2304 : : QVariant aggregate( QgsAggregateCalculator::Aggregate aggregate,
2305 : : const QString &fieldOrExpression,
2306 : : const QgsAggregateCalculator::AggregateParameters ¶meters = QgsAggregateCalculator::AggregateParameters(),
2307 : : QgsExpressionContext *context = nullptr,
2308 : : bool *ok = nullptr,
2309 : : QgsFeatureIds *fids = nullptr ) const;
2310 : :
2311 : : //! Sets the blending mode used for rendering each feature
2312 : : void setFeatureBlendMode( QPainter::CompositionMode blendMode );
2313 : : //! Returns the current blending mode for features
2314 : : QPainter::CompositionMode featureBlendMode() const;
2315 : :
2316 : : QString htmlMetadata() const FINAL;
2317 : :
2318 : : /**
2319 : : * Sets the simplification settings for fast rendering of features
2320 : : * \since QGIS 2.2
2321 : : */
2322 : 0 : void setSimplifyMethod( const QgsVectorSimplifyMethod &simplifyMethod ) { mSimplifyMethod = simplifyMethod; }
2323 : :
2324 : : /**
2325 : : * Returns the simplification settings for fast rendering of features
2326 : : * \since QGIS 2.2
2327 : : */
2328 : 0 : inline const QgsVectorSimplifyMethod &simplifyMethod() const { return mSimplifyMethod; }
2329 : :
2330 : : /**
2331 : : * Returns whether the VectorLayer can apply the specified simplification hint
2332 : : * \note Do not use in 3rd party code - may be removed in future version!
2333 : : * \since QGIS 2.2
2334 : : */
2335 : : bool simplifyDrawingCanbeApplied( const QgsRenderContext &renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint ) const;
2336 : :
2337 : : /**
2338 : : * Returns the conditional styles that are set for this layer. Style information is
2339 : : * used to render conditional formatting in the attribute table.
2340 : : * \returns Return a QgsConditionalLayerStyles object holding the conditional attribute
2341 : : * style information. Style information is generic and can be used for anything.
2342 : : * \since QGIS 2.12
2343 : : */
2344 : : QgsConditionalLayerStyles *conditionalStyles() const;
2345 : :
2346 : : /**
2347 : : * Returns the attribute table configuration object.
2348 : : * This defines the appearance of the attribute table.
2349 : : */
2350 : : QgsAttributeTableConfig attributeTableConfig() const;
2351 : :
2352 : : /**
2353 : : * Sets the attribute table configuration object.
2354 : : * This defines the appearance of the attribute table.
2355 : : */
2356 : : void setAttributeTableConfig( const QgsAttributeTableConfig &attributeTableConfig );
2357 : :
2358 : : /**
2359 : : * The mapTip is a pretty, html representation for feature information.
2360 : : *
2361 : : * It may also contain embedded expressions.
2362 : : *
2363 : : * \since QGIS 3.0
2364 : : */
2365 : : QString mapTipTemplate() const;
2366 : :
2367 : : /**
2368 : : * The mapTip is a pretty, html representation for feature information.
2369 : : *
2370 : : * It may also contain embedded expressions.
2371 : : *
2372 : : * \since QGIS 3.0
2373 : : */
2374 : : void setMapTipTemplate( const QString &mapTipTemplate );
2375 : :
2376 : : QgsExpressionContext createExpressionContext() const FINAL;
2377 : :
2378 : : QgsExpressionContextScope *createExpressionContextScope() const FINAL SIP_FACTORY;
2379 : :
2380 : : /**
2381 : : * Returns the configuration of the form used to represent this vector layer.
2382 : : *
2383 : : * \returns The configuration of this layers' form
2384 : : *
2385 : : * \since QGIS 2.14
2386 : : */
2387 : : QgsEditFormConfig editFormConfig() const;
2388 : :
2389 : : /**
2390 : : * Sets the \a editFormConfig (configuration) of the form used to represent this vector layer.
2391 : : *
2392 : : * \see editFormConfig()
2393 : : * \since QGIS 3.0
2394 : : */
2395 : : void setEditFormConfig( const QgsEditFormConfig &editFormConfig );
2396 : :
2397 : : /**
2398 : : * Flag allowing to indicate if the extent has to be read from the XML
2399 : : * document when data source has no metadata or if the data provider has
2400 : : * to determine it.
2401 : : *
2402 : : * \since QGIS 3.0
2403 : : */
2404 : : void setReadExtentFromXml( bool readExtentFromXml );
2405 : :
2406 : : /**
2407 : : * Returns TRUE if the extent is read from the XML document when data
2408 : : * source has no metadata, FALSE if it's the data provider which determines
2409 : : * it.
2410 : : *
2411 : : * \since QGIS 3.0
2412 : : */
2413 : : bool readExtentFromXml() const;
2414 : :
2415 : : /**
2416 : : * Tests if an edit command is active
2417 : : *
2418 : : * \since QGIS 3.0
2419 : : */
2420 : 0 : bool isEditCommandActive() const { return mEditCommandActive; }
2421 : :
2422 : : /**
2423 : : * Configuration and logic to apply automatically on any edit happening on this layer.
2424 : : *
2425 : : * \since QGIS 3.4
2426 : : */
2427 : : QgsGeometryOptions *geometryOptions() const;
2428 : :
2429 : : /**
2430 : : * Controls, if the layer is allowed to commit changes. If this is set to FALSE
2431 : : * it will not be possible to commit changes on this layer. This can be used to
2432 : : * define checks on a layer that need to be pass before the layer can be saved.
2433 : : * If you use this API, make sure that:
2434 : : *
2435 : : * - the user is visibly informed that his changes were not saved and what he needs
2436 : : * to do in order to be able to save the changes.
2437 : : * - to set the property back to TRUE, once the user has fixed his data.
2438 : : *
2439 : : * When calling \see commitChanges() this flag is checked just after the
2440 : : * \see beforeCommitChanges() signal is emitted, so it's possible to adjust it from there.
2441 : : *
2442 : : * \note Not available in Python bindings
2443 : : *
2444 : : * \since QGIS 3.4
2445 : : */
2446 : : bool allowCommit() const SIP_SKIP;
2447 : :
2448 : : /**
2449 : : * Controls, if the layer is allowed to commit changes. If this is set to FALSE
2450 : : * it will not be possible to commit changes on this layer. This can be used to
2451 : : * define checks on a layer that need to be pass before the layer can be saved.
2452 : : * If you use this API, make sure that:
2453 : : *
2454 : : * - the user is visibly informed that his changes were not saved and what he needs
2455 : : * to do in order to be able to save the changes.
2456 : : * - to set the property back to TRUE, once the user has fixed his data.
2457 : : *
2458 : : * When calling \see commitChanges() this flag is checked just after the
2459 : : * \see beforeCommitChanges() signal is emitted, so it's possible to adjust it from there.
2460 : : *
2461 : : * \note Not available in Python bindings
2462 : : *
2463 : : * \since QGIS 3.4
2464 : : */
2465 : : void setAllowCommit( bool allowCommit ) SIP_SKIP;
2466 : :
2467 : : /**
2468 : : * Returns the manager of the stored expressions for this layer.
2469 : : *
2470 : : * \since QGIS 3.10
2471 : : */
2472 : : QgsStoredExpressionManager *storedExpressionManager() { return mStoredExpressionManager; }
2473 : :
2474 : : public slots:
2475 : :
2476 : : /**
2477 : : * Selects feature by its ID
2478 : : *
2479 : : * \param featureId The id of the feature to select
2480 : : *
2481 : : * \see select( const QgsFeatureIds& )
2482 : : */
2483 : : void select( QgsFeatureId featureId );
2484 : :
2485 : : /**
2486 : : * Selects features by their ID
2487 : : *
2488 : : * \param featureIds The ids of the features to select
2489 : : *
2490 : : * \see select(QgsFeatureId)
2491 : : */
2492 : : Q_INVOKABLE void select( const QgsFeatureIds &featureIds );
2493 : :
2494 : : /**
2495 : : * Deselects feature by its ID
2496 : : *
2497 : : * \param featureId The id of the feature to deselect
2498 : : *
2499 : : * \see deselect(const QgsFeatureIds&)
2500 : : */
2501 : : void deselect( QgsFeatureId featureId );
2502 : :
2503 : : /**
2504 : : * Deselects features by their ID
2505 : : *
2506 : : * \param featureIds The ids of the features to deselect
2507 : : *
2508 : : * \see deselect(const QgsFeatureId)
2509 : : */
2510 : : Q_INVOKABLE void deselect( const QgsFeatureIds &featureIds );
2511 : :
2512 : : /**
2513 : : * Clear selection
2514 : : *
2515 : : * \see selectByIds()
2516 : : * \see reselect()
2517 : : */
2518 : : Q_INVOKABLE void removeSelection();
2519 : :
2520 : : /**
2521 : : * Reselects the previous set of selected features. This is only applicable
2522 : : * after a prior call to removeSelection().
2523 : : *
2524 : : * Any other modifications to the selection following a call to removeSelection() clears
2525 : : * memory of the previous selection and consequently calling reselect() has no impact.
2526 : : *
2527 : : * \see removeSelection()
2528 : : * \since QGIS 3.10
2529 : : */
2530 : : void reselect();
2531 : :
2532 : : /**
2533 : : * Update the extents for the layer. This is necessary if features are
2534 : : * added/deleted or the layer has been subsetted.
2535 : : *
2536 : : * \param force TRUE to update layer extent even if it's read from xml by default, FALSE otherwise
2537 : : */
2538 : : virtual void updateExtents( bool force = false );
2539 : :
2540 : : /**
2541 : : * Makes the layer editable.
2542 : : *
2543 : : * This starts an edit session on this layer. Changes made in this edit session will not
2544 : : * be made persistent until commitChanges() is called, and can be reverted by calling
2545 : : * rollBack().
2546 : : *
2547 : : * \returns TRUE if the layer was successfully made editable, or FALSE if the operation
2548 : : * failed (e.g. due to an underlying read-only data source, or lack of edit support
2549 : : * by the backend data provider).
2550 : : *
2551 : : * \see commitChanges()
2552 : : * \see rollBack()
2553 : : */
2554 : : Q_INVOKABLE bool startEditing();
2555 : :
2556 : : /**
2557 : : * Sets the coordinate transform context to \a transformContext
2558 : : *
2559 : : * \since QGIS 3.8
2560 : : */
2561 : : virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
2562 : :
2563 : : SpatialIndexPresence hasSpatialIndex() const override;
2564 : :
2565 : : bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
2566 : :
2567 : : signals:
2568 : :
2569 : : /**
2570 : : * Emitted when selection was changed
2571 : : *
2572 : : * \param selected Newly selected feature ids
2573 : : * \param deselected Ids of all features which have previously been selected but are not any more
2574 : : * \param clearAndSelect In case this is set to TRUE, the old selection was dismissed and the new selection corresponds to selected
2575 : : */
2576 : : void selectionChanged( const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect );
2577 : :
2578 : : //! Emitted when modifications has been done on layer
2579 : : void layerModified();
2580 : :
2581 : : /**
2582 : : * Emitted whenever the allowCommitChanged() property of this layer changes.
2583 : : *
2584 : : * \since QGIS 3.4
2585 : : */
2586 : : void allowCommitChanged();
2587 : :
2588 : : //! Emitted when the layer is checked for modifications. Use for last-minute additions.
2589 : : void beforeModifiedCheck() const;
2590 : :
2591 : : //! Emitted before editing on this layer is started.
2592 : : void beforeEditingStarted();
2593 : :
2594 : : //! Emitted when editing on this layer has started.
2595 : : void editingStarted();
2596 : :
2597 : : //! Emitted when edited changes have been successfully written to the data provider.
2598 : : void editingStopped();
2599 : :
2600 : : /**
2601 : : * Emitted before changes are committed to the data provider.
2602 : : *
2603 : : * The \a stopEditing flag specifies if the editing mode shall be left after this commit.
2604 : : */
2605 : : void beforeCommitChanges( bool stopEditing );
2606 : :
2607 : : //! Emitted before changes are rolled back.
2608 : : void beforeRollBack();
2609 : :
2610 : : /**
2611 : : * Emitted after changes are committed to the data provider.
2612 : : * \since QGIS 3.16
2613 : : */
2614 : : void afterCommitChanges();
2615 : :
2616 : : /**
2617 : : * Emitted after changes are rolled back.
2618 : : * \since QGIS 3.4
2619 : : */
2620 : : void afterRollBack();
2621 : :
2622 : : /**
2623 : : * Will be emitted, when a new attribute has been added to this vector layer.
2624 : : * Applies only to types QgsFields::OriginEdit, QgsFields::OriginProvider and QgsFields::OriginExpression
2625 : : *
2626 : : * \param idx The index of the new attribute
2627 : : *
2628 : : * \see updatedFields()
2629 : : */
2630 : : void attributeAdded( int idx );
2631 : :
2632 : : /**
2633 : : * Will be emitted, when an expression field is going to be added to this vector layer.
2634 : : * Applies only to types QgsFields::OriginExpression
2635 : : *
2636 : : * \param fieldName The name of the attribute to be added
2637 : : */
2638 : : void beforeAddingExpressionField( const QString &fieldName );
2639 : :
2640 : : /**
2641 : : * Will be emitted, when an attribute has been deleted from this vector layer.
2642 : : * Applies only to types QgsFields::OriginEdit, QgsFields::OriginProvider and QgsFields::OriginExpression
2643 : : *
2644 : : * \param idx The index of the deleted attribute
2645 : : *
2646 : : * \see updatedFields()
2647 : : */
2648 : : void attributeDeleted( int idx );
2649 : :
2650 : : /**
2651 : : * Will be emitted, when an expression field is going to be deleted from this vector layer.
2652 : : * Applies only to types QgsFields::OriginExpression
2653 : : *
2654 : : * \param idx The index of the attribute to be deleted
2655 : : */
2656 : : void beforeRemovingExpressionField( int idx );
2657 : :
2658 : : /**
2659 : : * Emitted when a new feature has been added to the layer
2660 : : *
2661 : : * \param fid The id of the new feature
2662 : : */
2663 : : void featureAdded( QgsFeatureId fid );
2664 : :
2665 : : /**
2666 : : * Emitted when a feature has been deleted.
2667 : : *
2668 : : * If you do expensive operations in a slot connected to this, you should prefer to use
2669 : : * featuresDeleted( const QgsFeatureIds& ).
2670 : : *
2671 : : * \param fid The id of the feature which has been deleted
2672 : : */
2673 : : void featureDeleted( QgsFeatureId fid );
2674 : :
2675 : : /**
2676 : : * Emitted when features have been deleted.
2677 : : *
2678 : : * If features are deleted within an edit command, this will only be emitted once at the end
2679 : : * to allow connected slots to minimize the overhead.
2680 : : * If features are deleted outside of an edit command, this signal will be emitted once per feature.
2681 : : *
2682 : : * \param fids The feature ids that have been deleted.
2683 : : */
2684 : : void featuresDeleted( const QgsFeatureIds &fids );
2685 : :
2686 : : /**
2687 : : * Emitted whenever the fields available from this layer have been changed.
2688 : : * This can be due to manually adding attributes or due to a join.
2689 : : */
2690 : : void updatedFields();
2691 : :
2692 : : /**
2693 : : * Emitted when the layer's subset string has changed.
2694 : : * \since QGIS 3.2
2695 : : */
2696 : : void subsetStringChanged();
2697 : :
2698 : : /**
2699 : : * Emitted whenever an attribute value change is done in the edit buffer.
2700 : : * Note that at this point the attribute change is not yet saved to the provider.
2701 : : *
2702 : : * \param fid The id of the changed feature
2703 : : * \param idx The attribute index of the changed attribute
2704 : : * \param value The new value of the attribute
2705 : : */
2706 : : void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );
2707 : :
2708 : : /**
2709 : : * Emitted whenever a geometry change is done in the edit buffer.
2710 : : * Note that at this point the geometry change is not yet saved to the provider.
2711 : : *
2712 : : * \param fid The id of the changed feature
2713 : : * \param geometry The new geometry
2714 : : */
2715 : : void geometryChanged( QgsFeatureId fid, const QgsGeometry &geometry );
2716 : :
2717 : : //! Emitted when attributes are deleted from the provider
2718 : : void committedAttributesDeleted( const QString &layerId, const QgsAttributeList &deletedAttributes );
2719 : : //! Emitted when attributes are added to the provider
2720 : : void committedAttributesAdded( const QString &layerId, const QList<QgsField> &addedAttributes );
2721 : : //! Emitted when features are added to the provider
2722 : : void committedFeaturesAdded( const QString &layerId, const QgsFeatureList &addedFeatures );
2723 : : //! Emitted when features are deleted from the provider
2724 : : void committedFeaturesRemoved( const QString &layerId, const QgsFeatureIds &deletedFeatureIds );
2725 : : //! Emitted when attribute value changes are saved to the provider
2726 : : void committedAttributeValuesChanges( const QString &layerId, const QgsChangedAttributesMap &changedAttributesValues );
2727 : : //! Emitted when geometry changes are saved to the provider
2728 : : void committedGeometriesChanges( const QString &layerId, const QgsGeometryMap &changedGeometries );
2729 : :
2730 : : //! Emitted when the font family defined for labeling layer is not found on system
2731 : : void labelingFontNotFound( QgsVectorLayer *layer, const QString &fontfamily );
2732 : :
2733 : : //! Signal emitted when setFeatureBlendMode() is called
2734 : : void featureBlendModeChanged( QPainter::CompositionMode blendMode );
2735 : :
2736 : : /**
2737 : : * Signal emitted when a new edit command has been started
2738 : : *
2739 : : * \param text Description for this edit command
2740 : : */
2741 : : void editCommandStarted( const QString &text );
2742 : :
2743 : : /**
2744 : : * Signal emitted, when an edit command successfully ended
2745 : : * \note This does not mean it is also committed, only that it is written
2746 : : * to the edit buffer. See beforeCommitChanges()
2747 : : */
2748 : : void editCommandEnded();
2749 : :
2750 : : /**
2751 : : * Signal emitted, when an edit command is destroyed
2752 : : * \note This is not a rollback, it is only related to the current edit command.
2753 : : * See beforeRollBack()
2754 : : */
2755 : : void editCommandDestroyed();
2756 : :
2757 : : /**
2758 : : * Signal emitted whenever the symbology (QML-file) for this layer is being read.
2759 : : * If there is custom style information saved in the file, you can connect to this signal
2760 : : * and update the layer style accordingly.
2761 : : *
2762 : : * \param element The XML layer style element.
2763 : : *
2764 : : * \param errorMessage Write error messages into this string.
2765 : : */
2766 : : void readCustomSymbology( const QDomElement &element, QString &errorMessage );
2767 : :
2768 : : /**
2769 : : * Signal emitted whenever the symbology (QML-file) for this layer is being written.
2770 : : * If there is custom style information you want to save to the file, you can connect
2771 : : * to this signal and update the element accordingly.
2772 : : *
2773 : : * \param element The XML element where you can add additional style information to.
2774 : : * \param doc The XML document that you can use to create new XML nodes.
2775 : : * \param errorMessage Write error messages into this string.
2776 : : */
2777 : : void writeCustomSymbology( QDomElement &element, QDomDocument &doc, QString &errorMessage ) const;
2778 : :
2779 : : /**
2780 : : * Emitted when the map tip changes
2781 : : *
2782 : : * \since QGIS 3.0
2783 : : */
2784 : : void mapTipTemplateChanged();
2785 : :
2786 : : /**
2787 : : * Emitted when the display expression changes
2788 : : *
2789 : : * \since QGIS 3.0
2790 : : */
2791 : : void displayExpressionChanged();
2792 : :
2793 : : /**
2794 : : * Signals an error related to this vector layer.
2795 : : */
2796 : : void raiseError( const QString &msg );
2797 : :
2798 : : /**
2799 : : * Will be emitted whenever the edit form configuration of this layer changes.
2800 : : *
2801 : : * \since QGIS 3.0
2802 : : */
2803 : : void editFormConfigChanged();
2804 : :
2805 : : /**
2806 : : * Emitted when the read only state of this layer is changed.
2807 : : * Only applies to manually set readonly state, not to the edit mode.
2808 : : *
2809 : : * \since QGIS 3.0
2810 : : */
2811 : : void readOnlyChanged();
2812 : :
2813 : : /**
2814 : : * Emitted when the read only state or the data provider of this layer is changed.
2815 : : *
2816 : : * \since QGIS 3.18
2817 : : */
2818 : : void supportsEditingChanged();
2819 : :
2820 : : /**
2821 : : * Emitted when the feature count for symbols on this layer has been recalculated.
2822 : : *
2823 : : * \since QGIS 3.0
2824 : : */
2825 : : void symbolFeatureCountMapChanged();
2826 : :
2827 : : protected:
2828 : : //! Sets the extent
2829 : : void setExtent( const QgsRectangle &rect ) FINAL;
2830 : :
2831 : : private slots:
2832 : : void invalidateSymbolCountedFlag();
2833 : : void onFeatureCounterCompleted();
2834 : : void onFeatureCounterTerminated();
2835 : : void onJoinedFieldsChanged();
2836 : : void onFeatureDeleted( QgsFeatureId fid );
2837 : : void onRelationsLoaded();
2838 : : void onSymbolsCounted();
2839 : : void onDirtyTransaction( const QString &sql, const QString &name );
2840 : : void emitDataChanged();
2841 : : void onAfterCommitChangesDependency();
2842 : :
2843 : : private:
2844 : : void updateDefaultValues( QgsFeatureId fid, QgsFeature feature = QgsFeature() );
2845 : :
2846 : : /**
2847 : : * Returns TRUE if the provider is in read-only mode
2848 : : */
2849 : : bool isReadOnly() const FINAL;
2850 : :
2851 : : /**
2852 : : * Bind layer to a specific data provider
2853 : : * \param provider provider key string, must match a valid QgsVectorDataProvider key. E.g. "postgres", "ogr", etc.
2854 : : * \param options provider options
2855 : : * \param flags provider flags, since QGIS 3.16
2856 : : */
2857 : : bool setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
2858 : :
2859 : : //! Read labeling from SLD
2860 : : void readSldLabeling( const QDomNode &node );
2861 : :
2862 : : //! Read settings from SLD TextSymbolizer element
2863 : : bool readSldTextSymbolizer( const QDomNode &node, QgsPalLayerSettings &settings ) const;
2864 : :
2865 : : //! Read simple labeling from layer's custom properties (QGIS 2.x projects)
2866 : : QgsAbstractVectorLayerLabeling *readLabelingFromCustomProperties();
2867 : :
2868 : : bool deleteFeatureCascade( QgsFeatureId fid, DeleteContext *context = nullptr );
2869 : :
2870 : : #ifdef SIP_RUN
2871 : : QgsVectorLayer( const QgsVectorLayer &rhs );
2872 : : #endif
2873 : : //! Returns the minimum or maximum value
2874 : : void minimumOrMaximumValue( int index, QVariant *minimum, QVariant *maximum ) const;
2875 : :
2876 : : QgsConditionalLayerStyles *mConditionalStyles = nullptr;
2877 : :
2878 : : //! Pointer to data provider derived from the abastract base class QgsDataProvider
2879 : : QgsVectorDataProvider *mDataProvider = nullptr;
2880 : :
2881 : : //! Pointer to temporal properties
2882 : : QgsVectorLayerTemporalProperties *mTemporalProperties = nullptr;
2883 : :
2884 : : //! The preview expression used to generate a human readable preview string for features
2885 : : QString mDisplayExpression;
2886 : :
2887 : : QString mMapTipTemplate;
2888 : :
2889 : : //! The user-defined actions that are accessed from the Identify Results dialog box
2890 : : QgsActionManager *mActions = nullptr;
2891 : :
2892 : : //! Flag indicating whether the layer is in read-only mode (editing disabled) or not
2893 : : bool mReadOnly = false;
2894 : :
2895 : : /**
2896 : : * Set holding the feature IDs that are activated. Note that if a feature
2897 : : subsequently gets deleted (i.e. by its addition to mDeletedFeatureIds),
2898 : : it always needs to be removed from mSelectedFeatureIds as well.
2899 : : */
2900 : : QgsFeatureIds mSelectedFeatureIds;
2901 : :
2902 : : /**
2903 : : * Stores the previous set of selected features, to allow for "reselect" operations.
2904 : : */
2905 : : QgsFeatureIds mPreviousSelectedFeatureIds;
2906 : :
2907 : : //! Field map to commit
2908 : : QgsFields mFields;
2909 : :
2910 : : //! Map that stores the aliases for attributes. Key is the attribute name and value the alias for that attribute
2911 : : QgsStringMap mAttributeAliasMap;
2912 : :
2913 : : //! Map which stores default value expressions for fields
2914 : : QMap<QString, QgsDefaultValue> mDefaultExpressionMap;
2915 : :
2916 : : //! An internal structure to keep track of fields that have a defaultValueOnUpdate
2917 : : QSet<int> mDefaultValueOnUpdateFields;
2918 : :
2919 : : //! Map which stores constraints for fields
2920 : : QMap< QString, QgsFieldConstraints::Constraints > mFieldConstraints;
2921 : :
2922 : : //! Map which stores constraint strength for fields
2923 : : QMap< QPair< QString, QgsFieldConstraints::Constraint >, QgsFieldConstraints::ConstraintStrength > mFieldConstraintStrength;
2924 : :
2925 : : //! Map which stores expression constraints for fields. Value is a pair of expression/description.
2926 : : QMap< QString, QPair< QString, QString > > mFieldConstraintExpressions;
2927 : :
2928 : : QMap< QString, QgsField::ConfigurationFlags > mFieldConfigurationFlags;
2929 : : QMap< QString, QgsEditorWidgetSetup > mFieldWidgetSetups;
2930 : :
2931 : : //! Holds the configuration for the edit form
2932 : : QgsEditFormConfig mEditFormConfig;
2933 : :
2934 : : //! Geometry type as defined in enum WkbType (qgis.h)
2935 : : QgsWkbTypes::Type mWkbType = QgsWkbTypes::Unknown;
2936 : :
2937 : : //! Renderer object which holds the information about how to display the features
2938 : : QgsFeatureRenderer *mRenderer = nullptr;
2939 : :
2940 : : //! Simplification object which holds the information about how to simplify the features for fast rendering
2941 : : QgsVectorSimplifyMethod mSimplifyMethod;
2942 : :
2943 : : //! Labeling configuration
2944 : : QgsAbstractVectorLayerLabeling *mLabeling = nullptr;
2945 : :
2946 : : //! True if labels are enabled
2947 : : bool mLabelsEnabled = false;
2948 : :
2949 : : //! Whether 'labeling font not found' has be shown for this layer (only show once in QgsMessageBar, on first rendering)
2950 : : bool mLabelFontNotFoundNotified = false;
2951 : :
2952 : : //! Blend mode for features
2953 : : QPainter::CompositionMode mFeatureBlendMode = QPainter::CompositionMode_SourceOver;
2954 : :
2955 : : //! Flag if the vertex markers should be drawn only for selection (TRUE) or for all features (FALSE)
2956 : : bool mVertexMarkerOnlyForSelection = false;
2957 : :
2958 : : QStringList mCommitErrors;
2959 : :
2960 : : //! stores information about uncommitted changes to layer
2961 : : QgsVectorLayerEditBuffer *mEditBuffer = nullptr;
2962 : : friend class QgsVectorLayerEditBuffer;
2963 : : friend class QgsVectorLayerEditPassthrough;
2964 : :
2965 : : //stores information about joined layers
2966 : : QgsVectorLayerJoinBuffer *mJoinBuffer = nullptr;
2967 : :
2968 : : //!stores information about server properties
2969 : : std::unique_ptr< QgsVectorLayerServerProperties > mServerProperties;
2970 : :
2971 : : //! stores information about expression fields on this layer
2972 : : QgsExpressionFieldBuffer *mExpressionFieldBuffer = nullptr;
2973 : :
2974 : : //diagram rendering object. 0 if diagram drawing is disabled
2975 : : QgsDiagramRenderer *mDiagramRenderer = nullptr;
2976 : :
2977 : : //stores infos about diagram placement (placement type, priority, position distance)
2978 : : QgsDiagramLayerSettings *mDiagramLayerSettings = nullptr;
2979 : :
2980 : : mutable bool mValidExtent = false;
2981 : : mutable bool mLazyExtent = true;
2982 : :
2983 : : //! Auxiliary layer
2984 : : std::unique_ptr<QgsAuxiliaryLayer> mAuxiliaryLayer;
2985 : :
2986 : : //! Key to use to join auxiliary layer
2987 : : QString mAuxiliaryLayerKey;
2988 : :
2989 : : // Features in renderer classes counted
2990 : : bool mSymbolFeatureCounted = false;
2991 : :
2992 : : // Feature counts for each renderer legend key
2993 : : QHash<QString, long> mSymbolFeatureCountMap;
2994 : : QHash<QString, QgsFeatureIds> mSymbolFeatureIdMap;
2995 : :
2996 : : //! True while an undo command is active
2997 : : bool mEditCommandActive = false;
2998 : :
2999 : : bool mReadExtentFromXml;
3000 : : QgsRectangle mXmlExtent;
3001 : :
3002 : : QgsFeatureIds mDeletedFids;
3003 : :
3004 : : QgsAttributeTableConfig mAttributeTableConfig;
3005 : :
3006 : : mutable QMutex mFeatureSourceConstructorMutex;
3007 : :
3008 : : QgsVectorLayerFeatureCounter *mFeatureCounter = nullptr;
3009 : :
3010 : : std::unique_ptr<QgsGeometryOptions> mGeometryOptions;
3011 : :
3012 : : bool mAllowCommit = true;
3013 : :
3014 : : //! Stored expression used for e.g. filter
3015 : : QgsStoredExpressionManager *mStoredExpressionManager = nullptr;
3016 : :
3017 : : friend class QgsVectorLayerFeatureSource;
3018 : :
3019 : : //! To avoid firing multiple time dataChanged signal on circular layer circular dependencies
3020 : : bool mDataChangedFired = false;
3021 : :
3022 : : QList<QgsWeakRelation> mWeakRelations;
3023 : :
3024 : : bool mSetLegendFromStyle = false;
3025 : :
3026 : : QList< QgsFeatureRendererGenerator * > mRendererGenerators;
3027 : : };
3028 : :
3029 : :
3030 : :
3031 : : // clazy:excludeall=qstring-allocations
3032 : :
3033 : : #endif
|