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 : : /**
1429 : : * Adds a new part polygon to a multipart feature
1430 : : * \returns QgsGeometry::OperationResult
1431 : : *
1432 : : * - Success
1433 : : * - LayerNotEditable
1434 : : * - SelectionIsEmpty
1435 : : * - SelectionIsGreaterThanOne
1436 : : * - AddPartSelectedGeometryNotFound
1437 : : * - AddPartNotMultiGeometry
1438 : : * - InvalidBaseGeometry
1439 : : * - InvalidInputGeometryType
1440 : : *
1441 : : * \note available in Python bindings as addPartV2
1442 : : * \note Calls to addPart() are only valid for layers in which edits have been enabled
1443 : : * by a call to startEditing(). Changes made to features using this method are not committed
1444 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1445 : : * changes can be discarded by calling rollBack().
1446 : : * \deprecated since QGIS 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.
1447 : : */
1448 : : Q_DECL_DEPRECATED QgsGeometry::OperationResult addPart( const QVector<QgsPointXY> &ring ) SIP_PYNAME( addPartV2 ) SIP_DEPRECATED;
1449 : :
1450 : : /**
1451 : : * Adds a new part polygon to a multipart feature
1452 : : * \returns QgsGeometry::OperationResult
1453 : : *
1454 : : * - Success
1455 : : * - LayerNotEditable
1456 : : * - SelectionIsEmpty
1457 : : * - SelectionIsGreaterThanOne
1458 : : * - AddPartSelectedGeometryNotFound
1459 : : * - AddPartNotMultiGeometry
1460 : : * - InvalidBaseGeometry
1461 : : * - InvalidInputGeometryType
1462 : : *
1463 : : * \note available in Python bindings as addPartV2
1464 : : * \note Calls to addPart() are only valid for layers in which edits have been enabled
1465 : : * by a call to startEditing(). Changes made to features using this method are not committed
1466 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1467 : : * changes can be discarded by calling rollBack().
1468 : : */
1469 : : Q_INVOKABLE QgsGeometry::OperationResult addPart( const QgsPointSequence &ring ) SIP_PYNAME( addPartV2 );
1470 : :
1471 : : /**
1472 : : * \note available in Python as addCurvedPart
1473 : : * \note Calls to addPart() are only valid for layers in which edits have been enabled
1474 : : * by a call to startEditing(). Changes made to features using this method are not committed
1475 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1476 : : * changes can be discarded by calling rollBack().
1477 : : */
1478 : : Q_INVOKABLE QgsGeometry::OperationResult addPart( QgsCurve *ring SIP_TRANSFER ) SIP_PYNAME( addCurvedPart );
1479 : :
1480 : : /**
1481 : : * Translates feature by dx, dy
1482 : : * \param featureId id of the feature to translate
1483 : : * \param dx translation of x-coordinate
1484 : : * \param dy translation of y-coordinate
1485 : : * \returns 0 in case of success
1486 : : * \note Calls to translateFeature() are only valid for layers in which edits have been enabled
1487 : : * by a call to startEditing(). Changes made to features using this method are not committed
1488 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1489 : : * changes can be discarded by calling rollBack().
1490 : : */
1491 : : Q_INVOKABLE int translateFeature( QgsFeatureId featureId, double dx, double dy );
1492 : :
1493 : : /**
1494 : : * Splits parts cut by the given line
1495 : : * \param splitLine line that splits the layer features
1496 : : * \param topologicalEditing TRUE if topological editing is enabled
1497 : : * \returns QgsGeometry::OperationResult
1498 : : *
1499 : : * - Success
1500 : : * - NothingHappened
1501 : : * - LayerNotEditable
1502 : : * - InvalidInputGeometryType
1503 : : * - InvalidBaseGeometry
1504 : : * - GeometryEngineError
1505 : : * - SplitCannotSplitPoint
1506 : : *
1507 : : * \note Calls to splitParts() are only valid for layers in which edits have been enabled
1508 : : * by a call to startEditing(). Changes made to features using this method are not committed
1509 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1510 : : * changes can be discarded by calling rollBack().
1511 : : * \deprecated since QGIS 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.
1512 : : */
1513 : : Q_DECL_DEPRECATED QgsGeometry::OperationResult splitParts( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false ) SIP_DEPRECATED;
1514 : :
1515 : : /**
1516 : : * Splits parts cut by the given line
1517 : : * \param splitLine line that splits the layer features
1518 : : * \param topologicalEditing TRUE if topological editing is enabled
1519 : : * \returns QgsGeometry::OperationResult
1520 : : *
1521 : : * - Success
1522 : : * - NothingHappened
1523 : : * - LayerNotEditable
1524 : : * - InvalidInputGeometryType
1525 : : * - InvalidBaseGeometry
1526 : : * - GeometryEngineError
1527 : : * - SplitCannotSplitPoint
1528 : : *
1529 : : * \note Calls to splitParts() are only valid for layers in which edits have been enabled
1530 : : * by a call to startEditing(). Changes made to features using this method are not committed
1531 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1532 : : * changes can be discarded by calling rollBack().
1533 : : */
1534 : : Q_INVOKABLE QgsGeometry::OperationResult splitParts( const QgsPointSequence &splitLine, bool topologicalEditing = false );
1535 : :
1536 : : /**
1537 : : * Splits features cut by the given line
1538 : : * \param splitLine line that splits the layer features
1539 : : * \param topologicalEditing TRUE if topological editing is enabled
1540 : : * \returns QgsGeometry::OperationResult
1541 : : *
1542 : : * - Success
1543 : : * - NothingHappened
1544 : : * - LayerNotEditable
1545 : : * - InvalidInputGeometryType
1546 : : * - InvalidBaseGeometry
1547 : : * - GeometryEngineError
1548 : : * - SplitCannotSplitPoint
1549 : : *
1550 : : * \note Calls to splitFeatures() are only valid for layers in which edits have been enabled
1551 : : * by a call to startEditing(). Changes made to features using this method are not committed
1552 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1553 : : * changes can be discarded by calling rollBack().
1554 : : * \deprecated since QGIS 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.
1555 : : */
1556 : : Q_DECL_DEPRECATED QgsGeometry::OperationResult splitFeatures( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false ) SIP_DEPRECATED;
1557 : :
1558 : : /**
1559 : : * Splits features cut by the given line
1560 : : * \param splitLine line that splits the layer features
1561 : : * \param topologicalEditing TRUE if topological editing is enabled
1562 : : * \returns QgsGeometry::OperationResult
1563 : : *
1564 : : * - Success
1565 : : * - NothingHappened
1566 : : * - LayerNotEditable
1567 : : * - InvalidInputGeometryType
1568 : : * - InvalidBaseGeometry
1569 : : * - GeometryEngineError
1570 : : * - SplitCannotSplitPoint
1571 : : *
1572 : : * \note Calls to splitFeatures() are only valid for layers in which edits have been enabled
1573 : : * by a call to startEditing(). Changes made to features using this method are not committed
1574 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1575 : : * changes can be discarded by calling rollBack().
1576 : : */
1577 : : Q_INVOKABLE QgsGeometry::OperationResult splitFeatures( const QgsPointSequence &splitLine, bool topologicalEditing = false );
1578 : :
1579 : : /**
1580 : : * Splits features cut by the given curve
1581 : : * \param curve curve that splits the layer features
1582 : : * \param[out] topologyTestPoints topological points to be tested against other layers
1583 : : * \param preserveCircular whether circular strings are preserved after splitting
1584 : : * \param topologicalEditing TRUE if topological editing is enabled
1585 : : * \returns QgsGeometry::OperationResult
1586 : : *
1587 : : * - Success
1588 : : * - NothingHappened
1589 : : * - LayerNotEditable
1590 : : * - InvalidInputGeometryType
1591 : : * - InvalidBaseGeometry
1592 : : * - GeometryEngineError
1593 : : * - SplitCannotSplitPoint
1594 : : *
1595 : : * \note Calls to splitFeatures() are only valid for layers in which edits have been enabled
1596 : : * by a call to startEditing(). Changes made to features using this method are not committed
1597 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1598 : : * changes can be discarded by calling rollBack().
1599 : : * \since QGIS 3.16
1600 : : */
1601 : : Q_INVOKABLE QgsGeometry::OperationResult splitFeatures( const QgsCurve *curve, QgsPointSequence &topologyTestPoints SIP_OUT, bool preserveCircular = false, bool topologicalEditing = false );
1602 : :
1603 : : /**
1604 : : * Adds topological points for every vertex of the geometry.
1605 : : * \param geom the geometry where each vertex is added to segments of other features
1606 : : * \returns 0 in case of success
1607 : : * \note geom is not going to be modified by the function
1608 : : * \note Calls to addTopologicalPoints() are only valid for layers in which edits have been enabled
1609 : : * by a call to startEditing(). Changes made to features using this method are not committed
1610 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1611 : : * changes can be discarded by calling rollBack().
1612 : : */
1613 : : int addTopologicalPoints( const QgsGeometry &geom );
1614 : :
1615 : : /**
1616 : : * Adds a vertex to segments which intersect point \a p but don't
1617 : : * already have a vertex there. If a feature already has a vertex at position \a p,
1618 : : * no additional vertex is inserted. This method is useful for topological
1619 : : * editing.
1620 : : * \param p position of the vertex
1621 : : * \returns 0 in case of success
1622 : : * \note Calls to addTopologicalPoints() are only valid for layers in which edits have been enabled
1623 : : * by a call to startEditing(). Changes made to features using this method are not committed
1624 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1625 : : * changes can be discarded by calling rollBack().
1626 : : * \deprecated since QGIS 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.
1627 : : */
1628 : : Q_DECL_DEPRECATED int addTopologicalPoints( const QgsPointXY &p ) SIP_DEPRECATED;
1629 : :
1630 : : /**
1631 : : * Adds a vertex to segments which intersect point \a p but don't
1632 : : * already have a vertex there. If a feature already has a vertex at position \a p,
1633 : : * no additional vertex is inserted. This method is useful for topological
1634 : : * editing.
1635 : : * \param p position of the vertex
1636 : : * \returns 0 in case of success
1637 : : * \note Calls to addTopologicalPoints() are only valid for layers in which edits have been enabled
1638 : : * by a call to startEditing(). Changes made to features using this method are not committed
1639 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1640 : : * changes can be discarded by calling rollBack().
1641 : : * \since 3.10
1642 : : */
1643 : : int addTopologicalPoints( const QgsPoint &p );
1644 : :
1645 : : /**
1646 : : * Adds a vertex to segments which intersect any of the points \a p but don't
1647 : : * already have a vertex there. If a feature already has a vertex at position \a p,
1648 : : * no additional vertex is inserted. This method is useful for topological
1649 : : * editing.
1650 : : * \param ps point sequence of the vertices
1651 : : * \returns 0 in case of success
1652 : : * \note Calls to addTopologicalPoints() are only valid for layers in which edits have been enabled
1653 : : * by a call to startEditing(). Changes made to features using this method are not committed
1654 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1655 : : * changes can be discarded by calling rollBack().
1656 : : * \since 3.16
1657 : : */
1658 : : int addTopologicalPoints( const QgsPointSequence &ps );
1659 : :
1660 : : /**
1661 : : * Access to const labeling configuration. May be NULLPTR if labeling is not used.
1662 : : * \note Labels will only be rendered if labelsEnabled() returns TRUE.
1663 : : * \see labelsEnabled()
1664 : : * \since QGIS 3.0
1665 : : */
1666 : 0 : const QgsAbstractVectorLayerLabeling *labeling() const SIP_SKIP { return mLabeling; }
1667 : :
1668 : : /**
1669 : : * Access to labeling configuration. May be NULLPTR if labeling is not used.
1670 : : * \note Labels will only be rendered if labelsEnabled() returns TRUE.
1671 : : * \see labelsEnabled()
1672 : : * \since QGIS 3.0
1673 : : */
1674 : 0 : QgsAbstractVectorLayerLabeling *labeling() { return mLabeling; }
1675 : :
1676 : : /**
1677 : : * Sets labeling configuration. Takes ownership of the object.
1678 : : * \since QGIS 3.0
1679 : : */
1680 : : void setLabeling( QgsAbstractVectorLayerLabeling *labeling SIP_TRANSFER );
1681 : :
1682 : : //! Returns TRUE if the provider is in editing mode
1683 : : bool isEditable() const FINAL;
1684 : :
1685 : : //! Returns TRUE if this is a geometry layer and FALSE in case of NoGeometry (table only) or UnknownGeometry
1686 : : bool isSpatial() const FINAL;
1687 : :
1688 : : //! Returns TRUE if the provider has been modified since the last commit
1689 : : virtual bool isModified() const;
1690 : :
1691 : : /**
1692 : : * Returns TRUE if the field comes from the auxiliary layer,
1693 : : * FALSE otherwise.
1694 : : *
1695 : : * \since QGIS 3.0
1696 : : */
1697 : : bool isAuxiliaryField( int index, int &srcIndex ) const;
1698 : :
1699 : : //! Synchronises with changes in the datasource
1700 : : void reload() FINAL;
1701 : :
1702 : : /**
1703 : : * Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context
1704 : : * \since QGIS 2.4
1705 : : */
1706 : : QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) FINAL SIP_FACTORY;
1707 : :
1708 : : QgsRectangle extent() const FINAL;
1709 : : QgsRectangle sourceExtent() const FINAL;
1710 : :
1711 : : /**
1712 : : * Returns the list of fields of this layer.
1713 : : * This also includes fields which have not yet been saved to the provider.
1714 : : *
1715 : : * \returns A list of fields
1716 : : */
1717 : : QgsFields fields() const FINAL;
1718 : :
1719 : : /**
1720 : : * Returns list of attribute indexes. i.e. a list from 0 ... fieldCount()
1721 : : */
1722 : 0 : inline QgsAttributeList attributeList() const { return mFields.allAttributesList(); }
1723 : :
1724 : : /**
1725 : : * Returns the list of attributes which make up the layer's primary keys.
1726 : : */
1727 : : QgsAttributeList primaryKeyAttributes() const;
1728 : :
1729 : : /**
1730 : : * Returns feature count including changes which have not yet been committed
1731 : : * If you need only the count of committed features call this method on this layer's provider.
1732 : : * \returns the number of features on this layer or -1 if unknown.
1733 : : */
1734 : : long featureCount() const FINAL;
1735 : :
1736 : : /**
1737 : : * Makes layer read-only (editing disabled) or not
1738 : : * \returns FALSE if the layer is in editing yet
1739 : : */
1740 : : bool setReadOnly( bool readonly = true );
1741 : :
1742 : : /**
1743 : : * Returns whether the layer supports editing or not
1744 : : * \return FALSE if the layer is read only or the data provider has no editing capabilities
1745 : : * \since QGIS 3.18
1746 : : */
1747 : : bool supportsEditing();
1748 : :
1749 : : /**
1750 : : * Changes a feature's \a geometry within the layer's edit buffer
1751 : : * (but does not immediately commit the changes). The \a fid argument
1752 : : * specifies the ID of the feature to be changed.
1753 : : *
1754 : : * If \a skipDefaultValue is set to TRUE, default field values will not
1755 : : * be updated. This can be used to override default field value expressions.
1756 : : *
1757 : : * \returns TRUE if the feature's geometry was successfully changed.
1758 : : *
1759 : : * \note Calls to changeGeometry() are only valid for layers in which edits have been enabled
1760 : : * by a call to startEditing(). Changes made to features using this method are not committed
1761 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1762 : : * changes can be discarded by calling rollBack().
1763 : : *
1764 : : * \see startEditing()
1765 : : * \see commitChanges()
1766 : : * \see changeAttributeValue()
1767 : : * \see updateFeature()
1768 : : */
1769 : : bool changeGeometry( QgsFeatureId fid, QgsGeometry &geometry, bool skipDefaultValue = false );
1770 : :
1771 : : /**
1772 : : * Changes an attribute value for a feature (but does not immediately commit the changes).
1773 : : * The \a fid argument specifies the ID of the feature to be changed.
1774 : : *
1775 : : * The \a field argument must specify a valid field index for the layer (where an index of 0
1776 : : * corresponds to the first field).
1777 : : *
1778 : : * The new value to be assigned to the field is given by \a newValue.
1779 : : *
1780 : : * If a valid QVariant is specified for \a oldValue, it will be used as the field value in the
1781 : : * case of an undo operation corresponding to this attribute value change. If an invalid
1782 : : * QVariant is used (the default behavior), then the feature's current value will be automatically
1783 : : * retrieved and used. Note that this involves a feature request to the underlying data provider,
1784 : : * so it is more efficient to explicitly pass an \a oldValue if it is already available.
1785 : : *
1786 : : * If \a skipDefaultValues is set to TRUE, default field values will not
1787 : : * be updated. This can be used to override default field value expressions.
1788 : : *
1789 : : * \returns TRUE if the feature's attribute was successfully changed.
1790 : : *
1791 : : * \note Calls to changeAttributeValue() are only valid for layers in which edits have been enabled
1792 : : * by a call to startEditing(). Changes made to features using this method are not committed
1793 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1794 : : * changes can be discarded by calling rollBack().
1795 : : *
1796 : : * \see startEditing()
1797 : : * \see commitChanges()
1798 : : * \see changeGeometry()
1799 : : * \see updateFeature()
1800 : : */
1801 : : bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant(), bool skipDefaultValues = false );
1802 : :
1803 : : /**
1804 : : * Changes attributes' values for a feature (but does not immediately
1805 : : * commit the changes).
1806 : : * The \a fid argument specifies the ID of the feature to be changed.
1807 : : *
1808 : : * The new values to be assigned to the fields are given by \a newValues.
1809 : : *
1810 : : * If a valid QVariant is specified for a field in \a oldValues, it will be
1811 : : * used as the field value in the case of an undo operation corresponding
1812 : : * to this attribute value change. If an invalid QVariant is used (the
1813 : : * default behavior), then the feature's current value will be
1814 : : * automatically retrieved and used. Note that this involves a feature
1815 : : * request to the underlying data provider, so it is more efficient to
1816 : : * explicitly pass an oldValue if it is already available.
1817 : : *
1818 : : * If \a skipDefaultValues is set to TRUE, default field values will not
1819 : : * be updated. This can be used to override default field value
1820 : : * expressions.
1821 : : *
1822 : : * \returns TRUE if feature's attributes was successfully changed.
1823 : : *
1824 : : * \note Calls to changeAttributeValues() are only valid for layers in
1825 : : * which edits have been enabled by a call to startEditing(). Changes made
1826 : : * to features using this method are not committed to the underlying data
1827 : : * provider until a commitChanges() call is made. Any uncommitted changes
1828 : : * can be discarded by calling rollBack().
1829 : : *
1830 : : * \see startEditing()
1831 : : * \see commitChanges()
1832 : : * \see changeGeometry()
1833 : : * \see updateFeature()
1834 : : * \see changeAttributeValue()
1835 : : *
1836 : : * \since QGIS 3.0
1837 : : */
1838 : : bool changeAttributeValues( QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues = QgsAttributeMap(), bool skipDefaultValues = false );
1839 : :
1840 : : /**
1841 : : * Add an attribute field (but does not commit it)
1842 : : * returns TRUE if the field was added
1843 : : *
1844 : : * \note Calls to addAttribute() are only valid for layers in which edits have been enabled
1845 : : * by a call to startEditing(). Changes made to features using this method are not committed
1846 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1847 : : * changes can be discarded by calling rollBack().
1848 : : */
1849 : : bool addAttribute( const QgsField &field );
1850 : :
1851 : : /**
1852 : : * Sets an alias (a display name) for attributes to display in dialogs
1853 : : *
1854 : : * \since QGIS 3.0
1855 : : */
1856 : : void setFieldAlias( int index, const QString &aliasString );
1857 : :
1858 : : /**
1859 : : * Removes an alias (a display name) for attributes to display in dialogs
1860 : : *
1861 : : * \since QGIS 3.0
1862 : : */
1863 : : void removeFieldAlias( int index );
1864 : :
1865 : : /**
1866 : : * Renames an attribute field (but does not commit it).
1867 : : * \param index attribute index
1868 : : * \param newName new name of field
1869 : : * \note Calls to renameAttribute() are only valid for layers in which edits have been enabled
1870 : : * by a call to startEditing(). Changes made to features using this method are not committed
1871 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1872 : : * changes can be discarded by calling rollBack().
1873 : : * \since QGIS 2.16
1874 : : */
1875 : : bool renameAttribute( int index, const QString &newName );
1876 : :
1877 : : /**
1878 : : * Returns the alias of an attribute name or a null string if there is no alias.
1879 : : *
1880 : : * \see {attributeDisplayName( int attributeIndex )} which returns the field name
1881 : : * if no alias is defined.
1882 : : */
1883 : : QString attributeAlias( int index ) const;
1884 : :
1885 : : //! Convenience function that returns the attribute alias if defined or the field name else
1886 : : QString attributeDisplayName( int index ) const;
1887 : :
1888 : : //! Returns a map of field name to attribute alias
1889 : : QgsStringMap attributeAliases() const;
1890 : :
1891 : : /**
1892 : : * A set of attributes that are not advertised in WMS requests with QGIS server.
1893 : : * \deprecated since QGIS 3.16, use fields().configurationFlags() instead
1894 : : */
1895 : : Q_DECL_DEPRECATED QSet<QString> excludeAttributesWms() const SIP_DEPRECATED;
1896 : :
1897 : : /**
1898 : : * A set of attributes that are not advertised in WMS requests with QGIS server.
1899 : : * \deprecated since QGIS 3.16, use setFieldConfigurationFlag instead
1900 : : */
1901 : : Q_DECL_DEPRECATED void setExcludeAttributesWms( const QSet<QString> &att ) SIP_DEPRECATED;
1902 : :
1903 : : /**
1904 : : * A set of attributes that are not advertised in WFS requests with QGIS server.
1905 : : * \deprecated since QGIS 3.16, use fields().configurationFlags() instead
1906 : : */
1907 : : Q_DECL_DEPRECATED QSet<QString> excludeAttributesWfs() const SIP_DEPRECATED;
1908 : :
1909 : : /**
1910 : : * A set of attributes that are not advertised in WFS requests with QGIS server.
1911 : : * \deprecated since QGIS 3.16, use setFieldConfigurationFlag instead
1912 : : */
1913 : : Q_DECL_DEPRECATED void setExcludeAttributesWfs( const QSet<QString> &att ) SIP_DEPRECATED;
1914 : :
1915 : : /**
1916 : : * Deletes an attribute field (but does not commit it).
1917 : : *
1918 : : * \note Calls to deleteAttribute() are only valid for layers in which edits have been enabled
1919 : : * by a call to startEditing(). Changes made to features using this method are not committed
1920 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1921 : : * changes can be discarded by calling rollBack().
1922 : : */
1923 : : virtual bool deleteAttribute( int attr );
1924 : :
1925 : : /**
1926 : : * Deletes a list of attribute fields (but does not commit it)
1927 : : *
1928 : : * \param attrs the indices of the attributes to delete
1929 : : * \returns TRUE if at least one attribute has been deleted
1930 : : *
1931 : : */
1932 : : bool deleteAttributes( const QList<int> &attrs );
1933 : :
1934 : : bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) FINAL;
1935 : :
1936 : : /**
1937 : : * Deletes a feature from the layer (but does not commit it).
1938 : : * \param fid The feature id to delete
1939 : : * \param context The chain of features who will be deleted for feedback and to avoid endless recursions
1940 : : *
1941 : : * \note Calls to deleteFeature() are only valid for layers in which edits have been enabled
1942 : : * by a call to startEditing(). Changes made to features using this method are not committed
1943 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1944 : : * changes can be discarded by calling rollBack().
1945 : : */
1946 : : bool deleteFeature( QgsFeatureId fid, DeleteContext *context = nullptr );
1947 : :
1948 : : /**
1949 : : * Deletes a set of features from the layer (but does not commit it)
1950 : : * \param fids The feature ids to delete
1951 : : * \param context The chain of features who will be deleted for feedback and to avoid endless recursions
1952 : : *
1953 : : * \returns FALSE if the layer is not in edit mode or does not support deleting
1954 : : * in case of an active transaction depends on the provider implementation
1955 : : *
1956 : : * \note Calls to deleteFeatures() are only valid for layers in which edits have been enabled
1957 : : * by a call to startEditing(). Changes made to features using this method are not committed
1958 : : * to the underlying data provider until a commitChanges() call is made. Any uncommitted
1959 : : * changes can be discarded by calling rollBack().
1960 : : */
1961 : : bool deleteFeatures( const QgsFeatureIds &fids, DeleteContext *context = nullptr );
1962 : :
1963 : : /**
1964 : : * Attempts to commit to the underlying data provider any buffered changes made since the
1965 : : * last to call to startEditing().
1966 : : *
1967 : : * Returns the result of the attempt. If a commit fails (i.e. FALSE is returned), the
1968 : : * in-memory changes are left untouched and are not discarded. This allows editing to
1969 : : * continue if the commit failed on e.g. a disallowed value in a Postgres
1970 : : * database - the user can re-edit and try again.
1971 : : *
1972 : : * The commits occur in distinct stages,
1973 : : * (add attributes, add features, change attribute values, change
1974 : : * geometries, delete features, delete attributes)
1975 : : * so if a stage fails, it can be difficult to roll back cleanly.
1976 : : * Therefore any error message returned by commitErrors() also includes which stage failed so
1977 : : * that the user has some chance of repairing the damage cleanly.
1978 : : *
1979 : : * By setting \a stopEditing to FALSE, the layer will stay in editing mode.
1980 : : * Otherwise the layer editing mode will be disabled if the commit is successful.
1981 : : *
1982 : : * \see startEditing()
1983 : : * \see commitErrors()
1984 : : * \see rollBack()
1985 : : */
1986 : : Q_INVOKABLE bool commitChanges( bool stopEditing = true );
1987 : :
1988 : : /**
1989 : : * Returns a list containing any error messages generated when attempting
1990 : : * to commit changes to the layer.
1991 : : * \see commitChanges()
1992 : : */
1993 : : QStringList commitErrors() const;
1994 : :
1995 : : /**
1996 : : * Stops a current editing operation and discards any uncommitted edits.
1997 : : *
1998 : : * If \a deleteBuffer is TRUE the editing buffer will be completely deleted (the default
1999 : : * behavior).
2000 : : *
2001 : : * \see startEditing()
2002 : : * \see commitChanges()
2003 : : */
2004 : : Q_INVOKABLE bool rollBack( bool deleteBuffer = true );
2005 : :
2006 : : /**
2007 : : * Returns the layer's relations, where the foreign key is on this layer.
2008 : : *
2009 : : * \param idx Only get relations, where idx forms part of the foreign key
2010 : : * \returns A list of relations
2011 : : */
2012 : : QList<QgsRelation> referencingRelations( int idx ) const;
2013 : :
2014 : : /**
2015 : : * Returns the layer's weak relations as specified in the layer's style.
2016 : : * \returns A list of weak relations
2017 : : * \note not available in Python bindings
2018 : : * \since QGIS 3.12
2019 : : */
2020 : : QList<QgsWeakRelation> weakRelations( ) const SIP_SKIP;
2021 : :
2022 : :
2023 : : //! Buffer with uncommitted editing operations. Only valid after editing has been turned on.
2024 : 0 : Q_INVOKABLE QgsVectorLayerEditBuffer *editBuffer() { return mEditBuffer; }
2025 : :
2026 : : /**
2027 : : * Buffer with uncommitted editing operations. Only valid after editing has been turned on.
2028 : : * \note not available in Python bindings
2029 : : */
2030 : 223 : const QgsVectorLayerEditBuffer *editBuffer() const SIP_SKIP { return mEditBuffer; }
2031 : :
2032 : : /**
2033 : : * Create edit command for undo/redo operations
2034 : : * \param text text which is to be displayed in undo window
2035 : : */
2036 : : void beginEditCommand( const QString &text );
2037 : :
2038 : : //! Finish edit command and add it to undo/redo stack
2039 : : void endEditCommand();
2040 : :
2041 : : //! Destroy active command and reverts all changes in it
2042 : : void destroyEditCommand();
2043 : :
2044 : : //! Editing vertex markers
2045 : : enum VertexMarkerType
2046 : : {
2047 : : SemiTransparentCircle,
2048 : : Cross,
2049 : : NoMarker
2050 : : };
2051 : :
2052 : : /**
2053 : : * Draws a vertex symbol at (screen) coordinates x, y. (Useful to assist vertex editing.)
2054 : : * \deprecated Use the equivalent QgsSymbolLayerUtils::drawVertexMarker function instead
2055 : : */
2056 : : Q_DECL_DEPRECATED static void drawVertexMarker( double x, double y, QPainter &p, QgsVectorLayer::VertexMarkerType type, int vertexSize );
2057 : :
2058 : : /**
2059 : : * Will regenerate the `fields` property of this layer by obtaining all fields
2060 : : * from the dataProvider, joined fields and virtual fields. It will also
2061 : : * take any changes made to default values into consideration.
2062 : : *
2063 : : * \note Unless the fields on the provider have directly been modified, there is
2064 : : * no reason to call this method.
2065 : : */
2066 : : void updateFields();
2067 : :
2068 : : /**
2069 : : * Returns the calculated default value for the specified field index. The default
2070 : : * value may be taken from a client side default value expression (see setDefaultValueDefinition())
2071 : : * or taken from the underlying data provider.
2072 : : * \param index field index
2073 : : * \param feature optional feature to use for default value evaluation. If passed,
2074 : : * then properties from the feature (such as geometry) can be used when calculating
2075 : : * the default value.
2076 : : * \param context optional expression context to evaluate expressions again. If not
2077 : : * specified, a default context will be created
2078 : : * \returns calculated default value
2079 : : * \see setDefaultValueDefinition()
2080 : : * \since QGIS 3.0
2081 : : */
2082 : : QVariant defaultValue( int index, const QgsFeature &feature = QgsFeature(),
2083 : : QgsExpressionContext *context = nullptr ) const;
2084 : :
2085 : : /**
2086 : : * Sets the definition of the expression to use when calculating the default value for a field.
2087 : : * \param index field index
2088 : : * \param definition default value definition to use and evaluate
2089 : : * when calculating default values for field. Pass
2090 : : * an empty expression to clear the default.
2091 : : *
2092 : : * \see defaultValue()
2093 : : * \see defaultValueDefinition()
2094 : : * \since QGIS 3.0
2095 : : */
2096 : : void setDefaultValueDefinition( int index, const QgsDefaultValue &definition );
2097 : :
2098 : : /**
2099 : : * Returns the definition of the expression used when calculating the default value for a field.
2100 : : * \param index field index
2101 : : * \returns definition of the default value with the expression evaluated
2102 : : * when calculating default values for field, or definition with an
2103 : : * empty string if no default is set
2104 : : * \see defaultValue()
2105 : : * \see setDefaultValueDefinition()
2106 : : * \since QGIS 3.0
2107 : : */
2108 : : QgsDefaultValue defaultValueDefinition( int index ) const;
2109 : :
2110 : : /**
2111 : : * Returns any constraints which are present for a specified
2112 : : * field index. These constraints may be inherited from the layer's data provider
2113 : : * or may be set manually on the vector layer from within QGIS.
2114 : : * \see setFieldConstraint()
2115 : : * \since QGIS 3.0
2116 : : */
2117 : : QgsFieldConstraints::Constraints fieldConstraints( int fieldIndex ) const;
2118 : :
2119 : : /**
2120 : : * Returns a map of constraint with their strength for a specific field of the layer.
2121 : : * \param fieldIndex field index
2122 : : * \since QGIS 3.0
2123 : : */
2124 : : QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength> fieldConstraintsAndStrength( int fieldIndex ) const;
2125 : :
2126 : : /**
2127 : : * Sets a constraint for a specified field index. Any constraints inherited from the layer's
2128 : : * data provider will be kept intact and cannot be modified. Ie, calling this method only allows for new
2129 : : * constraints to be added on top of the existing provider constraints.
2130 : : * \see fieldConstraints()
2131 : : * \see removeFieldConstraint()
2132 : : * \since QGIS 3.0
2133 : : */
2134 : : void setFieldConstraint( int index, QgsFieldConstraints::Constraint constraint, QgsFieldConstraints::ConstraintStrength strength = QgsFieldConstraints::ConstraintStrengthHard );
2135 : :
2136 : : /**
2137 : : * Removes a constraint for a specified field index. Any constraints inherited from the layer's
2138 : : * data provider will be kept intact and cannot be removed.
2139 : : * \see fieldConstraints()
2140 : : * \see setFieldConstraint()
2141 : : * \since QGIS 3.0
2142 : : */
2143 : : void removeFieldConstraint( int index, QgsFieldConstraints::Constraint constraint );
2144 : :
2145 : : /**
2146 : : * Returns the constraint expression for for a specified field index, if set.
2147 : : * \see fieldConstraints()
2148 : : * \see constraintDescription()
2149 : : * \see setConstraintExpression()
2150 : : * \since QGIS 3.0
2151 : : */
2152 : : QString constraintExpression( int index ) const;
2153 : :
2154 : : /**
2155 : : * Returns the descriptive name for the constraint expression for a specified field index.
2156 : : * \see fieldConstraints()
2157 : : * \see constraintExpression()
2158 : : * \see setConstraintExpression()
2159 : : * \since QGIS 3.0
2160 : : */
2161 : : QString constraintDescription( int index ) const;
2162 : :
2163 : : /**
2164 : : * Sets the constraint expression for the specified field index. An optional descriptive name for the constraint
2165 : : * can also be set. Setting an empty expression will clear any existing expression constraint.
2166 : : * \see constraintExpression()
2167 : : * \see constraintDescription()
2168 : : * \see fieldConstraints()
2169 : : * \since QGIS 3.0
2170 : : */
2171 : : void setConstraintExpression( int index, const QString &expression, const QString &description = QString() );
2172 : :
2173 : : /**
2174 : : * Sets the configuration flags of the field at given index
2175 : : * \see QgsField::ConfigurationFlag
2176 : : * \since QGIS 3.16
2177 : : */
2178 : : void setFieldConfigurationFlags( int index, QgsField::ConfigurationFlags flags ) SIP_SKIP;
2179 : :
2180 : : /**
2181 : : * Sets the given configuration \a flag for the field at given \a index to be \a active or not.
2182 : : * \since QGIS 3.16
2183 : : */
2184 : : void setFieldConfigurationFlag( int index, QgsField::ConfigurationFlag flag, bool active ) SIP_SKIP;
2185 : :
2186 : : /**
2187 : : * Returns the configuration flags of the field at given index
2188 : : * \see QgsField::ConfigurationFlag
2189 : : * \since QGIS 3.16
2190 : : */
2191 : : QgsField::ConfigurationFlags fieldConfigurationFlags( int index ) const SIP_SKIP;
2192 : :
2193 : : /**
2194 : : * \copydoc editorWidgetSetup
2195 : : */
2196 : : void setEditorWidgetSetup( int index, const QgsEditorWidgetSetup &setup );
2197 : :
2198 : : /**
2199 : : * The editor widget setup defines which QgsFieldFormatter and editor widget will be used
2200 : : * for the field at `index`.
2201 : : *
2202 : : * \since QGIS 3.0
2203 : : */
2204 : : QgsEditorWidgetSetup editorWidgetSetup( int index ) const;
2205 : :
2206 : : /**
2207 : : * Calculates a list of unique values contained within an attribute in the layer. Note that
2208 : : * in some circumstances when unsaved changes are present for the layer then the returned list
2209 : : * may contain outdated values (for instance when the attribute value in a saved feature has
2210 : : * been changed inside the edit buffer then the previous saved value will be included in the
2211 : : * returned list).
2212 : : * \param fieldIndex column index for attribute
2213 : : * \param limit maximum number of values to return (or -1 if unlimited)
2214 : : * \see minimumValue()
2215 : : * \see maximumValue()
2216 : : */
2217 : : QSet<QVariant> uniqueValues( int fieldIndex, int limit = -1 ) const FINAL;
2218 : :
2219 : : /**
2220 : : * Returns unique string values of an attribute which contain a specified subset string. Subset
2221 : : * matching is done in a case-insensitive manner. Note that
2222 : : * in some circumstances when unsaved changes are present for the layer then the returned list
2223 : : * may contain outdated values (for instance when the attribute value in a saved feature has
2224 : : * been changed inside the edit buffer then the previous saved value will be included in the
2225 : : * returned list).
2226 : : * \param index column index for attribute
2227 : : * \param substring substring to match (case insensitive)
2228 : : * \param limit maxmum number of the values to return, or -1 to return all unique values
2229 : : * \param feedback optional feedback object for canceling request
2230 : : * \returns list of unique strings containing substring
2231 : : */
2232 : : QStringList uniqueStringsMatching( int index, const QString &substring, int limit = -1,
2233 : : QgsFeedback *feedback = nullptr ) const;
2234 : :
2235 : : /**
2236 : : * Returns the minimum value for an attribute column or an invalid variant in case of error.
2237 : : * Note that in some circumstances when unsaved changes are present for the layer then the
2238 : : * returned value may be outdated (for instance when the attribute value in a saved feature has
2239 : : * been changed inside the edit buffer then the previous saved value may be returned as the minimum).
2240 : : * \see maximumValue()
2241 : : * \see uniqueValues()
2242 : : */
2243 : : QVariant minimumValue( int index ) const FINAL;
2244 : :
2245 : : /**
2246 : : * Returns the maximum value for an attribute column or an invalid variant in case of error.
2247 : : * Note that in some circumstances when unsaved changes are present for the layer then the
2248 : : * returned value may be outdated (for instance when the attribute value in a saved feature has
2249 : : * been changed inside the edit buffer then the previous saved value may be returned as the maximum).
2250 : : * \see minimumValue()
2251 : : * \see uniqueValues()
2252 : : */
2253 : : QVariant maximumValue( int index ) const FINAL;
2254 : :
2255 : : /**
2256 : : * Calculates an aggregated value from the layer's features.
2257 : : * Currently any filtering expression provided will override filters in the FeatureRequest.
2258 : : * \param aggregate aggregate to calculate
2259 : : * \param fieldOrExpression source field or expression to use as basis for aggregated values.
2260 : : * \param parameters parameters controlling aggregate calculation
2261 : : * \param context expression context for expressions and filters
2262 : : * \param ok if specified, will be set to TRUE if aggregate calculation was successful
2263 : : * \param fids list of fids to filter, otherwise will use all fids
2264 : : * \returns calculated aggregate value
2265 : : * \since QGIS 2.16
2266 : : */
2267 : : QVariant aggregate( QgsAggregateCalculator::Aggregate aggregate,
2268 : : const QString &fieldOrExpression,
2269 : : const QgsAggregateCalculator::AggregateParameters ¶meters = QgsAggregateCalculator::AggregateParameters(),
2270 : : QgsExpressionContext *context = nullptr,
2271 : : bool *ok = nullptr,
2272 : : QgsFeatureIds *fids = nullptr ) const;
2273 : :
2274 : : //! Sets the blending mode used for rendering each feature
2275 : : void setFeatureBlendMode( QPainter::CompositionMode blendMode );
2276 : : //! Returns the current blending mode for features
2277 : : QPainter::CompositionMode featureBlendMode() const;
2278 : :
2279 : : QString htmlMetadata() const FINAL;
2280 : :
2281 : : /**
2282 : : * Sets the simplification settings for fast rendering of features
2283 : : * \since QGIS 2.2
2284 : : */
2285 : 0 : void setSimplifyMethod( const QgsVectorSimplifyMethod &simplifyMethod ) { mSimplifyMethod = simplifyMethod; }
2286 : :
2287 : : /**
2288 : : * Returns the simplification settings for fast rendering of features
2289 : : * \since QGIS 2.2
2290 : : */
2291 : 0 : inline const QgsVectorSimplifyMethod &simplifyMethod() const { return mSimplifyMethod; }
2292 : :
2293 : : /**
2294 : : * Returns whether the VectorLayer can apply the specified simplification hint
2295 : : * \note Do not use in 3rd party code - may be removed in future version!
2296 : : * \since QGIS 2.2
2297 : : */
2298 : : bool simplifyDrawingCanbeApplied( const QgsRenderContext &renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint ) const;
2299 : :
2300 : : /**
2301 : : * Returns the conditional styles that are set for this layer. Style information is
2302 : : * used to render conditional formatting in the attribute table.
2303 : : * \returns Return a QgsConditionalLayerStyles object holding the conditional attribute
2304 : : * style information. Style information is generic and can be used for anything.
2305 : : * \since QGIS 2.12
2306 : : */
2307 : : QgsConditionalLayerStyles *conditionalStyles() const;
2308 : :
2309 : : /**
2310 : : * Returns the attribute table configuration object.
2311 : : * This defines the appearance of the attribute table.
2312 : : */
2313 : : QgsAttributeTableConfig attributeTableConfig() const;
2314 : :
2315 : : /**
2316 : : * Sets the attribute table configuration object.
2317 : : * This defines the appearance of the attribute table.
2318 : : */
2319 : : void setAttributeTableConfig( const QgsAttributeTableConfig &attributeTableConfig );
2320 : :
2321 : : /**
2322 : : * The mapTip is a pretty, html representation for feature information.
2323 : : *
2324 : : * It may also contain embedded expressions.
2325 : : *
2326 : : * \since QGIS 3.0
2327 : : */
2328 : : QString mapTipTemplate() const;
2329 : :
2330 : : /**
2331 : : * The mapTip is a pretty, html representation for feature information.
2332 : : *
2333 : : * It may also contain embedded expressions.
2334 : : *
2335 : : * \since QGIS 3.0
2336 : : */
2337 : : void setMapTipTemplate( const QString &mapTipTemplate );
2338 : :
2339 : : QgsExpressionContext createExpressionContext() const FINAL;
2340 : :
2341 : : QgsExpressionContextScope *createExpressionContextScope() const FINAL SIP_FACTORY;
2342 : :
2343 : : /**
2344 : : * Returns the configuration of the form used to represent this vector layer.
2345 : : *
2346 : : * \returns The configuration of this layers' form
2347 : : *
2348 : : * \since QGIS 2.14
2349 : : */
2350 : : QgsEditFormConfig editFormConfig() const;
2351 : :
2352 : : /**
2353 : : * Sets the \a editFormConfig (configuration) of the form used to represent this vector layer.
2354 : : *
2355 : : * \see editFormConfig()
2356 : : * \since QGIS 3.0
2357 : : */
2358 : : void setEditFormConfig( const QgsEditFormConfig &editFormConfig );
2359 : :
2360 : : /**
2361 : : * Flag allowing to indicate if the extent has to be read from the XML
2362 : : * document when data source has no metadata or if the data provider has
2363 : : * to determine it.
2364 : : *
2365 : : * \since QGIS 3.0
2366 : : */
2367 : : void setReadExtentFromXml( bool readExtentFromXml );
2368 : :
2369 : : /**
2370 : : * Returns TRUE if the extent is read from the XML document when data
2371 : : * source has no metadata, FALSE if it's the data provider which determines
2372 : : * it.
2373 : : *
2374 : : * \since QGIS 3.0
2375 : : */
2376 : : bool readExtentFromXml() const;
2377 : :
2378 : : /**
2379 : : * Tests if an edit command is active
2380 : : *
2381 : : * \since QGIS 3.0
2382 : : */
2383 : 0 : bool isEditCommandActive() const { return mEditCommandActive; }
2384 : :
2385 : : /**
2386 : : * Configuration and logic to apply automatically on any edit happening on this layer.
2387 : : *
2388 : : * \since QGIS 3.4
2389 : : */
2390 : : QgsGeometryOptions *geometryOptions() const;
2391 : :
2392 : : /**
2393 : : * Controls, if the layer is allowed to commit changes. If this is set to FALSE
2394 : : * it will not be possible to commit changes on this layer. This can be used to
2395 : : * define checks on a layer that need to be pass before the layer can be saved.
2396 : : * If you use this API, make sure that:
2397 : : *
2398 : : * - the user is visibly informed that his changes were not saved and what he needs
2399 : : * to do in order to be able to save the changes.
2400 : : * - to set the property back to TRUE, once the user has fixed his data.
2401 : : *
2402 : : * When calling \see commitChanges() this flag is checked just after the
2403 : : * \see beforeCommitChanges() signal is emitted, so it's possible to adjust it from there.
2404 : : *
2405 : : * \note Not available in Python bindings
2406 : : *
2407 : : * \since QGIS 3.4
2408 : : */
2409 : : bool allowCommit() const SIP_SKIP;
2410 : :
2411 : : /**
2412 : : * Controls, if the layer is allowed to commit changes. If this is set to FALSE
2413 : : * it will not be possible to commit changes on this layer. This can be used to
2414 : : * define checks on a layer that need to be pass before the layer can be saved.
2415 : : * If you use this API, make sure that:
2416 : : *
2417 : : * - the user is visibly informed that his changes were not saved and what he needs
2418 : : * to do in order to be able to save the changes.
2419 : : * - to set the property back to TRUE, once the user has fixed his data.
2420 : : *
2421 : : * When calling \see commitChanges() this flag is checked just after the
2422 : : * \see beforeCommitChanges() signal is emitted, so it's possible to adjust it from there.
2423 : : *
2424 : : * \note Not available in Python bindings
2425 : : *
2426 : : * \since QGIS 3.4
2427 : : */
2428 : : void setAllowCommit( bool allowCommit ) SIP_SKIP;
2429 : :
2430 : : /**
2431 : : * Returns the manager of the stored expressions for this layer.
2432 : : *
2433 : : * \since QGIS 3.10
2434 : : */
2435 : : QgsStoredExpressionManager *storedExpressionManager() { return mStoredExpressionManager; }
2436 : :
2437 : : public slots:
2438 : :
2439 : : /**
2440 : : * Selects feature by its ID
2441 : : *
2442 : : * \param featureId The id of the feature to select
2443 : : *
2444 : : * \see select( const QgsFeatureIds& )
2445 : : */
2446 : : void select( QgsFeatureId featureId );
2447 : :
2448 : : /**
2449 : : * Selects features by their ID
2450 : : *
2451 : : * \param featureIds The ids of the features to select
2452 : : *
2453 : : * \see select(QgsFeatureId)
2454 : : */
2455 : : Q_INVOKABLE void select( const QgsFeatureIds &featureIds );
2456 : :
2457 : : /**
2458 : : * Deselects feature by its ID
2459 : : *
2460 : : * \param featureId The id of the feature to deselect
2461 : : *
2462 : : * \see deselect(const QgsFeatureIds&)
2463 : : */
2464 : : void deselect( QgsFeatureId featureId );
2465 : :
2466 : : /**
2467 : : * Deselects features by their ID
2468 : : *
2469 : : * \param featureIds The ids of the features to deselect
2470 : : *
2471 : : * \see deselect(const QgsFeatureId)
2472 : : */
2473 : : Q_INVOKABLE void deselect( const QgsFeatureIds &featureIds );
2474 : :
2475 : : /**
2476 : : * Clear selection
2477 : : *
2478 : : * \see selectByIds()
2479 : : * \see reselect()
2480 : : */
2481 : : Q_INVOKABLE void removeSelection();
2482 : :
2483 : : /**
2484 : : * Reselects the previous set of selected features. This is only applicable
2485 : : * after a prior call to removeSelection().
2486 : : *
2487 : : * Any other modifications to the selection following a call to removeSelection() clears
2488 : : * memory of the previous selection and consequently calling reselect() has no impact.
2489 : : *
2490 : : * \see removeSelection()
2491 : : * \since QGIS 3.10
2492 : : */
2493 : : void reselect();
2494 : :
2495 : : /**
2496 : : * Update the extents for the layer. This is necessary if features are
2497 : : * added/deleted or the layer has been subsetted.
2498 : : *
2499 : : * \param force TRUE to update layer extent even if it's read from xml by default, FALSE otherwise
2500 : : */
2501 : : virtual void updateExtents( bool force = false );
2502 : :
2503 : : /**
2504 : : * Makes the layer editable.
2505 : : *
2506 : : * This starts an edit session on this layer. Changes made in this edit session will not
2507 : : * be made persistent until commitChanges() is called, and can be reverted by calling
2508 : : * rollBack().
2509 : : *
2510 : : * \returns TRUE if the layer was successfully made editable, or FALSE if the operation
2511 : : * failed (e.g. due to an underlying read-only data source, or lack of edit support
2512 : : * by the backend data provider).
2513 : : *
2514 : : * \see commitChanges()
2515 : : * \see rollBack()
2516 : : */
2517 : : Q_INVOKABLE bool startEditing();
2518 : :
2519 : : /**
2520 : : * Sets the coordinate transform context to \a transformContext
2521 : : *
2522 : : * \since QGIS 3.8
2523 : : */
2524 : : virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
2525 : :
2526 : : SpatialIndexPresence hasSpatialIndex() const override;
2527 : :
2528 : : bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
2529 : :
2530 : : signals:
2531 : :
2532 : : /**
2533 : : * Emitted when selection was changed
2534 : : *
2535 : : * \param selected Newly selected feature ids
2536 : : * \param deselected Ids of all features which have previously been selected but are not any more
2537 : : * \param clearAndSelect In case this is set to TRUE, the old selection was dismissed and the new selection corresponds to selected
2538 : : */
2539 : : void selectionChanged( const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect );
2540 : :
2541 : : //! Emitted when modifications has been done on layer
2542 : : void layerModified();
2543 : :
2544 : : /**
2545 : : * Emitted whenever the allowCommitChanged() property of this layer changes.
2546 : : *
2547 : : * \since QGIS 3.4
2548 : : */
2549 : : void allowCommitChanged();
2550 : :
2551 : : //! Emitted when the layer is checked for modifications. Use for last-minute additions.
2552 : : void beforeModifiedCheck() const;
2553 : :
2554 : : //! Emitted before editing on this layer is started.
2555 : : void beforeEditingStarted();
2556 : :
2557 : : //! Emitted when editing on this layer has started.
2558 : : void editingStarted();
2559 : :
2560 : : //! Emitted when edited changes have been successfully written to the data provider.
2561 : : void editingStopped();
2562 : :
2563 : : /**
2564 : : * Emitted before changes are committed to the data provider.
2565 : : *
2566 : : * The \a stopEditing flag specifies if the editing mode shall be left after this commit.
2567 : : */
2568 : : void beforeCommitChanges( bool stopEditing );
2569 : :
2570 : : //! Emitted before changes are rolled back.
2571 : : void beforeRollBack();
2572 : :
2573 : : /**
2574 : : * Emitted after changes are committed to the data provider.
2575 : : * \since QGIS 3.16
2576 : : */
2577 : : void afterCommitChanges();
2578 : :
2579 : : /**
2580 : : * Emitted after changes are rolled back.
2581 : : * \since QGIS 3.4
2582 : : */
2583 : : void afterRollBack();
2584 : :
2585 : : /**
2586 : : * Will be emitted, when a new attribute has been added to this vector layer.
2587 : : * Applies only to types QgsFields::OriginEdit, QgsFields::OriginProvider and QgsFields::OriginExpression
2588 : : *
2589 : : * \param idx The index of the new attribute
2590 : : *
2591 : : * \see updatedFields()
2592 : : */
2593 : : void attributeAdded( int idx );
2594 : :
2595 : : /**
2596 : : * Will be emitted, when an expression field is going to be added to this vector layer.
2597 : : * Applies only to types QgsFields::OriginExpression
2598 : : *
2599 : : * \param fieldName The name of the attribute to be added
2600 : : */
2601 : : void beforeAddingExpressionField( const QString &fieldName );
2602 : :
2603 : : /**
2604 : : * Will be emitted, when an attribute has been deleted from this vector layer.
2605 : : * Applies only to types QgsFields::OriginEdit, QgsFields::OriginProvider and QgsFields::OriginExpression
2606 : : *
2607 : : * \param idx The index of the deleted attribute
2608 : : *
2609 : : * \see updatedFields()
2610 : : */
2611 : : void attributeDeleted( int idx );
2612 : :
2613 : : /**
2614 : : * Will be emitted, when an expression field is going to be deleted from this vector layer.
2615 : : * Applies only to types QgsFields::OriginExpression
2616 : : *
2617 : : * \param idx The index of the attribute to be deleted
2618 : : */
2619 : : void beforeRemovingExpressionField( int idx );
2620 : :
2621 : : /**
2622 : : * Emitted when a new feature has been added to the layer
2623 : : *
2624 : : * \param fid The id of the new feature
2625 : : */
2626 : : void featureAdded( QgsFeatureId fid );
2627 : :
2628 : : /**
2629 : : * Emitted when a feature has been deleted.
2630 : : *
2631 : : * If you do expensive operations in a slot connected to this, you should prefer to use
2632 : : * featuresDeleted( const QgsFeatureIds& ).
2633 : : *
2634 : : * \param fid The id of the feature which has been deleted
2635 : : */
2636 : : void featureDeleted( QgsFeatureId fid );
2637 : :
2638 : : /**
2639 : : * Emitted when features have been deleted.
2640 : : *
2641 : : * If features are deleted within an edit command, this will only be emitted once at the end
2642 : : * to allow connected slots to minimize the overhead.
2643 : : * If features are deleted outside of an edit command, this signal will be emitted once per feature.
2644 : : *
2645 : : * \param fids The feature ids that have been deleted.
2646 : : */
2647 : : void featuresDeleted( const QgsFeatureIds &fids );
2648 : :
2649 : : /**
2650 : : * Emitted whenever the fields available from this layer have been changed.
2651 : : * This can be due to manually adding attributes or due to a join.
2652 : : */
2653 : : void updatedFields();
2654 : :
2655 : : /**
2656 : : * Emitted when the layer's subset string has changed.
2657 : : * \since QGIS 3.2
2658 : : */
2659 : : void subsetStringChanged();
2660 : :
2661 : : /**
2662 : : * Emitted whenever an attribute value change is done in the edit buffer.
2663 : : * Note that at this point the attribute change is not yet saved to the provider.
2664 : : *
2665 : : * \param fid The id of the changed feature
2666 : : * \param idx The attribute index of the changed attribute
2667 : : * \param value The new value of the attribute
2668 : : */
2669 : : void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );
2670 : :
2671 : : /**
2672 : : * Emitted whenever a geometry change is done in the edit buffer.
2673 : : * Note that at this point the geometry change is not yet saved to the provider.
2674 : : *
2675 : : * \param fid The id of the changed feature
2676 : : * \param geometry The new geometry
2677 : : */
2678 : : void geometryChanged( QgsFeatureId fid, const QgsGeometry &geometry );
2679 : :
2680 : : //! Emitted when attributes are deleted from the provider
2681 : : void committedAttributesDeleted( const QString &layerId, const QgsAttributeList &deletedAttributes );
2682 : : //! Emitted when attributes are added to the provider
2683 : : void committedAttributesAdded( const QString &layerId, const QList<QgsField> &addedAttributes );
2684 : : //! Emitted when features are added to the provider
2685 : : void committedFeaturesAdded( const QString &layerId, const QgsFeatureList &addedFeatures );
2686 : : //! Emitted when features are deleted from the provider
2687 : : void committedFeaturesRemoved( const QString &layerId, const QgsFeatureIds &deletedFeatureIds );
2688 : : //! Emitted when attribute value changes are saved to the provider
2689 : : void committedAttributeValuesChanges( const QString &layerId, const QgsChangedAttributesMap &changedAttributesValues );
2690 : : //! Emitted when geometry changes are saved to the provider
2691 : : void committedGeometriesChanges( const QString &layerId, const QgsGeometryMap &changedGeometries );
2692 : :
2693 : : //! Emitted when the font family defined for labeling layer is not found on system
2694 : : void labelingFontNotFound( QgsVectorLayer *layer, const QString &fontfamily );
2695 : :
2696 : : //! Signal emitted when setFeatureBlendMode() is called
2697 : : void featureBlendModeChanged( QPainter::CompositionMode blendMode );
2698 : :
2699 : : /**
2700 : : * Signal emitted when a new edit command has been started
2701 : : *
2702 : : * \param text Description for this edit command
2703 : : */
2704 : : void editCommandStarted( const QString &text );
2705 : :
2706 : : /**
2707 : : * Signal emitted, when an edit command successfully ended
2708 : : * \note This does not mean it is also committed, only that it is written
2709 : : * to the edit buffer. See beforeCommitChanges()
2710 : : */
2711 : : void editCommandEnded();
2712 : :
2713 : : /**
2714 : : * Signal emitted, when an edit command is destroyed
2715 : : * \note This is not a rollback, it is only related to the current edit command.
2716 : : * See beforeRollBack()
2717 : : */
2718 : : void editCommandDestroyed();
2719 : :
2720 : : /**
2721 : : * Signal emitted whenever the symbology (QML-file) for this layer is being read.
2722 : : * If there is custom style information saved in the file, you can connect to this signal
2723 : : * and update the layer style accordingly.
2724 : : *
2725 : : * \param element The XML layer style element.
2726 : : *
2727 : : * \param errorMessage Write error messages into this string.
2728 : : */
2729 : : void readCustomSymbology( const QDomElement &element, QString &errorMessage );
2730 : :
2731 : : /**
2732 : : * Signal emitted whenever the symbology (QML-file) for this layer is being written.
2733 : : * If there is custom style information you want to save to the file, you can connect
2734 : : * to this signal and update the element accordingly.
2735 : : *
2736 : : * \param element The XML element where you can add additional style information to.
2737 : : * \param doc The XML document that you can use to create new XML nodes.
2738 : : * \param errorMessage Write error messages into this string.
2739 : : */
2740 : : void writeCustomSymbology( QDomElement &element, QDomDocument &doc, QString &errorMessage ) const;
2741 : :
2742 : : /**
2743 : : * Emitted when the map tip changes
2744 : : *
2745 : : * \since QGIS 3.0
2746 : : */
2747 : : void mapTipTemplateChanged();
2748 : :
2749 : : /**
2750 : : * Emitted when the display expression changes
2751 : : *
2752 : : * \since QGIS 3.0
2753 : : */
2754 : : void displayExpressionChanged();
2755 : :
2756 : : /**
2757 : : * Signals an error related to this vector layer.
2758 : : */
2759 : : void raiseError( const QString &msg );
2760 : :
2761 : : /**
2762 : : * Will be emitted whenever the edit form configuration of this layer changes.
2763 : : *
2764 : : * \since QGIS 3.0
2765 : : */
2766 : : void editFormConfigChanged();
2767 : :
2768 : : /**
2769 : : * Emitted when the read only state of this layer is changed.
2770 : : * Only applies to manually set readonly state, not to the edit mode.
2771 : : *
2772 : : * \since QGIS 3.0
2773 : : */
2774 : : void readOnlyChanged();
2775 : :
2776 : : /**
2777 : : * Emitted when the read only state or the data provider of this layer is changed.
2778 : : *
2779 : : * \since QGIS 3.18
2780 : : */
2781 : : void supportsEditingChanged();
2782 : :
2783 : : /**
2784 : : * Emitted when the feature count for symbols on this layer has been recalculated.
2785 : : *
2786 : : * \since QGIS 3.0
2787 : : */
2788 : : void symbolFeatureCountMapChanged();
2789 : :
2790 : : protected:
2791 : : //! Sets the extent
2792 : : void setExtent( const QgsRectangle &rect ) FINAL;
2793 : :
2794 : : private slots:
2795 : : void invalidateSymbolCountedFlag();
2796 : : void onFeatureCounterCompleted();
2797 : : void onFeatureCounterTerminated();
2798 : : void onJoinedFieldsChanged();
2799 : : void onFeatureDeleted( QgsFeatureId fid );
2800 : : void onRelationsLoaded();
2801 : : void onSymbolsCounted();
2802 : : void onDirtyTransaction( const QString &sql, const QString &name );
2803 : : void emitDataChanged();
2804 : : void onAfterCommitChangesDependency();
2805 : :
2806 : : private:
2807 : : void updateDefaultValues( QgsFeatureId fid, QgsFeature feature = QgsFeature() );
2808 : :
2809 : : /**
2810 : : * Returns TRUE if the provider is in read-only mode
2811 : : */
2812 : : bool isReadOnly() const FINAL;
2813 : :
2814 : : /**
2815 : : * Bind layer to a specific data provider
2816 : : * \param provider provider key string, must match a valid QgsVectorDataProvider key. E.g. "postgres", "ogr", etc.
2817 : : * \param options provider options
2818 : : * \param flags provider flags, since QGIS 3.16
2819 : : */
2820 : : bool setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
2821 : :
2822 : : //! Read labeling from SLD
2823 : : void readSldLabeling( const QDomNode &node );
2824 : :
2825 : : //! Read settings from SLD TextSymbolizer element
2826 : : bool readSldTextSymbolizer( const QDomNode &node, QgsPalLayerSettings &settings ) const;
2827 : :
2828 : : //! Read simple labeling from layer's custom properties (QGIS 2.x projects)
2829 : : QgsAbstractVectorLayerLabeling *readLabelingFromCustomProperties();
2830 : :
2831 : : bool deleteFeatureCascade( QgsFeatureId fid, DeleteContext *context = nullptr );
2832 : :
2833 : : #ifdef SIP_RUN
2834 : : QgsVectorLayer( const QgsVectorLayer &rhs );
2835 : : #endif
2836 : : //! Returns the minimum or maximum value
2837 : : QVariant minimumOrMaximumValue( int index, bool minimum ) const;
2838 : :
2839 : : private: // Private attributes
2840 : : QgsConditionalLayerStyles *mConditionalStyles = nullptr;
2841 : :
2842 : : //! Pointer to data provider derived from the abastract base class QgsDataProvider
2843 : : QgsVectorDataProvider *mDataProvider = nullptr;
2844 : :
2845 : : //! Pointer to temporal properties
2846 : : QgsVectorLayerTemporalProperties *mTemporalProperties = nullptr;
2847 : :
2848 : : //! The preview expression used to generate a human readable preview string for features
2849 : : QString mDisplayExpression;
2850 : :
2851 : : QString mMapTipTemplate;
2852 : :
2853 : : //! The user-defined actions that are accessed from the Identify Results dialog box
2854 : : QgsActionManager *mActions = nullptr;
2855 : :
2856 : : //! Flag indicating whether the layer is in read-only mode (editing disabled) or not
2857 : : bool mReadOnly = false;
2858 : :
2859 : : /**
2860 : : * Set holding the feature IDs that are activated. Note that if a feature
2861 : : subsequently gets deleted (i.e. by its addition to mDeletedFeatureIds),
2862 : : it always needs to be removed from mSelectedFeatureIds as well.
2863 : : */
2864 : : QgsFeatureIds mSelectedFeatureIds;
2865 : :
2866 : : /**
2867 : : * Stores the previous set of selected features, to allow for "reselect" operations.
2868 : : */
2869 : : QgsFeatureIds mPreviousSelectedFeatureIds;
2870 : :
2871 : : //! Field map to commit
2872 : : QgsFields mFields;
2873 : :
2874 : : //! Map that stores the aliases for attributes. Key is the attribute name and value the alias for that attribute
2875 : : QgsStringMap mAttributeAliasMap;
2876 : :
2877 : : //! Map which stores default value expressions for fields
2878 : : QMap<QString, QgsDefaultValue> mDefaultExpressionMap;
2879 : :
2880 : : //! An internal structure to keep track of fields that have a defaultValueOnUpdate
2881 : : QSet<int> mDefaultValueOnUpdateFields;
2882 : :
2883 : : //! Map which stores constraints for fields
2884 : : QMap< QString, QgsFieldConstraints::Constraints > mFieldConstraints;
2885 : :
2886 : : //! Map which stores constraint strength for fields
2887 : : QMap< QPair< QString, QgsFieldConstraints::Constraint >, QgsFieldConstraints::ConstraintStrength > mFieldConstraintStrength;
2888 : :
2889 : : //! Map which stores expression constraints for fields. Value is a pair of expression/description.
2890 : : QMap< QString, QPair< QString, QString > > mFieldConstraintExpressions;
2891 : :
2892 : : QMap< QString, QgsField::ConfigurationFlags > mFieldConfigurationFlags;
2893 : : QMap< QString, QgsEditorWidgetSetup > mFieldWidgetSetups;
2894 : :
2895 : : //! Holds the configuration for the edit form
2896 : : QgsEditFormConfig mEditFormConfig;
2897 : :
2898 : : //! Geometry type as defined in enum WkbType (qgis.h)
2899 : : QgsWkbTypes::Type mWkbType = QgsWkbTypes::Unknown;
2900 : :
2901 : : //! Renderer object which holds the information about how to display the features
2902 : : QgsFeatureRenderer *mRenderer = nullptr;
2903 : :
2904 : : //! Simplification object which holds the information about how to simplify the features for fast rendering
2905 : : QgsVectorSimplifyMethod mSimplifyMethod;
2906 : :
2907 : : //! Labeling configuration
2908 : : QgsAbstractVectorLayerLabeling *mLabeling = nullptr;
2909 : :
2910 : : //! True if labels are enabled
2911 : : bool mLabelsEnabled = false;
2912 : :
2913 : : //! Whether 'labeling font not found' has be shown for this layer (only show once in QgsMessageBar, on first rendering)
2914 : : bool mLabelFontNotFoundNotified = false;
2915 : :
2916 : : //! Blend mode for features
2917 : : QPainter::CompositionMode mFeatureBlendMode = QPainter::CompositionMode_SourceOver;
2918 : :
2919 : : //! Flag if the vertex markers should be drawn only for selection (TRUE) or for all features (FALSE)
2920 : : bool mVertexMarkerOnlyForSelection = false;
2921 : :
2922 : : QStringList mCommitErrors;
2923 : :
2924 : : //! stores information about uncommitted changes to layer
2925 : : QgsVectorLayerEditBuffer *mEditBuffer = nullptr;
2926 : : friend class QgsVectorLayerEditBuffer;
2927 : : friend class QgsVectorLayerEditPassthrough;
2928 : :
2929 : : //stores information about joined layers
2930 : : QgsVectorLayerJoinBuffer *mJoinBuffer = nullptr;
2931 : :
2932 : : //!stores information about server properties
2933 : : std::unique_ptr< QgsVectorLayerServerProperties > mServerProperties;
2934 : :
2935 : : //! stores information about expression fields on this layer
2936 : : QgsExpressionFieldBuffer *mExpressionFieldBuffer = nullptr;
2937 : :
2938 : : //diagram rendering object. 0 if diagram drawing is disabled
2939 : : QgsDiagramRenderer *mDiagramRenderer = nullptr;
2940 : :
2941 : : //stores infos about diagram placement (placement type, priority, position distance)
2942 : : QgsDiagramLayerSettings *mDiagramLayerSettings = nullptr;
2943 : :
2944 : : mutable bool mValidExtent = false;
2945 : : mutable bool mLazyExtent = true;
2946 : :
2947 : : //! Auxiliary layer
2948 : : std::unique_ptr<QgsAuxiliaryLayer> mAuxiliaryLayer;
2949 : :
2950 : : //! Key to use to join auxiliary layer
2951 : : QString mAuxiliaryLayerKey;
2952 : :
2953 : : // Features in renderer classes counted
2954 : : bool mSymbolFeatureCounted = false;
2955 : :
2956 : : // Feature counts for each renderer legend key
2957 : : QHash<QString, long> mSymbolFeatureCountMap;
2958 : : QHash<QString, QgsFeatureIds> mSymbolFeatureIdMap;
2959 : :
2960 : : //! True while an undo command is active
2961 : : bool mEditCommandActive = false;
2962 : :
2963 : : bool mReadExtentFromXml;
2964 : : QgsRectangle mXmlExtent;
2965 : :
2966 : : QgsFeatureIds mDeletedFids;
2967 : :
2968 : : QgsAttributeTableConfig mAttributeTableConfig;
2969 : :
2970 : : mutable QMutex mFeatureSourceConstructorMutex;
2971 : :
2972 : : QgsVectorLayerFeatureCounter *mFeatureCounter = nullptr;
2973 : :
2974 : : std::unique_ptr<QgsGeometryOptions> mGeometryOptions;
2975 : :
2976 : : bool mAllowCommit = true;
2977 : :
2978 : : //! Stored expression used for e.g. filter
2979 : : QgsStoredExpressionManager *mStoredExpressionManager = nullptr;
2980 : :
2981 : : friend class QgsVectorLayerFeatureSource;
2982 : :
2983 : : //! To avoid firing multiple time dataChanged signal on circular layer circular dependencies
2984 : : bool mDataChangedFired = false;
2985 : :
2986 : : QList<QgsWeakRelation> mWeakRelations;
2987 : :
2988 : : bool mSetLegendFromStyle = false;
2989 : :
2990 : : QList< QgsFeatureRendererGenerator * > mRendererGenerators;
2991 : : };
2992 : :
2993 : :
2994 : :
2995 : : // clazy:excludeall=qstring-allocations
2996 : :
2997 : : #endif
|