QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsvectorlayer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorlayer.cpp
3  --------------------
4  begin : Oct 29, 2003
5  copyright : (C) 2003 by Gary E.Sherman
6  email : sherman at mrcc.com
7 
8  This class implements a generic means to display vector layers. The features
9  and attributes are read from the data store using a "data provider" plugin.
10  QgsVectorLayer can be used with any data store for which an appropriate
11  plugin is available.
12 
13 ***************************************************************************/
14 
15 /***************************************************************************
16  * *
17  * This program is free software; you can redistribute it and/or modify *
18  * it under the terms of the GNU General Public License as published by *
19  * the Free Software Foundation; either version 2 of the License, or *
20  * (at your option) any later version. *
21  * *
22  ***************************************************************************/
23 
24 #include "qgis.h" //for globals
25 #include "qgssettings.h"
26 #include "qgsvectorlayer.h"
27 #include "qgsactionmanager.h"
28 #include "qgsapplication.h"
29 #include "qgsclipper.h"
30 #include "qgsconditionalstyle.h"
32 #include "qgscoordinatetransform.h"
33 #include "qgsexception.h"
34 #include "qgscurve.h"
35 #include "qgsdatasourceuri.h"
37 #include "qgsexpressionnodeimpl.h"
38 #include "qgsfeature.h"
39 #include "qgsfeaturerequest.h"
40 #include "qgsfields.h"
41 #include "qgsmaplayerfactory.h"
42 #include "qgsmaplayerutils.h"
43 #include "qgsgeometry.h"
45 #include "qgslogger.h"
46 #include "qgsmaplayerlegend.h"
47 #include "qgsmaptopixel.h"
48 #include "qgsmessagelog.h"
49 #include "qgsogcutils.h"
50 #include "qgspainting.h"
51 #include "qgspointxy.h"
52 #include "qgsproject.h"
53 #include "qgsproviderregistry.h"
54 #include "qgsrectangle.h"
55 #include "qgsrelationmanager.h"
56 #include "qgsweakrelation.h"
57 #include "qgsrendercontext.h"
58 #include "qgsvectordataprovider.h"
66 #include "qgsvectorlayerlabeling.h"
67 #include "qgsvectorlayerrenderer.h"
70 #include "qgspoint.h"
71 #include "qgsrenderer.h"
72 #include "qgssymbollayer.h"
74 #include "qgsdiagramrenderer.h"
75 #include "qgsstyle.h"
76 #include "qgspallabeling.h"
77 #include "qgsrulebasedlabeling.h"
78 #include "qgssimplifymethod.h"
80 #include "qgsexpressioncontext.h"
81 #include "qgsfeedback.h"
82 #include "qgsxmlutils.h"
83 #include "qgsunittypes.h"
84 #include "qgstaskmanager.h"
85 #include "qgstransaction.h"
86 #include "qgsauxiliarystorage.h"
87 #include "qgsgeometryoptions.h"
89 #include "qgsruntimeprofiler.h"
91 #include "qgsvectorlayerutils.h"
93 #include "qgsprofilerequest.h"
94 
95 #include "diagram/qgsdiagram.h"
96 
97 #include <QDir>
98 #include <QFile>
99 #include <QImage>
100 #include <QPainter>
101 #include <QPainterPath>
102 #include <QPolygonF>
103 #include <QProgressDialog>
104 #include <QString>
105 #include <QDomNode>
106 #include <QVector>
107 #include <QStringBuilder>
108 #include <QUrl>
109 #include <QUndoCommand>
110 #include <QUrlQuery>
111 #include <QUuid>
112 #include <QRegularExpression>
113 #include <QTimer>
114 
115 #include <limits>
116 #include <optional>
117 
118 #ifdef TESTPROVIDERLIB
119 #include <dlfcn.h>
120 #endif
121 
122 typedef bool saveStyle_t(
123  const QString &uri,
124  const QString &qmlStyle,
125  const QString &sldStyle,
126  const QString &styleName,
127  const QString &styleDescription,
128  const QString &uiFileContent,
129  bool useAsDefault,
130  QString &errCause
131 );
132 
133 typedef QString loadStyle_t(
134  const QString &uri,
135  QString &errCause
136 );
137 
138 typedef int listStyles_t(
139  const QString &uri,
140  QStringList &ids,
141  QStringList &names,
142  QStringList &descriptions,
143  QString &errCause
144 );
145 
146 typedef QString getStyleById_t(
147  const QString &uri,
148  QString styleID,
149  QString &errCause
150 );
151 
152 typedef bool deleteStyleById_t(
153  const QString &uri,
154  QString styleID,
155  QString &errCause
156 );
157 
158 
159 QgsVectorLayer::QgsVectorLayer( const QString &vectorLayerPath,
160  const QString &baseName,
161  const QString &providerKey,
162  const QgsVectorLayer::LayerOptions &options )
163  : QgsMapLayer( QgsMapLayerType::VectorLayer, baseName, vectorLayerPath )
164  , mTemporalProperties( new QgsVectorLayerTemporalProperties( this ) )
165  , mElevationProperties( new QgsVectorLayerElevationProperties( this ) )
166  , mAuxiliaryLayer( nullptr )
167  , mAuxiliaryLayerKey( QString() )
168  , mReadExtentFromXml( options.readExtentFromXml )
169  , mRefreshRendererTimer( new QTimer( this ) )
170 {
172 
173  if ( options.fallbackCrs.isValid() )
174  setCrs( options.fallbackCrs, false );
175  mWkbType = options.fallbackWkbType;
176 
177  setProviderType( providerKey );
178 
179  mGeometryOptions = std::make_unique<QgsGeometryOptions>();
180  mActions = new QgsActionManager( this );
181  mConditionalStyles = new QgsConditionalLayerStyles( this );
182  mStoredExpressionManager = new QgsStoredExpressionManager();
183  mStoredExpressionManager->setParent( this );
184 
185  mJoinBuffer = new QgsVectorLayerJoinBuffer( this );
186  mJoinBuffer->setParent( this );
187  connect( mJoinBuffer, &QgsVectorLayerJoinBuffer::joinedFieldsChanged, this, &QgsVectorLayer::onJoinedFieldsChanged );
188 
189  mExpressionFieldBuffer = new QgsExpressionFieldBuffer();
190  // if we're given a provider type, try to create and bind one to this layer
191  if ( !vectorLayerPath.isEmpty() && !mProviderKey.isEmpty() )
192  {
193  QgsDataProvider::ProviderOptions providerOptions { options.transformContext };
194  QgsDataProvider::ReadFlags providerFlags = QgsDataProvider::ReadFlags();
195  if ( options.loadDefaultStyle )
196  {
197  providerFlags |= QgsDataProvider::FlagLoadDefaultStyle;
198  }
199  setDataSource( vectorLayerPath, baseName, providerKey, providerOptions, providerFlags );
200  }
201 
202  for ( const QgsField &field : std::as_const( mFields ) )
203  {
204  if ( !mAttributeAliasMap.contains( field.name() ) )
205  mAttributeAliasMap.insert( field.name(), QString() );
206  }
207 
208  if ( isValid() )
209  {
210  mTemporalProperties->setDefaultsFromDataProviderTemporalCapabilities( mDataProvider->temporalCapabilities() );
211  if ( !mTemporalProperties->isActive() )
212  {
213  // didn't populate temporal properties from provider metadata, so at least try to setup some initially nice
214  // selections
215  mTemporalProperties->guessDefaultsFromFields( mFields );
216  }
217 
218  mElevationProperties->setDefaultsFromLayer( this );
219  }
220 
221  connect( this, &QgsVectorLayer::selectionChanged, this, [ = ] { triggerRepaint(); } );
222  connect( QgsProject::instance()->relationManager(), &QgsRelationManager::relationsLoaded, this, &QgsVectorLayer::onRelationsLoaded );
223 
227 
228  // Default simplify drawing settings
229  QgsSettings settings;
230  mSimplifyMethod.setSimplifyHints( settings.flagValue( QStringLiteral( "qgis/simplifyDrawingHints" ), mSimplifyMethod.simplifyHints(), QgsSettings::NoSection ) );
231  mSimplifyMethod.setSimplifyAlgorithm( settings.enumValue( QStringLiteral( "qgis/simplifyAlgorithm" ), mSimplifyMethod.simplifyAlgorithm() ) );
232  mSimplifyMethod.setThreshold( settings.value( QStringLiteral( "qgis/simplifyDrawingTol" ), mSimplifyMethod.threshold() ).toFloat() );
233  mSimplifyMethod.setForceLocalOptimization( settings.value( QStringLiteral( "qgis/simplifyLocal" ), mSimplifyMethod.forceLocalOptimization() ).toBool() );
234  mSimplifyMethod.setMaximumScale( settings.value( QStringLiteral( "qgis/simplifyMaxScale" ), mSimplifyMethod.maximumScale() ).toFloat() );
235 
236  connect( mRefreshRendererTimer, &QTimer::timeout, this, [ = ] { triggerRepaint( true ); } );
237 }
238 
240 {
241  emit willBeDeleted();
242 
243  setValid( false );
244 
245  delete mDataProvider;
246  delete mEditBuffer;
247  delete mJoinBuffer;
248  delete mExpressionFieldBuffer;
249  delete mLabeling;
250  delete mDiagramLayerSettings;
251  delete mDiagramRenderer;
252 
253  delete mActions;
254 
255  delete mRenderer;
256  delete mConditionalStyles;
257  delete mStoredExpressionManager;
258 
259  if ( mFeatureCounter )
260  mFeatureCounter->cancel();
261 
262  qDeleteAll( mRendererGenerators );
263 }
264 
266 {
268  // We get the data source string from the provider when
269  // possible because some providers may have changed it
270  // directly (memory provider does that).
271  QString dataSource;
272  if ( mDataProvider )
273  {
274  dataSource = mDataProvider->dataSourceUri();
275  options.transformContext = mDataProvider->transformContext();
276  }
277  else
278  {
279  dataSource = source();
280  }
281  QgsVectorLayer *layer = new QgsVectorLayer( dataSource, name(), mProviderKey, options );
282  if ( mDataProvider && layer->dataProvider() )
283  {
284  layer->dataProvider()->handlePostCloneOperations( mDataProvider );
285  }
286  QgsMapLayer::clone( layer );
287 
288  QList<QgsVectorLayerJoinInfo> joins = vectorJoins();
289  const auto constJoins = joins;
290  for ( const QgsVectorLayerJoinInfo &join : constJoins )
291  {
292  // do not copy join information for auxiliary layer
293  if ( !auxiliaryLayer()
294  || ( auxiliaryLayer() && auxiliaryLayer()->id() != join.joinLayerId() ) )
295  layer->addJoin( join );
296  }
297 
298  if ( mDataProvider )
299  layer->setProviderEncoding( mDataProvider->encoding() );
301  layer->setMapTipTemplate( mapTipTemplate() );
302  layer->setReadOnly( isReadOnly() );
303  layer->selectByIds( selectedFeatureIds() );
307 
308  const auto constActions = actions()->actions();
309  for ( const QgsAction &action : constActions )
310  {
311  layer->actions()->addAction( action );
312  }
313 
314  if ( auto *lRenderer = renderer() )
315  {
316  layer->setRenderer( lRenderer->clone() );
317  }
318 
319  if ( auto *lLabeling = labeling() )
320  {
321  layer->setLabeling( lLabeling->clone() );
322  }
323  layer->setLabelsEnabled( labelsEnabled() );
324 
325  layer->setSimplifyMethod( simplifyMethod() );
326 
327  if ( auto *lDiagramRenderer = diagramRenderer() )
328  {
329  layer->setDiagramRenderer( lDiagramRenderer->clone() );
330  }
331 
332  if ( auto *lDiagramLayerSettings = diagramLayerSettings() )
333  {
334  layer->setDiagramLayerSettings( *lDiagramLayerSettings );
335  }
336 
337  for ( int i = 0; i < fields().count(); i++ )
338  {
339  layer->setFieldAlias( i, attributeAlias( i ) );
341  layer->setEditorWidgetSetup( i, editorWidgetSetup( i ) );
344 
345  QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength> constraints = fieldConstraintsAndStrength( i );
346  auto constraintIt = constraints.constBegin();
347  for ( ; constraintIt != constraints.constEnd(); ++ constraintIt )
348  {
349  layer->setFieldConstraint( i, constraintIt.key(), constraintIt.value() );
350  }
351 
352  if ( fields().fieldOrigin( i ) == QgsFields::OriginExpression )
353  {
354  layer->addExpressionField( expressionField( i ), fields().at( i ) );
355  }
356  }
357 
358  layer->setEditFormConfig( editFormConfig() );
359 
360  if ( auto *lAuxiliaryLayer = auxiliaryLayer() )
361  layer->setAuxiliaryLayer( lAuxiliaryLayer->clone( layer ) );
362 
363  layer->mElevationProperties = mElevationProperties->clone();
364  layer->mElevationProperties->setParent( layer );
365 
366  return layer;
367 }
368 
370 {
371  if ( mDataProvider )
372  {
373  return mDataProvider->storageType();
374  }
375  return QString();
376 }
377 
378 
380 {
381  if ( mDataProvider )
382  {
383  return mDataProvider->capabilitiesString();
384  }
385  return QString();
386 }
387 
389 {
390  return mDataProvider && mDataProvider->isSqlQuery();
391 }
392 
393 Qgis::VectorLayerTypeFlags QgsVectorLayer::vectorLayerTypeFlags() const
394 {
395  return mDataProvider ? mDataProvider->vectorLayerTypeFlags() : Qgis::VectorLayerTypeFlags();
396 }
397 
399 {
400  if ( mDataProvider )
401  {
402  return mDataProvider->dataComment();
403  }
404  return QString();
405 }
406 
408 {
409  return crs();
410 }
411 
413 {
414  return name();
415 }
416 
418 {
419  if ( mDataProvider )
420  {
421  mDataProvider->reloadData();
422  updateFields();
423  }
424 }
425 
427 {
428  return new QgsVectorLayerRenderer( this, rendererContext );
429 }
430 
431 
432 void QgsVectorLayer::drawVertexMarker( double x, double y, QPainter &p, Qgis::VertexMarkerType type, int m )
433 {
434  switch ( type )
435  {
437  p.setPen( QColor( 50, 100, 120, 200 ) );
438  p.setBrush( QColor( 200, 200, 210, 120 ) );
439  p.drawEllipse( x - m, y - m, m * 2 + 1, m * 2 + 1 );
440  break;
441 
443  p.setPen( QColor( 255, 0, 0 ) );
444  p.drawLine( x - m, y + m, x + m, y - m );
445  p.drawLine( x - m, y - m, x + m, y + m );
446  break;
447 
449  break;
450  }
451 }
452 
454 {
455  mSelectedFeatureIds.insert( fid );
456  mPreviousSelectedFeatureIds.clear();
457 
458  emit selectionChanged( QgsFeatureIds() << fid, QgsFeatureIds(), false );
459 }
460 
461 void QgsVectorLayer::select( const QgsFeatureIds &featureIds )
462 {
463  mSelectedFeatureIds.unite( featureIds );
464  mPreviousSelectedFeatureIds.clear();
465 
466  emit selectionChanged( featureIds, QgsFeatureIds(), false );
467 }
468 
470 {
471  mSelectedFeatureIds.remove( fid );
472  mPreviousSelectedFeatureIds.clear();
473 
474  emit selectionChanged( QgsFeatureIds(), QgsFeatureIds() << fid, false );
475 }
476 
477 void QgsVectorLayer::deselect( const QgsFeatureIds &featureIds )
478 {
479  mSelectedFeatureIds.subtract( featureIds );
480  mPreviousSelectedFeatureIds.clear();
481 
482  emit selectionChanged( QgsFeatureIds(), featureIds, false );
483 }
484 
486 {
487  // normalize the rectangle
488  rect.normalize();
489 
490  QgsFeatureIds newSelection;
491 
493  .setFilterRect( rect )
495  .setNoAttributes() );
496 
497  QgsFeature feat;
498  while ( features.nextFeature( feat ) )
499  {
500  newSelection << feat.id();
501  }
502  features.close();
503 
504  selectByIds( newSelection, behavior );
505 }
506 
507 void QgsVectorLayer::selectByExpression( const QString &expression, Qgis::SelectBehavior behavior, QgsExpressionContext *context )
508 {
509  QgsFeatureIds newSelection;
510 
511  std::optional< QgsExpressionContext > defaultContext;
512  if ( !context )
513  {
514  defaultContext.emplace( QgsExpressionContextUtils::globalProjectLayerScopes( this ) );
515  context = &defaultContext.value();
516  }
517 
519  {
521  .setExpressionContext( *context )
523  .setNoAttributes();
524 
525  QgsFeatureIterator features = getFeatures( request );
526 
527  if ( behavior == Qgis::SelectBehavior::AddToSelection )
528  {
529  newSelection = selectedFeatureIds();
530  }
531  QgsFeature feat;
532  while ( features.nextFeature( feat ) )
533  {
534  newSelection << feat.id();
535  }
536  features.close();
537  }
539  {
540  QgsExpression exp( expression );
541  exp.prepare( context );
542 
543  QgsFeatureIds oldSelection = selectedFeatureIds();
544  QgsFeatureRequest request = QgsFeatureRequest().setFilterFids( oldSelection );
545 
546  //refine request
547  if ( !exp.needsGeometry() )
549  request.setSubsetOfAttributes( exp.referencedColumns(), fields() );
550 
551  QgsFeatureIterator features = getFeatures( request );
552  QgsFeature feat;
553  while ( features.nextFeature( feat ) )
554  {
555  context->setFeature( feat );
556  bool matches = exp.evaluate( context ).toBool();
557 
558  if ( matches && behavior == Qgis::SelectBehavior::IntersectSelection )
559  {
560  newSelection << feat.id();
561  }
562  else if ( !matches && behavior == Qgis::SelectBehavior::RemoveFromSelection )
563  {
564  newSelection << feat.id();
565  }
566  }
567  }
568 
569  selectByIds( newSelection );
570 }
571 
573 {
574  QgsFeatureIds newSelection;
575 
576  switch ( behavior )
577  {
579  newSelection = ids;
580  break;
581 
583  newSelection = mSelectedFeatureIds + ids;
584  break;
585 
587  newSelection = mSelectedFeatureIds - ids;
588  break;
589 
591  newSelection = mSelectedFeatureIds.intersect( ids );
592  break;
593  }
594 
595  QgsFeatureIds deselectedFeatures = mSelectedFeatureIds - newSelection;
596  mSelectedFeatureIds = newSelection;
597  mPreviousSelectedFeatureIds.clear();
598 
599  emit selectionChanged( newSelection, deselectedFeatures, true );
600 }
601 
602 void QgsVectorLayer::modifySelection( const QgsFeatureIds &selectIds, const QgsFeatureIds &deselectIds )
603 {
604  QgsFeatureIds intersectingIds = selectIds & deselectIds;
605  if ( !intersectingIds.isEmpty() )
606  {
607  QgsDebugMsgLevel( QStringLiteral( "Trying to select and deselect the same item at the same time. Unsure what to do. Selecting dubious items." ), 3 );
608  }
609 
610  mSelectedFeatureIds -= deselectIds;
611  mSelectedFeatureIds += selectIds;
612  mPreviousSelectedFeatureIds.clear();
613 
614  emit selectionChanged( selectIds, deselectIds - intersectingIds, false );
615 }
616 
618 {
620  ids.subtract( mSelectedFeatureIds );
621  selectByIds( ids );
622 }
623 
625 {
627 }
628 
630 {
631  // normalize the rectangle
632  rect.normalize();
633 
635  .setFilterRect( rect )
637  .setNoAttributes() );
638 
639  QgsFeatureIds selectIds;
640  QgsFeatureIds deselectIds;
641 
642  QgsFeature fet;
643  while ( fit.nextFeature( fet ) )
644  {
645  if ( mSelectedFeatureIds.contains( fet.id() ) )
646  {
647  deselectIds << fet.id();
648  }
649  else
650  {
651  selectIds << fet.id();
652  }
653  }
654 
655  modifySelection( selectIds, deselectIds );
656 }
657 
659 {
660  if ( mSelectedFeatureIds.isEmpty() )
661  return;
662 
663  const QgsFeatureIds previous = mSelectedFeatureIds;
665  mPreviousSelectedFeatureIds = previous;
666 }
667 
669 {
670  if ( mPreviousSelectedFeatureIds.isEmpty() || !mSelectedFeatureIds.empty() )
671  return;
672 
673  selectByIds( mPreviousSelectedFeatureIds );
674 }
675 
677 {
678  return mDataProvider;
679 }
680 
682 {
683  return mDataProvider;
684 }
685 
687 {
688  return mTemporalProperties;
689 }
690 
692 {
693  return mElevationProperties;
694 }
695 
697 {
698  QgsProfileRequest modifiedRequest( request );
700  return new QgsVectorLayerProfileGenerator( this, modifiedRequest );
701 }
702 
703 void QgsVectorLayer::setProviderEncoding( const QString &encoding )
704 {
705  if ( isValid() && mDataProvider && mDataProvider->encoding() != encoding )
706  {
707  mDataProvider->setEncoding( encoding );
708  updateFields();
709  }
710 }
711 
713 {
714  delete mDiagramRenderer;
715  mDiagramRenderer = r;
716  emit rendererChanged();
717  emit styleChanged();
718 }
719 
721 {
722  return QgsWkbTypes::geometryType( mWkbType );
723 }
724 
726 {
727  return mWkbType;
728 }
729 
731 {
732  if ( !isValid() || !isSpatial() || mSelectedFeatureIds.isEmpty() || !mDataProvider ) //no selected features
733  {
734  return QgsRectangle( 0, 0, 0, 0 );
735  }
736 
737  QgsRectangle r, retval;
738  retval.setMinimal();
739 
740  QgsFeature fet;
741  if ( mDataProvider->capabilities() & QgsVectorDataProvider::SelectAtId )
742  {
744  .setFilterFids( mSelectedFeatureIds )
745  .setNoAttributes() );
746 
747  while ( fit.nextFeature( fet ) )
748  {
749  if ( !fet.hasGeometry() )
750  continue;
751  r = fet.geometry().boundingBox();
752  retval.combineExtentWith( r );
753  }
754  }
755  else
756  {
758  .setNoAttributes() );
759 
760  while ( fit.nextFeature( fet ) )
761  {
762  if ( mSelectedFeatureIds.contains( fet.id() ) )
763  {
764  if ( fet.hasGeometry() )
765  {
766  r = fet.geometry().boundingBox();
767  retval.combineExtentWith( r );
768  }
769  }
770  }
771  }
772 
773  if ( retval.width() == 0.0 || retval.height() == 0.0 )
774  {
775  // If all of the features are at the one point, buffer the
776  // rectangle a bit. If they are all at zero, do something a bit
777  // more crude.
778 
779  if ( retval.xMinimum() == 0.0 && retval.xMaximum() == 0.0 &&
780  retval.yMinimum() == 0.0 && retval.yMaximum() == 0.0 )
781  {
782  retval.set( -1.0, -1.0, 1.0, 1.0 );
783  }
784  }
785 
786  return retval;
787 }
788 
790 {
791  return mLabelsEnabled && static_cast< bool >( mLabeling );
792 }
793 
795 {
796  mLabelsEnabled = enabled;
797 }
798 
800 {
801  if ( !mDiagramRenderer || !mDiagramLayerSettings )
802  return false;
803 
804  QList<QgsDiagramSettings> settingList = mDiagramRenderer->diagramSettings();
805  if ( !settingList.isEmpty() )
806  {
807  return settingList.at( 0 ).enabled;
808  }
809  return false;
810 }
811 
812 long long QgsVectorLayer::featureCount( const QString &legendKey ) const
813 {
814  if ( !mSymbolFeatureCounted )
815  return -1;
816 
817  return mSymbolFeatureCountMap.value( legendKey, -1 );
818 }
819 
820 QgsFeatureIds QgsVectorLayer::symbolFeatureIds( const QString &legendKey ) const
821 {
822  if ( !mSymbolFeatureCounted )
823  return QgsFeatureIds();
824 
825  return mSymbolFeatureIdMap.value( legendKey, QgsFeatureIds() );
826 }
828 {
829  if ( ( mSymbolFeatureCounted || mFeatureCounter ) && !( storeSymbolFids && mSymbolFeatureIdMap.isEmpty() ) )
830  return mFeatureCounter;
831 
832  mSymbolFeatureCountMap.clear();
833  mSymbolFeatureIdMap.clear();
834 
835  if ( !isValid() )
836  {
837  QgsDebugMsgLevel( QStringLiteral( "invoked with invalid layer" ), 3 );
838  return mFeatureCounter;
839  }
840  if ( !mDataProvider )
841  {
842  QgsDebugMsgLevel( QStringLiteral( "invoked with null mDataProvider" ), 3 );
843  return mFeatureCounter;
844  }
845  if ( !mRenderer )
846  {
847  QgsDebugMsgLevel( QStringLiteral( "invoked with null mRenderer" ), 3 );
848  return mFeatureCounter;
849  }
850 
851  if ( !mFeatureCounter || ( storeSymbolFids && mSymbolFeatureIdMap.isEmpty() ) )
852  {
853  mFeatureCounter = new QgsVectorLayerFeatureCounter( this, QgsExpressionContext(), storeSymbolFids );
854  connect( mFeatureCounter, &QgsTask::taskCompleted, this, &QgsVectorLayer::onFeatureCounterCompleted, Qt::UniqueConnection );
855  connect( mFeatureCounter, &QgsTask::taskTerminated, this, &QgsVectorLayer::onFeatureCounterTerminated, Qt::UniqueConnection );
856  QgsApplication::taskManager()->addTask( mFeatureCounter );
857  }
858 
859  return mFeatureCounter;
860 }
861 
863 {
864  // do not update extent by default when trust project option is activated
865  if ( force || !mReadExtentFromXml || ( mReadExtentFromXml && mXmlExtent.isNull() ) )
866  mValidExtent = false;
867 }
868 
870 {
872  mValidExtent = true;
873 }
874 
875 void QgsVectorLayer::updateDefaultValues( QgsFeatureId fid, QgsFeature feature )
876 {
877  if ( !mDefaultValueOnUpdateFields.isEmpty() )
878  {
879  if ( !feature.isValid() )
880  feature = getFeature( fid );
881 
882  int size = mFields.size();
883  for ( int idx : std::as_const( mDefaultValueOnUpdateFields ) )
884  {
885  if ( idx < 0 || idx >= size )
886  continue;
887 
888  feature.setAttribute( idx, defaultValue( idx, feature ) );
889  updateFeature( feature, true );
890  }
891  }
892 }
893 
895 {
896  QgsRectangle rect;
897  rect.setMinimal();
898 
899  if ( !isSpatial() )
900  return rect;
901 
902  if ( !mValidExtent && mLazyExtent && mReadExtentFromXml && !mXmlExtent.isNull() )
903  {
904  updateExtent( mXmlExtent );
905  mValidExtent = true;
906  mLazyExtent = false;
907  }
908 
909  if ( !mValidExtent && mLazyExtent && mDataProvider && mDataProvider->isValid() )
910  {
911  // store the extent
912  updateExtent( mDataProvider->extent() );
913  mValidExtent = true;
914  mLazyExtent = false;
915 
916  // show the extent
917  QgsDebugMsgLevel( QStringLiteral( "Extent of layer: %1" ).arg( mExtent.toString() ), 3 );
918  }
919 
920  if ( mValidExtent )
921  return QgsMapLayer::extent();
922 
923  if ( !isValid() || !mDataProvider )
924  {
925  QgsDebugMsgLevel( QStringLiteral( "invoked with invalid layer or null mDataProvider" ), 3 );
926  return rect;
927  }
928 
929  if ( !mEditBuffer ||
930  ( !mDataProvider->transaction() && ( mEditBuffer->deletedFeatureIds().isEmpty() && mEditBuffer->changedGeometries().isEmpty() ) ) ||
931  QgsDataSourceUri( mDataProvider->dataSourceUri() ).useEstimatedMetadata() )
932  {
933  mDataProvider->updateExtents();
934 
935  // get the extent of the layer from the provider
936  // but only when there are some features already
937  if ( mDataProvider->featureCount() != 0 )
938  {
939  const QgsRectangle r = mDataProvider->extent();
940  rect.combineExtentWith( r );
941  }
942 
943  if ( mEditBuffer && !mDataProvider->transaction() )
944  {
945  const auto addedFeatures = mEditBuffer->addedFeatures();
946  for ( QgsFeatureMap::const_iterator it = addedFeatures.constBegin(); it != addedFeatures.constEnd(); ++it )
947  {
948  if ( it->hasGeometry() )
949  {
950  const QgsRectangle r = it->geometry().boundingBox();
951  rect.combineExtentWith( r );
952  }
953  }
954  }
955  }
956  else
957  {
959  .setNoAttributes() );
960 
961  QgsFeature fet;
962  while ( fit.nextFeature( fet ) )
963  {
964  if ( fet.hasGeometry() && fet.geometry().type() != QgsWkbTypes::UnknownGeometry )
965  {
966  const QgsRectangle bb = fet.geometry().boundingBox();
967  rect.combineExtentWith( bb );
968  }
969  }
970  }
971 
972  if ( rect.xMinimum() > rect.xMaximum() && rect.yMinimum() > rect.yMaximum() )
973  {
974  // special case when there are no features in provider nor any added
975  rect = QgsRectangle(); // use rectangle with zero coordinates
976  }
977 
978  updateExtent( rect );
979  mValidExtent = true;
980 
981  // Send this (hopefully) up the chain to the map canvas
982  emit recalculateExtents();
983 
984  return rect;
985 }
986 
988 {
989  return extent();
990 }
991 
992 QString QgsVectorLayer::subsetString() const
993 {
994  if ( !isValid() || !mDataProvider )
995  {
996  QgsDebugMsgLevel( QStringLiteral( "invoked with invalid layer or null mDataProvider" ), 3 );
997  return customProperty( QStringLiteral( "storedSubsetString" ) ).toString();
998  }
999  return mDataProvider->subsetString();
1000 }
1001 
1002 bool QgsVectorLayer::setSubsetString( const QString &subset )
1003 {
1004  if ( !isValid() || !mDataProvider )
1005  {
1006  QgsDebugMsgLevel( QStringLiteral( "invoked with invalid layer or null mDataProvider or while editing" ), 3 );
1007  setCustomProperty( QStringLiteral( "storedSubsetString" ), subset );
1008  return false;
1009  }
1010  else if ( mEditBuffer )
1011  {
1012  QgsDebugMsgLevel( QStringLiteral( "invoked while editing" ), 3 );
1013  return false;
1014  }
1015 
1016  if ( subset == mDataProvider->subsetString() )
1017  return true;
1018 
1019  bool res = mDataProvider->setSubsetString( subset );
1020 
1021  // get the updated data source string from the provider
1022  mDataSource = mDataProvider->dataSourceUri();
1023  updateExtents();
1024  updateFields();
1025 
1026  if ( res )
1027  {
1028  emit subsetStringChanged();
1029  triggerRepaint();
1030  }
1031 
1032  return res;
1033 }
1034 
1036 {
1037  if ( isValid() && mDataProvider && !mEditBuffer && ( isSpatial() && geometryType() != QgsWkbTypes::PointGeometry ) && ( mSimplifyMethod.simplifyHints() & simplifyHint ) && renderContext.useRenderingOptimization() )
1038  {
1039  double maximumSimplificationScale = mSimplifyMethod.maximumScale();
1040 
1041  // check maximum scale at which generalisation should be carried out
1042  return !( maximumSimplificationScale > 1 && renderContext.rendererScale() <= maximumSimplificationScale );
1043  }
1044  return false;
1045 }
1046 
1048 {
1049  return mConditionalStyles;
1050 }
1051 
1053 {
1054  if ( !isValid() || !mDataProvider )
1055  return QgsFeatureIterator();
1056 
1057  return QgsFeatureIterator( new QgsVectorLayerFeatureIterator( new QgsVectorLayerFeatureSource( this ), true, request ) );
1058 }
1059 
1061 {
1062  QgsFeature feature;
1064  if ( feature.isValid() )
1065  return feature.geometry();
1066  else
1067  return QgsGeometry();
1068 }
1069 
1071 {
1072  if ( !isValid() || !mEditBuffer || !mDataProvider )
1073  return false;
1074 
1075 
1076  if ( mGeometryOptions->isActive() )
1077  {
1078  QgsGeometry geom = feature.geometry();
1079  mGeometryOptions->apply( geom );
1080  feature.setGeometry( geom );
1081  }
1082 
1083  bool success = mEditBuffer->addFeature( feature );
1084 
1085  if ( success )
1086  {
1087  updateExtents();
1088 
1089  if ( mJoinBuffer->containsJoins() )
1090  success = mJoinBuffer->addFeature( feature );
1091  }
1092 
1093  return success;
1094 }
1095 
1096 bool QgsVectorLayer::updateFeature( QgsFeature &updatedFeature, bool skipDefaultValues )
1097 {
1098  if ( !mEditBuffer || !mDataProvider )
1099  {
1100  return false;
1101  }
1102 
1103  QgsFeature currentFeature = getFeature( updatedFeature.id() );
1104  if ( currentFeature.isValid() )
1105  {
1106  bool hasChanged = false;
1107  bool hasError = false;
1108 
1109  if ( ( updatedFeature.hasGeometry() || currentFeature.hasGeometry() ) && !updatedFeature.geometry().equals( currentFeature.geometry() ) )
1110  {
1111  QgsGeometry geometry = updatedFeature.geometry();
1112  if ( changeGeometry( updatedFeature.id(), geometry, true ) )
1113  {
1114  hasChanged = true;
1115  updatedFeature.setGeometry( geometry );
1116  }
1117  else
1118  {
1119  QgsDebugMsgLevel( QStringLiteral( "geometry of feature %1 could not be changed." ).arg( updatedFeature.id() ), 3 );
1120  }
1121  }
1122 
1123  QgsAttributes fa = updatedFeature.attributes();
1124  QgsAttributes ca = currentFeature.attributes();
1125 
1126  for ( int attr = 0; attr < fa.count(); ++attr )
1127  {
1128  if ( !qgsVariantEqual( fa.at( attr ), ca.at( attr ) ) )
1129  {
1130  if ( changeAttributeValue( updatedFeature.id(), attr, fa.at( attr ), ca.at( attr ), true ) )
1131  {
1132  hasChanged = true;
1133  }
1134  else
1135  {
1136  QgsDebugMsgLevel( QStringLiteral( "attribute %1 of feature %2 could not be changed." ).arg( attr ).arg( updatedFeature.id() ), 3 );
1137  hasError = true;
1138  }
1139  }
1140  }
1141  if ( hasChanged && !mDefaultValueOnUpdateFields.isEmpty() && !skipDefaultValues )
1142  updateDefaultValues( updatedFeature.id(), updatedFeature );
1143 
1144  return !hasError;
1145  }
1146  else
1147  {
1148  QgsDebugMsgLevel( QStringLiteral( "feature %1 could not be retrieved" ).arg( updatedFeature.id() ), 3 );
1149  return false;
1150  }
1151 }
1152 
1153 
1154 bool QgsVectorLayer::insertVertex( double x, double y, QgsFeatureId atFeatureId, int beforeVertex )
1155 {
1156  if ( !isValid() || !mEditBuffer || !mDataProvider )
1157  return false;
1158 
1159  QgsVectorLayerEditUtils utils( this );
1160  bool result = utils.insertVertex( x, y, atFeatureId, beforeVertex );
1161  if ( result )
1162  updateExtents();
1163  return result;
1164 }
1165 
1166 
1167 bool QgsVectorLayer::insertVertex( const QgsPoint &point, QgsFeatureId atFeatureId, int beforeVertex )
1168 {
1169  if ( !isValid() || !mEditBuffer || !mDataProvider )
1170  return false;
1171 
1172  QgsVectorLayerEditUtils utils( this );
1173  bool result = utils.insertVertex( point, atFeatureId, beforeVertex );
1174  if ( result )
1175  updateExtents();
1176  return result;
1177 }
1178 
1179 
1180 bool QgsVectorLayer::moveVertex( double x, double y, QgsFeatureId atFeatureId, int atVertex )
1181 {
1182  if ( !isValid() || !mEditBuffer || !mDataProvider )
1183  return false;
1184 
1185  QgsVectorLayerEditUtils utils( this );
1186  bool result = utils.moveVertex( x, y, atFeatureId, atVertex );
1187 
1188  if ( result )
1189  updateExtents();
1190  return result;
1191 }
1192 
1193 bool QgsVectorLayer::moveVertex( const QgsPoint &p, QgsFeatureId atFeatureId, int atVertex )
1194 {
1195  if ( !isValid() || !mEditBuffer || !mDataProvider )
1196  return false;
1197 
1198  QgsVectorLayerEditUtils utils( this );
1199  bool result = utils.moveVertex( p, atFeatureId, atVertex );
1200 
1201  if ( result )
1202  updateExtents();
1203  return result;
1204 }
1205 
1207 {
1208  if ( !isValid() || !mEditBuffer || !mDataProvider )
1210 
1211  QgsVectorLayerEditUtils utils( this );
1212  Qgis::VectorEditResult result = utils.deleteVertex( featureId, vertex );
1213 
1214  if ( result == Qgis::VectorEditResult::Success )
1215  updateExtents();
1216  return result;
1217 }
1218 
1219 
1221 {
1222  if ( !isValid() || !mDataProvider || !( mDataProvider->capabilities() & QgsVectorDataProvider::DeleteFeatures ) )
1223  {
1224  return false;
1225  }
1226 
1227  if ( !isEditable() )
1228  {
1229  return false;
1230  }
1231 
1232  int deleted = 0;
1233  int count = mSelectedFeatureIds.size();
1234  // Make a copy since deleteFeature modifies mSelectedFeatureIds
1235  QgsFeatureIds selectedFeatures( mSelectedFeatureIds );
1236  for ( QgsFeatureId fid : std::as_const( selectedFeatures ) )
1237  {
1238  deleted += deleteFeature( fid, context ); // removes from selection
1239  }
1240 
1241  triggerRepaint();
1242  updateExtents();
1243 
1244  if ( deletedCount )
1245  {
1246  *deletedCount = deleted;
1247  }
1248 
1249  return deleted == count;
1250 }
1251 
1252 static const QgsPointSequence vectorPointXY2pointSequence( const QVector<QgsPointXY> &points )
1253 {
1254  QgsPointSequence pts;
1255  pts.reserve( points.size() );
1256  QVector<QgsPointXY>::const_iterator it = points.constBegin();
1257  while ( it != points.constEnd() )
1258  {
1259  pts.append( QgsPoint( *it ) );
1260  ++it;
1261  }
1262  return pts;
1263 }
1264 Qgis::GeometryOperationResult QgsVectorLayer::addRing( const QVector<QgsPointXY> &ring, QgsFeatureId *featureId )
1265 {
1266  return addRing( vectorPointXY2pointSequence( ring ), featureId );
1267 }
1268 
1270 {
1271  if ( !isValid() || !mEditBuffer || !mDataProvider )
1273 
1274  QgsVectorLayerEditUtils utils( this );
1276 
1277  //first try with selected features
1278  if ( !mSelectedFeatureIds.isEmpty() )
1279  {
1280  result = utils.addRing( ring, mSelectedFeatureIds, featureId );
1281  }
1282 
1284  {
1285  //try with all intersecting features
1286  result = utils.addRing( ring, QgsFeatureIds(), featureId );
1287  }
1288 
1289  return result;
1290 }
1291 
1293 {
1294  if ( !isValid() || !mEditBuffer || !mDataProvider )
1295  {
1296  delete ring;
1298  }
1299 
1300  if ( !ring )
1301  {
1303  }
1304 
1305  if ( !ring->isClosed() )
1306  {
1307  delete ring;
1309  }
1310 
1311  QgsVectorLayerEditUtils utils( this );
1313 
1314  //first try with selected features
1315  if ( !mSelectedFeatureIds.isEmpty() )
1316  {
1317  result = utils.addRing( static_cast< QgsCurve * >( ring->clone() ), mSelectedFeatureIds, featureId );
1318  }
1319 
1321  {
1322  //try with all intersecting features
1323  result = utils.addRing( static_cast< QgsCurve * >( ring->clone() ), QgsFeatureIds(), featureId );
1324  }
1325 
1326  delete ring;
1327  return result;
1328 }
1329 
1330 Qgis::GeometryOperationResult QgsVectorLayer::addPart( const QList<QgsPointXY> &points )
1331 {
1332  QgsPointSequence pts;
1333  pts.reserve( points.size() );
1334  for ( QList<QgsPointXY>::const_iterator it = points.constBegin(); it != points.constEnd() ; ++it )
1335  {
1336  pts.append( QgsPoint( *it ) );
1337  }
1338  return addPart( pts );
1339 }
1340 
1341 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1342 Qgis::GeometryOperationResult QgsVectorLayer::addPart( const QVector<QgsPointXY> &points )
1343 {
1344  return addPart( vectorPointXY2pointSequence( points ) );
1345 }
1346 #endif
1347 
1349 {
1350  if ( !isValid() || !mEditBuffer || !mDataProvider )
1352 
1353  //number of selected features must be 1
1354 
1355  if ( mSelectedFeatureIds.empty() )
1356  {
1357  QgsDebugMsgLevel( QStringLiteral( "Number of selected features <1" ), 3 );
1359  }
1360  else if ( mSelectedFeatureIds.size() > 1 )
1361  {
1362  QgsDebugMsgLevel( QStringLiteral( "Number of selected features >1" ), 3 );
1364  }
1365 
1366  QgsVectorLayerEditUtils utils( this );
1367  Qgis::GeometryOperationResult result = utils.addPart( points, *mSelectedFeatureIds.constBegin() );
1368 
1370  updateExtents();
1371  return result;
1372 }
1373 
1375 {
1376  if ( !isValid() || !mEditBuffer || !mDataProvider )
1378 
1379  //number of selected features must be 1
1380 
1381  if ( mSelectedFeatureIds.empty() )
1382  {
1383  QgsDebugMsgLevel( QStringLiteral( "Number of selected features <1" ), 3 );
1385  }
1386  else if ( mSelectedFeatureIds.size() > 1 )
1387  {
1388  QgsDebugMsgLevel( QStringLiteral( "Number of selected features >1" ), 3 );
1390  }
1391 
1392  QgsVectorLayerEditUtils utils( this );
1393  Qgis::GeometryOperationResult result = utils.addPart( ring, *mSelectedFeatureIds.constBegin() );
1394 
1396  updateExtents();
1397  return result;
1398 }
1399 
1400 // TODO QGIS 4.0 -- this should return Qgis::GeometryOperationResult, not int
1401 int QgsVectorLayer::translateFeature( QgsFeatureId featureId, double dx, double dy )
1402 {
1403  if ( !isValid() || !mEditBuffer || !mDataProvider )
1404  return static_cast< int >( Qgis::GeometryOperationResult::LayerNotEditable );
1405 
1406  QgsVectorLayerEditUtils utils( this );
1407  int result = utils.translateFeature( featureId, dx, dy );
1408 
1409  if ( result == static_cast< int >( Qgis::GeometryOperationResult::Success ) )
1410  updateExtents();
1411  return result;
1412 }
1413 
1414 Qgis::GeometryOperationResult QgsVectorLayer::splitParts( const QVector<QgsPointXY> &splitLine, bool topologicalEditing )
1415 {
1416  return splitParts( vectorPointXY2pointSequence( splitLine ), topologicalEditing );
1417 }
1418 
1420 {
1421  if ( !isValid() || !mEditBuffer || !mDataProvider )
1423 
1424  QgsVectorLayerEditUtils utils( this );
1425  return utils.splitParts( splitLine, topologicalEditing );
1426 }
1427 
1428 Qgis::GeometryOperationResult QgsVectorLayer::splitFeatures( const QVector<QgsPointXY> &splitLine, bool topologicalEditing )
1429 {
1430  return splitFeatures( vectorPointXY2pointSequence( splitLine ), topologicalEditing );
1431 }
1432 
1434 {
1435  QgsLineString splitLineString( splitLine );
1436  QgsPointSequence topologyTestPoints;
1437  bool preserveCircular = false;
1438  return splitFeatures( &splitLineString, topologyTestPoints, preserveCircular, topologicalEditing );
1439 }
1440 
1441 Qgis::GeometryOperationResult QgsVectorLayer::splitFeatures( const QgsCurve *curve, QgsPointSequence &topologyTestPoints, bool preserveCircular, bool topologicalEditing )
1442 {
1443  if ( !isValid() || !mEditBuffer || !mDataProvider )
1445 
1446  QgsVectorLayerEditUtils utils( this );
1447  return utils.splitFeatures( curve, topologyTestPoints, preserveCircular, topologicalEditing );
1448 }
1449 
1451 {
1452  if ( !isValid() || !mEditBuffer || !mDataProvider )
1453  return -1;
1454 
1455  QgsVectorLayerEditUtils utils( this );
1456  return utils.addTopologicalPoints( geom );
1457 }
1458 
1460 {
1461  return addTopologicalPoints( QgsPoint( p ) );
1462 }
1463 
1465 {
1466  if ( !isValid() || !mEditBuffer || !mDataProvider )
1467  return -1;
1468 
1469  QgsVectorLayerEditUtils utils( this );
1470  return utils.addTopologicalPoints( p );
1471 }
1472 
1474 {
1475  if ( !mValid || !mEditBuffer || !mDataProvider )
1476  return -1;
1477 
1478  QgsVectorLayerEditUtils utils( this );
1479  return utils.addTopologicalPoints( ps );
1480 }
1481 
1483 {
1484  if ( mLabeling == labeling )
1485  return;
1486 
1487  delete mLabeling;
1488  mLabeling = labeling;
1489 }
1490 
1492 {
1493  if ( project() && project()->transactionMode() == Qgis::TransactionMode::BufferedGroups )
1494  return project()->startEditing( this );
1495 
1496  if ( !isValid() || !mDataProvider )
1497  {
1498  return false;
1499  }
1500 
1501  // allow editing if provider supports any of the capabilities
1502  if ( !supportsEditing() )
1503  {
1504  return false;
1505  }
1506 
1507  if ( mEditBuffer )
1508  {
1509  // editing already underway
1510  return false;
1511  }
1512 
1513  mDataProvider->enterUpdateMode();
1514 
1515  emit beforeEditingStarted();
1516 
1517  createEditBuffer();
1518 
1519  updateFields();
1520 
1521  emit editingStarted();
1522 
1523  return true;
1524 }
1525 
1527 {
1528  if ( mDataProvider )
1529  mDataProvider->setTransformContext( transformContext );
1530 }
1531 
1533 {
1534  return mDataProvider ? mDataProvider->hasSpatialIndex() : QgsFeatureSource::SpatialIndexUnknown;
1535 }
1536 
1538 {
1539  if ( mRenderer )
1540  if ( !mRenderer->accept( visitor ) )
1541  return false;
1542 
1543  if ( mLabeling )
1544  if ( !mLabeling->accept( visitor ) )
1545  return false;
1546 
1547  return true;
1548 }
1549 
1550 bool QgsVectorLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &context )
1551 {
1552  QgsDebugMsgLevel( QStringLiteral( "Datasource in QgsVectorLayer::readXml: %1" ).arg( mDataSource.toLocal8Bit().data() ), 3 );
1553 
1554  //process provider key
1555  QDomNode pkeyNode = layer_node.namedItem( QStringLiteral( "provider" ) );
1556 
1557  if ( pkeyNode.isNull() )
1558  {
1559  mProviderKey.clear();
1560  }
1561  else
1562  {
1563  QDomElement pkeyElt = pkeyNode.toElement();
1564  mProviderKey = pkeyElt.text();
1565  }
1566 
1567  // determine type of vector layer
1568  if ( !mProviderKey.isNull() )
1569  {
1570  // if the provider string isn't empty, then we successfully
1571  // got the stored provider
1572  }
1573  else if ( mDataSource.contains( QLatin1String( "dbname=" ) ) )
1574  {
1575  mProviderKey = QStringLiteral( "postgres" );
1576  }
1577  else
1578  {
1579  mProviderKey = QStringLiteral( "ogr" );
1580  }
1581 
1582  QgsDataProvider::ProviderOptions options { context.transformContext() };
1583  QgsDataProvider::ReadFlags flags;
1585  {
1587  }
1588  if ( ( mReadFlags & QgsMapLayer::FlagDontResolveLayers ) || !setDataProvider( mProviderKey, options, flags ) )
1589  {
1591  {
1592  QgsDebugMsg( QStringLiteral( "Could not set data provider for layer %1" ).arg( publicSource() ) );
1593  }
1594  const QDomElement elem = layer_node.toElement();
1595 
1596  // for invalid layer sources, we fallback to stored wkbType if available
1597  if ( elem.hasAttribute( QStringLiteral( "wkbType" ) ) )
1598  mWkbType = qgsEnumKeyToValue( elem.attribute( QStringLiteral( "wkbType" ) ), mWkbType );
1599  }
1600 
1601  QDomElement pkeyElem = pkeyNode.toElement();
1602  if ( !pkeyElem.isNull() )
1603  {
1604  QString encodingString = pkeyElem.attribute( QStringLiteral( "encoding" ) );
1605  if ( mDataProvider && !encodingString.isEmpty() )
1606  {
1607  mDataProvider->setEncoding( encodingString );
1608  }
1609  }
1610 
1611  // load vector joins - does not resolve references to layers yet
1612  mJoinBuffer->readXml( layer_node );
1613 
1614  updateFields();
1615 
1616  // If style doesn't include a legend, we'll need to make a default one later...
1617  mSetLegendFromStyle = false;
1618 
1619  QString errorMsg;
1620  if ( !readSymbology( layer_node, errorMsg, context ) )
1621  {
1622  return false;
1623  }
1624 
1625  readStyleManager( layer_node );
1626 
1627  QDomNode depsNode = layer_node.namedItem( QStringLiteral( "dataDependencies" ) );
1628  QDomNodeList depsNodes = depsNode.childNodes();
1629  QSet<QgsMapLayerDependency> sources;
1630  for ( int i = 0; i < depsNodes.count(); i++ )
1631  {
1632  QString source = depsNodes.at( i ).toElement().attribute( QStringLiteral( "id" ) );
1633  sources << QgsMapLayerDependency( source );
1634  }
1635  setDependencies( sources );
1636 
1637  if ( !mSetLegendFromStyle )
1639 
1640  // read extent
1642  {
1643  mReadExtentFromXml = true;
1644  }
1645  if ( mReadExtentFromXml )
1646  {
1647  const QDomNode extentNode = layer_node.namedItem( QStringLiteral( "extent" ) );
1648  if ( !extentNode.isNull() )
1649  {
1650  mXmlExtent = QgsXmlUtils::readRectangle( extentNode.toElement() );
1651  }
1652  }
1653 
1654  // auxiliary layer
1655  const QDomNode asNode = layer_node.namedItem( QStringLiteral( "auxiliaryLayer" ) );
1656  const QDomElement asElem = asNode.toElement();
1657  if ( !asElem.isNull() )
1658  {
1659  mAuxiliaryLayerKey = asElem.attribute( QStringLiteral( "key" ) );
1660  }
1661 
1662  // QGIS Server WMS Dimensions
1663  mServerProperties->readXml( layer_node );
1664 
1665  return isValid(); // should be true if read successfully
1666 
1667 } // void QgsVectorLayer::readXml
1668 
1669 
1670 void QgsVectorLayer::setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider,
1671  const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags )
1672 {
1674 
1675  mDataSource = dataSource;
1676  setName( baseName );
1677  setDataProvider( provider, options, flags );
1678 
1679  if ( !isValid() )
1680  {
1681  return;
1682  }
1683 
1684  // Always set crs
1686 
1687  bool loadDefaultStyleFlag = false;
1689  {
1690  loadDefaultStyleFlag = true;
1691  }
1692 
1693  // reset style if loading default style, style is missing, or geometry type is has changed (and layer is valid)
1694  if ( !renderer() || !legend() || ( isValid() && geomType != geometryType() ) || loadDefaultStyleFlag )
1695  {
1696  std::unique_ptr< QgsScopedRuntimeProfile > profile;
1697  if ( QgsApplication::profiler()->groupIsActive( QStringLiteral( "projectload" ) ) )
1698  profile = std::make_unique< QgsScopedRuntimeProfile >( tr( "Load layer style" ), QStringLiteral( "projectload" ) );
1699 
1700  bool defaultLoadedFlag = false;
1701 
1702  // defer style changed signal until we've set the renderer, labeling, everything.
1703  // we don't want multiple signals!
1704  ScopedIntIncrementor styleChangedSignalBlocker( &mBlockStyleChangedSignal );
1705 
1706  // need to check whether the default style included a legend, and if not, we need to make a default legend
1707  // later...
1708  mSetLegendFromStyle = false;
1709 
1710  // first check if there is a default style / propertysheet defined
1711  // for this layer and if so apply it
1712  // this should take precedence over all
1713  if ( !defaultLoadedFlag && loadDefaultStyleFlag )
1714  {
1715  loadDefaultStyle( defaultLoadedFlag );
1716  }
1717 
1718  if ( loadDefaultStyleFlag && !defaultLoadedFlag && isSpatial() && mDataProvider->capabilities() & QgsVectorDataProvider::CreateRenderer )
1719  {
1720  // if we didn't load a default style for this layer, try to create a renderer directly from the data provider
1721  std::unique_ptr< QgsFeatureRenderer > defaultRenderer( mDataProvider->createRenderer() );
1722  if ( defaultRenderer )
1723  {
1724  defaultLoadedFlag = true;
1725  setRenderer( defaultRenderer.release() );
1726  }
1727  }
1728 
1729  // if the default style failed to load or was disabled use some very basic defaults
1730  if ( !defaultLoadedFlag && isSpatial() )
1731  {
1732  // add single symbol renderer
1734  }
1735 
1736  if ( !mSetLegendFromStyle )
1738 
1739  if ( mDataProvider->capabilities() & QgsVectorDataProvider::CreateLabeling )
1740  {
1741  std::unique_ptr< QgsAbstractVectorLayerLabeling > defaultLabeling( mDataProvider->createLabeling() );
1742  if ( defaultLabeling )
1743  {
1744  setLabeling( defaultLabeling.release() );
1745  setLabelsEnabled( true );
1746  }
1747  }
1748 
1749  styleChangedSignalBlocker.release();
1750  emitStyleChanged();
1751  }
1752 }
1753 
1754 QString QgsVectorLayer::loadDefaultStyle( bool &resultFlag )
1755 {
1756  // first try to load a user-defined default style - this should always take precedence
1757  QString res = QgsMapLayer::loadDefaultStyle( resultFlag );
1758  if ( resultFlag )
1759  return res;
1760 
1761  if ( isSpatial() && mDataProvider->capabilities() & QgsVectorDataProvider::CreateRenderer )
1762  {
1763  // otherwise try to create a renderer directly from the data provider
1764  std::unique_ptr< QgsFeatureRenderer > defaultRenderer( mDataProvider->createRenderer() );
1765  if ( defaultRenderer )
1766  {
1767  resultFlag = true;
1768  setRenderer( defaultRenderer.release() );
1769  return QString();
1770  }
1771  }
1772 
1773  return QString();
1774 }
1775 
1776 bool QgsVectorLayer::setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags )
1777 {
1778  mProviderKey = provider;
1779  delete mDataProvider;
1780 
1781  // For Postgres provider primary key unicity is tested at construction time,
1782  // so it has to be set before initializing the provider,
1783  // this manipulation is necessary to preserve default behavior when
1784  // "trust layer metadata" project level option is set and checkPrimaryKeyUnicity
1785  // was not explicitly passed in the uri
1786  if ( provider.compare( QLatin1String( "postgres" ) ) == 0 )
1787  {
1788  const QString checkUnicityKey { QStringLiteral( "checkPrimaryKeyUnicity" ) };
1790  if ( ! uri.hasParam( checkUnicityKey ) )
1791  {
1792  uri.setParam( checkUnicityKey, mReadExtentFromXml ? "0" : "1" );
1793  mDataSource = uri.uri( false );
1794  }
1795  }
1796 
1797  std::unique_ptr< QgsScopedRuntimeProfile > profile;
1798  if ( QgsApplication::profiler()->groupIsActive( QStringLiteral( "projectload" ) ) )
1799  profile = std::make_unique< QgsScopedRuntimeProfile >( tr( "Create %1 provider" ).arg( provider ), QStringLiteral( "projectload" ) );
1800 
1801  mDataProvider = qobject_cast<QgsVectorDataProvider *>( QgsProviderRegistry::instance()->createProvider( provider, mDataSource, options, flags ) );
1802  if ( !mDataProvider )
1803  {
1804  setValid( false );
1805  QgsDebugMsgLevel( QStringLiteral( "Unable to get data provider" ), 2 );
1806  return false;
1807  }
1808 
1809  mDataProvider->setParent( this );
1810  connect( mDataProvider, &QgsVectorDataProvider::raiseError, this, &QgsVectorLayer::raiseError );
1811 
1812  QgsDebugMsgLevel( QStringLiteral( "Instantiated the data provider plugin" ), 2 );
1813 
1814  setValid( mDataProvider->isValid() );
1815  if ( !isValid() )
1816  {
1817  QgsDebugMsgLevel( QStringLiteral( "Invalid provider plugin %1" ).arg( QString( mDataSource.toUtf8() ) ), 2 );
1818  return false;
1819  }
1820 
1821  if ( profile )
1822  profile->switchTask( tr( "Read layer metadata" ) );
1823  if ( mDataProvider->capabilities() & QgsVectorDataProvider::ReadLayerMetadata )
1824  {
1825  // we combine the provider metadata with the layer's existing metadata, so as not to reset any user customizations to the metadata
1826  // back to the default if a layer's data source is changed
1827  QgsLayerMetadata newMetadata = mDataProvider->layerMetadata();
1828  // this overwrites the provider metadata with any properties which are non-empty from the existing layer metadata
1829  newMetadata.combine( &mMetadata );
1830 
1831  setMetadata( newMetadata );
1832  QgsDebugMsgLevel( QStringLiteral( "Set Data provider QgsLayerMetadata identifier[%1]" ).arg( metadata().identifier() ), 4 );
1833  }
1834 
1835  // TODO: Check if the provider has the capability to send fullExtentCalculated
1836  connect( mDataProvider, &QgsVectorDataProvider::fullExtentCalculated, this, [ = ] { updateExtents(); } );
1837 
1838  // get and store the feature type
1839  mWkbType = mDataProvider->wkbType();
1840 
1841  // before we update the layer fields from the provider, we first copy any default set alias and
1842  // editor widget config from the data provider fields, if present
1843  const QgsFields providerFields = mDataProvider->fields();
1844  for ( const QgsField &field : providerFields )
1845  {
1846  // we only copy defaults from the provider if we aren't overriding any configuration made in the layer
1847  if ( !field.editorWidgetSetup().isNull() && mFieldWidgetSetups.value( field.name() ).isNull() )
1848  {
1849  mFieldWidgetSetups[ field.name() ] = field.editorWidgetSetup();
1850  }
1851  if ( !field.alias().isEmpty() && mAttributeAliasMap.value( field.name() ).isEmpty() )
1852  {
1853  mAttributeAliasMap[ field.name() ] = field.alias();
1854  }
1855  }
1856 
1857  if ( profile )
1858  profile->switchTask( tr( "Read layer fields" ) );
1859  updateFields();
1860 
1861  if ( mProviderKey == QLatin1String( "postgres" ) )
1862  {
1863  // update datasource from data provider computed one
1864  mDataSource = mDataProvider->dataSourceUri( false );
1865 
1866  QgsDebugMsgLevel( QStringLiteral( "Beautifying layer name %1" ).arg( name() ), 3 );
1867 
1868  // adjust the display name for postgres layers
1869  const QRegularExpression reg( R"lit("[^"]+"\."([^"] + )"( \([^)]+\))?)lit" );
1870  const QRegularExpressionMatch match = reg.match( name() );
1871  if ( match.hasMatch() )
1872  {
1873  QStringList stuff = match.capturedTexts();
1874  QString lName = stuff[1];
1875 
1876  const QMap<QString, QgsMapLayer *> &layers = QgsProject::instance()->mapLayers();
1877 
1878  QMap<QString, QgsMapLayer *>::const_iterator it;
1879  for ( it = layers.constBegin(); it != layers.constEnd() && ( *it )->name() != lName; ++it )
1880  ;
1881 
1882  if ( it != layers.constEnd() && stuff.size() > 2 )
1883  {
1884  lName += '.' + stuff[2].mid( 2, stuff[2].length() - 3 );
1885  }
1886 
1887  if ( !lName.isEmpty() )
1888  setName( lName );
1889  }
1890  QgsDebugMsgLevel( QStringLiteral( "Beautified layer name %1" ).arg( name() ), 3 );
1891  }
1892  else if ( mProviderKey == QLatin1String( "osm" ) )
1893  {
1894  // make sure that the "observer" has been removed from URI to avoid crashes
1895  mDataSource = mDataProvider->dataSourceUri();
1896  }
1897  else if ( provider == QLatin1String( "ogr" ) )
1898  {
1899  // make sure that the /vsigzip or /vsizip is added to uri, if applicable
1900  mDataSource = mDataProvider->dataSourceUri();
1901  if ( mDataSource.right( 10 ) == QLatin1String( "|layerid=0" ) )
1902  mDataSource.chop( 10 );
1903  }
1904  else if ( provider == QLatin1String( "memory" ) )
1905  {
1906  // required so that source differs between memory layers
1907  mDataSource = mDataSource + QStringLiteral( "&uid=%1" ).arg( QUuid::createUuid().toString() );
1908  }
1909  else if ( provider == QLatin1String( "hana" ) )
1910  {
1911  // update datasource from data provider computed one
1912  mDataSource = mDataProvider->dataSourceUri( false );
1913  }
1914 
1915  connect( mDataProvider, &QgsVectorDataProvider::dataChanged, this, &QgsVectorLayer::emitDataChanged );
1916  connect( mDataProvider, &QgsVectorDataProvider::dataChanged, this, &QgsVectorLayer::removeSelection );
1917 
1918  return true;
1919 } // QgsVectorLayer:: setDataProvider
1920 
1921 
1922 
1923 
1924 /* virtual */
1925 bool QgsVectorLayer::writeXml( QDomNode &layer_node,
1926  QDomDocument &document,
1927  const QgsReadWriteContext &context ) const
1928 {
1929  // first get the layer element so that we can append the type attribute
1930 
1931  QDomElement mapLayerNode = layer_node.toElement();
1932 
1933  if ( mapLayerNode.isNull() || ( "maplayer" != mapLayerNode.nodeName() ) )
1934  {
1935  QgsDebugMsgLevel( QStringLiteral( "can't find <maplayer>" ), 2 );
1936  return false;
1937  }
1938 
1939  mapLayerNode.setAttribute( QStringLiteral( "type" ), QgsMapLayerFactory::typeToString( QgsMapLayerType::VectorLayer ) );
1940 
1941  // set the geometry type
1942  mapLayerNode.setAttribute( QStringLiteral( "geometry" ), QgsWkbTypes::geometryDisplayString( geometryType() ) );
1943  mapLayerNode.setAttribute( QStringLiteral( "wkbType" ), qgsEnumValueToKey( wkbType() ) );
1944 
1945  // add provider node
1946  if ( mDataProvider )
1947  {
1948  QDomElement provider = document.createElement( QStringLiteral( "provider" ) );
1949  provider.setAttribute( QStringLiteral( "encoding" ), mDataProvider->encoding() );
1950  QDomText providerText = document.createTextNode( providerType() );
1951  provider.appendChild( providerText );
1952  layer_node.appendChild( provider );
1953  }
1954 
1955  //save joins
1956  mJoinBuffer->writeXml( layer_node, document );
1957 
1958  // dependencies
1959  QDomElement dependenciesElement = document.createElement( QStringLiteral( "layerDependencies" ) );
1960  const auto constDependencies = dependencies();
1961  for ( const QgsMapLayerDependency &dep : constDependencies )
1962  {
1963  if ( dep.type() != QgsMapLayerDependency::PresenceDependency )
1964  continue;
1965  QDomElement depElem = document.createElement( QStringLiteral( "layer" ) );
1966  depElem.setAttribute( QStringLiteral( "id" ), dep.layerId() );
1967  dependenciesElement.appendChild( depElem );
1968  }
1969  layer_node.appendChild( dependenciesElement );
1970 
1971  // change dependencies
1972  QDomElement dataDependenciesElement = document.createElement( QStringLiteral( "dataDependencies" ) );
1973  for ( const QgsMapLayerDependency &dep : constDependencies )
1974  {
1975  if ( dep.type() != QgsMapLayerDependency::DataDependency )
1976  continue;
1977  QDomElement depElem = document.createElement( QStringLiteral( "layer" ) );
1978  depElem.setAttribute( QStringLiteral( "id" ), dep.layerId() );
1979  dataDependenciesElement.appendChild( depElem );
1980  }
1981  layer_node.appendChild( dataDependenciesElement );
1982 
1983  // save expression fields
1984  mExpressionFieldBuffer->writeXml( layer_node, document );
1985 
1986  writeStyleManager( layer_node, document );
1987 
1988  // auxiliary layer
1989  QDomElement asElem = document.createElement( QStringLiteral( "auxiliaryLayer" ) );
1990  if ( mAuxiliaryLayer )
1991  {
1992  const QString pkField = mAuxiliaryLayer->joinInfo().targetFieldName();
1993  asElem.setAttribute( QStringLiteral( "key" ), pkField );
1994  }
1995  layer_node.appendChild( asElem );
1996 
1997  // save QGIS Server properties (WMS Dimension, metadata URLS...)
1998  mServerProperties->writeXml( layer_node, document );
1999 
2000  // renderer specific settings
2001  QString errorMsg;
2002  return writeSymbology( layer_node, document, errorMsg, context );
2003 }
2004 
2005 QString QgsVectorLayer::encodedSource( const QString &source, const QgsReadWriteContext &context ) const
2006 {
2007  QString src( source );
2008 
2009  // TODO: what about postgres, mysql and others, they should not go through writePath()
2010  if ( providerType() == QLatin1String( "spatialite" ) )
2011  {
2012  QgsDataSourceUri uri( src );
2013  QString database = context.pathResolver().writePath( uri.database() );
2014  uri.setConnection( uri.host(), uri.port(), database, uri.username(), uri.password() );
2015  src = uri.uri();
2016  }
2017  else if ( providerType() == QLatin1String( "ogr" ) )
2018  {
2019  QStringList theURIParts = src.split( '|' );
2020  theURIParts[0] = context.pathResolver().writePath( theURIParts[0] );
2021  src = theURIParts.join( QLatin1Char( '|' ) );
2022  }
2023  else if ( providerType() == QLatin1String( "gpx" ) )
2024  {
2025  QStringList theURIParts = src.split( '?' );
2026  theURIParts[0] = context.pathResolver().writePath( theURIParts[0] );
2027  src = theURIParts.join( QLatin1Char( '?' ) );
2028  }
2029  else if ( providerType() == QLatin1String( "delimitedtext" ) )
2030  {
2031  QUrl urlSource = QUrl::fromEncoded( src.toLatin1() );
2032  QUrl urlDest = QUrl::fromLocalFile( context.pathResolver().writePath( urlSource.toLocalFile() ) );
2033  urlDest.setQuery( urlSource.query() );
2034  src = QString::fromLatin1( urlDest.toEncoded() );
2035  }
2036  else if ( providerType() == QLatin1String( "memory" ) )
2037  {
2038  // Refetch the source from the provider, because adding fields actually changes the source for this provider.
2039  src = dataProvider()->dataSourceUri();
2040  }
2041  else if ( providerType() == QLatin1String( "virtual" ) )
2042  {
2043  QUrl urlSource = QUrl::fromEncoded( src.toLatin1() );
2044  QStringList theURIParts;
2045 
2046  QUrlQuery query = QUrlQuery( urlSource.query() );
2047  QList<QPair<QString, QString> > queryItems = query.queryItems();
2048 
2049  for ( int i = 0; i < queryItems.size(); i++ )
2050  {
2051  QString key = queryItems.at( i ).first;
2052  QString value = queryItems.at( i ).second;
2053  if ( key == QLatin1String( "layer" ) )
2054  {
2055  // syntax: provider:url_encoded_source_URI(:name(:encoding)?)?
2056  theURIParts = value.split( ':' );
2057  theURIParts[1] = QUrl::fromPercentEncoding( theURIParts[1].toUtf8() );
2058 
2059  if ( theURIParts[0] == QLatin1String( "delimitedtext" ) )
2060  {
2061  QUrl urlSource = QUrl( theURIParts[1] );
2062  QUrl urlDest = QUrl::fromLocalFile( context.pathResolver().writePath( urlSource.toLocalFile() ) );
2063  urlDest.setQuery( urlSource.query() );
2064  theURIParts[1] = QUrl::toPercentEncoding( urlDest.toString(), QByteArray( "" ), QByteArray( ":" ) );
2065  }
2066  else
2067  {
2068  theURIParts[1] = context.pathResolver().writePath( theURIParts[1] );
2069  theURIParts[1] = QUrl::toPercentEncoding( theURIParts[1] );
2070  }
2071 
2072  queryItems[i].second = theURIParts.join( QLatin1Char( ':' ) ) ;
2073  }
2074  }
2075 
2076  query.setQueryItems( queryItems );
2077 
2078  QUrl urlDest = QUrl( urlSource );
2079  urlDest.setQuery( query.query() );
2080  src = QString::fromLatin1( urlDest.toEncoded() );
2081  }
2082  else
2083  {
2084  src = context.pathResolver().writePath( src );
2085  }
2086 
2087  return src;
2088 }
2089 
2090 QString QgsVectorLayer::decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const
2091 {
2092  QString src( source );
2093 
2094  if ( provider == QLatin1String( "spatialite" ) )
2095  {
2096  QgsDataSourceUri uri( src );
2097  uri.setDatabase( context.pathResolver().readPath( uri.database() ) );
2098  src = uri.uri();
2099  }
2100  else if ( provider == QLatin1String( "ogr" ) )
2101  {
2102  QStringList theURIParts = src.split( '|' );
2103  theURIParts[0] = context.pathResolver().readPath( theURIParts[0] );
2104  src = theURIParts.join( QLatin1Char( '|' ) );
2105  }
2106  else if ( provider == QLatin1String( "gpx" ) )
2107  {
2108  QStringList theURIParts = src.split( '?' );
2109  theURIParts[0] = context.pathResolver().readPath( theURIParts[0] );
2110  src = theURIParts.join( QLatin1Char( '?' ) );
2111  }
2112  else if ( provider == QLatin1String( "delimitedtext" ) )
2113  {
2114  QUrl urlSource = QUrl::fromEncoded( src.toLatin1() );
2115 
2116  if ( !src.startsWith( QLatin1String( "file:" ) ) )
2117  {
2118  QUrl file = QUrl::fromLocalFile( src.left( src.indexOf( '?' ) ) );
2119  urlSource.setScheme( QStringLiteral( "file" ) );
2120  urlSource.setPath( file.path() );
2121  }
2122 
2123  QUrl urlDest = QUrl::fromLocalFile( context.pathResolver().readPath( urlSource.toLocalFile() ) );
2124  urlDest.setQuery( urlSource.query() );
2125  src = QString::fromLatin1( urlDest.toEncoded() );
2126  }
2127  else if ( provider == QLatin1String( "virtual" ) )
2128  {
2129  QUrl urlSource = QUrl::fromEncoded( src.toLatin1() );
2130  QStringList theURIParts;
2131 
2132  QUrlQuery query = QUrlQuery( urlSource.query() );
2133  QList<QPair<QString, QString> > queryItems = query.queryItems();
2134 
2135  for ( int i = 0; i < queryItems.size(); i++ )
2136  {
2137  QString key = queryItems.at( i ).first;
2138  QString value = queryItems.at( i ).second;
2139  if ( key == QLatin1String( "layer" ) )
2140  {
2141  // syntax: provider:url_encoded_source_URI(:name(:encoding)?)?
2142  theURIParts = value.split( ':' );
2143  theURIParts[1] = QUrl::fromPercentEncoding( theURIParts[1].toUtf8() );
2144 
2145  if ( theURIParts[0] == QLatin1String( "delimitedtext" ) )
2146  {
2147  QUrl urlSource = QUrl( theURIParts[1] );
2148 
2149  if ( !theURIParts[1].startsWith( QLatin1String( "file:" ) ) )
2150  {
2151  QUrl file = QUrl::fromLocalFile( theURIParts[1].left( theURIParts[1].indexOf( '?' ) ) );
2152  urlSource.setScheme( QStringLiteral( "file" ) );
2153  urlSource.setPath( file.path() );
2154  }
2155 
2156  QUrl urlDest = QUrl::fromLocalFile( context.pathResolver().readPath( urlSource.toLocalFile() ) );
2157  urlDest.setQuery( urlSource.query() );
2158 
2159  theURIParts[1] = urlDest.toString();
2160  }
2161  else
2162  {
2163  theURIParts[1] = context.pathResolver().readPath( theURIParts[1] );
2164  }
2165 
2166  theURIParts[1] = QUrl::toPercentEncoding( theURIParts[1] );
2167  queryItems[i].second = theURIParts.join( QLatin1Char( ':' ) ) ;
2168  }
2169  }
2170 
2171  query.setQueryItems( queryItems );
2172 
2173  QUrl urlDest = QUrl( urlSource );
2174  urlDest.setQuery( query.query() );
2175  src = QString::fromLatin1( urlDest.toEncoded() );
2176  }
2177  else
2178  {
2179  src = context.pathResolver().readPath( src );
2180  }
2181 
2182  return src;
2183 }
2184 
2185 
2186 
2188 {
2190  mJoinBuffer->resolveReferences( project );
2191 }
2192 
2193 
2194 bool QgsVectorLayer::readSymbology( const QDomNode &layerNode, QString &errorMessage,
2195  QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
2196 {
2197  if ( categories.testFlag( Fields ) )
2198  {
2199  if ( !mExpressionFieldBuffer )
2200  mExpressionFieldBuffer = new QgsExpressionFieldBuffer();
2201  mExpressionFieldBuffer->readXml( layerNode );
2202 
2203  updateFields();
2204  }
2205 
2206  if ( categories.testFlag( Relations ) )
2207  {
2208  QgsReadWriteContextCategoryPopper p = context.enterCategory( tr( "Relations" ) );
2209 
2210  const QgsPathResolver resolver { QgsProject::instance()->pathResolver() };
2211 
2212  // Restore referenced layers: relations where "this" is the child layer (the referencing part, that holds the FK)
2213  QDomNodeList referencedLayersNodeList = layerNode.toElement().elementsByTagName( QStringLiteral( "referencedLayers" ) );
2214  if ( referencedLayersNodeList.size() > 0 )
2215  {
2216  const QDomNodeList relationNodes { referencedLayersNodeList.at( 0 ).childNodes() };
2217  for ( int i = 0; i < relationNodes.length(); ++i )
2218  {
2219  const QDomElement relationElement = relationNodes.at( i ).toElement();
2220 
2221  mWeakRelations.push_back( QgsWeakRelation::readXml( this, QgsWeakRelation::Referencing, relationElement, resolver ) );
2222  }
2223  }
2224 
2225  // Restore referencing layers: relations where "this" is the parent layer (the referenced part where the FK points to)
2226  QDomNodeList referencingLayersNodeList = layerNode.toElement().elementsByTagName( QStringLiteral( "referencingLayers" ) );
2227  if ( referencingLayersNodeList.size() > 0 )
2228  {
2229  const QDomNodeList relationNodes { referencingLayersNodeList.at( 0 ).childNodes() };
2230  for ( int i = 0; i < relationNodes.length(); ++i )
2231  {
2232  const QDomElement relationElement = relationNodes.at( i ).toElement();
2233  mWeakRelations.push_back( QgsWeakRelation::readXml( this, QgsWeakRelation::Referenced, relationElement, resolver ) );
2234  }
2235  }
2236  }
2237 
2238  QDomElement layerElement = layerNode.toElement();
2239 
2240  readCommonStyle( layerElement, context, categories );
2241 
2242  readStyle( layerNode, errorMessage, context, categories );
2243 
2244  if ( categories.testFlag( MapTips ) )
2245  mMapTipTemplate = layerNode.namedItem( QStringLiteral( "mapTip" ) ).toElement().text();
2246 
2247  if ( categories.testFlag( LayerConfiguration ) )
2248  mDisplayExpression = layerNode.namedItem( QStringLiteral( "previewExpression" ) ).toElement().text();
2249 
2250  // Try to migrate pre QGIS 3.0 display field property
2251  QString displayField = layerNode.namedItem( QStringLiteral( "displayfield" ) ).toElement().text();
2252  if ( mFields.lookupField( displayField ) < 0 )
2253  {
2254  // if it's not a field, it's a maptip
2255  if ( mMapTipTemplate.isEmpty() && categories.testFlag( MapTips ) )
2256  mMapTipTemplate = displayField;
2257  }
2258  else
2259  {
2260  if ( mDisplayExpression.isEmpty() && categories.testFlag( LayerConfiguration ) )
2261  mDisplayExpression = QgsExpression::quotedColumnRef( displayField );
2262  }
2263 
2264  // process the attribute actions
2265  if ( categories.testFlag( Actions ) )
2266  mActions->readXml( layerNode );
2267 
2268  if ( categories.testFlag( Fields ) )
2269  {
2270  // IMPORTANT - we don't clear mAttributeAliasMap here, as it may contain aliases which are coming direct
2271  // from the data provider. Instead we leave any existing aliases and only overwrite them if the style
2272  // has a specific value for that field's alias
2273  QDomNode aliasesNode = layerNode.namedItem( QStringLiteral( "aliases" ) );
2274  if ( !aliasesNode.isNull() )
2275  {
2276  QDomElement aliasElem;
2277 
2278  QDomNodeList aliasNodeList = aliasesNode.toElement().elementsByTagName( QStringLiteral( "alias" ) );
2279  for ( int i = 0; i < aliasNodeList.size(); ++i )
2280  {
2281  aliasElem = aliasNodeList.at( i ).toElement();
2282 
2283  QString field;
2284  if ( aliasElem.hasAttribute( QStringLiteral( "field" ) ) )
2285  {
2286  field = aliasElem.attribute( QStringLiteral( "field" ) );
2287  }
2288  else
2289  {
2290  int index = aliasElem.attribute( QStringLiteral( "index" ) ).toInt();
2291 
2292  if ( index >= 0 && index < fields().count() )
2293  field = fields().at( index ).name();
2294  }
2295 
2296  QString alias;
2297 
2298  if ( !aliasElem.attribute( QStringLiteral( "name" ) ).isEmpty() )
2299  {
2300  //if it has alias
2301  alias = context.projectTranslator()->translate( QStringLiteral( "project:layers:%1:fieldaliases" ).arg( layerNode.namedItem( QStringLiteral( "id" ) ).toElement().text() ), aliasElem.attribute( QStringLiteral( "name" ) ) );
2302  QgsDebugMsgLevel( "context" + QStringLiteral( "project:layers:%1:fieldaliases" ).arg( layerNode.namedItem( QStringLiteral( "id" ) ).toElement().text() ) + " source " + aliasElem.attribute( QStringLiteral( "name" ) ), 3 );
2303  }
2304  else
2305  {
2306  //if it has no alias, it should be the fields translation
2307  alias = context.projectTranslator()->translate( QStringLiteral( "project:layers:%1:fieldaliases" ).arg( layerNode.namedItem( QStringLiteral( "id" ) ).toElement().text() ), field );
2308  QgsDebugMsgLevel( "context" + QStringLiteral( "project:layers:%1:fieldaliases" ).arg( layerNode.namedItem( QStringLiteral( "id" ) ).toElement().text() ) + " source " + field, 3 );
2309  //if it gets the exact field value, there has been no translation (or not even translation loaded) - so no alias should be generated;
2310  if ( alias == aliasElem.attribute( QStringLiteral( "field" ) ) )
2311  alias.clear();
2312  }
2313 
2314  QgsDebugMsgLevel( "field " + field + " origalias " + aliasElem.attribute( QStringLiteral( "name" ) ) + " trans " + alias, 3 );
2315  mAttributeAliasMap.insert( field, alias );
2316  }
2317  }
2318 
2319  // default expressions
2320  mDefaultExpressionMap.clear();
2321  QDomNode defaultsNode = layerNode.namedItem( QStringLiteral( "defaults" ) );
2322  if ( !defaultsNode.isNull() )
2323  {
2324  QDomNodeList defaultNodeList = defaultsNode.toElement().elementsByTagName( QStringLiteral( "default" ) );
2325  for ( int i = 0; i < defaultNodeList.size(); ++i )
2326  {
2327  QDomElement defaultElem = defaultNodeList.at( i ).toElement();
2328 
2329  QString field = defaultElem.attribute( QStringLiteral( "field" ), QString() );
2330  QString expression = defaultElem.attribute( QStringLiteral( "expression" ), QString() );
2331  bool applyOnUpdate = defaultElem.attribute( QStringLiteral( "applyOnUpdate" ), QStringLiteral( "0" ) ) == QLatin1String( "1" );
2332  if ( field.isEmpty() || expression.isEmpty() )
2333  continue;
2334 
2335  mDefaultExpressionMap.insert( field, QgsDefaultValue( expression, applyOnUpdate ) );
2336  }
2337  }
2338 
2339  // constraints
2340  mFieldConstraints.clear();
2341  mFieldConstraintStrength.clear();
2342  QDomNode constraintsNode = layerNode.namedItem( QStringLiteral( "constraints" ) );
2343  if ( !constraintsNode.isNull() )
2344  {
2345  QDomNodeList constraintNodeList = constraintsNode.toElement().elementsByTagName( QStringLiteral( "constraint" ) );
2346  for ( int i = 0; i < constraintNodeList.size(); ++i )
2347  {
2348  QDomElement constraintElem = constraintNodeList.at( i ).toElement();
2349 
2350  QString field = constraintElem.attribute( QStringLiteral( "field" ), QString() );
2351  int constraints = constraintElem.attribute( QStringLiteral( "constraints" ), QStringLiteral( "0" ) ).toInt();
2352  if ( field.isEmpty() || constraints == 0 )
2353  continue;
2354 
2355  mFieldConstraints.insert( field, static_cast< QgsFieldConstraints::Constraints >( constraints ) );
2356 
2357  int uniqueStrength = constraintElem.attribute( QStringLiteral( "unique_strength" ), QStringLiteral( "1" ) ).toInt();
2358  int notNullStrength = constraintElem.attribute( QStringLiteral( "notnull_strength" ), QStringLiteral( "1" ) ).toInt();
2359  int expStrength = constraintElem.attribute( QStringLiteral( "exp_strength" ), QStringLiteral( "1" ) ).toInt();
2360 
2361  mFieldConstraintStrength.insert( qMakePair( field, QgsFieldConstraints::ConstraintUnique ), static_cast< QgsFieldConstraints::ConstraintStrength >( uniqueStrength ) );
2362  mFieldConstraintStrength.insert( qMakePair( field, QgsFieldConstraints::ConstraintNotNull ), static_cast< QgsFieldConstraints::ConstraintStrength >( notNullStrength ) );
2363  mFieldConstraintStrength.insert( qMakePair( field, QgsFieldConstraints::ConstraintExpression ), static_cast< QgsFieldConstraints::ConstraintStrength >( expStrength ) );
2364  }
2365  }
2366  mFieldConstraintExpressions.clear();
2367  QDomNode constraintExpressionsNode = layerNode.namedItem( QStringLiteral( "constraintExpressions" ) );
2368  if ( !constraintExpressionsNode.isNull() )
2369  {
2370  QDomNodeList constraintNodeList = constraintExpressionsNode.toElement().elementsByTagName( QStringLiteral( "constraint" ) );
2371  for ( int i = 0; i < constraintNodeList.size(); ++i )
2372  {
2373  QDomElement constraintElem = constraintNodeList.at( i ).toElement();
2374 
2375  QString field = constraintElem.attribute( QStringLiteral( "field" ), QString() );
2376  QString exp = constraintElem.attribute( QStringLiteral( "exp" ), QString() );
2377  QString desc = constraintElem.attribute( QStringLiteral( "desc" ), QString() );
2378  if ( field.isEmpty() || exp.isEmpty() )
2379  continue;
2380 
2381  mFieldConstraintExpressions.insert( field, qMakePair( exp, desc ) );
2382  }
2383  }
2384 
2385  updateFields();
2386  }
2387 
2388  // load field configuration
2389  if ( categories.testFlag( Fields ) || categories.testFlag( Forms ) )
2390  {
2391  QgsReadWriteContextCategoryPopper p = context.enterCategory( tr( "Forms" ) );
2392 
2393  QDomElement widgetsElem = layerNode.namedItem( QStringLiteral( "fieldConfiguration" ) ).toElement();
2394  QDomNodeList fieldConfigurationElementList = widgetsElem.elementsByTagName( QStringLiteral( "field" ) );
2395  for ( int i = 0; i < fieldConfigurationElementList.size(); ++i )
2396  {
2397  const QDomElement fieldConfigElement = fieldConfigurationElementList.at( i ).toElement();
2398  const QDomElement fieldWidgetElement = fieldConfigElement.elementsByTagName( QStringLiteral( "editWidget" ) ).at( 0 ).toElement();
2399 
2400  QString fieldName = fieldConfigElement.attribute( QStringLiteral( "name" ) );
2401 
2402  if ( categories.testFlag( Fields ) )
2403  mFieldConfigurationFlags[fieldName] = qgsFlagKeysToValue( fieldConfigElement.attribute( QStringLiteral( "configurationFlags" ) ), QgsField::ConfigurationFlag::None );
2404 
2405  // Load editor widget configuration
2406  if ( categories.testFlag( Forms ) )
2407  {
2408  const QString widgetType = fieldWidgetElement.attribute( QStringLiteral( "type" ) );
2409  const QDomElement cfgElem = fieldConfigElement.elementsByTagName( QStringLiteral( "config" ) ).at( 0 ).toElement();
2410  const QDomElement optionsElem = cfgElem.childNodes().at( 0 ).toElement();
2411  QVariantMap optionsMap = QgsXmlUtils::readVariant( optionsElem ).toMap();
2412  if ( widgetType == QLatin1String( "ValueRelation" ) )
2413  {
2414  optionsMap[ QStringLiteral( "Value" ) ] = context.projectTranslator()->translate( QStringLiteral( "project:layers:%1:fields:%2:valuerelationvalue" ).arg( layerNode.namedItem( QStringLiteral( "id" ) ).toElement().text(), fieldName ), optionsMap[ QStringLiteral( "Value" ) ].toString() );
2415  }
2416  QgsEditorWidgetSetup setup = QgsEditorWidgetSetup( widgetType, optionsMap );
2417  mFieldWidgetSetups[fieldName] = setup;
2418  }
2419  }
2420  }
2421 
2422  // Legacy reading for QGIS 3.14 and older projects
2423  // Attributes excluded from WMS and WFS
2424  if ( categories.testFlag( Fields ) )
2425  {
2426  const QList<QPair<QString, QgsField::ConfigurationFlag>> legacyConfig
2427  {
2428  qMakePair( QStringLiteral( "excludeAttributesWMS" ), QgsField::ConfigurationFlag::HideFromWms ),
2429  qMakePair( QStringLiteral( "excludeAttributesWFS" ), QgsField::ConfigurationFlag::HideFromWfs )
2430  };
2431  for ( const auto &config : legacyConfig )
2432  {
2433  QDomNode excludeNode = layerNode.namedItem( config.first );
2434  if ( !excludeNode.isNull() )
2435  {
2436  QDomNodeList attributeNodeList = excludeNode.toElement().elementsByTagName( QStringLiteral( "attribute" ) );
2437  for ( int i = 0; i < attributeNodeList.size(); ++i )
2438  {
2439  QString fieldName = attributeNodeList.at( i ).toElement().text();
2440  if ( !mFieldConfigurationFlags.contains( fieldName ) )
2441  mFieldConfigurationFlags[fieldName] = config.second;
2442  else
2443  mFieldConfigurationFlags[fieldName].setFlag( config.second, true );
2444  }
2445  }
2446  }
2447  }
2448 
2449  if ( categories.testFlag( GeometryOptions ) )
2450  mGeometryOptions->readXml( layerNode.namedItem( QStringLiteral( "geometryOptions" ) ) );
2451 
2452  if ( categories.testFlag( Forms ) )
2453  mEditFormConfig.readXml( layerNode, context );
2454 
2455  if ( categories.testFlag( AttributeTable ) )
2456  {
2457  mAttributeTableConfig.readXml( layerNode );
2458  mConditionalStyles->readXml( layerNode, context );
2459  mStoredExpressionManager->readXml( layerNode );
2460  }
2461 
2462  if ( categories.testFlag( CustomProperties ) )
2463  readCustomProperties( layerNode, QStringLiteral( "variable" ) );
2464 
2465  QDomElement mapLayerNode = layerNode.toElement();
2466  if ( categories.testFlag( LayerConfiguration )
2467  && mapLayerNode.attribute( QStringLiteral( "readOnly" ), QStringLiteral( "0" ) ).toInt() == 1 )
2468  mReadOnly = true;
2469 
2470  updateFields();
2471 
2472  if ( categories.testFlag( Legend ) )
2473  {
2474  QgsReadWriteContextCategoryPopper p = context.enterCategory( tr( "Legend" ) );
2475 
2476  const QDomElement legendElem = layerNode.firstChildElement( QStringLiteral( "legend" ) );
2477  if ( !legendElem.isNull() )
2478  {
2479  std::unique_ptr< QgsMapLayerLegend > legend( QgsMapLayerLegend::defaultVectorLegend( this ) );
2480  legend->readXml( legendElem, context );
2481  setLegend( legend.release() );
2482  mSetLegendFromStyle = true;
2483  }
2484  }
2485 
2486  return true;
2487 }
2488 
2489 bool QgsVectorLayer::readStyle( const QDomNode &node, QString &errorMessage,
2490  QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
2491 {
2492  bool result = true;
2493  emit readCustomSymbology( node.toElement(), errorMessage );
2494 
2495  // we must try to restore a renderer if our geometry type is unknown
2496  // as this allows the renderer to be correctly restored even for layers
2497  // with broken sources
2498  if ( isSpatial() || mWkbType == QgsWkbTypes::Unknown )
2499  {
2500  // defer style changed signal until we've set the renderer, labeling, everything.
2501  // we don't want multiple signals!
2502  ScopedIntIncrementor styleChangedSignalBlocker( &mBlockStyleChangedSignal );
2503 
2504  // try renderer v2 first
2505  if ( categories.testFlag( Symbology ) )
2506  {
2507  QgsReadWriteContextCategoryPopper p = context.enterCategory( tr( "Symbology" ) );
2508 
2509  QDomElement rendererElement = node.firstChildElement( RENDERER_TAG_NAME );
2510  if ( !rendererElement.isNull() )
2511  {
2512  QgsFeatureRenderer *r = QgsFeatureRenderer::load( rendererElement, context );
2513  if ( r )
2514  {
2515  setRenderer( r );
2516  }
2517  else
2518  {
2519  result = false;
2520  }
2521  }
2522  // make sure layer has a renderer - if none exists, fallback to a default renderer
2523  if ( isSpatial() && !renderer() )
2524  {
2526  }
2527  }
2528 
2529  // read labeling definition
2530  if ( categories.testFlag( Labeling ) )
2531  {
2532  QgsReadWriteContextCategoryPopper p = context.enterCategory( tr( "Labeling" ) );
2533 
2534  QDomElement labelingElement = node.firstChildElement( QStringLiteral( "labeling" ) );
2536  if ( labelingElement.isNull() ||
2537  ( labelingElement.attribute( QStringLiteral( "type" ) ) == QLatin1String( "simple" ) && labelingElement.firstChildElement( QStringLiteral( "settings" ) ).isNull() ) )
2538  {
2539  // make sure we have custom properties for labeling for 2.x projects
2540  // (custom properties should be already loaded when reading the whole layer from XML,
2541  // but when reading style, custom properties are not read)
2542  readCustomProperties( node, QStringLiteral( "labeling" ) );
2543 
2544  // support for pre-QGIS 3 labeling configurations written in custom properties
2545  labeling = readLabelingFromCustomProperties();
2546  }
2547  else
2548  {
2549  labeling = QgsAbstractVectorLayerLabeling::create( labelingElement, context );
2550  }
2551  setLabeling( labeling );
2552 
2553  if ( node.toElement().hasAttribute( QStringLiteral( "labelsEnabled" ) ) )
2554  mLabelsEnabled = node.toElement().attribute( QStringLiteral( "labelsEnabled" ) ).toInt();
2555  else
2556  mLabelsEnabled = true;
2557  }
2558 
2559  if ( categories.testFlag( Symbology ) )
2560  {
2561  // get and set the blend mode if it exists
2562  QDomNode blendModeNode = node.namedItem( QStringLiteral( "blendMode" ) );
2563  if ( !blendModeNode.isNull() )
2564  {
2565  QDomElement e = blendModeNode.toElement();
2566  setBlendMode( QgsPainting::getCompositionMode( static_cast< QgsPainting::BlendMode >( e.text().toInt() ) ) );
2567  }
2568 
2569  // get and set the feature blend mode if it exists
2570  QDomNode featureBlendModeNode = node.namedItem( QStringLiteral( "featureBlendMode" ) );
2571  if ( !featureBlendModeNode.isNull() )
2572  {
2573  QDomElement e = featureBlendModeNode.toElement();
2574  setFeatureBlendMode( QgsPainting::getCompositionMode( static_cast< QgsPainting::BlendMode >( e.text().toInt() ) ) );
2575  }
2576  }
2577 
2578  // get and set the layer transparency and scale visibility if they exists
2579  if ( categories.testFlag( Rendering ) )
2580  {
2581  QDomNode layerTransparencyNode = node.namedItem( QStringLiteral( "layerTransparency" ) );
2582  if ( !layerTransparencyNode.isNull() )
2583  {
2584  QDomElement e = layerTransparencyNode.toElement();
2585  setOpacity( 1.0 - e.text().toInt() / 100.0 );
2586  }
2587  QDomNode layerOpacityNode = node.namedItem( QStringLiteral( "layerOpacity" ) );
2588  if ( !layerOpacityNode.isNull() )
2589  {
2590  QDomElement e = layerOpacityNode.toElement();
2591  setOpacity( e.text().toDouble() );
2592  }
2593 
2594  const bool hasScaleBasedVisibiliy { node.attributes().namedItem( QStringLiteral( "hasScaleBasedVisibilityFlag" ) ).nodeValue() == '1' };
2595  setScaleBasedVisibility( hasScaleBasedVisibiliy );
2596  bool ok;
2597  const double maxScale { node.attributes().namedItem( QStringLiteral( "maxScale" ) ).nodeValue().toDouble( &ok ) };
2598  if ( ok )
2599  {
2600  setMaximumScale( maxScale );
2601  }
2602  const double minScale { node.attributes().namedItem( QStringLiteral( "minScale" ) ).nodeValue().toDouble( &ok ) };
2603  if ( ok )
2604  {
2605  setMinimumScale( minScale );
2606  }
2607 
2608  QDomElement e = node.toElement();
2609 
2610  // get the simplification drawing settings
2611  mSimplifyMethod.setSimplifyHints( static_cast< QgsVectorSimplifyMethod::SimplifyHints >( e.attribute( QStringLiteral( "simplifyDrawingHints" ), QStringLiteral( "1" ) ).toInt() ) );
2612  mSimplifyMethod.setSimplifyAlgorithm( static_cast< QgsVectorSimplifyMethod::SimplifyAlgorithm >( e.attribute( QStringLiteral( "simplifyAlgorithm" ), QStringLiteral( "0" ) ).toInt() ) );
2613  mSimplifyMethod.setThreshold( e.attribute( QStringLiteral( "simplifyDrawingTol" ), QStringLiteral( "1" ) ).toFloat() );
2614  mSimplifyMethod.setForceLocalOptimization( e.attribute( QStringLiteral( "simplifyLocal" ), QStringLiteral( "1" ) ).toInt() );
2615  mSimplifyMethod.setMaximumScale( e.attribute( QStringLiteral( "simplifyMaxScale" ), QStringLiteral( "1" ) ).toFloat() );
2616 
2617  if ( mRenderer )
2618  mRenderer->setReferenceScale( e.attribute( QStringLiteral( "symbologyReferenceScale" ), QStringLiteral( "-1" ) ).toDouble() );
2619  }
2620 
2621  //diagram renderer and diagram layer settings
2622  if ( categories.testFlag( Diagrams ) )
2623  {
2624  QgsReadWriteContextCategoryPopper p = context.enterCategory( tr( "Diagrams" ) );
2625 
2626  delete mDiagramRenderer;
2627  mDiagramRenderer = nullptr;
2628  QDomElement singleCatDiagramElem = node.firstChildElement( QStringLiteral( "SingleCategoryDiagramRenderer" ) );
2629  if ( !singleCatDiagramElem.isNull() )
2630  {
2631  mDiagramRenderer = new QgsSingleCategoryDiagramRenderer();
2632  mDiagramRenderer->readXml( singleCatDiagramElem, context );
2633  }
2634  QDomElement linearDiagramElem = node.firstChildElement( QStringLiteral( "LinearlyInterpolatedDiagramRenderer" ) );
2635  if ( !linearDiagramElem.isNull() )
2636  {
2637  if ( linearDiagramElem.hasAttribute( QStringLiteral( "classificationAttribute" ) ) )
2638  {
2639  // fix project from before QGIS 3.0
2640  int idx = linearDiagramElem.attribute( QStringLiteral( "classificationAttribute" ) ).toInt();
2641  if ( idx >= 0 && idx < mFields.count() )
2642  linearDiagramElem.setAttribute( QStringLiteral( "classificationField" ), mFields.at( idx ).name() );
2643  }
2644 
2645  mDiagramRenderer = new QgsLinearlyInterpolatedDiagramRenderer();
2646  mDiagramRenderer->readXml( linearDiagramElem, context );
2647  }
2648 
2649  if ( mDiagramRenderer )
2650  {
2651  QDomElement diagramSettingsElem = node.firstChildElement( QStringLiteral( "DiagramLayerSettings" ) );
2652  if ( !diagramSettingsElem.isNull() )
2653  {
2654  bool oldXPos = diagramSettingsElem.hasAttribute( QStringLiteral( "xPosColumn" ) );
2655  bool oldYPos = diagramSettingsElem.hasAttribute( QStringLiteral( "yPosColumn" ) );
2656  bool oldShow = diagramSettingsElem.hasAttribute( QStringLiteral( "showColumn" ) );
2657  if ( oldXPos || oldYPos || oldShow )
2658  {
2659  // fix project from before QGIS 3.0
2661  if ( oldXPos )
2662  {
2663  int xPosColumn = diagramSettingsElem.attribute( QStringLiteral( "xPosColumn" ) ).toInt();
2664  if ( xPosColumn >= 0 && xPosColumn < mFields.count() )
2665  ddp.setProperty( QgsDiagramLayerSettings::PositionX, QgsProperty::fromField( mFields.at( xPosColumn ).name(), true ) );
2666  }
2667  if ( oldYPos )
2668  {
2669  int yPosColumn = diagramSettingsElem.attribute( QStringLiteral( "yPosColumn" ) ).toInt();
2670  if ( yPosColumn >= 0 && yPosColumn < mFields.count() )
2671  ddp.setProperty( QgsDiagramLayerSettings::PositionY, QgsProperty::fromField( mFields.at( yPosColumn ).name(), true ) );
2672  }
2673  if ( oldShow )
2674  {
2675  int showColumn = diagramSettingsElem.attribute( QStringLiteral( "showColumn" ) ).toInt();
2676  if ( showColumn >= 0 && showColumn < mFields.count() )
2677  ddp.setProperty( QgsDiagramLayerSettings::Show, QgsProperty::fromField( mFields.at( showColumn ).name(), true ) );
2678  }
2679  QDomElement propertiesElem = diagramSettingsElem.ownerDocument().createElement( QStringLiteral( "properties" ) );
2681  {
2682  { QgsDiagramLayerSettings::PositionX, QgsPropertyDefinition( "positionX", QObject::tr( "Position (X)" ), QgsPropertyDefinition::Double ) },
2683  { QgsDiagramLayerSettings::PositionY, QgsPropertyDefinition( "positionY", QObject::tr( "Position (Y)" ), QgsPropertyDefinition::Double ) },
2684  { QgsDiagramLayerSettings::Show, QgsPropertyDefinition( "show", QObject::tr( "Show diagram" ), QgsPropertyDefinition::Boolean ) },
2685  };
2686  ddp.writeXml( propertiesElem, defs );
2687  diagramSettingsElem.appendChild( propertiesElem );
2688  }
2689 
2690  delete mDiagramLayerSettings;
2691  mDiagramLayerSettings = new QgsDiagramLayerSettings();
2692  mDiagramLayerSettings->readXml( diagramSettingsElem );
2693  }
2694  }
2695  }
2696  // end diagram
2697 
2698  styleChangedSignalBlocker.release();
2699  emitStyleChanged();
2700  }
2701  return result;
2702 }
2703 
2704 
2705 bool QgsVectorLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
2706  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
2707 {
2708  QDomElement layerElement = node.toElement();
2709  writeCommonStyle( layerElement, doc, context, categories );
2710 
2711  ( void )writeStyle( node, doc, errorMessage, context, categories );
2712 
2713  if ( categories.testFlag( GeometryOptions ) )
2714  mGeometryOptions->writeXml( node );
2715 
2716  if ( categories.testFlag( Legend ) && legend() )
2717  {
2718  QDomElement legendElement = legend()->writeXml( doc, context );
2719  if ( !legendElement.isNull() )
2720  node.appendChild( legendElement );
2721  }
2722 
2723  // Relation information for both referenced and referencing sides
2724  if ( categories.testFlag( Relations ) )
2725  {
2726  // Store referenced layers: relations where "this" is the child layer (the referencing part, that holds the FK)
2727  QDomElement referencedLayersElement = doc.createElement( QStringLiteral( "referencedLayers" ) );
2728  node.appendChild( referencedLayersElement );
2729 
2730  const auto constReferencingRelations { QgsProject::instance()->relationManager()->referencingRelations( this ) };
2731  for ( const auto &rel : constReferencingRelations )
2732  {
2733  if ( rel.type() == QgsRelation::Normal )
2734  {
2735  QgsWeakRelation::writeXml( this, QgsWeakRelation::Referencing, rel, referencedLayersElement, doc );
2736  }
2737  }
2738 
2739  // Store referencing layers: relations where "this" is the parent layer (the referenced part, that holds the FK)
2740  QDomElement referencingLayersElement = doc.createElement( QStringLiteral( "referencingLayers" ) );
2741  node.appendChild( referencedLayersElement );
2742 
2743  const auto constReferencedRelations { QgsProject::instance()->relationManager()->referencedRelations( this ) };
2744  for ( const auto &rel : constReferencedRelations )
2745  {
2746  if ( rel.type() == QgsRelation::Normal )
2747  {
2748  QgsWeakRelation::writeXml( this, QgsWeakRelation::Referenced, rel, referencingLayersElement, doc );
2749  }
2750  }
2751 
2752  }
2753 
2754  // write field configurations
2755  if ( categories.testFlag( Fields ) || categories.testFlag( Forms ) )
2756  {
2757  QDomElement fieldConfigurationElement;
2758  // field configuration flag
2759  fieldConfigurationElement = doc.createElement( QStringLiteral( "fieldConfiguration" ) );
2760  node.appendChild( fieldConfigurationElement );
2761 
2762  for ( const QgsField &field : std::as_const( mFields ) )
2763  {
2764  QDomElement fieldElement = doc.createElement( QStringLiteral( "field" ) );
2765  fieldElement.setAttribute( QStringLiteral( "name" ), field.name() );
2766  fieldConfigurationElement.appendChild( fieldElement );
2767 
2768  if ( categories.testFlag( Fields ) )
2769  {
2770  fieldElement.setAttribute( QStringLiteral( "configurationFlags" ), qgsFlagValueToKeys( field.configurationFlags() ) );
2771  }
2772 
2773  if ( categories.testFlag( Forms ) )
2774  {
2776 
2777  // TODO : wrap this part in an if to only save if it was user-modified
2778  QDomElement editWidgetElement = doc.createElement( QStringLiteral( "editWidget" ) );
2779  fieldElement.appendChild( editWidgetElement );
2780  editWidgetElement.setAttribute( QStringLiteral( "type" ), field.editorWidgetSetup().type() );
2781  QDomElement editWidgetConfigElement = doc.createElement( QStringLiteral( "config" ) );
2782 
2783  editWidgetConfigElement.appendChild( QgsXmlUtils::writeVariant( widgetSetup.config(), doc ) );
2784  editWidgetElement.appendChild( editWidgetConfigElement );
2785  // END TODO : wrap this part in an if to only save if it was user-modified
2786  }
2787  }
2788  }
2789 
2790  if ( categories.testFlag( Fields ) )
2791  {
2792  //attribute aliases
2793  QDomElement aliasElem = doc.createElement( QStringLiteral( "aliases" ) );
2794  for ( const QgsField &field : std::as_const( mFields ) )
2795  {
2796  QDomElement aliasEntryElem = doc.createElement( QStringLiteral( "alias" ) );
2797  aliasEntryElem.setAttribute( QStringLiteral( "field" ), field.name() );
2798  aliasEntryElem.setAttribute( QStringLiteral( "index" ), mFields.indexFromName( field.name() ) );
2799  aliasEntryElem.setAttribute( QStringLiteral( "name" ), field.alias() );
2800  aliasElem.appendChild( aliasEntryElem );
2801  }
2802  node.appendChild( aliasElem );
2803 
2804  //default expressions
2805  QDomElement defaultsElem = doc.createElement( QStringLiteral( "defaults" ) );
2806  for ( const QgsField &field : std::as_const( mFields ) )
2807  {
2808  QDomElement defaultElem = doc.createElement( QStringLiteral( "default" ) );
2809  defaultElem.setAttribute( QStringLiteral( "field" ), field.name() );
2810  defaultElem.setAttribute( QStringLiteral( "expression" ), field.defaultValueDefinition().expression() );
2811  defaultElem.setAttribute( QStringLiteral( "applyOnUpdate" ), field.defaultValueDefinition().applyOnUpdate() ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
2812  defaultsElem.appendChild( defaultElem );
2813  }
2814  node.appendChild( defaultsElem );
2815 
2816  // constraints
2817  QDomElement constraintsElem = doc.createElement( QStringLiteral( "constraints" ) );
2818  for ( const QgsField &field : std::as_const( mFields ) )
2819  {
2820  QDomElement constraintElem = doc.createElement( QStringLiteral( "constraint" ) );
2821  constraintElem.setAttribute( QStringLiteral( "field" ), field.name() );
2822  constraintElem.setAttribute( QStringLiteral( "constraints" ), field.constraints().constraints() );
2823  constraintElem.setAttribute( QStringLiteral( "unique_strength" ), field.constraints().constraintStrength( QgsFieldConstraints::ConstraintUnique ) );
2824  constraintElem.setAttribute( QStringLiteral( "notnull_strength" ), field.constraints().constraintStrength( QgsFieldConstraints::ConstraintNotNull ) );
2825  constraintElem.setAttribute( QStringLiteral( "exp_strength" ), field.constraints().constraintStrength( QgsFieldConstraints::ConstraintExpression ) );
2826  constraintsElem.appendChild( constraintElem );
2827  }
2828  node.appendChild( constraintsElem );
2829 
2830  // constraint expressions
2831  QDomElement constraintExpressionsElem = doc.createElement( QStringLiteral( "constraintExpressions" ) );
2832  for ( const QgsField &field : std::as_const( mFields ) )
2833  {
2834  QDomElement constraintExpressionElem = doc.createElement( QStringLiteral( "constraint" ) );
2835  constraintExpressionElem.setAttribute( QStringLiteral( "field" ), field.name() );
2836  constraintExpressionElem.setAttribute( QStringLiteral( "exp" ), field.constraints().constraintExpression() );
2837  constraintExpressionElem.setAttribute( QStringLiteral( "desc" ), field.constraints().constraintDescription() );
2838  constraintExpressionsElem.appendChild( constraintExpressionElem );
2839  }
2840  node.appendChild( constraintExpressionsElem );
2841 
2842  // save expression fields
2843  if ( !mExpressionFieldBuffer )
2844  {
2845  // can happen when saving style on a invalid layer
2847  dummy.writeXml( node, doc );
2848  }
2849  else
2850  {
2851  mExpressionFieldBuffer->writeXml( node, doc );
2852  }
2853  }
2854 
2855  // add attribute actions
2856  if ( categories.testFlag( Actions ) )
2857  mActions->writeXml( node );
2858 
2859  if ( categories.testFlag( AttributeTable ) )
2860  {
2861  mAttributeTableConfig.writeXml( node );
2862  mConditionalStyles->writeXml( node, doc, context );
2863  mStoredExpressionManager->writeXml( node );
2864  }
2865 
2866  if ( categories.testFlag( Forms ) )
2867  mEditFormConfig.writeXml( node, context );
2868 
2869  // save readonly state
2870  if ( categories.testFlag( LayerConfiguration ) )
2871  node.toElement().setAttribute( QStringLiteral( "readOnly" ), mReadOnly );
2872 
2873  // save preview expression
2874  if ( categories.testFlag( LayerConfiguration ) )
2875  {
2876  QDomElement prevExpElem = doc.createElement( QStringLiteral( "previewExpression" ) );
2877  QDomText prevExpText = doc.createTextNode( mDisplayExpression );
2878  prevExpElem.appendChild( prevExpText );
2879  node.appendChild( prevExpElem );
2880  }
2881 
2882  // save map tip
2883  if ( categories.testFlag( MapTips ) )
2884  {
2885  QDomElement mapTipElem = doc.createElement( QStringLiteral( "mapTip" ) );
2886  QDomText mapTipText = doc.createTextNode( mMapTipTemplate );
2887  mapTipElem.appendChild( mapTipText );
2888  node.toElement().appendChild( mapTipElem );
2889  }
2890 
2891  return true;
2892 }
2893 
2894 bool QgsVectorLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
2895  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
2896 {
2897  QDomElement mapLayerNode = node.toElement();
2898 
2899  emit writeCustomSymbology( mapLayerNode, doc, errorMessage );
2900 
2901  // we must try to write the renderer if our geometry type is unknown
2902  // as this allows the renderer to be correctly restored even for layers
2903  // with broken sources
2904  if ( isSpatial() || mWkbType == QgsWkbTypes::Unknown )
2905  {
2906  if ( categories.testFlag( Symbology ) )
2907  {
2908  if ( mRenderer )
2909  {
2910  QDomElement rendererElement = mRenderer->save( doc, context );
2911  node.appendChild( rendererElement );
2912  }
2913  }
2914 
2915  if ( categories.testFlag( Labeling ) )
2916  {
2917  if ( mLabeling )
2918  {
2919  QDomElement labelingElement = mLabeling->save( doc, context );
2920  node.appendChild( labelingElement );
2921  }
2922  mapLayerNode.setAttribute( QStringLiteral( "labelsEnabled" ), mLabelsEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
2923  }
2924 
2925  // save the simplification drawing settings
2926  if ( categories.testFlag( Rendering ) )
2927  {
2928  mapLayerNode.setAttribute( QStringLiteral( "simplifyDrawingHints" ), QString::number( mSimplifyMethod.simplifyHints() ) );
2929  mapLayerNode.setAttribute( QStringLiteral( "simplifyAlgorithm" ), QString::number( mSimplifyMethod.simplifyAlgorithm() ) );
2930  mapLayerNode.setAttribute( QStringLiteral( "simplifyDrawingTol" ), QString::number( mSimplifyMethod.threshold() ) );
2931  mapLayerNode.setAttribute( QStringLiteral( "simplifyLocal" ), mSimplifyMethod.forceLocalOptimization() ? 1 : 0 );
2932  mapLayerNode.setAttribute( QStringLiteral( "simplifyMaxScale" ), QString::number( mSimplifyMethod.maximumScale() ) );
2933  }
2934 
2935  //save customproperties
2936  if ( categories.testFlag( CustomProperties ) )
2937  {
2938  writeCustomProperties( node, doc );
2939  }
2940 
2941  if ( categories.testFlag( Symbology ) )
2942  {
2943  // add the blend mode field
2944  QDomElement blendModeElem = doc.createElement( QStringLiteral( "blendMode" ) );
2945  QDomText blendModeText = doc.createTextNode( QString::number( QgsPainting::getBlendModeEnum( blendMode() ) ) );
2946  blendModeElem.appendChild( blendModeText );
2947  node.appendChild( blendModeElem );
2948 
2949  // add the feature blend mode field
2950  QDomElement featureBlendModeElem = doc.createElement( QStringLiteral( "featureBlendMode" ) );
2951  QDomText featureBlendModeText = doc.createTextNode( QString::number( QgsPainting::getBlendModeEnum( featureBlendMode() ) ) );
2952  featureBlendModeElem.appendChild( featureBlendModeText );
2953  node.appendChild( featureBlendModeElem );
2954  }
2955 
2956  // add the layer opacity and scale visibility
2957  if ( categories.testFlag( Rendering ) )
2958  {
2959  QDomElement layerOpacityElem = doc.createElement( QStringLiteral( "layerOpacity" ) );
2960  QDomText layerOpacityText = doc.createTextNode( QString::number( opacity() ) );
2961  layerOpacityElem.appendChild( layerOpacityText );
2962  node.appendChild( layerOpacityElem );
2963  mapLayerNode.setAttribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ), hasScaleBasedVisibility() ? 1 : 0 );
2964  mapLayerNode.setAttribute( QStringLiteral( "maxScale" ), maximumScale() );
2965  mapLayerNode.setAttribute( QStringLiteral( "minScale" ), minimumScale() );
2966 
2967  mapLayerNode.setAttribute( QStringLiteral( "symbologyReferenceScale" ), mRenderer ? mRenderer->referenceScale() : -1 );
2968  }
2969 
2970  if ( categories.testFlag( Diagrams ) && mDiagramRenderer )
2971  {
2972  mDiagramRenderer->writeXml( mapLayerNode, doc, context );
2973  if ( mDiagramLayerSettings )
2974  mDiagramLayerSettings->writeXml( mapLayerNode, doc );
2975  }
2976  }
2977  return true;
2978 }
2979 
2980 bool QgsVectorLayer::readSld( const QDomNode &node, QString &errorMessage )
2981 {
2982  // get the Name element
2983  QDomElement nameElem = node.firstChildElement( QStringLiteral( "Name" ) );
2984  if ( nameElem.isNull() )
2985  {
2986  errorMessage = QStringLiteral( "Warning: Name element not found within NamedLayer while it's required." );
2987  }
2988 
2989  if ( isSpatial() )
2990  {
2991  QgsFeatureRenderer *r = QgsFeatureRenderer::loadSld( node, geometryType(), errorMessage );
2992  if ( !r )
2993  return false;
2994 
2995  // defer style changed signal until we've set the renderer, labeling, everything.
2996  // we don't want multiple signals!
2997  ScopedIntIncrementor styleChangedSignalBlocker( &mBlockStyleChangedSignal );
2998 
2999  setRenderer( r );
3000 
3001  // labeling
3002  readSldLabeling( node );
3003 
3004  styleChangedSignalBlocker.release();
3005  emitStyleChanged();
3006  }
3007  return true;
3008 }
3009 
3010 bool QgsVectorLayer::writeSld( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QVariantMap &props ) const
3011 {
3012  Q_UNUSED( errorMessage )
3013 
3014  QVariantMap localProps = QVariantMap( props );
3015  if ( hasScaleBasedVisibility() )
3016  {
3018  }
3019 
3020  if ( isSpatial() )
3021  {
3022  // store the Name element
3023  QDomElement nameNode = doc.createElement( QStringLiteral( "se:Name" ) );
3024  nameNode.appendChild( doc.createTextNode( name() ) );
3025  node.appendChild( nameNode );
3026 
3027  QDomElement userStyleElem = doc.createElement( QStringLiteral( "UserStyle" ) );
3028  node.appendChild( userStyleElem );
3029 
3030  QDomElement nameElem = doc.createElement( QStringLiteral( "se:Name" ) );
3031  nameElem.appendChild( doc.createTextNode( name() ) );
3032 
3033  userStyleElem.appendChild( nameElem );
3034 
3035  QDomElement featureTypeStyleElem = doc.createElement( QStringLiteral( "se:FeatureTypeStyle" ) );
3036  userStyleElem.appendChild( featureTypeStyleElem );
3037 
3038  mRenderer->toSld( doc, featureTypeStyleElem, localProps );
3039  if ( labelsEnabled() )
3040  {
3041  mLabeling->toSld( featureTypeStyleElem, localProps );
3042  }
3043  }
3044  return true;
3045 }
3046 
3047 
3048 bool QgsVectorLayer::changeGeometry( QgsFeatureId fid, QgsGeometry &geom, bool skipDefaultValue )
3049 {
3050  if ( !mEditBuffer || !mDataProvider )
3051  {
3052  return false;
3053  }
3054 
3055  if ( mGeometryOptions->isActive() )
3056  mGeometryOptions->apply( geom );
3057 
3058  updateExtents();
3059 
3060  bool result = mEditBuffer->changeGeometry( fid, geom );
3061 
3062  if ( result )
3063  {
3064  updateExtents();
3065  if ( !skipDefaultValue && !mDefaultValueOnUpdateFields.isEmpty() )
3066  updateDefaultValues( fid );
3067  }
3068  return result;
3069 }
3070 
3071 
3072 bool QgsVectorLayer::changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue, bool skipDefaultValues )
3073 {
3074  bool result = false;
3075 
3076  switch ( fields().fieldOrigin( field ) )
3077  {
3078  case QgsFields::OriginJoin:
3079  result = mJoinBuffer->changeAttributeValue( fid, field, newValue, oldValue );
3080  if ( result )
3081  emit attributeValueChanged( fid, field, newValue );
3082  break;
3083 
3085  case QgsFields::OriginEdit:
3087  {
3088  if ( mEditBuffer && mDataProvider )
3089  result = mEditBuffer->changeAttributeValue( fid, field, newValue, oldValue );
3090  break;
3091  }
3092 
3094  break;
3095  }
3096 
3097  if ( result && !skipDefaultValues && !mDefaultValueOnUpdateFields.isEmpty() )
3098  updateDefaultValues( fid );
3099 
3100  return result;
3101 }
3102 
3103 bool QgsVectorLayer::changeAttributeValues( QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues, bool skipDefaultValues )
3104 {
3105  bool result = true;
3106 
3107  QgsAttributeMap newValuesJoin;
3108  QgsAttributeMap oldValuesJoin;
3109 
3110  QgsAttributeMap newValuesNotJoin;
3111  QgsAttributeMap oldValuesNotJoin;
3112 
3113  for ( auto it = newValues.constBegin(); it != newValues.constEnd(); ++it )
3114  {
3115  const int field = it.key();
3116  const QVariant newValue = it.value();
3117  QVariant oldValue;
3118 
3119  if ( oldValues.contains( field ) )
3120  oldValue = oldValues[field];
3121 
3122  switch ( fields().fieldOrigin( field ) )
3123  {
3124  case QgsFields::OriginJoin:
3125  newValuesJoin[field] = newValue;
3126  oldValuesJoin[field] = oldValue;
3127  break;
3128 
3130  case QgsFields::OriginEdit:
3132  {
3133  newValuesNotJoin[field] = newValue;
3134  oldValuesNotJoin[field] = oldValue;
3135  break;
3136  }
3137 
3139  break;
3140  }
3141  }
3142 
3143  if ( ! newValuesJoin.isEmpty() && mJoinBuffer )
3144  {
3145  result = mJoinBuffer->changeAttributeValues( fid, newValuesJoin, oldValuesJoin );
3146  }
3147 
3148  if ( ! newValuesNotJoin.isEmpty() && mEditBuffer && mDataProvider )
3149  {
3150  result &= mEditBuffer->changeAttributeValues( fid, newValuesNotJoin, oldValues );
3151  }
3152 
3153  if ( result && !skipDefaultValues && !mDefaultValueOnUpdateFields.isEmpty() )
3154  {
3155  updateDefaultValues( fid );
3156  }
3157 
3158  return result;
3159 }
3160 
3162 {
3163  if ( !mEditBuffer || !mDataProvider )
3164  return false;
3165 
3166  return mEditBuffer->addAttribute( field );
3167 }
3168 
3170 {
3171  if ( attIndex < 0 || attIndex >= fields().count() )
3172  return;
3173 
3174  QString name = fields().at( attIndex ).name();
3175  mFields[ attIndex ].setAlias( QString() );
3176  if ( mAttributeAliasMap.contains( name ) )
3177  {
3178  mAttributeAliasMap.remove( name );
3179  updateFields();
3180  mEditFormConfig.setFields( mFields );
3181  emit layerModified();
3182  }
3183 }
3184 
3185 bool QgsVectorLayer::renameAttribute( int index, const QString &newName )
3186 {
3187  if ( index < 0 || index >= fields().count() )
3188  return false;
3189 
3190  switch ( mFields.fieldOrigin( index ) )
3191  {
3193  {
3194  if ( mExpressionFieldBuffer )
3195  {
3196  int oi = mFields.fieldOriginIndex( index );
3197  mExpressionFieldBuffer->renameExpression( oi, newName );
3198  updateFields();
3199  return true;
3200  }
3201  else
3202  {
3203  return false;
3204  }
3205  }
3206 
3208  case QgsFields::OriginEdit:
3209 
3210  if ( !mEditBuffer || !mDataProvider )
3211  return false;
3212 
3213  return mEditBuffer->renameAttribute( index, newName );
3214 
3215  case QgsFields::OriginJoin:
3217  return false;
3218 
3219  }
3220 
3221  return false; // avoid warning
3222 }
3223 
3224 void QgsVectorLayer::setFieldAlias( int attIndex, const QString &aliasString )
3225 {
3226  if ( attIndex < 0 || attIndex >= fields().count() )
3227  return;
3228 
3229  QString name = fields().at( attIndex ).name();
3230 
3231  mAttributeAliasMap.insert( name, aliasString );
3232  mFields[ attIndex ].setAlias( aliasString );
3233  mEditFormConfig.setFields( mFields );
3234  emit layerModified(); // TODO[MD]: should have a different signal?
3235 }
3236 
3237 QString QgsVectorLayer::attributeAlias( int index ) const
3238 {
3239  if ( index < 0 || index >= fields().count() )
3240  return QString();
3241 
3242  return fields().at( index ).alias();
3243 }
3244 
3245 QString QgsVectorLayer::attributeDisplayName( int index ) const
3246 {
3247  if ( index >= 0 && index < mFields.count() )
3248  return mFields.at( index ).displayName();
3249  else
3250  return QString();
3251 }
3252 
3254 {
3255  return mAttributeAliasMap;
3256 }
3257 
3259 {
3260  QSet<QString> excludeList;
3261  QMap< QString, QgsField::ConfigurationFlags >::const_iterator flagsIt = mFieldConfigurationFlags.constBegin();
3262  for ( ; flagsIt != mFieldConfigurationFlags.constEnd(); ++flagsIt )
3263  {
3264  if ( flagsIt->testFlag( QgsField::ConfigurationFlag::HideFromWms ) )
3265  {
3266  excludeList << flagsIt.key();
3267  }
3268  }
3269  return excludeList;
3270 }
3271 
3272 void QgsVectorLayer::setExcludeAttributesWms( const QSet<QString> &att )
3273 {
3274  QMap< QString, QgsField::ConfigurationFlags >::iterator flagsIt = mFieldConfigurationFlags.begin();
3275  for ( ; flagsIt != mFieldConfigurationFlags.end(); ++flagsIt )
3276  {
3277  flagsIt->setFlag( QgsField::ConfigurationFlag::HideFromWms, att.contains( flagsIt.key() ) );
3278  }
3279  updateFields();
3280 }
3281 
3283 {
3284  QSet<QString> excludeList;
3285  QMap< QString, QgsField::ConfigurationFlags >::const_iterator flagsIt = mFieldConfigurationFlags.constBegin();
3286  for ( ; flagsIt != mFieldConfigurationFlags.constEnd(); ++flagsIt )
3287  {
3288  if ( flagsIt->testFlag( QgsField::ConfigurationFlag::HideFromWfs ) )
3289  {
3290  excludeList << flagsIt.key();
3291  }
3292  }
3293  return excludeList;
3294 }
3295 
3296 void QgsVectorLayer::setExcludeAttributesWfs( const QSet<QString> &att )
3297 {
3298  QMap< QString, QgsField::ConfigurationFlags >::iterator flagsIt = mFieldConfigurationFlags.begin();
3299  for ( ; flagsIt != mFieldConfigurationFlags.end(); ++flagsIt )
3300  {
3301  flagsIt->setFlag( QgsField::ConfigurationFlag::HideFromWfs, att.contains( flagsIt.key() ) );
3302  }
3303  updateFields();
3304 }
3305 
3307 {
3308  if ( index < 0 || index >= fields().count() )
3309  return false;
3310 
3311  if ( mFields.fieldOrigin( index ) == QgsFields::OriginExpression )
3312  {
3313  removeExpressionField( index );
3314  return true;
3315  }
3316 
3317  if ( !mEditBuffer || !mDataProvider )
3318  return false;
3319 
3320  return mEditBuffer->deleteAttribute( index );
3321 }
3322 
3323 bool QgsVectorLayer::deleteAttributes( const QList<int> &attrs )
3324 {
3325  bool deleted = false;
3326 
3327  // Remove multiple occurrences of same attribute
3328  QList<int> attrList = qgis::setToList( qgis::listToSet( attrs ) );
3329 
3330  std::sort( attrList.begin(), attrList.end(), std::greater<int>() );
3331 
3332  for ( int attr : std::as_const( attrList ) )
3333  {
3334  if ( deleteAttribute( attr ) )
3335  {
3336  deleted = true;
3337  }
3338  }
3339 
3340  return deleted;
3341 }
3342 
3343 bool QgsVectorLayer::deleteFeatureCascade( QgsFeatureId fid, QgsVectorLayer::DeleteContext *context )
3344 {
3345  if ( !mEditBuffer )
3346  return false;
3347 
3348  if ( context && context->cascade )
3349  {
3350  const QList<QgsRelation> relations = context->project->relationManager()->referencedRelations( this );
3351  const bool hasRelationsOrJoins = !relations.empty() || mJoinBuffer->containsJoins();
3352  if ( hasRelationsOrJoins )
3353  {
3354  if ( context->mHandledFeatures.contains( this ) )
3355  {
3356  QgsFeatureIds &handledFeatureIds = context->mHandledFeatures[ this ];
3357  if ( handledFeatureIds.contains( fid ) )
3358  {
3359  // avoid endless recursion
3360  return false;
3361  }
3362  else
3363  {
3364  // add feature id
3365  handledFeatureIds << fid;
3366  }
3367  }
3368  else
3369  {
3370  // add layer and feature id
3371  context->mHandledFeatures.insert( this, QgsFeatureIds() << fid );
3372  }
3373 
3374  for ( const QgsRelation &relation : relations )
3375  {
3376  //check if composition (and not association)
3377  if ( relation.strength() == QgsRelation::Composition )
3378  {
3379  //get features connected over this relation
3380  QgsFeatureIterator relatedFeaturesIt = relation.getRelatedFeatures( getFeature( fid ) );
3381  QgsFeatureIds childFeatureIds;
3382  QgsFeature childFeature;
3383  while ( relatedFeaturesIt.nextFeature( childFeature ) )
3384  {
3385  childFeatureIds.insert( childFeature.id() );
3386  }
3387  if ( childFeatureIds.count() > 0 )
3388  {
3389  relation.referencingLayer()->startEditing();
3390  relation.referencingLayer()->deleteFeatures( childFeatureIds, context );
3391  }
3392  }
3393  }
3394  }
3395  }
3396 
3397  if ( mJoinBuffer->containsJoins() )
3398  mJoinBuffer->deleteFeature( fid, context );
3399 
3400  bool res = mEditBuffer->deleteFeature( fid );
3401 
3402  return res;
3403 }
3404 
3406 {
3407  if ( !mEditBuffer )
3408  return false;
3409 
3410  bool res = deleteFeatureCascade( fid, context );
3411 
3412  if ( res )
3413  {
3414  updateExtents();
3415  }
3416 
3417  return res;
3418 }
3419 
3421 {
3422  bool res = true;
3423  const auto constFids = fids;
3424  for ( QgsFeatureId fid : constFids )
3425  res = deleteFeatureCascade( fid, context ) && res;
3426 
3427  if ( res )
3428  {
3429  mSelectedFeatureIds.subtract( fids ); // remove it from selection
3430  updateExtents();
3431  }
3432 
3433  return res;
3434 }
3435 
3437 {
3438  return mFields;
3439 }
3440 
3442 {
3443  QgsAttributeList pkAttributesList;
3444  if ( !mDataProvider )
3445  return pkAttributesList;
3446 
3447  QgsAttributeList providerIndexes = mDataProvider->pkAttributeIndexes();
3448  for ( int i = 0; i < mFields.count(); ++i )
3449  {
3450  if ( mFields.fieldOrigin( i ) == QgsFields::OriginProvider &&
3451  providerIndexes.contains( mFields.fieldOriginIndex( i ) ) )
3452  pkAttributesList << i;
3453  }
3454 
3455  return pkAttributesList;
3456 }
3457 
3459 {
3460  if ( !mDataProvider )
3461  return static_cast< long long >( Qgis::FeatureCountState::UnknownCount );
3462  return mDataProvider->featureCount() +
3463  ( mEditBuffer && ! mDataProvider->transaction() ? mEditBuffer->addedFeatures().size() - mEditBuffer->deletedFeatureIds().size() : 0 );
3464 }
3465 
3467 {
3468  const QgsFeatureIds deletedFeatures( mEditBuffer && ! mDataProvider->transaction() ? mEditBuffer->deletedFeatureIds() : QgsFeatureIds() );
3469  const QgsFeatureMap addedFeatures( mEditBuffer && ! mDataProvider->transaction() ? mEditBuffer->addedFeatures() : QgsFeatureMap() );
3470 
3471  if ( mEditBuffer && !deletedFeatures.empty() )
3472  {
3473  if ( addedFeatures.size() > deletedFeatures.size() )
3474  return QgsFeatureSource::FeatureAvailability::FeaturesAvailable;
3475  else
3476  return QgsFeatureSource::FeatureAvailability::FeaturesMaybeAvailable;
3477  }
3478 
3479  if ( ( !mEditBuffer || addedFeatures.empty() ) && mDataProvider && mDataProvider->empty() )
3480  return QgsFeatureSource::FeatureAvailability::NoFeaturesAvailable;
3481  else
3482  return QgsFeatureSource::FeatureAvailability::FeaturesAvailable;
3483 }
3484 
3485 bool QgsVectorLayer::commitChanges( bool stopEditing )
3486 {
3487  if ( project() && project()->transactionMode() == Qgis::TransactionMode::BufferedGroups )
3488  return project()->commitChanges( mCommitErrors, stopEditing, this );
3489 
3490  mCommitErrors.clear();
3491 
3492  if ( !mDataProvider )
3493  {
3494  mCommitErrors << tr( "ERROR: no provider" );
3495  return false;
3496  }
3497 
3498  if ( !mEditBuffer )
3499  {
3500  mCommitErrors << tr( "ERROR: layer not editable" );
3501  return false;
3502  }
3503 
3504  emit beforeCommitChanges( stopEditing );
3505 
3506  if ( !mAllowCommit )
3507  return false;
3508 
3509  mCommitChangesActive = true;
3510 
3511  bool success = false;
3512  if ( mEditBuffer->editBufferGroup() )
3513  success = mEditBuffer->editBufferGroup()->commitChanges( mCommitErrors, stopEditing );
3514  else
3515  success = mEditBuffer->commitChanges( mCommitErrors );
3516 
3517  mCommitChangesActive = false;
3518 
3519  if ( !mDeletedFids.empty() )
3520  {
3521  emit featuresDeleted( mDeletedFids );
3522  mDeletedFids.clear();
3523  }
3524 
3525  if ( success )
3526  {
3527  if ( stopEditing )
3528  {
3529  clearEditBuffer();
3530  }
3531  undoStack()->clear();
3532  emit afterCommitChanges();
3533  if ( stopEditing )
3534  emit editingStopped();
3535  }
3536  else
3537  {
3538  QgsMessageLog::logMessage( tr( "Commit errors:\n %1" ).arg( mCommitErrors.join( QLatin1String( "\n " ) ) ) );
3539  }
3540 
3541  updateFields();
3542 
3543  mDataProvider->updateExtents();
3544  mDataProvider->leaveUpdateMode();
3545 
3546  // This second call is required because OGR provider with JSON
3547  // driver might have changed fields order after the call to
3548  // leaveUpdateMode
3549  if ( mFields.names() != mDataProvider->fields().names() )
3550  {
3551  updateFields();
3552  }
3553 
3554  triggerRepaint();
3555 
3556  return success;
3557 }
3558 
3559 QStringList QgsVectorLayer::commitErrors() const
3560 {
3561  return mCommitErrors;
3562 }
3563 
3564 bool QgsVectorLayer::rollBack( bool deleteBuffer )
3565 {
3566  if ( project() && project()->transactionMode() == Qgis::TransactionMode::BufferedGroups )
3567  return project()->rollBack( mCommitErrors, deleteBuffer, this );
3568 
3569  if ( !mEditBuffer )
3570  {
3571  return false;
3572  }
3573 
3574  if ( !mDataProvider )
3575  {
3576  mCommitErrors << tr( "ERROR: no provider" );
3577  return false;
3578  }
3579 
3580  bool rollbackExtent = !mDataProvider->transaction() && ( !mEditBuffer->deletedFeatureIds().isEmpty() ||
3581  !mEditBuffer->addedFeatures().isEmpty() ||
3582  !mEditBuffer->changedGeometries().isEmpty() );
3583 
3584  emit beforeRollBack();
3585 
3586  mEditBuffer->rollBack();
3587 
3588  emit afterRollBack();
3589 
3590  if ( isModified() )
3591  {
3592  // new undo stack roll back method
3593  // old method of calling every undo could cause many canvas refreshes
3594  undoStack()->setIndex( 0 );
3595  }
3596 
3597  updateFields();
3598 
3599  if ( deleteBuffer )
3600  {
3601  delete mEditBuffer;
3602  mEditBuffer = nullptr;
3603  undoStack()->clear();
3604  }
3605  emit editingStopped();
3606 
3607  if ( rollbackExtent )
3608  updateExtents();
3609 
3610  mDataProvider->leaveUpdateMode();
3611 
3612  triggerRepaint();
3613  return true;
3614 }
3615 
3617 {
3618  return mSelectedFeatureIds.size();
3619 }
3620 
3622 {
3623  return mSelectedFeatureIds;
3624 }
3625 
3627 {
3628  QgsFeatureList features;
3629  features.reserve( mSelectedFeatureIds.count() );
3630  QgsFeature f;
3631 
3633 
3634  while ( it.nextFeature( f ) )
3635  {
3636  features.push_back( f );
3637  }
3638 
3639  return features;
3640 }
3641 
3643 {
3644  if ( mSelectedFeatureIds.isEmpty() )
3645  return QgsFeatureIterator();
3646 
3649 
3650  if ( mSelectedFeatureIds.count() == 1 )
3651  request.setFilterFid( *mSelectedFeatureIds.constBegin() );
3652  else
3653  request.setFilterFids( mSelectedFeatureIds );
3654 
3655  return getFeatures( request );
3656 }
3657 
3659 {
3660  if ( !mEditBuffer || !mDataProvider )
3661  return false;
3662 
3663  if ( mGeometryOptions->isActive() )
3664  {
3665  for ( auto feature = features.begin(); feature != features.end(); ++feature )
3666  {
3667  QgsGeometry geom = feature->geometry();
3668  mGeometryOptions->apply( geom );
3669  feature->setGeometry( geom );
3670  }
3671  }
3672 
3673  bool res = mEditBuffer->addFeatures( features );
3674  updateExtents();
3675 
3676  if ( res && mJoinBuffer->containsJoins() )
3677  res = mJoinBuffer->addFeatures( features );
3678 
3679  return res;
3680 }
3681 
3683 {
3684  // if layer is not spatial, it has not CRS!
3685  setCrs( ( isSpatial() && mDataProvider ) ? mDataProvider->crs() : QgsCoordinateReferenceSystem() );
3686 }
3687 
3689 {
3691  if ( exp.isField() )
3692  {
3693  return static_cast<const QgsExpressionNodeColumnRef *>( exp.rootNode() )->name();
3694  }
3695 
3696  return QString();
3697 }
3698 
3699 void QgsVectorLayer::setDisplayExpression( const QString &displayExpression )
3700 {
3701  if ( mDisplayExpression == displayExpression )
3702  return;
3703 
3704  mDisplayExpression = displayExpression;
3705  emit displayExpressionChanged();
3706 }
3707 
3708 QString QgsVectorLayer::displayExpression() const
3709 {
3710  if ( !mDisplayExpression.isEmpty() || mFields.isEmpty() )
3711  {
3712  return mDisplayExpression;
3713  }
3714  else
3715  {
3716  const QString candidateName = QgsVectorLayerUtils::guessFriendlyIdentifierField( mFields );
3717  if ( !candidateName.isEmpty() )
3718  {
3719  return QgsExpression::quotedColumnRef( candidateName );
3720  }
3721  else
3722  {
3723  return QString();
3724  }
3725  }
3726 }
3727 
3729 {
3730  return ( mEditBuffer && mDataProvider );
3731 }
3732 
3734 {
3737 }
3738 
3739 bool QgsVectorLayer::isReadOnly() const
3740 {
3741  return mReadOnly;
3742 }
3743 
3744 bool QgsVectorLayer::setReadOnly( bool readonly )
3745 {
3746  // exit if the layer is in editing mode
3747  if ( readonly && mEditBuffer )
3748  return false;
3749 
3750  mReadOnly = readonly;
3751  emit readOnlyChanged();
3752  return true;
3753 }
3754 
3756 {
3757  if ( ! mDataProvider )
3758  return false;
3759 
3760  return mDataProvider->capabilities() & QgsVectorDataProvider::EditingCapabilities && ! mReadOnly;
3761 }
3762 
3764 {
3765  emit beforeModifiedCheck();
3766  return mEditBuffer && mEditBuffer->isModified();
3767 }
3768 
3769 bool QgsVectorLayer::isAuxiliaryField( int index, int &srcIndex ) const
3770 {
3771  bool auxiliaryField = false;
3772  srcIndex = -1;
3773 
3774  if ( !auxiliaryLayer() )
3775  return auxiliaryField;
3776 
3777  if ( index >= 0 && fields().fieldOrigin( index ) == QgsFields::OriginJoin )
3778  {
3779  const QgsVectorLayerJoinInfo *info = mJoinBuffer->joinForFieldIndex( index, fields(), srcIndex );
3780 
3781  if ( info && info->joinLayerId() == auxiliaryLayer()->id() )
3782  auxiliaryField = true;
3783  }
3784 
3785  return auxiliaryField;
3786 }
3787 
3789 {
3790  // we must allow setting a renderer if our geometry type is unknown
3791  // as this allows the renderer to be correctly set even for layers
3792  // with broken sources
3793  if ( !isSpatial() && mWkbType != QgsWkbTypes::Unknown )
3794  return;
3795 
3796  if ( r != mRenderer )
3797  {
3798  delete mRenderer;
3799  mRenderer = r;
3800  mSymbolFeatureCounted = false;
3801  mSymbolFeatureCountMap.clear();
3802  mSymbolFeatureIdMap.clear();
3803 
3804  if ( mRenderer )
3805  {
3806  const double refreshRate = QgsSymbolLayerUtils::rendererFrameRate( mRenderer );
3807  if ( refreshRate <= 0 )
3808  {
3809  mRefreshRendererTimer->stop();
3810  mRefreshRendererTimer->setInterval( 0 );
3811  }
3812  else
3813  {
3814  mRefreshRendererTimer->setInterval( 1000 / refreshRate );
3815  mRefreshRendererTimer->start();
3816  }
3817  }
3818 
3819  emit rendererChanged();
3820  emitStyleChanged();
3821  }
3822 }
3823 
3825 {
3826  if ( generator )
3827  {
3828  mRendererGenerators << generator;
3829  }
3830 }
3831 
3833 {
3834  for ( int i = mRendererGenerators.count() - 1; i >= 0; --i )
3835  {
3836  if ( mRendererGenerators.at( i )->id() == id )
3837  {
3838  delete mRendererGenerators.at( i );
3839  mRendererGenerators.removeAt( i );
3840  }
3841  }
3842 }
3843 
3844 QList<const QgsFeatureRendererGenerator *> QgsVectorLayer::featureRendererGenerators() const
3845 {
3846  QList< const QgsFeatureRendererGenerator * > res;
3847  for ( const QgsFeatureRendererGenerator *generator : mRendererGenerators )
3848  res << generator;
3849  return res;
3850 }
3851 
3852 void QgsVectorLayer::beginEditCommand( const QString &text )
3853 {
3854  if ( !mDataProvider )
3855  {
3856  return;
3857  }
3858  if ( mDataProvider->transaction() )
3859  {
3860  QString ignoredError;
3861  mDataProvider->transaction()->createSavepoint( ignoredError );
3862  }
3863  undoStack()->beginMacro( text );
3864  mEditCommandActive = true;
3865  emit editCommandStarted( text );
3866 }
3867 
3869 {
3870  if ( !mDataProvider )
3871  {
3872  return;
3873  }
3874  undoStack()->endMacro();
3875  mEditCommandActive = false;
3876  if ( !mDeletedFids.isEmpty() )
3877  {
3878  if ( selectedFeatureCount() > 0 )
3879  {
3880  mSelectedFeatureIds.subtract( mDeletedFids );
3881  }
3882  emit featuresDeleted( mDeletedFids );
3883  mDeletedFids.clear();
3884  }
3885  emit editCommandEnded();
3886 }
3887 
3889 {
3890  if ( !mDataProvider )
3891  {
3892  return;
3893  }
3894  undoStack()->endMacro();
3895  undoStack()->undo();
3896 
3897  // it's not directly possible to pop the last command off the stack (the destroyed one)
3898  // and delete, so we add a dummy obsolete command to force this to occur.
3899  // Pushing the new command deletes the destroyed one, and since the new
3900  // command is obsolete it's automatically deleted by the undo stack.
3901  std::unique_ptr< QUndoCommand > command = std::make_unique< QUndoCommand >();
3902  command->setObsolete( true );
3903  undoStack()->push( command.release() );
3904 
3905  mEditCommandActive = false;
3906  mDeletedFids.clear();
3907  emit editCommandDestroyed();
3908 }
3909 
3911 {
3912  return mJoinBuffer->addJoin( joinInfo );
3913 }
3914 
3915 
3916 bool QgsVectorLayer::removeJoin( const QString &joinLayerId )
3917 {
3918  return mJoinBuffer->removeJoin( joinLayerId );
3919 }
3920 
3921 const QList< QgsVectorLayerJoinInfo > QgsVectorLayer::vectorJoins() const
3922 {
3923  return mJoinBuffer->vectorJoins();
3924 }
3925 
3926 int QgsVectorLayer::addExpressionField( const QString &exp, const QgsField &fld )
3927 {
3928  emit beforeAddingExpressionField( fld.name() );
3929  mExpressionFieldBuffer->addExpression( exp, fld );
3930  updateFields();
3931  int idx = mFields.indexFromName( fld.name() );
3932  emit attributeAdded( idx );
3933  return idx;
3934 }
3935 
3937 {
3938  emit beforeRemovingExpressionField( index );
3939  int oi = mFields.fieldOriginIndex( index );
3940  mExpressionFieldBuffer->removeExpression( oi );
3941  updateFields();
3942  emit attributeDeleted( index );
3943 }
3944 
3945 QString QgsVectorLayer::expressionField( int index ) const
3946 {
3947  if ( mFields.fieldOrigin( index ) != QgsFields::OriginExpression )
3948  return QString();
3949 
3950  int oi = mFields.fieldOriginIndex( index );
3951  if ( oi < 0 || oi >= mExpressionFieldBuffer->expressions().size() )
3952  return QString();
3953 
3954  return mExpressionFieldBuffer->expressions().at( oi ).cachedExpression.expression();
3955 }
3956 
3957 void QgsVectorLayer::updateExpressionField( int index, const QString &exp )
3958 {
3959  int oi = mFields.fieldOriginIndex( index );
3960  mExpressionFieldBuffer->updateExpression( oi, exp );
3961 }
3962 
3964 {
3965  if ( !mDataProvider )
3966  return;
3967 
3968  QgsFields oldFields = mFields;
3969 
3970  mFields = mDataProvider->fields();
3971 
3972  // added / removed fields
3973  if ( mEditBuffer )
3974  mEditBuffer->updateFields( mFields );
3975 
3976  // joined fields
3977  if ( mJoinBuffer->containsJoins() )
3978  mJoinBuffer->updateFields( mFields );
3979 
3980  if ( mExpressionFieldBuffer )
3981  mExpressionFieldBuffer->updateFields( mFields );
3982 
3983  // set aliases and default values
3984  QMap< QString, QString >::const_iterator aliasIt = mAttributeAliasMap.constBegin();
3985  for ( ; aliasIt != mAttributeAliasMap.constEnd(); ++aliasIt )
3986  {
3987  int index = mFields.lookupField( aliasIt.key() );
3988  if ( index < 0 )
3989  continue;
3990 
3991  mFields[ index ].setAlias( aliasIt.value() );
3992  }
3993 
3994  // Update configuration flags
3995  QMap< QString, QgsField::ConfigurationFlags >::const_iterator flagsIt = mFieldConfigurationFlags.constBegin();
3996  for ( ; flagsIt != mFieldConfigurationFlags.constEnd(); ++flagsIt )
3997  {
3998  int index = mFields.lookupField( flagsIt.key() );
3999  if ( index < 0 )
4000  continue;
4001 
4002  mFields[index].setConfigurationFlags( flagsIt.value() );
4003  }
4004 
4005  // Update default values
4006  mDefaultValueOnUpdateFields.clear();
4007  QMap< QString, QgsDefaultValue >::const_iterator defaultIt = mDefaultExpressionMap.constBegin();
4008  for ( ; defaultIt != mDefaultExpressionMap.constEnd(); ++defaultIt )
4009  {
4010  int index = mFields.lookupField( defaultIt.key() );
4011  if ( index < 0 )
4012  continue;
4013 
4014  mFields[ index ].setDefaultValueDefinition( defaultIt.value() );
4015  if ( defaultIt.value().applyOnUpdate() )
4016  mDefaultValueOnUpdateFields.insert( index );
4017  }
4018 
4019  QMap< QString, QgsFieldConstraints::Constraints >::const_iterator constraintIt = mFieldConstraints.constBegin();
4020  for ( ; constraintIt != mFieldConstraints.constEnd(); ++constraintIt )
4021  {
4022  int index = mFields.lookupField( constraintIt.key() );
4023  if ( index < 0 )
4024  continue;
4025 
4026  QgsFieldConstraints constraints = mFields.at( index ).constraints();
4027 
4028  // always keep provider constraints intact
4029  if ( !( constraints.constraints() & QgsFieldConstraints::ConstraintNotNull ) && ( constraintIt.value() & QgsFieldConstraints::ConstraintNotNull ) )
4031  if ( !( constraints.constraints() & QgsFieldConstraints::ConstraintUnique ) && ( constraintIt.value() & QgsFieldConstraints::ConstraintUnique ) )
4033  if ( !( constraints.constraints() & QgsFieldConstraints::ConstraintExpression ) && ( constraintIt.value() & QgsFieldConstraints::ConstraintExpression ) )
4035  mFields[ index ].setConstraints( constraints );
4036  }
4037 
4038  QMap< QString, QPair< QString, QString > >::const_iterator constraintExpIt = mFieldConstraintExpressions.constBegin();
4039  for ( ; constraintExpIt != mFieldConstraintExpressions.constEnd(); ++constraintExpIt )
4040  {
4041  int index = mFields.lookupField( constraintExpIt.key() );
4042  if ( index < 0 )
4043  continue;
4044 
4045  QgsFieldConstraints constraints = mFields.at( index ).constraints();
4046 
4047  // always keep provider constraints intact
4049  continue;
4050 
4051  constraints.setConstraintExpression( constraintExpIt.value().first, constraintExpIt.value().second );
4052  mFields[ index ].setConstraints( constraints );
4053  }
4054 
4055  QMap< QPair< QString, QgsFieldConstraints::Constraint >, QgsFieldConstraints::ConstraintStrength >::const_iterator constraintStrengthIt = mFieldConstraintStrength.constBegin();
4056  for ( ; constraintStrengthIt != mFieldConstraintStrength.constEnd(); ++constraintStrengthIt )
4057  {
4058  int index = mFields.lookupField( constraintStrengthIt.key().first );
4059  if ( index < 0 )
4060  continue;
4061 
4062  QgsFieldConstraints constraints = mFields.at( index ).constraints();
4063 
4064  // always keep provider constraints intact
4066  continue;
4067 
4068  constraints.setConstraintStrength( constraintStrengthIt.key().second, constraintStrengthIt.value() );
4069  mFields[ index ].setConstraints( constraints );
4070  }
4071 
4072  auto fieldWidgetIterator = mFieldWidgetSetups.constBegin();
4073  for ( ; fieldWidgetIterator != mFieldWidgetSetups.constEnd(); ++ fieldWidgetIterator )
4074  {
4075  int index = mFields.indexOf( fieldWidgetIterator.key() );
4076  if ( index < 0 )
4077  continue;
4078 
4079  mFields[index].setEditorWidgetSetup( fieldWidgetIterator.value() );
4080  }
4081 
4082  if ( oldFields != mFields )
4083  {
4084  emit updatedFields();
4085  mEditFormConfig.setFields( mFields );
4086  }
4087 
4088 }
4089 
4090 
4091 QVariant QgsVectorLayer::defaultValue( int index, const QgsFeature &feature, QgsExpressionContext *context ) const
4092 {
4093  if ( index < 0 || index >= mFields.count() || !mDataProvider )
4094  return QVariant();
4095 
4096  QString expression = mFields.at( index ).defaultValueDefinition().expression();
4097  if ( expression.isEmpty() )
4098  return mDataProvider->defaultValue( index );
4099 
4100  QgsExpressionContext *evalContext = context;
4101  std::unique_ptr< QgsExpressionContext > tempContext;
4102  if ( !evalContext )
4103  {
4104  // no context passed, so we create a default one
4106  evalContext = tempContext.get();
4107  }
4108 
4109  if ( feature.isValid() )
4110  {
4112  featScope->setFeature( feature );
4113  featScope->setFields( feature.fields() );
4114  evalContext->appendScope( featScope );
4115  }
4116 
4117  QVariant val;
4118  QgsExpression exp( expression );
4119  exp.prepare( evalContext );
4120  if ( exp.hasEvalError() )
4121  {
4122  QgsLogger::warning( "Error evaluating default value: " + exp.evalErrorString() );
4123  }
4124  else
4125  {
4126  val = exp.evaluate( evalContext );
4127  }
4128 
4129  if ( feature.isValid() )
4130  {
4131  delete evalContext->popScope();
4132  }
4133 
4134  return val;
4135 }
4136 
4138 {
4139  if ( index < 0 || index >= mFields.count() )
4140  return;
4141 
4142  if ( definition.isValid() )
4143  {
4144  mDefaultExpressionMap.insert( mFields.at( index ).name(), definition );
4145  }
4146  else
4147  {
4148  mDefaultExpressionMap.remove( mFields.at( index ).name() );
4149  }
4150  updateFields();
4151 }
4152 
4154 {
4155  if ( index < 0 || index >= mFields.count() )
4156  return QgsDefaultValue();
4157  else
4158  return mFields.at( index ).defaultValueDefinition();
4159 }
4160 
4161 QSet<QVariant> QgsVectorLayer::uniqueValues( int index, int limit ) const
4162 {
4163  QSet<QVariant> uniqueValues;
4164  if ( !mDataProvider )
4165  {
4166  return uniqueValues;
4167  }
4168 
4169  QgsFields::FieldOrigin origin = mFields.fieldOrigin( index );
4170  switch ( origin )
4171  {
4173  return uniqueValues;
4174 
4175  case QgsFields::OriginProvider: //a provider field
4176  {
4177  uniqueValues = mDataProvider->uniqueValues( index, limit );
4178 
4179  if ( mEditBuffer && ! mDataProvider->transaction() )
4180  {
4181  QSet<QString> vals;
4182  const auto constUniqueValues = uniqueValues;
4183  for ( const QVariant &v : constUniqueValues )
4184  {
4185  vals << v.toString();
4186  }
4187 
4188  QgsFeatureMap added = mEditBuffer->addedFeatures();
4189  QMapIterator< QgsFeatureId, QgsFeature > addedIt( added );
4190  while ( addedIt.hasNext() && ( limit < 0 || uniqueValues.count() < limit ) )
4191  {
4192  addedIt.next();
4193  QVariant v = addedIt.value().attribute( index );
4194  if ( v.isValid() )
4195  {
4196  QString vs = v.toString();
4197  if ( !vals.contains( vs ) )
4198  {
4199  vals << vs;
4200  uniqueValues << v;
4201  }
4202  }
4203  }
4204 
4205  QMapIterator< QgsFeatureId, QgsAttributeMap > it( mEditBuffer->changedAttributeValues() );
4206  while ( it.hasNext() && ( limit < 0 || uniqueValues.count() < limit ) )
4207  {
4208  it.next();
4209  QVariant v = it.value().value( index );
4210  if ( v.isValid() )
4211  {
4212  QString vs = v.toString();
4213  if ( !vals.contains( vs ) )
4214  {
4215  vals << vs;
4216  uniqueValues << v;
4217  }
4218  }
4219  }
4220  }
4221 
4222  return uniqueValues;
4223  }
4224 
4225  case QgsFields::OriginEdit:
4226  // the layer is editable, but in certain cases it can still be avoided going through all features
4227  if ( mDataProvider->transaction() || (
4228  mEditBuffer->deletedFeatureIds().isEmpty() &&
4229  mEditBuffer->addedFeatures().isEmpty() &&
4230  !mEditBuffer->deletedAttributeIds().contains( index ) &&
4231  mEditBuffer->changedAttributeValues().isEmpty() ) )
4232  {
4233  uniqueValues = mDataProvider->uniqueValues( index, limit );
4234  return uniqueValues;
4235  }
4236  FALLTHROUGH
4237  //we need to go through each feature
4238  case QgsFields::OriginJoin:
4240  {
4241  QgsAttributeList attList;
4242  attList << index;
4243 
4246  .setSubsetOfAttributes( attList ) );
4247 
4248  QgsFeature f;
4249  QVariant currentValue;
4250  QHash<QString, QVariant> val;
4251  while ( fit.nextFeature( f ) )
4252  {
4253  currentValue = f.attribute( index );
4254  val.insert( currentValue.toString(), currentValue );
4255  if ( limit >= 0 && val.size() >= limit )
4256  {
4257  break;
4258  }
4259  }
4260 
4261  return qgis::listToSet( val.values() );
4262  }
4263  }
4264 
4265  Q_ASSERT_X( false, "QgsVectorLayer::uniqueValues()", "Unknown source of the field!" );
4266  return uniqueValues;
4267 }
4268 
4269 QStringList QgsVectorLayer::uniqueStringsMatching( int index, const QString &substring, int limit, QgsFeedback *feedback ) const
4270 {
4271  QStringList results;
4272  if ( !mDataProvider )
4273  {
4274  return results;
4275  }
4276 
4277  QgsFields::FieldOrigin origin = mFields.fieldOrigin( index );
4278  switch ( origin )
4279  {
4281  return results;
4282 
4283  case QgsFields::OriginProvider: //a provider field
4284  {
4285  results = mDataProvider->uniqueStringsMatching( index, substring, limit, feedback );
4286 
4287  if ( mEditBuffer && ! mDataProvider->transaction() )
4288  {
4289  QgsFeatureMap added = mEditBuffer->addedFeatures();
4290  QMapIterator< QgsFeatureId, QgsFeature > addedIt( added );
4291  while ( addedIt.hasNext() && ( limit < 0 || results.count() < limit ) && ( !feedback || !feedback->isCanceled() ) )
4292  {
4293  addedIt.next();
4294  QVariant v = addedIt.value().attribute( index );
4295  if ( v.isValid() )
4296  {
4297  QString vs = v.toString();
4298  if ( vs.contains( substring, Qt::CaseInsensitive ) && !results.contains( vs ) )
4299  {
4300  results << vs;
4301  }
4302  }
4303  }
4304 
4305  QMapIterator< QgsFeatureId, QgsAttributeMap > it( mEditBuffer->changedAttributeValues() );
4306  while ( it.hasNext() && ( limit < 0 || results.count() < limit ) && ( !feedback || !feedback->isCanceled() ) )
4307  {
4308  it.next();
4309  QVariant v = it.value().value( index );
4310  if ( v.isValid() )
4311  {
4312  QString vs = v.toString();
4313  if ( vs.contains( substring, Qt::CaseInsensitive ) && !results.contains( vs ) )
4314  {
4315  results << vs;
4316  }
4317  }
4318  }
4319  }
4320 
4321  return results;
4322  }
4323 
4324  case QgsFields::OriginEdit:
4325  // the layer is editable, but in certain cases it can still be avoided going through all features
4326  if ( mDataProvider->transaction() || ( mEditBuffer->deletedFeatureIds().isEmpty() &&
4327  mEditBuffer->addedFeatures().isEmpty() &&
4328  !mEditBuffer->deletedAttributeIds().contains( index ) &&
4329  mEditBuffer->changedAttributeValues().isEmpty() ) )
4330  {
4331  return mDataProvider->uniqueStringsMatching( index, substring, limit, feedback );
4332  }
4333  FALLTHROUGH
4334  //we need to go through each feature
4335  case QgsFields::OriginJoin:
4337  {
4338  QgsAttributeList attList;
4339  attList << index;
4340 
4341  QgsFeatureRequest request;
4342  request.setSubsetOfAttributes( attList );
4344  QString fieldName = mFields.at( index ).name();
4345  request.setFilterExpression( QStringLiteral( "\"%1\" ILIKE '%%2%'" ).arg( fieldName, substring ) );
4346  QgsFeatureIterator fit = getFeatures( request );
4347 
4348  QgsFeature f;
4349  QString currentValue;
4350  while ( fit.nextFeature( f ) )
4351  {
4352  currentValue = f.attribute( index ).toString();
4353  if ( !results.contains( currentValue ) )
4354  results << currentValue;
4355 
4356  if ( ( limit >= 0 && results.size() >= limit ) || ( feedback && feedback->isCanceled() ) )
4357  {
4358  break;
4359  }
4360  }
4361 
4362  return results;
4363  }
4364  }
4365 
4366  Q_ASSERT_X( false, "QgsVectorLayer::uniqueStringsMatching()", "Unknown source of the field!" );
4367  return results;
4368 }
4369 
4370 QVariant QgsVectorLayer::minimumValue( int index ) const
4371 {
4372  QVariant minimum;
4373  minimumOrMaximumValue( index, &minimum, nullptr );
4374  return minimum;
4375 }
4376 
4377 QVariant QgsVectorLayer::maximumValue( int index ) const
4378 {
4379  QVariant maximum;
4380  minimumOrMaximumValue( index, nullptr, &maximum );
4381  return maximum;
4382 }
4383 
4384 void QgsVectorLayer::minimumAndMaximumValue( int index, QVariant &minimum, QVariant &maximum ) const
4385 {
4386  minimumOrMaximumValue( index, &minimum, &maximum );
4387 }
4388 
4389 void QgsVectorLayer::minimumOrMaximumValue( int index, QVariant *minimum, QVariant *maximum ) const
4390 {
4391  if ( minimum )
4392  *minimum = QVariant();
4393  if ( maximum )
4394  *maximum = QVariant();
4395 
4396  if ( !mDataProvider )
4397  {
4398  return;
4399  }
4400 
4401  QgsFields::FieldOrigin origin = mFields.fieldOrigin( index );
4402 
4403  switch ( origin )
4404  {
4406  {
4407  return;
4408  }
4409 
4410  case QgsFields::OriginProvider: //a provider field
4411  {
4412  if ( minimum )
4413  *minimum = mDataProvider->minimumValue( index );
4414  if ( maximum )
4415  *maximum = mDataProvider->maximumValue( index );
4416  if ( mEditBuffer && ! mDataProvider->transaction() )
4417  {
4418  const QgsFeatureMap added = mEditBuffer->addedFeatures();
4419  QMapIterator< QgsFeatureId, QgsFeature > addedIt( added );
4420  while ( addedIt.hasNext() )
4421  {
4422  addedIt.next();
4423  const QVariant v = addedIt.value().attribute( index );
4424  if ( minimum && v.isValid() && qgsVariantLessThan( v, *minimum ) )
4425  *minimum = v;
4426  if ( maximum && v.isValid() && qgsVariantGreaterThan( v, *maximum ) )
4427  *maximum = v;
4428  }
4429 
4430  QMapIterator< QgsFeatureId, QgsAttributeMap > it( mEditBuffer->changedAttributeValues() );
4431  while ( it.hasNext() )
4432  {
4433  it.next();
4434  const QVariant v = it.value().value( index );
4435  if ( minimum && v.isValid() && qgsVariantLessThan( v, *minimum ) )
4436  *minimum = v;
4437  if ( maximum && v.isValid() && qgsVariantGreaterThan( v, *maximum ) )
4438  *maximum = v;
4439  }
4440  }
4441  return;
4442  }
4443 
4444  case QgsFields::OriginEdit:
4445  {
4446  // the layer is editable, but in certain cases it can still be avoided going through all features
4447  if ( mDataProvider->transaction() || ( mEditBuffer->deletedFeatureIds().isEmpty() &&
4448  mEditBuffer->addedFeatures().isEmpty() &&
4449  !mEditBuffer->deletedAttributeIds().contains( index ) &&
4450  mEditBuffer->changedAttributeValues().isEmpty() ) )
4451  {
4452  if ( minimum )
4453  *minimum = mDataProvider->minimumValue( index );
4454  if ( maximum )
4455  *maximum = mDataProvider->maximumValue( index );
4456  return;
4457  }
4458  }
4459  FALLTHROUGH
4460  // no choice but to go through all features
4462  case QgsFields::OriginJoin:
4463  {
4464  // we need to go through each feature
4465  QgsAttributeList attList;
4466  attList << index;
4467 
4470  .setSubsetOfAttributes( attList ) );
4471 
4472  QgsFeature f;
4473  bool firstValue = true;
4474  while ( fit.nextFeature( f ) )
4475  {
4476  const QVariant currentValue = f.attribute( index );
4477  if ( currentValue.isNull() )
4478  continue;
4479 
4480  if ( firstValue )
4481  {
4482  if ( minimum )
4483  *minimum = currentValue;
4484  if ( maximum )
4485  *maximum = currentValue;
4486  firstValue = false;
4487  }
4488  else
4489  {
4490  if ( minimum && currentValue.isValid() && qgsVariantLessThan( currentValue, *minimum ) )
4491  *minimum = currentValue;
4492  if ( maximum && currentValue.isValid() && qgsVariantGreaterThan( currentValue, *maximum ) )
4493  *maximum = currentValue;
4494  }
4495  }
4496  return;
4497  }
4498  }
4499 
4500  Q_ASSERT_X( false, "QgsVectorLayer::minimumOrMaximumValue()", "Unknown source of the field!" );
4501 }
4502 
4503 void QgsVectorLayer::createEditBuffer()
4504 {
4505  if ( mEditBuffer )
4506  clearEditBuffer();
4507 
4508  if ( mDataProvider->transaction() )
4509  {
4510  mEditBuffer = new QgsVectorLayerEditPassthrough( this );
4511 
4512  connect( mDataProvider->transaction(), &QgsTransaction::dirtied, this, &QgsVectorLayer::onDirtyTransaction, Qt::UniqueConnection );
4513  }
4514  else
4515  {
4516  mEditBuffer = new QgsVectorLayerEditBuffer( this );
4517  }
4518  // forward signals
4519  connect( mEditBuffer, &QgsVectorLayerEditBuffer::layerModified, this, &QgsVectorLayer::invalidateSymbolCountedFlag );
4520  connect( mEditBuffer, &QgsVectorLayerEditBuffer::layerModified, this, &QgsVectorLayer::layerModified ); // TODO[MD]: necessary?
4521  //connect( mEditBuffer, SIGNAL( layerModified() ), this, SLOT( triggerRepaint() ) ); // TODO[MD]: works well?
4523  connect( mEditBuffer, &QgsVectorLayerEditBuffer::featureDeleted, this, &QgsVectorLayer::onFeatureDeleted );
4534 
4535 }
4536 
4537 void QgsVectorLayer::clearEditBuffer()
4538 {
4539  delete mEditBuffer;
4540  mEditBuffer = nullptr;
4541 }
4542 
4543 QVariant QgsVectorLayer::aggregate( QgsAggregateCalculator::Aggregate aggregate, const QString &fieldOrExpression,
4545  bool *ok, QgsFeatureIds *fids, QgsFeedback *feedback, QString *error ) const
4546 {
4547  if ( ok )
4548  *ok = false;
4549  if ( error )
4550  error->clear();
4551 
4552  if ( !mDataProvider )
4553  {
4554  if ( error )
4555  *error = tr( "Layer is invalid" );
4556  return QVariant();
4557  }
4558 
4559  // test if we are calculating based on a field
4560  const int attrIndex = QgsExpression::expressionToLayerFieldIndex( fieldOrExpression, this );
4561  if ( attrIndex >= 0 )
4562  {
4563  // aggregate is based on a field - if it's a provider field, we could possibly hand over the calculation
4564  // to the provider itself
4565  QgsFields::FieldOrigin origin = mFields.fieldOrigin( attrIndex );
4566  if ( origin == QgsFields::OriginProvider )
4567  {
4568  bool providerOk = false;
4569  QVariant val = mDataProvider->aggregate( aggregate, attrIndex, parameters, context, providerOk, fids );
4570  if ( providerOk )
4571  {
4572  // provider handled calculation
4573  if ( ok )
4574  *ok = true;
4575  return val;
4576  }
4577  }
4578  }
4579 
4580  // fallback to using aggregate calculator to determine aggregate
4581  QgsAggregateCalculator c( this );
4582  if ( fids )
4583  c.setFidsFilter( *fids );
4584  c.setParameters( parameters );
4585  bool aggregateOk = false;
4586  const QVariant result = c.calculate( aggregate, fieldOrExpression, context, &aggregateOk, feedback );
4587  if ( ok )
4588  *ok = aggregateOk;
4589  if ( !aggregateOk && error )
4590  *error = c.lastError();
4591 
4592  return result;
4593 }
4594 
4595 void QgsVectorLayer::setFeatureBlendMode( QPainter::CompositionMode featureBlendMode )
4596 {
4597  if ( mFeatureBlendMode == featureBlendMode )
4598  return;
4599 
4600  mFeatureBlendMode = featureBlendMode;
4602  emitStyleChanged();
4603 }
4604 
4605 QPainter::CompositionMode QgsVectorLayer::featureBlendMode() const
4606 {
4607  return mFeatureBlendMode;
4608 }
4609 
4610 void QgsVectorLayer::readSldLabeling( const QDomNode &node )
4611 {
4612  setLabeling( nullptr ); // start with no labeling
4613  setLabelsEnabled( false );
4614 
4615  QDomElement element = node.toElement();
4616  if ( element.isNull() )
4617  return;
4618 
4619  QDomElement userStyleElem = element.firstChildElement( QStringLiteral( "UserStyle" ) );
4620  if ( userStyleElem.isNull() )
4621  {
4622  QgsDebugMsgLevel( QStringLiteral( "Info: UserStyle element not found." ), 4 );
4623  return;
4624  }
4625 
4626  QDomElement featTypeStyleElem = userStyleElem.firstChildElement( QStringLiteral( "FeatureTypeStyle" ) );
4627  if ( featTypeStyleElem.isNull() )
4628  {
4629  QgsDebugMsgLevel( QStringLiteral( "Info: FeatureTypeStyle element not found." ), 4 );
4630  return;
4631  }
4632 
4633  // create empty FeatureTypeStyle element to merge TextSymbolizer's Rule's from all FeatureTypeStyle's
4634  QDomElement mergedFeatTypeStyle = featTypeStyleElem.cloneNode( false ).toElement();
4635 
4636  // use the RuleRenderer when more rules are present or the rule
4637  // has filters or min/max scale denominators set,
4638  // otherwise use the Simple labeling
4639  bool needRuleBasedLabeling = false;
4640  int ruleCount = 0;
4641 
4642  while ( !featTypeStyleElem.isNull() )
4643  {
4644  QDomElement ruleElem = featTypeStyleElem.firstChildElement( QStringLiteral( "Rule" ) );
4645  while ( !ruleElem.isNull() )
4646  {
4647  // test rule children element to check if we need to create RuleRenderer
4648  // and if the rule has a symbolizer
4649  bool hasTextSymbolizer = false;
4650  bool hasRuleBased = false;
4651  QDomElement ruleChildElem = ruleElem.firstChildElement();
4652  while ( !ruleChildElem.isNull() )
4653  {
4654  // rule has filter or min/max scale denominator, use the RuleRenderer
4655  if ( ruleChildElem.localName() == QLatin1String( "Filter" ) ||
4656  ruleChildElem.localName() == QLatin1String( "MinScaleDenominator" ) ||
4657  ruleChildElem.localName() == QLatin1String( "MaxScaleDenominator" ) )
4658  {
4659  hasRuleBased = true;
4660  }
4661  // rule has a renderer symbolizer, not a text symbolizer
4662  else if ( ruleChildElem.localName() == QLatin1String( "TextSymbolizer" ) )
4663  {
4664  QgsDebugMsgLevel( QStringLiteral( "Info: TextSymbolizer element found" ), 4 );
4665  hasTextSymbolizer = true;
4666  }
4667 
4668  ruleChildElem = ruleChildElem.nextSiblingElement();
4669  }
4670 
4671  if ( hasTextSymbolizer )
4672  {
4673  ruleCount++;
4674 
4675  // append a clone of all Rules to the merged FeatureTypeStyle element
4676  mergedFeatTypeStyle.appendChild( ruleElem.cloneNode().toElement() );
4677 
4678  if ( hasRuleBased )
4679  {
4680  QgsDebugMsgLevel( QStringLiteral( "Info: Filter or Min/MaxScaleDenominator element found: need a RuleBasedLabeling" ), 4 );
4681  needRuleBasedLabeling = true;
4682  }
4683  }
4684 
4685  // more rules present, use the RuleRenderer
4686  if ( ruleCount > 1 )
4687  {
4688  QgsDebugMsgLevel( QStringLiteral( "Info: More Rule elements found: need a RuleBasedLabeling" ), 4 );
4689  needRuleBasedLabeling = true;
4690  }
4691 
4692  // not use the rule based labeling if no rules with textSymbolizer
4693  if ( ruleCount == 0 )
4694  {
4695  needRuleBasedLabeling = false;
4696  }
4697 
4698  ruleElem = ruleElem.nextSiblingElement( QStringLiteral( "Rule" ) );
4699  }
4700  featTypeStyleElem = featTypeStyleElem.nextSiblingElement( QStringLiteral( "FeatureTypeStyle" ) );
4701  }
4702 
4703  if ( ruleCount == 0 )
4704  {
4705  QgsDebugMsgLevel( QStringLiteral( "Info: No TextSymbolizer element." ), 4 );
4706  return;
4707  }
4708 
4709  QDomElement ruleElem = mergedFeatTypeStyle.firstChildElement( QStringLiteral( "Rule" ) );
4710 
4711  if ( needRuleBasedLabeling )
4712  {
4713  QgsDebugMsgLevel( QStringLiteral( "Info: rule based labeling" ), 4 );
4714  QgsRuleBasedLabeling::Rule *rootRule = new QgsRuleBasedLabeling::Rule( nullptr );
4715  while ( !ruleElem.isNull() )
4716  {
4717 
4718  QString label, description, filterExp;
4719  int scaleMinDenom = 0, scaleMaxDenom = 0;
4720  QgsPalLayerSettings settings;
4721 
4722  // retrieve the Rule element child nodes
4723  QDomElement childElem = ruleElem.firstChildElement();
4724  while ( !childElem.isNull() )
4725  {
4726  if ( childElem.localName() == QLatin1String( "Name" ) )
4727  {
4728  // <se:Name> tag contains the rule identifier,
4729  // so prefer title tag for the label property value
4730  if ( label.isEmpty() )
4731  label = childElem.firstChild().nodeValue();
4732  }
4733  else if ( childElem.localName() == QLatin1String( "Description" ) )
4734  {
4735  // <se:Description> can contains a title and an abstract
4736  QDomElement titleElem = childElem.firstChildElement( QStringLiteral( "Title" ) );
4737  if ( !titleElem.isNull() )
4738  {
4739  label = titleElem.firstChild().nodeValue();
4740  }
4741 
4742  QDomElement abstractElem = childElem.firstChildElement( QStringLiteral( "Abstract" ) );
4743  if ( !abstractElem.isNull() )
4744  {
4745  description = abstractElem.firstChild().nodeValue();
4746  }
4747  }
4748  else if ( childElem.localName() == QLatin1String( "Abstract" ) )
4749  {
4750  // <sld:Abstract> (v1.0)
4751  description = childElem.firstChild().nodeValue();
4752  }
4753  else if ( childElem.localName() == QLatin1String( "Title" ) )
4754  {
4755  // <sld:Title> (v1.0)
4756  label = childElem.firstChild().nodeValue();
4757  }
4758  else if ( childElem.localName() == QLatin1String( "Filter" ) )
4759  {
4760  QgsExpression *filter = QgsOgcUtils::expressionFromOgcFilter( childElem );
4761  if ( filter )
4762  {
4763  if ( filter->hasParserError() )
4764  {
4765  QgsDebugMsgLevel( QStringLiteral( "SLD Filter parsing error: %1" ).arg( filter->parserErrorString() ), 3 );
4766  }
4767  else
4768  {
4769  filterExp = filter->expression();
4770  }
4771  delete filter;
4772  }
4773  }
4774  else if ( childElem.localName() == QLatin1String( "MinScaleDenominator" ) )
4775  {
4776  bool ok;
4777  int v = childElem.firstChild().nodeValue().toInt( &ok );
4778  if ( ok )
4779  scaleMinDenom = v;
4780  }
4781  else if ( childElem.localName() == QLatin1String( "MaxScaleDenominator" ) )
4782  {
4783  bool ok;
4784  int v = childElem.firstChild().nodeValue().toInt( &ok );
4785  if ( ok )
4786  scaleMaxDenom = v;
4787  }
4788  else if ( childElem.localName() == QLatin1String( "TextSymbolizer" ) )
4789  {
4790  readSldTextSymbolizer( childElem, settings );
4791  }
4792 
4793  childElem = childElem.nextSiblingElement();
4794  }
4795 
4796  QgsRuleBasedLabeling::Rule *ruleLabeling = new QgsRuleBasedLabeling::Rule( new QgsPalLayerSettings( settings ), scaleMinDenom, scaleMaxDenom, filterExp, label );
4797  rootRule->appendChild( ruleLabeling );
4798 
4799  ruleElem = ruleElem.nextSiblingElement();
4800  }
4801 
4802  setLabeling( new QgsRuleBasedLabeling( rootRule ) );
4803  setLabelsEnabled( true );
4804  }
4805  else
4806  {
4807  QgsDebugMsgLevel( QStringLiteral( "Info: simple labeling" ), 4 );
4808  // retrieve the TextSymbolizer element child node
4809  QDomElement textSymbolizerElem = ruleElem.firstChildElement( QStringLiteral( "TextSymbolizer" ) );
4811  if ( readSldTextSymbolizer( textSymbolizerElem, s ) )
4812  {
4814  setLabelsEnabled( true );
4815  }
4816  }
4817 }
4818 
4819 bool QgsVectorLayer::readSldTextSymbolizer( const QDomNode &node, QgsPalLayerSettings &settings ) const
4820 {
4821  if ( node.localName() != QLatin1String( "TextSymbolizer" ) )
4822  {
4823  QgsDebugMsgLevel( QStringLiteral( "Not a TextSymbolizer element: %1" ).arg( node.localName() ), 3 );
4824  return false;
4825  }
4826  QDomElement textSymbolizerElem = node.toElement();
4827  // Label
4828  QDomElement labelElem = textSymbolizerElem.firstChildElement( QStringLiteral( "Label" ) );
4829  if ( !labelElem.isNull() )
4830  {
4831  QDomElement propertyNameElem = labelElem.firstChildElement( QStringLiteral( "PropertyName" ) );
4832  if ( !propertyNameElem.isNull() )
4833  {
4834  // set labeling defaults
4835 
4836  // label attribute
4837  QString labelAttribute = propertyNameElem.text();
4838  settings.fieldName = labelAttribute;
4839  settings.isExpression = false;
4840 
4841  int fieldIndex = mFields.lookupField( labelAttribute );
4842  if ( fieldIndex == -1 )
4843  {
4844  // label attribute is not in columns, check if it is an expression
4845  QgsExpression exp( labelAttribute );
4846  if ( !exp.hasEvalError() )
4847  {
4848  settings.isExpression = true;
4849  }
4850  else
4851  {
4852  QgsDebugMsgLevel( QStringLiteral( "SLD label attribute error: %1" ).arg( exp.evalErrorString() ), 3 );
4853  }
4854  }
4855  }
4856  else
4857  {
4858  QgsDebugMsgLevel( QStringLiteral( "Info: PropertyName element not found." ), 4 );
4859  return false;
4860  }
4861  }
4862  else
4863  {
4864  QgsDebugMsgLevel( QStringLiteral( "Info: Label element not found." ), 4 );
4865  return false;
4866  }
4867 
4869  if ( textSymbolizerElem.hasAttribute( QStringLiteral( "uom" ) ) )
4870  {
4871  sldUnitSize = QgsSymbolLayerUtils::decodeSldUom( textSymbolizerElem.attribute( QStringLiteral( "uom" ) ) );
4872  }
4873 
4874  QString fontFamily = QStringLiteral( "Sans-Serif" );
4875  int fontPointSize = 10;
4877  int fontWeight = -1;
4878  bool fontItalic = false;
4879  bool fontUnderline = false;
4880 
4881  // Font
4882  QDomElement fontElem = textSymbolizerElem.firstChildElement( QStringLiteral( "Font" ) );
4883  if ( !fontElem.isNull() )
4884  {
4885  QgsStringMap fontSvgParams = QgsSymbolLayerUtils::getSvgParameterList( fontElem );
4886  for ( QgsStringMap::iterator it = fontSvgParams.begin(); it != fontSvgParams.end(); ++it )
4887  {
4888  QgsDebugMsgLevel( QStringLiteral( "found fontSvgParams %1: %2" ).arg( it.key(), it.value() ), 4 );
4889 
4890  if ( it.key() == QLatin1String( "font-family" ) )
4891  {
4892  fontFamily = it.value();
4893  }
4894  else if ( it.key() == QLatin1String( "font-style" ) )
4895  {
4896  fontItalic = ( it.value() == QLatin1String( "italic" ) ) || ( it.value() == QLatin1String( "Italic" ) );
4897  }
4898  else if ( it.key() == QLatin1String( "font-size" ) )
4899  {
4900  bool ok;
4901  int fontSize = it.value().toInt( &ok );
4902  if ( ok )
4903  {
4904  fontPointSize = fontSize;
4905  fontUnitSize = sldUnitSize;
4906  }
4907  }
4908  else if ( it.key() == QLatin1String( "font-weight" ) )
4909  {
4910  if ( ( it.value() == QLatin1String( "bold" ) ) || ( it.value() == QLatin1String( "Bold" ) ) )
4911  fontWeight = QFont::Bold;
4912  }
4913  else if ( it.key() == QLatin1String( "font-underline" ) )
4914  {
4915  fontUnderline = ( it.value() == QLatin1String( "underline" ) ) || ( it.value() == QLatin1String( "Underline" ) );
4916  }
4917  }
4918  }
4919 
4920  QgsTextFormat format;
4921  QFont font( fontFamily, fontPointSize, fontWeight, fontItalic );
4922  font.setUnderline( fontUnderline );
4923  format.setFont( font );
4924  format.setSize( fontPointSize );
4925  format.setSizeUnit( fontUnitSize );
4926 
4927  // Fill
4928  QDomElement fillElem = textSymbolizerElem.firstChildElement( QStringLiteral( "Fill" ) );
4929  QColor textColor;
4930  Qt::BrushStyle textBrush = Qt::SolidPattern;
4931  QgsSymbolLayerUtils::fillFromSld( fillElem, textBrush, textColor );
4932  if ( textColor.isValid() )
4933  {
4934  QgsDebugMsgLevel( QStringLiteral( "Info: textColor %1." ).arg( QVariant( textColor ).toString() ), 4 );
4935  format.setColor( textColor );
4936  }
4937 
4938  QgsTextBufferSettings bufferSettings;
4939 
4940  // Halo
4941  QDomElement haloElem = textSymbolizerElem.firstChildElement( QStringLiteral( "Halo" ) );
4942  if ( !haloElem.isNull() )
4943  {
4944  bufferSettings.setEnabled( true );
4945  bufferSettings.setSize( 1 );
4946 
4947  QDomElement radiusElem = haloElem.firstChildElement( QStringLiteral( "Radius" ) );
4948  if ( !radiusElem.isNull() )
4949  {
4950  bool ok;
4951  double bufferSize = radiusElem.text().toDouble( &ok );
4952  if ( ok )
4953  {
4954  bufferSettings.setSize( bufferSize );
4955  bufferSettings.setSizeUnit( sldUnitSize );
4956  }
4957  }
4958 
4959  QDomElement haloFillElem = haloElem.firstChildElement( QStringLiteral( "Fill" ) );
4960  QColor bufferColor;
4961  Qt::BrushStyle bufferBrush = Qt::SolidPattern;
4962  QgsSymbolLayerUtils::fillFromSld( haloFillElem, bufferBrush, bufferColor );
4963  if ( bufferColor.isValid() )
4964  {
4965  QgsDebugMsgLevel( QStringLiteral( "Info: bufferColor %1." ).arg( QVariant( bufferColor ).toString() ), 4 );
4966  bufferSettings.setColor( bufferColor );
4967  }
4968  }
4969 
4970  // LabelPlacement
4971  QDomElement labelPlacementElem = textSymbolizerElem.firstChildElement( QStringLiteral( "LabelPlacement" ) );
4972  if ( !labelPlacementElem.isNull() )
4973  {
4974  // PointPlacement
4975  QDomElement pointPlacementElem = labelPlacementElem.firstChildElement( QStringLiteral( "PointPlacement" ) );
4976  if ( !pointPlacementElem.isNull() )
4977  {
4980  {
4982  }
4983 
4984  QDomElement displacementElem = pointPlacementElem.firstChildElement( QStringLiteral( "Displacement" ) );
4985  if ( !displacementElem.isNull() )
4986  {
4987  QDomElement displacementXElem = displacementElem.firstChildElement( QStringLiteral( "DisplacementX" ) );
4988  if ( !displacementXElem.isNull() )
4989  {
4990  bool ok;
4991  double xOffset = displacementXElem.text().toDouble( &ok );
4992  if ( ok )
4993  {
4994  settings.xOffset = xOffset;
4995  settings.offsetUnits = sldUnitSize;
4996  }
4997  }
4998  QDomElement displacementYElem = displacementElem.firstChildElement( QStringLiteral( "DisplacementY" ) );
4999  if ( !displacementYElem.isNull() )
5000  {
5001  bool ok;
5002  double yOffset = displacementYElem.text().toDouble( &ok );
5003  if ( ok )
5004  {
5005  settings.yOffset = yOffset;
5006  settings.offsetUnits = sldUnitSize;
5007  }
5008  }
5009  }
5010  QDomElement anchorPointElem = pointPlacementElem.firstChildElement( QStringLiteral( "AnchorPoint" ) );
5011  if ( !anchorPointElem.isNull() )
5012  {
5013  QDomElement anchorPointXElem = anchorPointElem.firstChildElement( QStringLiteral( "AnchorPointX" ) );
5014  if ( !anchorPointXElem.isNull() )
5015  {
5016  bool ok;
5017  double xOffset = anchorPointXElem.text().toDouble( &ok );
5018  if ( ok )
5019  {
5020  settings.xOffset = xOffset;
5021  settings.offsetUnits = sldUnitSize;
5022  }
5023  }
5024  QDomElement anchorPointYElem = anchorPointElem.firstChildElement( QStringLiteral( "AnchorPointY" ) );
5025  if ( !anchorPointYElem.isNull() )
5026  {
5027  bool ok;
5028  double yOffset = anchorPointYElem.text().toDouble( &ok );
5029  if ( ok )
5030  {
5031  settings.yOffset = yOffset;
5032  settings.offsetUnits = sldUnitSize;
5033  }
5034  }
5035  }
5036 
5037  QDomElement rotationElem = pointPlacementElem.firstChildElement( QStringLiteral( "Rotation" ) );
5038  if ( !rotationElem.isNull() )
5039  {
5040  bool ok;
5041  double rotation = rotationElem.text().toDouble( &ok );
5042  if ( ok )
5043  {
5044  settings.angleOffset = 360 - rotation;
5045  }
5046  }
5047  }
5048  else
5049  {
5050  // PointPlacement
5051  QDomElement linePlacementElem = labelPlacementElem.firstChildElement( QStringLiteral( "LinePlacement" ) );
5052  if ( !linePlacementElem.isNull() )
5053  {
5055  }
5056  }
5057  }
5058 
5059  // read vendor options
5060  QgsStringMap vendorOptions;
5061  QDomElement vendorOptionElem = textSymbolizerElem.firstChildElement( QStringLiteral( "VendorOption" ) );
5062  while ( !vendorOptionElem.isNull() && vendorOptionElem.localName() == QLatin1String( "VendorOption" ) )
5063  {
5064  QString optionName = vendorOptionElem.attribute( QStringLiteral( "name" ) );
5065  QString optionValue;
5066  if ( vendorOptionElem.firstChild().nodeType() == QDomNode::TextNode )
5067  {
5068  optionValue = vendorOptionElem.firstChild().nodeValue();
5069  }
5070  else
5071  {
5072  if ( vendorOptionElem.firstChild().nodeType() == QDomNode::ElementNode &&
5073  vendorOptionElem.firstChild().localName() == QLatin1String( "Literal" ) )
5074  {
5075  QgsDebugMsg( vendorOptionElem.firstChild().localName() );
5076  optionValue = vendorOptionElem.firstChild().firstChild().nodeValue();
5077  }
5078  else
5079  {
5080  QgsDebugMsg( QStringLiteral( "unexpected child of %1 named %2" ).arg( vendorOptionElem.localName(), optionName ) );
5081  }
5082  }
5083 
5084  if ( !optionName.isEmpty() && !optionValue.isEmpty() )
5085  {
5086  vendorOptions[ optionName ] = optionValue;
5087  }
5088 
5089  vendorOptionElem = vendorOptionElem.nextSiblingElement();
5090  }
5091  if ( !vendorOptions.isEmpty() )
5092  {
5093  for ( QgsStringMap::iterator it = vendorOptions.begin(); it != vendorOptions.end(); ++it )
5094  {
5095  if ( it.key() == QLatin1String( "underlineText" ) && it.value() == QLatin1String( "true" ) )
5096  {
5097  font.setUnderline( true );
5098  format.setFont( font );
5099  }
5100  else if ( it.key() == QLatin1String( "strikethroughText" ) && it.value() == QLatin1String( "true" ) )
5101  {
5102  font.setStrikeOut( true );
5103  format.setFont( font );
5104  }
5105  else if ( it.key() == QLatin1String( "maxDisplacement" ) )
5106  {
5108  }
5109  else if ( it.key() == QLatin1String( "followLine" ) && it.value() == QLatin1String( "true" ) )
5110  {
5112  {
5114  }
5115  else
5116  {
5118  }
5119  }
5120  else if ( it.key() == QLatin1String( "maxAngleDelta" ) )
5121  {
5122  bool ok;
5123  double angle = it.value().toDouble( &ok );
5124  if ( ok )
5125  {
5126  settings.maxCurvedCharAngleIn = angle;
5127  settings.maxCurvedCharAngleOut = angle;
5128  }
5129  }
5130  // miscellaneous options
5131  else if ( it.key() == QLatin1String( "conflictResolution" ) && it.value() == QLatin1String( "false" ) )
5132  {
5134  }
5135  else if ( it.key() == QLatin1String( "forceLeftToRight" ) && it.value() == QLatin1String( "false" ) )
5136  {
5137  settings.upsidedownLabels = Qgis::UpsideDownLabelHandling::AlwaysAllowUpsideDown;
5138  }
5139  else if ( it.key() == QLatin1String( "group" ) && it.value() == QLatin1String( "yes" ) )
5140  {
5141  settings.lineSettings().setMergeLines( true );
5142  }
5143  else if ( it.key() == QLatin1String( "labelAllGroup" ) && it.value() == QLatin1String( "true" ) )
5144  {
5145  settings.lineSettings().setMergeLines( true );
5146  }
5147  }
5148  }
5149 
5150  format.setBuffer( bufferSettings );
5151  settings.setFormat( format );
5152  return true;
5153 }
5154 
5156 {
5157  return mEditFormConfig;
5158 }
5159 
5161 {
5162  if ( mEditFormConfig == editFormConfig )
5163  return;
5164 
5165  mEditFormConfig = editFormConfig;
5166  mEditFormConfig.onRelationsLoaded();
5167  emit editFormConfigChanged();
5168 }
5169 
5170 QString QgsVectorLayer::mapTipTemplate() const
5171 {
5172  return mMapTipTemplate;
5173 }
5174 
5175 void QgsVectorLayer::setMapTipTemplate( const QString &mapTip )
5176 {
5177  if ( mMapTipTemplate == mapTip )
5178  return;
5179 
5180  mMapTipTemplate = mapTip;
5181  emit mapTipTemplateChanged();
5182 }
5183 
5185 {
5186  QgsAttributeTableConfig config = mAttributeTableConfig;
5187 
5188  if ( config.isEmpty() )
5189  config.update( fields() );
5190 
5191  return config;
5192 }
5193 
5195 {
5196  if ( mAttributeTableConfig != attributeTableConfig )
5197  {
5198  mAttributeTableConfig = attributeTableConfig;
5199  emit configChanged();
5200  }
5201 }
5202 
5204 {
5206 }
5207 
5209 {
5211 }
5212 
5214 {
5215  if ( !mDiagramLayerSettings )
5216  mDiagramLayerSettings = new QgsDiagramLayerSettings();
5217  *mDiagramLayerSettings = s;
5218 }
5219 
5221 {
5222  QgsLayerMetadataFormatter htmlFormatter( metadata() );
5223  QString myMetadata = QStringLiteral( "<html><head></head>\n<body>\n" );
5224 
5225  myMetadata += generalHtmlMetadata();
5226 
5227  // Begin Provider section
5228  myMetadata += QStringLiteral( "<h1>" ) + tr( "Information from provider" ) + QStringLiteral( "</h1>\n<hr>\n" );
5229  myMetadata += QLatin1String( "<table class=\"list-view\">\n" );
5230 
5231  // storage type
5232  if ( !storageType().isEmpty() )
5233  {
5234  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Storage" ) + QStringLiteral( "</td><td>" ) + storageType() + QStringLiteral( "</td></tr>\n" );
5235  }
5236 
5237  // comment
5238  if ( !dataComment().isEmpty() )
5239  {
5240  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Comment" ) + QStringLiteral( "</td><td>" ) + dataComment() + QStringLiteral( "</td></tr>\n" );
5241  }
5242 
5243  // encoding
5244  const QgsVectorDataProvider *provider = dataProvider();
5245  if ( provider )
5246  {
5247  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Encoding" ) + QStringLiteral( "</td><td>" ) + provider->encoding() + QStringLiteral( "</td></tr>\n" );
5248  }
5249 
5250  if ( isSpatial() )
5251  {
5252  // geom type
5254  if ( type < 0 || type > QgsWkbTypes::NullGeometry )
5255  {
5256  QgsDebugMsgLevel( QStringLiteral( "Invalid vector type" ), 2 );
5257  }
5258  else
5259  {
5260  QString typeString( QStringLiteral( "%1 (%2)" ).arg( QgsWkbTypes::geometryDisplayString( geometryType() ),
5262  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Geometry" ) + QStringLiteral( "</td><td>" ) + typeString + QStringLiteral( "</td></tr>\n" );
5263  }
5264 
5265  // Extent
5266  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Extent" ) + QStringLiteral( "</td><td>" ) + extent().toString() + QStringLiteral( "</td></tr>\n" );
5267  }
5268 
5269  // feature count
5270  QLocale locale = QLocale();
5271  locale.setNumberOptions( locale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
5272  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
5273  + tr( "Feature count" ) + QStringLiteral( "</td><td>" )
5274  + ( featureCount() == -1 ? tr( "unknown" ) : locale.toString( static_cast<qlonglong>( featureCount() ) ) )
5275  + QStringLiteral( "</td></tr>\n" );
5276 
5277  // End Provider section
5278  myMetadata += QLatin1String( "</table>\n<br><br>" );
5279 
5280  if ( isSpatial() )
5281  {
5282  // CRS
5283  myMetadata += crsHtmlMetadata();
5284  }
5285 
5286  // identification section
5287  myMetadata += QStringLiteral( "<h1>" ) + tr( "Identification" ) + QStringLiteral( "</h1>\n<hr>\n" );
5288  myMetadata += htmlFormatter.identificationSectionHtml( );
5289  myMetadata += QLatin1String( "<br><br>\n" );
5290 
5291  // extent section
5292  myMetadata += QStringLiteral( "<h1>" ) + tr( "Extent" ) + QStringLiteral( "</h1>\n<hr>\n" );
5293  myMetadata += htmlFormatter.extentSectionHtml( isSpatial() );
5294  myMetadata += QLatin1String( "<br><br>\n" );
5295 
5296  // Start the Access section
5297  myMetadata += QStringLiteral( "<h1>" ) + tr( "Access" ) + QStringLiteral( "</h1>\n<hr>\n" );
5298  myMetadata += htmlFormatter.accessSectionHtml( );
5299  myMetadata += QLatin1String( "<br><br>\n" );
5300 
5301  // Fields section
5302  myMetadata += QStringLiteral( "<h1>" ) + tr( "Fields" ) + QStringLiteral( "</h1>\n<hr>\n<table class=\"list-view\">\n" );
5303 
5304  // primary key
5305  QgsAttributeList pkAttrList = primaryKeyAttributes();
5306  if ( !pkAttrList.isEmpty() )
5307  {
5308  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Primary key attributes" ) + QStringLiteral( "</td><td>" );
5309  const auto constPkAttrList = pkAttrList;
5310  for ( int idx : constPkAttrList )
5311  {
5312  myMetadata += fields().at( idx ).name() + ' ';
5313  }
5314  myMetadata += QLatin1String( "</td></tr>\n" );
5315  }
5316 
5317  const QgsFields myFields = fields();
5318 
5319  // count fields
5320  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Count" ) + QStringLiteral( "</td><td>" ) + QString::number( myFields.size() ) + QStringLiteral( "</td></tr>\n" );
5321 
5322  myMetadata += QLatin1String( "</table>\n<br><table width=\"100%\" class=\"tabular-view\">\n" );
5323  myMetadata += QLatin1String( "<tr><th>" ) + tr( "Field" ) + QLatin1String( "</th><th>" ) + tr( "Type" ) + QLatin1String( "</th><th>" ) + tr( "Length" ) + QLatin1String( "</th><th>" ) + tr( "Precision" ) + QLatin1String( "</th><th>" ) + tr( "Comment" ) + QLatin1String( "</th></tr>\n" );
5324 
5325  for ( int i = 0; i < myFields.size(); ++i )
5326  {
5327  QgsField myField = myFields.at( i );
5328  QString rowClass;
5329  if ( i % 2 )
5330  rowClass = QStringLiteral( "class=\"odd-row\"" );
5331  myMetadata += QLatin1String( "<tr " ) + rowClass + QLatin1String( "><td>" ) + myField.name() + QLatin1String( "</td><td>" ) + myField.typeName() + QLatin1String( "</td><td>" ) + QString::number( myField.length() ) + QLatin1String( "</td><td>" ) + QString::number( myField.precision() ) + QLatin1String( "</td><td>" ) + myField.comment() + QLatin1String( "</td></tr>\n" );
5332  }
5333 
5334  //close field list
5335  myMetadata += QLatin1String( "</table>\n<br><br>" );
5336 
5337  // Start the contacts section
5338  myMetadata += QStringLiteral( "<h1>" ) + tr( "Contacts" ) + QStringLiteral( "</h1>\n<hr>\n" );
5339  myMetadata += htmlFormatter.contactsSectionHtml( );
5340  myMetadata += QLatin1String( "<br><br>\n" );
5341 
5342  // Start the links section
5343  myMetadata += QStringLiteral( "<h1>" ) + tr( "Links" ) + QStringLiteral( "</h1>\n<hr>\n" );
5344  myMetadata += htmlFormatter.linksSectionHtml( );
5345  myMetadata += QLatin1String( "<br><br>\n" );
5346 
5347  // Start the history section
5348  myMetadata += QStringLiteral( "<h1>" ) + tr( "History" ) + QStringLiteral( "</h1>\n<hr>\n" );
5349  myMetadata += htmlFormatter.historySectionHtml( );
5350  myMetadata += QLatin1String( "<br><br>\n" );
5351 
5352  myMetadata += QLatin1String( "\n</body>\n</html>\n" );
5353  return myMetadata;
5354 }
5355 
5356 void QgsVectorLayer::invalidateSymbolCountedFlag()
5357 {
5358  mSymbolFeatureCounted = false;
5359 }
5360 
5361 void QgsVectorLayer::onFeatureCounterCompleted()
5362 {
5363  onSymbolsCounted();
5364  mFeatureCounter = nullptr;
5365 }
5366 
5367 void QgsVectorLayer::onFeatureCounterTerminated()
5368 {
5369  mFeatureCounter = nullptr;
5370 }
5371 
5372 void QgsVectorLayer::onJoinedFieldsChanged()
5373 {
5374  // some of the fields of joined layers have changed -> we need to update this layer's fields too
5375  updateFields();
5376 }
5377 
5378 void QgsVectorLayer::onFeatureDeleted( QgsFeatureId fid )
5379 {
5380  if ( mEditCommandActive || mCommitChangesActive )
5381  {
5382  mDeletedFids << fid;
5383  }
5384  else
5385  {
5386  mSelectedFeatureIds.remove( fid );
5387  emit featuresDeleted( QgsFeatureIds() << fid );
5388  }
5389 
5390  emit featureDeleted( fid );
5391 }
5392 
5393 void QgsVectorLayer::onRelationsLoaded()
5394 {
5395  mEditFormConfig.onRelationsLoaded();
5396 }
5397 
5398 void QgsVectorLayer::onSymbolsCounted()
5399 {
5400  if ( mFeatureCounter )
5401  {
5402  mSymbolFeatureCounted = true;
5403  mSymbolFeatureCountMap = mFeatureCounter->symbolFeatureCountMap();
5404  mSymbolFeatureIdMap = mFeatureCounter->symbolFeatureIdMap();
5406  }
5407 }
5408 
5409 QList<QgsRelation> QgsVectorLayer::referencingRelations( int idx ) const
5410 {
5411  return QgsProject::instance()->relationManager()->referencingRelations( this, idx );
5412 }
5413 
5414 QList<QgsWeakRelation> QgsVectorLayer::weakRelations() const
5415 {
5416  return mWeakRelations;
5417 }
5418 
5419 int QgsVectorLayer::listStylesInDatabase( QStringList &ids, QStringList &names, QStringList &descriptions, QString &msgError )
5420 {
5421  return QgsProviderRegistry::instance()->listStyles( mProviderKey, mDataSource, ids, names, descriptions, msgError );
5422 }
5423 
5424 QString QgsVectorLayer::getStyleFromDatabase( const QString &styleId, QString &msgError )
5425 {
5426  return QgsProviderRegistry::instance()->getStyleById( mProviderKey, mDataSource, styleId, msgError );
5427 }
5428 
5429 bool QgsVectorLayer::deleteStyleFromDatabase( const QString &styleId, QString &msgError )
5430 {
5431  return QgsProviderRegistry::instance()->deleteStyleById( mProviderKey, mDataSource, styleId, msgError );
5432 }
5433 
5434 
5435 void QgsVectorLayer::saveStyleToDatabase( const QString &name, const QString &description,
5436  bool useAsDefault, const QString &uiFileContent, QString &msgError, QgsMapLayer::StyleCategories categories )
5437 {
5438 
5439  QString sldStyle, qmlStyle;
5440  QDomDocument qmlDocument, sldDocument;
5441  QgsReadWriteContext context;
5442  exportNamedStyle( qmlDocument, msgError, context, categories );
5443  if ( !msgError.isNull() )
5444  {
5445  return;
5446  }
5447  qmlStyle = qmlDocument.toString();
5448 
5449  this->exportSldStyle( sldDocument, msgError );
5450  if ( !msgError.isNull() )
5451  {
5452  return;
5453  }
5454  sldStyle = sldDocument.toString();
5455 
5457  mDataSource, qmlStyle, sldStyle, name,
5458  description, uiFileContent, useAsDefault, msgError );
5459 }
5460 
5461 
5462 
5463 QString QgsVectorLayer::loadNamedStyle( const QString &theURI, bool &resultFlag, QgsMapLayer::StyleCategories categories )
5464 {
5465  return loadNamedStyle( theURI, resultFlag, false, categories );
5466 }
5467 
5468 bool QgsVectorLayer::loadAuxiliaryLayer( const QgsAuxiliaryStorage &storage, const QString &key )
5469 {
5470  bool rc = false;
5471 
5472  QString joinKey = mAuxiliaryLayerKey;
5473  if ( !key.isEmpty() )
5474  joinKey = key;
5475 
5476  if ( storage.isValid() && !joinKey.isEmpty() )
5477  {
5478  QgsAuxiliaryLayer *alayer = nullptr;
5479 
5480  int idx = fields().lookupField( joinKey );
5481 
5482  if ( idx >= 0 )
5483  {
5484  alayer = storage.createAuxiliaryLayer( fields().field( idx ), this );
5485 
5486  if ( alayer )
5487  {
5488  setAuxiliaryLayer( alayer );
5489  rc = true;
5490  }
5491  }
5492  }
5493 
5494  return rc;
5495 }
5496 
5498 {
5499  mAuxiliaryLayerKey.clear();
5500 
5501  if ( mAuxiliaryLayer )
5502  removeJoin( mAuxiliaryLayer->id() );
5503 
5504  if ( alayer )
5505  {
5506  addJoin( alayer->joinInfo() );
5507 
5508  if ( !alayer->isEditable() )
5509  alayer->startEditing();
5510 
5511  mAuxiliaryLayerKey = alayer->joinInfo().targetFieldName();
5512  }
5513 
5514  mAuxiliaryLayer.reset( alayer );
5515  if ( mAuxiliaryLayer )
5516  mAuxiliaryLayer->setParent( this );
5517  updateFields();
5518 }
5519 
5521 {
5522  return mAuxiliaryLayer.get();
5523 }
5524 
5526 {
5527  return mAuxiliaryLayer.get();
5528 }
5529 
5530 QString QgsVectorLayer::loadNamedStyle( const QString &theURI, bool &resultFlag, bool loadFromLocalDB, QgsMapLayer::StyleCategories categories )
5531 {
5532  QgsDataSourceUri dsUri( theURI );
5533  QString returnMessage;
5534  QString qml, errorMsg;
5535  if ( !loadFromLocalDB && mDataProvider && mDataProvider->isSaveAndLoadStyleToDatabaseSupported() )
5536  {
5538  }
5539  if ( !qml.isEmpty() )
5540  {
5541  QDomDocument myDocument( QStringLiteral( "qgis" ) );
5542  myDocument.setContent( qml );
5543  resultFlag = importNamedStyle( myDocument, errorMsg );
5544  returnMessage = QObject::tr( "Loaded from Provider" );
5545  }
5546  else
5547  {
5548  returnMessage = QgsMapLayer::loadNamedStyle( theURI, resultFlag, categories );
5549  }
5550 
5551  if ( resultFlag )
5552  emit styleLoaded( categories );
5553 
5554  return returnMessage;
5555 }
5556 
5557 QSet<QgsMapLayerDependency> QgsVectorLayer::dependencies() const
5558 {
5559  if ( mDataProvider )
5560  return mDataProvider->dependencies() + mDependencies;
5561  return mDependencies;
5562 }
5563 
5564 void QgsVectorLayer::emitDataChanged()
5565 {
5566  if ( mDataChangedFired )
5567  return;
5568 
5569  updateExtents(); // reset cached extent to reflect data changes
5570 
5571  mDataChangedFired = true;
5572  emit dataChanged();
5573  mDataChangedFired = false;
5574 }
5575 
5576 void QgsVectorLayer::onAfterCommitChangesDependency()
5577 {
5578  mDataChangedFired = true;
5579  reload();
5580  mDataChangedFired = false;
5581 }
5582 
5583 bool QgsVectorLayer::setDependencies( const QSet<QgsMapLayerDependency> &oDeps )
5584 {
5585  QSet<QgsMapLayerDependency> deps;
5586  const auto constODeps = oDeps;
5587  for ( const QgsMapLayerDependency &dep : constODeps )
5588  {
5589  if ( dep.origin() == QgsMapLayerDependency::FromUser )
5590  deps << dep;
5591  }
5592 
5593  QSet<QgsMapLayerDependency> toAdd = deps - dependencies();
5594 
5595  // disconnect layers that are not present in the list of dependencies anymore
5596  for ( const QgsMapLayerDependency &dep : std::as_const( mDependencies ) )
5597  {
5598  QgsVectorLayer *lyr = static_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( dep.layerId() ) );
5599  if ( !lyr )
5600  continue;
5601  disconnect( lyr, &QgsVectorLayer::featureAdded, this, &QgsVectorLayer::emitDataChanged );
5602  disconnect( lyr, &QgsVectorLayer::featureDeleted, this, &QgsVectorLayer::emitDataChanged );
5603  disconnect( lyr, &QgsVectorLayer::geometryChanged, this, &QgsVectorLayer::emitDataChanged );
5604  disconnect( lyr, &QgsVectorLayer::dataChanged, this, &QgsVectorLayer::emitDataChanged );
5606  disconnect( lyr, &QgsVectorLayer::afterCommitChanges, this, &QgsVectorLayer::onAfterCommitChangesDependency );
5607  }
5608 
5609  // assign new dependencies
5610  if ( mDataProvider )
5611  mDependencies = mDataProvider->dependencies() + deps;
5612  else
5613  mDependencies = deps;
5614  emit dependenciesChanged();
5615 
5616  // connect to new layers
5617  for ( const QgsMapLayerDependency &dep : std::as_const( mDependencies ) )
5618  {
5619  QgsVectorLayer *lyr = static_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( dep.layerId() ) );
5620  if ( !lyr )
5621  continue;
5622  connect( lyr, &QgsVectorLayer::featureAdded, this, &QgsVectorLayer::emitDataChanged );
5623  connect( lyr, &QgsVectorLayer::featureDeleted, this, &QgsVectorLayer::emitDataChanged );
5624  connect( lyr, &QgsVectorLayer::geometryChanged, this, &QgsVectorLayer::emitDataChanged );
5625  connect( lyr, &QgsVectorLayer::dataChanged, this, &QgsVectorLayer::emitDataChanged );
5627  connect( lyr, &QgsVectorLayer::afterCommitChanges, this, &QgsVectorLayer::onAfterCommitChangesDependency );
5628  }
5629 
5630  // if new layers are present, emit a data change
5631  if ( ! toAdd.isEmpty() )
5632  emitDataChanged();
5633 
5634  return true;
5635 }
5636 
5637 QgsFieldConstraints::Constraints QgsVectorLayer::fieldConstraints( int fieldIndex ) const
5638 {
5639  if ( fieldIndex < 0 || fieldIndex >= mFields.count() || !mDataProvider )
5640  return QgsFieldConstraints::Constraints();
5641 
5642  QgsFieldConstraints::Constraints constraints = mFields.at( fieldIndex ).constraints().constraints();
5643 
5644  // make sure provider constraints are always present!
5645  if ( mFields.fieldOrigin( fieldIndex ) == QgsFields::OriginProvider )
5646  {
5647  constraints |= mDataProvider->fieldConstraints( mFields.fieldOriginIndex( fieldIndex ) );
5648  }
5649 
5650  return constraints;
5651 }
5652 
5653 QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength> QgsVectorLayer::fieldConstraintsAndStrength( int fieldIndex ) const
5654 {
5655  QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength > m;
5656 
5657  if ( fieldIndex < 0 || fieldIndex >= mFields.count() )
5658  return m;
5659 
5660  QString name = mFields.at( fieldIndex ).name();
5661 
5662  QMap< QPair< QString, QgsFieldConstraints::Constraint >, QgsFieldConstraints::ConstraintStrength >::const_iterator conIt = mFieldConstraintStrength.constBegin();
5663  for ( ; conIt != mFieldConstraintStrength.constEnd(); ++conIt )
5664  {
5665  if ( conIt.key().first == name )
5666  {
5667  m[ conIt.key().second ] = mFieldConstraintStrength.value( conIt.key() );
5668  }
5669  }
5670 
5671  return m;
5672 }
5673 
5675 {
5676  if ( index < 0 || index >= mFields.count() )
5677  return;
5678 
5679  QString name = mFields.at( index ).name();
5680 
5681  // add constraint to existing constraints
5682  QgsFieldConstraints::Constraints constraints = mFieldConstraints.value( name, QgsFieldConstraints::Constraints() );
5683  constraints |= constraint;
5684  mFieldConstraints.insert( name, constraints );
5685 
5686  mFieldConstraintStrength.insert( qMakePair( name, constraint ), strength );
5687 
5688  updateFields();
5689 }
5690 
5692 {
5693  if ( index < 0 || index >= mFields.count() )
5694  return;
5695 
5696  QString name = mFields.at( index ).name();
5697 
5698  // remove constraint from existing constraints
5699  QgsFieldConstraints::Constraints constraints = mFieldConstraints.value( name, QgsFieldConstraints::Constraints() );
5700  constraints &= ~constraint;
5701  mFieldConstraints.insert( name, constraints );
5702 
5703  mFieldConstraintStrength.remove( qMakePair( name, constraint ) );
5704 
5705  updateFields();
5706 }
5707 
5708 QString QgsVectorLayer::constraintExpression( int index ) const
5709 {
5710  if ( index < 0 || index >= mFields.count() )
5711  return QString();
5712 
5713  return mFields.at( index ).constraints().constraintExpression();
5714 }
5715 
5716 QString QgsVectorLayer::constraintDescription( int index ) const
5717 {
5718  if ( index < 0 || index >= mFields.count() )
5719  return QString();
5720 
5721  return mFields.at( index ).constraints().constraintDescription();
5722 }
5723 
5724 void QgsVectorLayer::setConstraintExpression( int index, const QString &expression, const QString &description )
5725 {
5726  if ( index < 0 || index >= mFields.count() )
5727  return;
5728 
5729  if ( expression.isEmpty() )
5730  {
5731  mFieldConstraintExpressions.remove( mFields.at( index ).name() );
5732  }
5733  else
5734  {
5735  mFieldConstraintExpressions.insert( mFields.at( index ).name(), qMakePair( expression, description ) );
5736  }
5737  updateFields();
5738 }
5739 
5740 void QgsVectorLayer::setFieldConfigurationFlags( int index, QgsField::ConfigurationFlags flags )
5741 {
5742  if ( index < 0 || index >= mFields.count() )
5743  return;
5744 
5745  mFieldConfigurationFlags.insert( mFields.at( index ).name(), flags );
5746  updateFields();
5747 }
5748 
5750 {
5751  if ( index < 0 || index >= mFields.count() )
5752  return;
5753  QgsField::ConfigurationFlags flags = mFields.at( index ).configurationFlags();
5754  flags.setFlag( flag, active );
5756 }
5757 
5758 QgsField::ConfigurationFlags QgsVectorLayer::fieldConfigurationFlags( int index ) const
5759 {
5760 
5761  if ( index < 0 || index >= mFields.count() )
5763 
5764  return mFields.at( index ).configurationFlags();
5765 }
5766 
5768 {
5769  if ( index < 0 || index >= mFields.count() )
5770  return;
5771 
5772  if ( setup.isNull() )
5773  mFieldWidgetSetups.remove( mFields.at( index ).name() );
5774  else
5775  mFieldWidgetSetups.insert( mFields.at( index ).name(), setup );
5776  updateFields();
5777 }
5778 
5780 {
5781 
5782  if ( index < 0 || index >= mFields.count() )
5783  return QgsEditorWidgetSetup();
5784 
5785  return mFields.at( index ).editorWidgetSetup();
5786 }
5787 
5788 QgsAbstractVectorLayerLabeling *QgsVectorLayer::readLabelingFromCustomProperties()
5789 {
5791  if ( customProperty( QStringLiteral( "labeling" ) ).toString() == QLatin1String( "pal" ) )
5792  {
5793  if ( customProperty( QStringLiteral( "labeling/enabled" ), QVariant( false ) ).toBool() )
5794  {
5795  // try to load from custom properties
5796  QgsPalLayerSettings settings;
5797  settings.readFromLayerCustomProperties( this );
5798  labeling = new QgsVectorLayerSimpleLabeling( settings );
5799  }
5800 
5801  // also clear old-style labeling config
5802  removeCustomProperty( QStringLiteral( "labeling" ) );
5803  const auto constCustomPropertyKeys = customPropertyKeys();
5804  for ( const QString &key : constCustomPropertyKeys )
5805  {
5806  if ( key.startsWith( QLatin1String( "labeling/" ) ) )
5807  removeCustomProperty( key );
5808  }
5809  }
5810 
5811  return labeling;
5812 }
5813 
5815 {
5816  return mAllowCommit;
5817 }
5818 
5819 void QgsVectorLayer::setAllowCommit( bool allowCommit )
5820 {
5821  if ( mAllowCommit == allowCommit )
5822  return;
5823 
5824  mAllowCommit = allowCommit;
5825  emit allowCommitChanged();
5826 }
5827 
5829 {
5830  return mGeometryOptions.get();
5831 }
5832 
5833 void QgsVectorLayer::setReadExtentFromXml( bool readExtentFromXml )
5834 {
5835  mReadExtentFromXml = readExtentFromXml;
5836 }
5837 
5839 {
5840  return mReadExtentFromXml;
5841 }
5842 
5843 void QgsVectorLayer::onDirtyTransaction( const QString &sql, const QString &name )
5844 {
5846  if ( tr && mEditBuffer )
5847  {
5848  qobject_cast<QgsVectorLayerEditPassthrough *>( mEditBuffer )->update( tr, sql, name );
5849  }
5850 }
5851 
5852 QList<QgsVectorLayer *> QgsVectorLayer::DeleteContext::handledLayers( bool includeAuxiliaryLayers ) const
5853 {
5854  QList<QgsVectorLayer *> layers;
5855  QMap<QgsVectorLayer *, QgsFeatureIds>::const_iterator i;
5856  for ( i = mHandledFeatures.begin(); i != mHandledFeatures.end(); ++i )
5857  {
5858  if ( includeAuxiliaryLayers || !qobject_cast< QgsAuxiliaryLayer * >( i.key() ) )
5859  layers.append( i.key() );
5860  }
5861  return layers;
5862 }
5863 
5865 {
5866  return mHandledFeatures[layer];
5867 }
QgsCurve
Abstract base class for curved geometry type.
Definition: qgscurve.h:35
QgsVectorLayer::setRenderer
void setRenderer(QgsFeatureRenderer *r)
Sets the feature renderer which will be invoked to represent this layer in 2D map views.
Definition: qgsvectorlayer.cpp:3788
QgsVectorLayer::sourceName
QString sourceName() const FINAL
Returns a friendly display name for the source.
Definition: qgsvectorlayer.cpp:412
QgsFields::OriginProvider
@ OriginProvider
Field comes from the underlying data provider of the vector layer (originIndex = index in provider's ...
Definition: qgsfields.h:51
QgsFeatureRequest::NoGeometry
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
Definition: qgsfeaturerequest.h:115
QgsVectorLayerFeatureCounter
Counts the features in a QgsVectorLayer in task. You should most likely not use this directly and ins...
Definition: qgsvectorlayerfeaturecounter.h:33
QgsVectorLayer::setDiagramRenderer
void setDiagramRenderer(QgsDiagramRenderer *r)
Sets diagram rendering object (takes ownership)
Definition: qgsvectorlayer.cpp:712
QgsVectorLayer::getFeatures
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
Definition: qgsvectorlayer.cpp:1052
QgsMapLayer::willBeDeleted
void willBeDeleted()
Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid...
QgsMapLayer::crsHtmlMetadata
QString crsHtmlMetadata() const
Returns a HTML fragment containing the layer's CRS metadata, for use in the htmlMetadata() method.
Definition: qgsmaplayer.cpp:2372
QgsTextBufferSettings::setSizeUnit
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units used for the buffer size.
Definition: qgstextbuffersettings.cpp:97
QgsVectorLayer::LayerOptions::loadDefaultStyle
bool loadDefaultStyle
Set to true if the default layer style should be loaded.
Definition: qgsvectorlayer.h:434
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsWeakRelation::writeXml
static void writeXml(const QgsVectorLayer *layer, WeakRelationType type, const QgsRelation &relation, QDomNode &node, QDomDocument &doc)
Writes a weak relation infoto an XML structure.
Definition: qgsweakrelation.cpp:139
QgsProject::relationManager
QgsRelationManager relationManager
Definition: qgsproject.h:114
QgsMapLayer::crs
QgsCoordinateReferenceSystem crs
Definition: qgsmaplayer.h:79
QgsVectorLayer::addFeatures
bool addFeatures(QgsFeatureList &features, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) FINAL
Adds a list of features to the sink.
Definition: qgsvectorlayer.cpp:3658
QgsVectorLayer::beforeRemovingExpressionField
void beforeRemovingExpressionField(int idx)
Will be emitted, when an expression field is going to be deleted from this vector layer.
QgsMapLayer::emitStyleChanged
void emitStyleChanged()
Triggers an emission of the styleChanged() signal.
Definition: qgsmaplayer.cpp:2145
QgsExpressionFieldBuffer::writeXml
void writeXml(QDomNode &layer_node, QDomDocument &document) const
Saves expressions to xml under the layer node.
Definition: qgsexpressionfieldbuffer.cpp:43
QgsVectorLayer::removeSelection
Q_INVOKABLE void removeSelection()
Clear selection.
Definition: qgsvectorlayer.cpp:658
QgsExpressionContextScope::setFeature
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the scope.
Definition: qgsexpressioncontext.h:319
QgsDataSourceUri::useEstimatedMetadata
bool useEstimatedMetadata() const
Returns true if estimated metadata should be used for the connection.
Definition: qgsdatasourceuri.cpp:353
QgsVectorLayer::getStyleFromDatabase
virtual QString getStyleFromDatabase(const QString &styleId, QString &msgError)
Returns the named style corresponding to style id provided.
Definition: qgsvectorlayer.cpp:5424
QgsFields::FieldOrigin
FieldOrigin
Definition: qgsfields.h:48
QgsVectorLayer::setReadExtentFromXml
void setReadExtentFromXml(bool readExtentFromXml)
Flag allowing to indicate if the extent has to be read from the XML document when data source has no ...
Definition: qgsvectorlayer.cpp:5833
QgsVectorSimplifyMethod::setForceLocalOptimization
void setForceLocalOptimization(bool localOptimization)
Sets where the simplification executes, after fetch the geometries from provider, or when supported,...
Definition: qgsvectorsimplifymethod.h:92
qgsfields.h
QgsMapLayer::readCommonStyle
void readCommonStyle(const QDomElement &layerElement, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read style data common to all layer types.
Definition: qgsmaplayer.cpp:1869
QgsMapLayer::dependenciesChanged
void dependenciesChanged()
Emitted when dependencies are changed.
qgsexpressioncontextutils.h
QgsPalLayerSettings::placement
Qgis::LabelPlacement placement
Label placement mode.
Definition: qgspallabeling.h:434
QgsVectorLayer::diagramsEnabled
bool diagramsEnabled() const
Returns whether the layer contains diagrams which are enabled and should be drawn.
Definition: qgsvectorlayer.cpp:799
qgsconditionalstyle.h
QgsFields::OriginEdit
@ OriginEdit
Field has been temporarily added in editing mode (originIndex = index in the list of added attributes...
Definition: qgsfields.h:53
QgsActionManager::addAction
QUuid addAction(QgsAction::ActionType type, const QString &name, const QString &command, bool capture=false)
Add an action with the given name and action details.
Definition: qgsactionmanager.cpp:44
QgsRectangle::height
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
Definition: qgsrectangle.h:230
QgsVectorLayer::selectByIds
Q_INVOKABLE void selectByIds(const QgsFeatureIds &ids, Qgis::SelectBehavior behavior=Qgis::SelectBehavior::SetSelection)
Selects matching features using a list of feature IDs.
Definition: qgsvectorlayer.cpp:572
QgsVectorDataProvider::DeleteFeatures
@ DeleteFeatures
Allows deletion of features.
Definition: qgsvectordataprovider.h:76
Qgis::FeatureCountState::UnknownCount
@ UnknownCount
Provider returned an unknown feature count.
QgsVectorLayer::featureBlendMode
QPainter::CompositionMode featureBlendMode() const
Returns the current blending mode for features.
Definition: qgsvectorlayer.cpp:4605
QgsProperty::fromField
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
Definition: qgsproperty.cpp:245
QgsFeatureRenderer::defaultRenderer
static QgsFeatureRenderer * defaultRenderer(QgsWkbTypes::GeometryType geomType)
Returns a new renderer - used by default in vector layers.
Definition: qgsrenderer.cpp:79
QgsFeatureSource::hasSpatialIndex
virtual SpatialIndexPresence hasSpatialIndex() const
Returns an enum value representing the presence of a valid spatial index on the source,...
Definition: qgsfeaturesource.cpp:190
QgsVectorLayer::createExpressionContextScope
QgsExpressionContextScope * createExpressionContextScope() const FINAL
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Definition: qgsvectorlayer.cpp:5208
QgsMapLayer::resolveReferences
virtual void resolveReferences(QgsProject *project)
Resolve references to other layers (kept as layer IDs after reading XML) into layer objects.
Definition: qgsmaplayer.cpp:772
QgsVectorLayer::symbolFeatureIds
QgsFeatureIds symbolFeatureIds(const QString &legendKey) const
Ids of features rendered with specified legend key.
Definition: qgsvectorlayer.cpp:820
QgsDataSourceUri
Class for storing the component parts of a RDBMS data source URI (e.g. a Postgres data source).
Definition: qgsdatasourceuri.h:37
qgspallabeling.h
QgsOgcUtils::expressionFromOgcFilter
static QgsExpression * expressionFromOgcFilter(const QDomElement &element, QgsVectorLayer *layer=nullptr)
Parse XML with OGC filter into QGIS expression.
Definition: qgsogcutils.cpp:1670
Qgis::VertexMarkerType::SemiTransparentCircle
@ SemiTransparentCircle
Semi-transparent circle marker.
QgsAggregateCalculator
Utility class for calculating aggregates for a field (or expression) over the features from a vector ...
Definition: qgsaggregatecalculator.h:44
QgsVectorDataProvider::CreateRenderer
@ CreateRenderer
Provider can create feature renderers using backend-specific formatting information....
Definition: qgsvectordataprovider.h:95
qgsEnumValueToKey
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition: qgis.h:2440
Qgis::VertexMarkerType::NoMarker
@ NoMarker
No marker.
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:57
QgsFieldConstraints::setConstraintExpression
void setConstraintExpression(const QString &expression, const QString &description=QString())
Set the constraint expression for the field.
Definition: qgsfieldconstraints.cpp:72
QgsVectorLayer::wkbType
Q_INVOKABLE QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
Definition: qgsvectorlayer.cpp:725
qgsruntimeprofiler.h
QgsWkbTypes::displayString
static QString displayString(Type type) SIP_HOLDGIL
Returns a non-translated display string type for a WKB type, e.g., the geometry name used in WKT geom...
Definition: qgswkbtypes.cpp:145
QgsMapLayer::FlagTrustLayerMetadata
@ FlagTrustLayerMetadata
Trust layer metadata. Improves layer load time by skipping expensive checks like primary key unicity,...
Definition: qgsmaplayer.h:641
QgsVectorLayer::selectAll
Q_INVOKABLE void selectAll()
Select all the features.
Definition: qgsvectorlayer.cpp:624
QgsDataSourceUri::password
QString password() const
Returns the password stored in the URI.
Definition: qgsdatasourceuri.cpp:285
qgsfeaturerequest.h
QgsVectorLayer::createProfileGenerator
QgsAbstractProfileGenerator * createProfileGenerator(const QgsProfileRequest &request) override
Given a profile request, returns a new profile generator ready for generating elevation profiles.
Definition: qgsvectorlayer.cpp:696
QgsPalLayerSettings::angleOffset
double angleOffset
Label rotation, in degrees clockwise.
Definition: qgspallabeling.h:561
QgsTextFormat::setFont
void setFont(const QFont &font)
Sets the font used for rendering text.
Definition: qgstextformat.cpp:207
QgsVectorDataProvider::dataComment
virtual QString dataComment() const override
Returns a short comment for the data that this provider is providing access to (e....
Definition: qgsvectordataprovider.cpp:92
QgsMapLayer::configChanged
void configChanged()
Emitted whenever the configuration is changed.
QgsMapLayer::FlagReadExtentFromXml
@ FlagReadExtentFromXml
Read extent from xml and skip get extent from provider.
Definition: qgsmaplayer.h:642
QgsMapLayer::editingStopped
void editingStopped()
Emitted when edited changes have been successfully written to the data provider.
QgsRuleBasedLabeling::Rule
A child rule for QgsRuleBasedLabeling.
Definition: qgsrulebasedlabeling.h:55
QgsUnitTypes::RenderUnit
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:167
QgsVectorLayer::moveVertex
bool moveVertex(double x, double y, QgsFeatureId atFeatureId, int atVertex)
Moves the vertex at the given position number, ring and item (first number is index 0),...
Definition: qgsvectorlayer.cpp:1180
QgsVectorDataProvider::pkAttributeIndexes
virtual QgsAttributeList pkAttributeIndexes() const
Returns list of indexes of fields that make up the primary key.
Definition: qgsvectordataprovider.cpp:366
QgsDefaultValue
The QgsDefaultValue class provides a container for managing client side default values for fields.
Definition: qgsdefaultvalue.h:48
QgsVectorLayer::updateExtents
virtual void updateExtents(bool force=false)
Update the extents for the layer.
Definition: qgsvectorlayer.cpp:862
QgsVectorLayer::uniqueStringsMatching
QStringList uniqueStringsMatching(int index, const QString &substring, int limit=-1, QgsFeedback *feedback=nullptr) const
Returns unique string values of an attribute which contain a specified subset string.
Definition: qgsvectorlayer.cpp:4269
QgsVectorLayer::dataProvider
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
Definition: qgsvectorlayer.cpp:676
QgsVectorLayerEditBuffer::isModified
virtual bool isModified() const
Returns true if the provider has been modified since the last commit.
Definition: qgsvectorlayereditbuffer.cpp:47
QgsFieldConstraints::setConstraint
void setConstraint(Constraint constraint, ConstraintOrigin origin=ConstraintOriginLayer)
Sets a constraint on the field.
Definition: qgsfieldconstraints.cpp:48
QgsDataProvider::ProviderOptions
Setting options for creating vector data providers.
Definition: qgsdataprovider.h:107
QgsRectangle::combineExtentWith
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
Definition: qgsrectangle.h:391
QgsPainting::BlendMode
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer.
Definition: qgspainting.h:49
QgsExpressionContext::popScope
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
Definition: qgsexpressioncontext.cpp:504
QgsSettings::value
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Definition: qgssettings.cpp:161
QgsMapLayer::Labeling
@ Labeling
Labeling.
Definition: qgsmaplayer.h:163
QgsRectangle::set
void set(const QgsPointXY &p1, const QgsPointXY &p2, bool normalize=true)
Sets the rectangle from two QgsPoints.
Definition: qgsrectangle.h:122
QgsVectorLayer::updateFields
void updateFields()
Will regenerate the fields property of this layer by obtaining all fields from the dataProvider,...
Definition: qgsvectorlayer.cpp:3963
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsFeatureRequest::ExactIntersect
@ ExactIntersect
Use exact geometry intersection (slower) instead of bounding boxes.
Definition: qgsfeaturerequest.h:117
QgsPalLayerSettings::maxCurvedCharAngleOut
double maxCurvedCharAngleOut
Maximum angle between outside curved label characters (valid range -20.0 to -95.0)
Definition: qgspallabeling.h:590
QgsVectorLayer::minimumAndMaximumValue
void minimumAndMaximumValue(int index, QVariant &minimum, QVariant &maximum) const
Calculates both the minimum and maximum value for an attribute column.
Definition: qgsvectorlayer.cpp:4384
QgsExpression::evalErrorString
QString evalErrorString() const
Returns evaluation error.
Definition: qgsexpression.cpp:383
qgsrectangle.h
qgsweakrelation.h
QgsAuxiliaryLayer
Class allowing to manage the auxiliary storage for a vector layer.
Definition: qgsauxiliarystorage.h:61
QgsEditorWidgetSetup
Holder for the widget type and its configuration for a field.
Definition: qgseditorwidgetsetup.h:28
QgsWkbTypes::NullGeometry
@ NullGeometry
Definition: qgswkbtypes.h:146
QgsVectorLayer::supportsEditing
bool supportsEditing
Definition: qgsvectorlayer.h:400
QgsVectorLayer::featureCount
long long featureCount() const FINAL
Returns feature count including changes which have not yet been committed If you need only the count ...
Definition: qgsvectorlayer.cpp:3458
QgsVectorLayer::featuresDeleted
void featuresDeleted(const QgsFeatureIds &fids)
Emitted when features have been deleted.
QgsVectorDataProvider::raiseError
void raiseError(const QString &msg) const
Signals an error in this provider.
QgsMapLayerType::VectorLayer
@ VectorLayer
Vector layer.
QgsField::ConfigurationFlag
ConfigurationFlag
Configuration flags for fields These flags are meant to be user-configurable and are not describing a...
Definition: qgsfield.h:79
QgsField::length
int length
Definition: qgsfield.h:56
QgsExpression::referencedColumns
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
Definition: qgsexpression.cpp:221
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:48
QgsFields::isEmpty
bool isEmpty() const
Checks whether the container is empty.
Definition: qgsfields.cpp:128
QgsVectorLayerJoinBuffer::writeXml
void writeXml(QDomNode &layer_node, QDomDocument &document) const
Saves mVectorJoins to xml under the layer node.
Definition: qgsvectorlayerjoinbuffer.cpp:294
QgsRelation::Normal
@ Normal
A normal relation.
Definition: qgsrelation.h:61
QgsProject::rollBack
bool rollBack(QStringList &rollbackErrors, bool stopEditing=true, QgsVectorLayer *vectorLayer=nullptr)
Stops a current editing operation on vectorLayer and discards any uncommitted edits.
Definition: qgsproject.cpp:729
QgsVectorLayer::setMapTipTemplate
void setMapTipTemplate(const QString &mapTipTemplate)
The mapTip is a pretty, html representation for feature information.
Definition: qgsvectorlayer.cpp:5175
QgsVectorLayer::insertVertex
bool insertVertex(double x, double y, QgsFeatureId atFeatureId, int beforeVertex)
Inserts a new vertex before the given vertex number, in the given ring, item (first number is index 0...
Definition: qgsvectorlayer.cpp:1154
QgsVectorLayer::DeleteContext::cascade
bool cascade
Definition: qgsvectorlayer.h:517
QgsVectorLayer::committedAttributesAdded
void committedAttributesAdded(const QString &layerId, const QList< QgsField > &addedAttributes)
Emitted when attributes are added to the provider if not in transaction mode.
QgsVectorLayer::attributeAlias
QString attributeAlias(int index) const
Returns the alias of an attribute name or a null string if there is no alias.
Definition: qgsvectorlayer.cpp:3237
QgsVectorLayer::setDefaultValueDefinition
void setDefaultValueDefinition(int index, const QgsDefaultValue &definition)
Sets the definition of the expression to use when calculating the default value for a field.
Definition: qgsvectorlayer.cpp:4137
QgsDebugMsgLevel
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
qgssinglesymbolrenderer.h
QgsVectorLayerEditBuffer::addAttribute
virtual bool addAttribute(const QgsField &field)
Adds an attribute field (but does not commit it) returns true if the field was added.
Definition: qgsvectorlayereditbuffer.cpp:270
qgsexpressionfieldbuffer.h
QgsMapLayer::opacity
double opacity
Definition: qgsmaplayer.h:82
QgsPalLayerSettings
Contains settings for how a map layer will be labeled.
Definition: qgspallabeling.h:86
QgsMapLayer::setFlags
void setFlags(QgsMapLayer::LayerFlags flags)
Returns the flags for this layer.
Definition: qgsmaplayer.cpp:155
QgsVectorLayerEditBuffer::committedGeometriesChanges
void committedGeometriesChanges(const QString &layerId, const QgsGeometryMap &changedGeometries)
qgstaskmanager.h
QgsProviderRegistry::getStyleById
QString getStyleById(const QString &providerKey, const QString &uri, const QString &styleId, QString &errCause)
Gets a layer style defined by styleId.
Definition: qgsproviderregistry.cpp:652
QgsMapLayerElevationProperties
Base class for storage of map layer elevation properties.
Definition: qgsmaplayerelevationproperties.h:41
QgsMapLayer::clone
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
QgsProject::mapLayers
QMap< QString, QgsMapLayer * > mapLayers(const bool validOnly=false) const
Returns a map of all registered layers by layer ID.
Definition: qgsproject.cpp:3955
QgsMapLayer::blendMode
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
Definition: qgsmaplayer.cpp:320
QgsVectorLayerFeatureCounter::symbolFeatureIdMap
QHash< QString, QgsFeatureIds > symbolFeatureIdMap() const
Returns the QgsFeatureIds for each symbol.
Definition: qgsvectorlayerfeaturecounter.cpp:132
QgsFeatureRenderer::accept
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
Definition: qgsrenderer.cpp:489
qgsmaptopixel.h
QgsMapLayer::setCustomProperty
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
Definition: qgsmaplayer.cpp:1976
QgsTextBufferSettings::setEnabled
void setEnabled(bool enabled)
Sets whether the text buffer will be drawn.
Definition: qgstextbuffersettings.cpp:77
QgsVectorDataProvider::handlePostCloneOperations
virtual void handlePostCloneOperations(QgsVectorDataProvider *source)
Handles any post-clone operations required after this vector data provider was cloned from the source...
Definition: qgsvectordataprovider.cpp:916
QgsLayerMetadataFormatter::historySectionHtml
QString historySectionHtml() const
Formats the "History" section according to a metadata object.
Definition: qgslayermetadataformatter.cpp:229
QgsVectorLayerEditUtils::deleteVertex
Qgis::VectorEditResult deleteVertex(QgsFeatureId featureId, int vertex)
Deletes a vertex from a feature.
Definition: qgsvectorlayereditutils.cpp:97
QgsAggregateCalculator::AggregateParameters
A bundle of parameters controlling aggregate calculation.
Definition: qgsaggregatecalculator.h:94
QgsFieldConstraints
Stores information about constraints which may be present on a field.
Definition: qgsfieldconstraints.h:32
qgsVariantLessThan
bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is less than the second.
Definition: qgis.cpp:119
QgsMapLayer::mReadFlags
QgsMapLayer::ReadFlags mReadFlags
Read flags. It's up to the subclass to respect these when restoring state from XML.
Definition: qgsmaplayer.h:1987
QgsVectorDataProvider::encoding
QString encoding() const
Returns the encoding which is used for accessing data.
Definition: qgsvectordataprovider.cpp:242
QgsVectorDataProvider::fields
QgsFields fields() const override=0
Returns the fields associated with this data provider.
QgsLayerMetadataFormatter
Class for metadata formatter.
Definition: qgslayermetadataformatter.h:33
QgsVectorLayer::beforeRollBack
void beforeRollBack()
Emitted before changes are rolled back.
qgsvectorlayerundocommand.h
QgsVectorSimplifyMethod::setThreshold
void setThreshold(float threshold)
Sets the simplification threshold of the vector layer managed.
Definition: qgsvectorsimplifymethod.h:87
QgsVectorSimplifyMethod::SimplifyHint
SimplifyHint
Simplification flags for fast rendering of features.
Definition: qgsvectorsimplifymethod.h:50
QgsDataProvider::setSubsetString
virtual bool setSubsetString(const QString &subset, bool updateFeatureCount=true)
Set the subset string used to create a subset of features in the layer.
Definition: qgsdataprovider.h:262
QgsVectorLayer::DeleteContext
Context for cascade delete features.
Definition: qgsvectorlayer.h:495
QgsConditionalLayerStyles::writeXml
bool writeXml(QDomNode &node, QDomDocument &doc, const QgsReadWriteContext &context) const
Writes the condition styles state to a DOM node.
Definition: qgsconditionalstyle.cpp:56
QgsVectorLayer::LayerOptions::transformContext
QgsCoordinateTransformContext transformContext
Coordinate transform context.
Definition: qgsvectorlayer.h:446
QgsMapLayer::importNamedStyle
virtual bool importNamedStyle(QDomDocument &doc, QString &errorMsg, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Import the properties of this layer from a QDomDocument.
Definition: qgsmaplayer.cpp:1227
QgsField::ConfigurationFlag::None
@ None
No flag is defined.
QgsExpression::rootNode
const QgsExpressionNode * rootNode() const
Returns the root node of the expression.
Definition: qgsexpression.cpp:1355
qgsvectorlayerrenderer.h
QgsExpressionNodeColumnRef
An expression node which takes it value from a feature's field.
Definition: qgsexpressionnodeimpl.h:512
QgsFeatureSink::addFeature
virtual bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags())
Adds a single feature to the sink.
Definition: qgsfeaturesink.cpp:20
QgsDataProvider::FlagTrustDataSource
@ FlagTrustDataSource
Trust datasource config (primary key unicity, geometry type and srid, etc). Improves provider load ti...
Definition: qgsdataprovider.h:123
QgsProject::pathResolver
QgsPathResolver pathResolver() const
Returns path resolver object with considering whether the project uses absolute or relative paths and...
Definition: qgsproject.cpp:3094
QgsUnitTypes::RenderPoints
@ RenderPoints
Points (e.g., for font sizes)
Definition: qgsunittypes.h:173
QgsVectorLayer::beforeEditingStarted
void beforeEditingStarted()
Emitted before editing on this layer is started.
QgsLayerMetadata
A structured metadata store for a map layer.
Definition: qgslayermetadata.h:56
QgsMapLayerType
QgsMapLayerType
Types of layers that can be added to a map.
Definition: qgis.h:46
QgsVectorLayer::isSqlQuery
bool isSqlQuery() const
Returns true if the layer is a query (SQL) layer.
Definition: qgsvectorlayer.cpp:388
QgsVectorLayer::addExpressionField
int addExpressionField(const QString &exp, const QgsField &fld)
Add a new field which is calculated by the expression specified.
Definition: qgsvectorlayer.cpp:3926
QgsFields::count
int count() const
Returns number of items.
Definition: qgsfields.cpp:133
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:44
QgsRectangle::yMinimum
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:198
QgsProviderRegistry::listStyles
int listStyles(const QString &providerKey, const QString &uri, QStringList &ids, QStringList &names, QStringList &descriptions, QString &errCause)
Lists stored layer styles in the provider defined by providerKey and uri.
Definition: qgsproviderregistry.cpp:622
QgsMapLayer::writeCustomProperties
void writeCustomProperties(QDomNode &layerNode, QDomDocument &doc) const
Write custom properties to project file.
Definition: qgsmaplayer.cpp:795
QgsEditorWidgetSetup::config
QVariantMap config() const
Definition: qgseditorwidgetsetup.h:64
QgsExpressionContextUtils::layerScope
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Definition: qgsexpressioncontextutils.cpp:334
qgsFlagKeysToValue
T qgsFlagKeysToValue(const QString &keys, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given keys of a flag.
Definition: qgis.h:2520
QgsVectorLayer::deleteVertex
Qgis::VectorEditResult deleteVertex(QgsFeatureId featureId, int vertex)
Deletes a vertex from a feature.
Definition: qgsvectorlayer.cpp:1206
QgsVectorLayer::geometryOptions
QgsGeometryOptions * geometryOptions() const
Configuration and logic to apply automatically on any edit happening on this layer.
Definition: qgsvectorlayer.cpp:5828
QgsVectorLayer::dependencies
QSet< QgsMapLayerDependency > dependencies() const FINAL
Gets the list of dependencies.
Definition: qgsvectorlayer.cpp:5557
QgsVectorLayer::isAuxiliaryField
bool isAuxiliaryField(int index, int &srcIndex) const
Returns true if the field comes from the auxiliary layer, false otherwise.
Definition: qgsvectorlayer.cpp:3769
qgsfeature.h
QgsPalLayerSettings::yOffset
double yOffset
Vertical offset of label.
Definition: qgspallabeling.h:542
QgsVectorLayer::attributeDeleted
void attributeDeleted(int idx)
Will be emitted, when an attribute has been deleted from this vector layer.
Qgis::GeometryOperationResult::AddRingNotClosed
@ AddRingNotClosed
The input ring is not closed.
QgsSymbolLayerUtils::mergeScaleDependencies
static void mergeScaleDependencies(double mScaleMinDenom, double mScaleMaxDenom, QVariantMap &props)
Merges the local scale limits, if any, with the ones already in the map, if any.
Definition: qgssymbollayerutils.cpp:4854
QgsMapLayer::AttributeTable
@ AttributeTable
Attribute table settings: choice and order of columns, conditional styling.
Definition: qgsmaplayer.h:169
QgsFieldConstraints::constraintExpression
QString constraintExpression() const
Returns the constraint expression for the field, if set.
Definition: qgsfieldconstraints.cpp:67
QgsVectorLayer::excludeAttributesWms
Q_DECL_DEPRECATED QSet< QString > excludeAttributesWms() const
A set of attributes that are not advertised in WMS requests with QGIS server.
Definition: qgsvectorlayer.cpp:3258
QgsFeature::geometry
QgsGeometry geometry
Definition: qgsfeature.h:71
QgsAbstractProfileGenerator
Abstract base class for objects which generate elevation profiles.
Definition: qgsabstractprofilegenerator.h:392
QgsVectorSimplifyMethod::simplifyAlgorithm
SimplifyAlgorithm simplifyAlgorithm() const
Gets the local simplification algorithm of the vector layer managed.
Definition: qgsvectorsimplifymethod.h:79
QgsVectorLayer::loadNamedStyle
virtual QString loadNamedStyle(const QString &theURI, bool &resultFlag, bool loadFromLocalDb, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Loads a named style from file/local db/datasource db.
Definition: qgsvectorlayer.cpp:5530
Qgis::GeometryOperationResult::SelectionIsGreaterThanOne
@ SelectionIsGreaterThanOne
More than one features were selected.
QgsVectorLayer::setAllowCommit
void setAllowCommit(bool allowCommit)
Controls, if the layer is allowed to commit changes.
Definition: qgsvectorlayer.cpp:5819
QgsFeedback::isCanceled
bool isCanceled() const SIP_HOLDGIL
Tells whether the operation has been canceled already.
Definition: qgsfeedback.h:67
QgsWkbTypes::geometryDisplayString
static QString geometryDisplayString(GeometryType type) SIP_HOLDGIL
Returns a display string for a geometry type.
Definition: qgswkbtypes.cpp:223
qgis.h
QgsVectorLayer::constraintExpression
QString constraintExpression(int index) const
Returns the constraint expression for for a specified field index, if set.
Definition: qgsvectorlayer.cpp:5708
QgsVectorDataProvider::empty
virtual bool empty() const
Returns true if the layer does not contain any feature.
Definition: qgsvectordataprovider.cpp:51
QgsGeometryOptions
The QgsGeometryOptions class contains options to automatically adjust geometries to constraints on a ...
Definition: qgsgeometryoptions.h:36
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
Qgis::SelectBehavior::AddToSelection
@ AddToSelection
Add selection to current selection.
QgsRectangle::setMinimal
void setMinimal() SIP_HOLDGIL
Set a rectangle so that min corner is at max and max corner is at min.
Definition: qgsrectangle.h:172
QgsMapLayerLegend::writeXml
virtual QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Writes configuration to a DOM element, to be used later with readXml()
Definition: qgsmaplayerlegend.cpp:47
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:480
QgsVectorLayer::beforeCommitChanges
void beforeCommitChanges(bool stopEditing)
Emitted before changes are committed to the data provider.
QgsVectorLayerJoinBuffer::joinForFieldIndex
const QgsVectorLayerJoinInfo * joinForFieldIndex(int index, const QgsFields &fields, int &sourceFieldIndex) const
Finds the vector join for a layer field index.
Definition: qgsvectorlayerjoinbuffer.cpp:425
QgsRelation::Composition
@ Composition
Fix relation, related elements are part of the parent and a parent copy will copy any children or del...
Definition: qgsrelation.h:73
QgsSymbolLayerUtils::rendererFrameRate
static double rendererFrameRate(const QgsFeatureRenderer *renderer)
Calculates the frame rate (in frames per second) at which the given renderer must be redrawn.
Definition: qgssymbollayerutils.cpp:4957
QgsField::typeName
QString typeName() const
Gets the field type.
Definition: qgsfield.cpp:139
QgsDataSourceUri::setDatabase
void setDatabase(const QString &database)
Sets the URI database name.
Definition: qgsdatasourceuri.cpp:732
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g. symbol) nodes (using the visitor pattern)...
Definition: qgsstyleentityvisitor.h:33
QgsActionManager::writeXml
bool writeXml(QDomNode &layer_node) const
Writes the actions out in XML format.
Definition: qgsactionmanager.cpp:232
QgsVectorLayer::isSpatial
bool isSpatial() const FINAL
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
Definition: qgsvectorlayer.cpp:3733
QgsPropertyDefinition::Double
@ Double
Double value (including negative values)
Definition: qgsproperty.h:57
QgsVectorLayerJoinBuffer::readXml
void readXml(const QDomNode &layer_node)
Reads joins from project file.
Definition: qgsvectorlayerjoinbuffer.cpp:343
qgsunittypes.h
QgsDefaultValue::isValid
bool isValid() const
Returns if this default value should be applied.
Definition: qgsdefaultvalue.cpp:51
QgsVectorDataProvider::transaction
virtual QgsTransaction * transaction() const
Returns the transaction this data provider is included in, if any.
Definition: qgsvectordataprovider.cpp:653
QgsVectorLayer::deleteStyleFromDatabase
virtual bool deleteStyleFromDatabase(const QString &styleId, QString &msgError)
Deletes a style from the database.
Definition: qgsvectorlayer.cpp:5429
QgsVectorLayer::auxiliaryLayer
QgsAuxiliaryLayer * auxiliaryLayer()
Returns the current auxiliary layer.
Definition: qgsvectorlayer.cpp:5520
QgsExpressionContextUtils::globalProjectLayerScopes
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Definition: qgsexpressioncontextutils.cpp:377
QgsVectorLayer::setDiagramLayerSettings
void setDiagramLayerSettings(const QgsDiagramLayerSettings &s)
Definition: qgsvectorlayer.cpp:5213
QgsVectorLayerTemporalProperties::guessDefaultsFromFields
void guessDefaultsFromFields(const QgsFields &fields)
Attempts to setup the temporal properties by scanning a set of fields and looking for standard naming...
Definition: qgsvectorlayertemporalproperties.cpp:609
QgsSettings
This class is a composition of two QSettings instances:
Definition: qgssettings.h:61
QgsVectorDataProvider::featureCount
long long featureCount() const override=0
Number of features in the layer.
QgsMapLayer::Fields
@ Fields
Aliases, widgets, WMS/WFS, expressions, constraints, virtual fields.
Definition: qgsmaplayer.h:164
qgsdiagram.h
QgsLayerMetadataFormatter::contactsSectionHtml
QString contactsSectionHtml() const
Formats the "Contacts" section according to a metadata object.
Definition: qgslayermetadataformatter.cpp:50
qgsfeaturerenderergenerator.h
qgsvectorlayereditutils.h
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:69
QgsFeatureSource::uniqueValues
virtual QSet< QVariant > uniqueValues(int fieldIndex, int limit=-1) const
Returns the set of unique values contained within the specified fieldIndex from this source.
Definition: qgsfeaturesource.cpp:31
QgsMapLayer::setBlendMode
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
Definition: qgsmaplayer.cpp:310
QgsVectorLayer::allowCommitChanged
void allowCommitChanged()
Emitted whenever the allowCommitChanged() property of this layer changes.
QgsVectorLayer::featureDeleted
void featureDeleted(QgsFeatureId fid)
Emitted when a feature has been deleted.
QgsVectorLayerEditBuffer::addFeature
virtual bool addFeature(QgsFeature &f)
Adds a feature.
Definition: qgsvectorlayereditbuffer.cpp:127
QgsVectorLayer::startEditing
Q_INVOKABLE bool startEditing()
Makes the layer editable.
Definition: qgsvectorlayer.cpp:1491
QgsVectorLayer::readStyle
bool readStyle(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) FINAL
Definition: qgsvectorlayer.cpp:2489
QgsMapLayer::readCustomProperties
void readCustomProperties(const QDomNode &layerNode, const QString &keyStartsWith=QString())
Read custom properties from project file.
Definition: qgsmaplayer.cpp:780
QgsVectorSimplifyMethod::setSimplifyHints
void setSimplifyHints(SimplifyHints simplifyHints)
Sets the simplification hints of the vector layer managed.
Definition: qgsvectorsimplifymethod.h:62
QgsVectorDataProvider::isSaveAndLoadStyleToDatabaseSupported
virtual bool isSaveAndLoadStyleToDatabaseSupported() const
It returns false by default.
Definition: qgsvectordataprovider.cpp:744
QgsTransaction
This class allows including a set of layers in a database-side transaction, provided the layer data p...
Definition: qgstransaction.h:56
QgsMapLayer::isValid
bool isValid
Definition: qgsmaplayer.h:81
qgspoint.h
QgsVectorLayer::subsetStringChanged
void subsetStringChanged()
Emitted when the layer's subset string has changed.
QgsFeatureRequest::setSubsetOfAttributes
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
Definition: qgsfeaturerequest.cpp:228
FALLTHROUGH
#define FALLTHROUGH
Definition: qgis.h:2847
QgsAbstractVectorLayerLabeling::toSld
virtual void toSld(QDomNode &parent, const QVariantMap &props) const
Writes the SE 1.1 TextSymbolizer element based on the current layer labeling settings.
Definition: qgsvectorlayerlabeling.h:110
QgsMapLayer::editingStarted
void editingStarted()
Emitted when editing on this layer has started.
field
const QgsField & field
Definition: qgsfield.h:463
QgsExpressionContextScope::setFields
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the scope.
Definition: qgsexpressioncontext.cpp:199
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsVectorLayer::diagramRenderer
const QgsDiagramRenderer * diagramRenderer() const
Definition: qgsvectorlayer.h:892
QgsVectorLayer::capabilitiesString
QString capabilitiesString() const
Capabilities for this layer, comma separated and translated.
Definition: qgsvectorlayer.cpp:379
QgsFieldConstraints::Constraint
Constraint
Constraints which may be present on a field.
Definition: qgsfieldconstraints.h:43
QgsExpressionFieldBuffer::updateExpression
void updateExpression(int index, const QString &exp)
Changes the expression at a given index.
Definition: qgsexpressionfieldbuffer.cpp:38
QgsVectorLayer::editFormConfigChanged
void editFormConfigChanged()
Will be emitted whenever the edit form configuration of this layer changes.
QgsDataProvider::dataChanged
void dataChanged()
Emitted whenever a change is made to the data provider which may have caused changes in the provider'...
QgsVectorLayer::htmlMetadata
QString htmlMetadata() const FINAL
Obtain a formatted HTML string containing assorted metadata for this layer.
Definition: qgsvectorlayer.cpp:5220
QgsConditionalLayerStyles
The QgsConditionalLayerStyles class holds conditional style information for a layer....
Definition: qgsconditionalstyle.h:40
QgsLineString
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:44
QgsReadWriteContext::transformContext
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
Definition: qgsreadwritecontext.cpp:77
QgsVectorLayerEditBuffer::layerModified
void layerModified()
Emitted when modifications has been done on layer.
qgsvectorlayerfeaturecounter.h
QgsDataProvider::fullExtentCalculated
void fullExtentCalculated()
Emitted whenever a deferred extent calculation is completed by the provider.
QgsProject::mapLayer
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
Definition: qgsproject.cpp:3680
QgsDataProvider::dataSourceUri
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Gets the data source specification.
Definition: qgsdataprovider.h:166
QgsVectorDataProvider::fieldConstraints
QgsFieldConstraints::Constraints fieldConstraints(int fieldIndex) const
Returns any constraints which are present at the provider for a specified field index.
Definition: qgsvectordataprovider.cpp:165
QgsVectorLayer::setConstraintExpression
void setConstraintExpression(int index, const QString &expression, const QString &description=QString())
Sets the constraint expression for the specified field index.
Definition: qgsvectorlayer.cpp:5724
QgsMapLayer::customPropertyKeys
Q_INVOKABLE QStringList customPropertyKeys() const
Returns list of all keys within custom properties.
Definition: qgsmaplayer.cpp:1971
QgsVectorDataProvider::temporalCapabilities
QgsVectorDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
Definition: qgsvectordataprovider.cpp:921
QgsVectorLayer::afterCommitChanges
void afterCommitChanges()
Emitted after changes are committed to the data provider.
QgsVectorLayer::updateExpressionField
void updateExpressionField(int index, const QString &exp)
Changes the expression used to define an expression based (virtual) field.
Definition: qgsvectorlayer.cpp:3957
QgsAttributeList
QList< int > QgsAttributeList
Definition: qgsfield.h:26
QgsVectorDataProvider::isSqlQuery
virtual bool isSqlQuery() const
Returns true if the layer is a query (SQL) layer.
Definition: qgsvectordataprovider.cpp:64
QgsVectorLayer::setAuxiliaryLayer
void setAuxiliaryLayer(QgsAuxiliaryLayer *layer=nullptr)
Sets the current auxiliary layer.
Definition: qgsvectorlayer.cpp:5497
Qgis::SelectBehavior::IntersectSelection
@ IntersectSelection
Modify current selection to include only select features which match.
QgsMapLayer::legend
QgsMapLayerLegend * legend() const
Can be nullptr.
Definition: qgsmaplayer.cpp:2087
QgsVectorLayerJoinBuffer::updateFields
void updateFields(QgsFields &fields)
Updates field map with joined attributes.
Definition: qgsvectorlayerjoinbuffer.cpp:232
QgsFeatureRendererGenerator
An interface for objects which generate feature renderers for vector layers.
Definition: qgsfeaturerenderergenerator.h:31
QgsVectorLayer::accept
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Definition: qgsvectorlayer.cpp:1537
Qgis::LabelOverlapHandling::AllowOverlapIfRequired
@ AllowOverlapIfRequired
Avoids overlapping labels when possible, but permit overlaps if labels for features cannot otherwise ...
QgsVectorLayer::setLabelsEnabled
void setLabelsEnabled(bool enabled)
Sets whether labels should be enabled for the layer.
Definition: qgsvectorlayer.cpp:794
QgsVectorLayerEditBuffer::deleteAttribute
virtual bool deleteAttribute(int attr)
Deletes an attribute field (but does not commit it)
Definition: qgsvectorlayereditbuffer.cpp:293
QgsVectorLayer::fieldConstraintsAndStrength
QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength > fieldConstraintsAndStrength(int fieldIndex) const
Returns a map of constraint with their strength for a specific field of the layer.
Definition: qgsvectorlayer.cpp:5653
QgsFeatureRenderer::load
static QgsFeatureRenderer * load(QDomElement &symbologyElem, const QgsReadWriteContext &context)
create a renderer from XML element
Definition: qgsrenderer.cpp:157
QgsMapLayer::setMetadata
virtual void setMetadata(const QgsLayerMetadata &metadata)
Sets the layer's metadata store.
Definition: qgsmaplayer.cpp:2128
QgsLabelLineSettings::setMergeLines
void setMergeLines(bool merge)
Sets whether connected line features with identical label text should be merged prior to generating l...
Definition: qgslabellinesettings.h:122
QgsVectorLayerJoinInfo::joinLayerId
QString joinLayerId() const
ID of the joined layer - may be used to resolve reference to the joined layer.
Definition: qgsvectorlayerjoininfo.h:63
QgsDiagramLayerSettings::Show
@ Show
Whether to show the diagram.
Definition: qgsdiagramrenderer.h:101
QgsField::name
QString name
Definition: qgsfield.h:60
QgsVectorLayer::beginEditCommand
void beginEditCommand(const QString &text)
Create edit command for undo/redo operations.
Definition: qgsvectorlayer.cpp:3852
QgsVectorLayer::drawVertexMarker
static Q_DECL_DEPRECATED void drawVertexMarker(double x, double y, QPainter &p, Qgis::VertexMarkerType type, int vertexSize)
Draws a vertex symbol at (screen) coordinates x, y.
Definition: qgsvectorlayer.cpp:432
QgsExpressionFieldBuffer::removeExpression
void removeExpression(int index)
Remove an expression from the buffer.
Definition: qgsexpressionfieldbuffer.cpp:28
QgsMapLayer::setCrs
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
Definition: qgsmaplayer.cpp:937
QgsVectorLayerEditBuffer::attributeValueChanged
void attributeValueChanged(QgsFeatureId fid, int idx, const QVariant &)
QgsProfileRequest::expressionContext
QgsExpressionContext & expressionContext()
Returns the expression context used to evaluate expressions.
Definition: qgsprofilerequest.h:193
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsFieldConstraints::ConstraintNotNull
@ ConstraintNotNull
Field may not be null.
Definition: qgsfieldconstraints.h:45
QgsFeatureRequest::SubsetOfAttributes
@ SubsetOfAttributes
Fetch only a subset of attributes (setSubsetOfAttributes sets this flag)
Definition: qgsfeaturerequest.h:116
QgsVectorLayer::committedFeaturesAdded
void committedFeaturesAdded(const QString &layerId, const QgsFeatureList &addedFeatures)
Emitted when features are added to the provider if not in transaction mode.
QgsProject::commitChanges
bool commitChanges(QStringList &commitErrors, bool stopEditing=true, QgsVectorLayer *vectorLayer=nullptr)
Attempts to commit to the underlying data provider any buffered changes made since the last to call t...
Definition: qgsproject.cpp:705
QgsRuleBasedLabeling
Rule based labeling for a vector layer.
Definition: qgsrulebasedlabeling.h:42
deleteStyleById_t
bool deleteStyleById_t(const QString &uri, QString styleID, QString &errCause)
Definition: qgsvectorlayer.cpp:152
QgsAuxiliaryStorage::isValid
bool isValid() const
Returns the status of the auxiliary storage currently defined.
Definition: qgsauxiliarystorage.cpp:619
QgsVectorLayerEditBuffer::committedAttributesAdded
void committedAttributesAdded(const QString &layerId, const QList< QgsField > &addedAttributes)
QgsVectorLayer::setFieldConstraint
void setFieldConstraint(int index, QgsFieldConstraints::Constraint constraint, QgsFieldConstraints::ConstraintStrength strength=QgsFieldConstraints::ConstraintStrengthHard)
Sets a constraint for a specified field index.
Definition: qgsvectorlayer.cpp:5674
QgsVectorDataProvider::setEncoding
virtual void setEncoding(const QString &e)
Set encoding used for accessing data from layer.
Definition: qgsvectordataprovider.cpp:213
QgsVectorLayer::defaultValue
QVariant defaultValue(int index, const QgsFeature &feature=QgsFeature(), QgsExpressionContext *context=nullptr) const
Returns the calculated default value for the specified field index.
Definition: qgsvectorlayer.cpp:4091
QgsVectorLayer::changeAttributeValue
bool changeAttributeValue(QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue=QVariant(), bool skipDefaultValues=false)
Changes an attribute value for a feature (but does not immediately commit the changes).
Definition: qgsvectorlayer.cpp:3072
QgsWkbTypes::PolygonGeometry
@ PolygonGeometry
Definition: qgswkbtypes.h:144
QgsVectorLayerEditBuffer::geometryChanged
void geometryChanged(QgsFeatureId fid, const QgsGeometry &geom)
Emitted when a feature's geometry is changed.
qgsogcutils.h
QgsMapLayer::mShouldValidateCrs
bool mShouldValidateCrs
true if the layer's CRS should be validated and invalid CRSes are not permitted.
Definition: qgsmaplayer.h:1994
QgsDataSourceUri::port
QString port() const
Returns the port stored in the URI.
Definition: qgsdatasourceuri.cpp:295
QgsExpressionFieldBuffer::updateFields
void updateFields(QgsFields &flds) const
Adds fields with the expressions buffered in this object to a QgsFields object.
Definition: qgsexpressionfieldbuffer.cpp:93
QgsVectorDataProvider::defaultValue
virtual QVariant defaultValue(int fieldIndex) const
Returns any literal default values which are present at the provider for a specified field index.
Definition: qgsvectordataprovider.cpp:153
QgsError::clear
void clear()
Clear error messages.
Definition: qgserror.h:127
QgsVectorLayer::isEditable
bool isEditable() const FINAL
Returns true if the provider is in editing mode.
Definition: qgsvectorlayer.cpp:3728
QgsMapLayer::mProviderKey
QString mProviderKey
Data provider key (name of the data provider)
Definition: qgsmaplayer.h:1982
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
QgsVectorLayer::LayerOptions::fallbackCrs
QgsCoordinateReferenceSystem fallbackCrs
Fallback layer coordinate reference system.
Definition: qgsvectorlayer.h:472
QgsVectorLayerEditUtils::addTopologicalPoints
int addTopologicalPoints(const QgsGeometry &geom)
Adds topological points for every vertex of the geometry.
Definition: qgsvectorlayereditutils.cpp:535
QgsFeatureRequest::setExpressionContext
QgsFeatureRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate filter expressions.
Definition: qgsfeaturerequest.cpp:187
QgsMapLayer::Rendering
@ Rendering
Rendering: scale visibility, simplify method, opacity.
Definition: qgsmaplayer.h:170
QgsFeatureRequest::setFilterFid
QgsFeatureRequest & setFilterFid(QgsFeatureId fid)
Sets the feature ID that should be fetched.
Definition: qgsfeaturerequest.cpp:141
QgsDataProvider::transformContext
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
Definition: qgsdataprovider.cpp:81
QgsDiagramLayerSettings::PositionY
@ PositionY
Y-coordinate data defined diagram position.
Definition: qgsdiagramrenderer.h:96
QgsMapLayerRenderer
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Definition: qgsmaplayerrenderer.h:54
QgsField::configurationFlags
ConfigurationFlags configurationFlags
Definition: qgsfield.h:64
QgsVectorLayer::setEditorWidgetSetup
void setEditorWidgetSetup(int index, const QgsEditorWidgetSetup &setup)
The editor widget setup defines which QgsFieldFormatter and editor widget will be used for the field ...
Definition: qgsvectorlayer.cpp:5767
QgsMapLayer::providerType
QString providerType() const
Returns the provider type (provider key) for this layer.
Definition: qgsmaplayer.cpp:1864
QgsPalLayerSettings::placementSettings
const QgsLabelPlacementSettings & placementSettings() const
Returns the label placement settings.
Definition: qgspallabeling.h:949
QgsTaskManager::addTask
long addTask(QgsTask *task, int priority=0)
Adds a task to the manager.
Definition: qgstaskmanager.cpp:420
QgsLayerMetadataFormatter::linksSectionHtml
QString linksSectionHtml() const
Formats the "Links" section according to a metadata object.
Definition: qgslayermetadataformatter.cpp:255
QgsExpressionFieldBuffer::readXml
void readXml(const QDomNode &layer_node)
Reads expressions from project file.
Definition: qgsexpressionfieldbuffer.cpp:66
QgsVectorLayer::encodedSource
QString encodedSource(const QString &source, const QgsReadWriteContext &context) const FINAL
Called by writeLayerXML(), used by derived classes to encode provider's specific data source to proje...
Definition: qgsvectorlayer.cpp:2005
QgsFeatureRequest::setFilterExpression
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
Definition: qgsfeaturerequest.cpp:167
QgsTask::taskCompleted
void taskCompleted()
Will be emitted by task to indicate its successful completion.
QgsVectorLayer::changeAttributeValues
bool changeAttributeValues(QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues=QgsAttributeMap(), bool skipDefaultValues=false)
Changes attributes' values for a feature (but does not immediately commit the changes).
Definition: qgsvectorlayer.cpp:3103
QgsVectorLayer::removeFieldAlias
void removeFieldAlias(int index)
Removes an alias (a display name) for attributes to display in dialogs.
Definition: qgsvectorlayer.cpp:3169
QgsFieldConstraints::setConstraintStrength
void setConstraintStrength(Constraint constraint, ConstraintStrength strength)
Sets the strength of a constraint.
Definition: qgsfieldconstraints.cpp:36
QgsVectorSimplifyMethod::maximumScale
float maximumScale() const
Gets the maximum scale at which the layer should be simplified.
Definition: qgsvectorsimplifymethod.h:99
QgsFeatureRenderer::referenceScale
double referenceScale() const
Returns the symbology reference scale.
Definition: qgsrenderer.h:466
qgsauxiliarystorage.h
qgsmaplayerfactory.h
QgsAuxiliaryStorage::createAuxiliaryLayer
QgsAuxiliaryLayer * createAuxiliaryLayer(const QgsField &field, QgsVectorLayer *layer) const
Creates an auxiliary layer for a vector layer.
Definition: qgsauxiliarystorage.cpp:652
qgsVariantGreaterThan
bool qgsVariantGreaterThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is greater than the second.
Definition: qgis.cpp:187
QgsVectorLayerEditBuffer::changeGeometry
virtual bool changeGeometry(QgsFeatureId fid, const QgsGeometry &geom)
Change feature's geometry.
Definition: qgsvectorlayereditbuffer.cpp:209
QgsVectorLayer::renameAttribute
bool renameAttribute(int index, const QString &newName)
Renames an attribute field (but does not commit it).
Definition: qgsvectorlayer.cpp:3185
qgsapplication.h
QgsPainting::getBlendModeEnum
static QgsPainting::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
Definition: qgspainting.cpp:80
QgsVectorDataProvider::SelectAtId
@ SelectAtId
Fast access to features using their ID.
Definition: qgsvectordataprovider.h:81
QgsFeatureSource::allFeatureIds
virtual QgsFeatureIds allFeatureIds() const
Returns a list of all feature IDs for features present in the source.
Definition: qgsfeaturesource.cpp:115
QgsRectangle::normalize
void normalize()
Normalize the rectangle so it has non-negative width/height.
Definition: qgsrectangle.h:203
QgsMapLayer::GeometryOptions
@ GeometryOptions
Geometry validation configuration.
Definition: qgsmaplayer.h:172
QgsVectorLayer::writeXml
bool writeXml(QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context) const FINAL
Writes vector layer specific state to project file Dom node.
Definition: qgsvectorlayer.cpp:1925
QgsDiagramLayerSettings::writeXml
void writeXml(QDomElement &layerElem, QDomDocument &doc) const
Writes the diagram settings to a DOM element.
Definition: qgsdiagramrenderer.cpp:143
QgsVectorLayer::simplifyDrawingCanbeApplied
bool simplifyDrawingCanbeApplied(const QgsRenderContext &renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint) const
Returns whether the VectorLayer can apply the specified simplification hint.
Definition: qgsvectorlayer.cpp:1035
QgsVectorLayerJoinInfo::targetFieldName
QString targetFieldName() const
Returns name of the field of our layer that will be used for join.
Definition: qgsvectorlayerjoininfo.h:68
QgsVectorLayer::editorWidgetSetup
QgsEditorWidgetSetup editorWidgetSetup(int index) const
The editor widget setup defines which QgsFieldFormatter and editor widget will be used for the field ...
Definition: qgsvectorlayer.cpp:5779
QgsMapLayer::triggerRepaint
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
Definition: qgsmaplayer.cpp:2114
QgsMapLayer::dataSourceChanged
void dataSourceChanged()
Emitted whenever the layer's data source has been changed.
QgsProviderRegistry::deleteStyleById
bool deleteStyleById(const QString &providerKey, const QString &uri, const QString &styleId, QString &errCause)
Deletes a layer style defined by styleId.
Definition: qgsproviderregistry.cpp:667
QgsVectorLayer::DeleteContext::handledFeatures
QgsFeatureIds handledFeatures(QgsVectorLayer *layer) const
Returns a list of feature IDs from the specified layer affected by the delete operation.
Definition: qgsvectorlayer.cpp:5864
QgsPalLayerSettings::xOffset
double xOffset
Horizontal offset of label.
Definition: qgspallabeling.h:534
QgsAttributeTableConfig
This is a container for configuration of the attribute table. The configuration is specific for one v...
Definition: qgsattributetableconfig.h:36
QgsVectorDataProvider::ReadLayerMetadata
@ ReadLayerMetadata
Provider can read layer metadata from data store. Since QGIS 3.0. See QgsDataProvider::layerMetadata(...
Definition: qgsvectordataprovider.h:92
QgsVectorLayer::fields
QgsFields fields() const FINAL
Returns the list of fields of this layer.
Definition: qgsvectorlayer.cpp:3436
QgsField::precision
int precision
Definition: qgsfield.h:57
QgsVectorLayer::changeGeometry
bool changeGeometry(QgsFeatureId fid, QgsGeometry &geometry, bool skipDefaultValue=false)
Changes a feature's geometry within the layer's edit buffer (but does not immediately commit the chan...
Definition: qgsvectorlayer.cpp:3048
QgsRectangle::xMaximum
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:183
QgsFeature::id
QgsFeatureId id
Definition: qgsfeature.h:68
qgsFlagValueToKeys
QString qgsFlagValueToKeys(const T &value, bool *returnOk=nullptr)
Returns the value for the given keys of a flag.
Definition: qgis.h:2498
QgsEditorWidgetSetup::type
QString type() const
Definition: qgseditorwidgetsetup.h:59
QgsMapLayer::FlagDontResolveLayers
@ FlagDontResolveLayers
Don't resolve layer paths or create data providers for layers.
Definition: qgsmaplayer.h:640
QgsTextFormat
Container for all settings relating to text rendering.
Definition: qgstextformat.h:40
QgsTextFormat::setColor
void setColor(const QColor &color)
Sets the color that text will be rendered in.
Definition: qgstextformat.cpp:302
QgsFeatureRequest
This class wraps a request for features to a vector layer (or directly its vector data provider).
Definition: qgsfeaturerequest.h:83
QgsFeatureRenderer::save
virtual QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context)
Stores renderer properties to an XML element.
Definition: qgsrenderer.cpp:193
QgsMapLayer::flags
QgsMapLayer::LayerFlags flags() const
Returns the flags for this layer.
Definition: qgsmaplayer.cpp:150
QgsVectorLayer::setLabeling
void setLabeling(QgsAbstractVectorLayerLabeling *labeling)
Sets labeling configuration.
Definition: qgsvectorlayer.cpp:1482
QgsMapLayer::MapTips
@ MapTips
Map tips.
Definition: qgsmaplayer.h:167
QgsPropertiesDefinition
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
Definition: qgspropertycollection.h:29
QgsVectorDataProvider::capabilities
virtual Q_INVOKABLE QgsVectorDataProvider::Capabilities capabilities() const
Returns flags containing the supported capabilities.
Definition: qgsvectordataprovider.cpp:208
QgsPathResolver::writePath
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
Definition: qgspathresolver.cpp:225
qgsvectorlayertemporalproperties.h
QgsVectorLayerEditBuffer::committedFeaturesAdded
void committedFeaturesAdded(const QString &layerId, const QgsFeatureList &addedFeatures)
QgsVectorLayer::dataComment
QString dataComment() const
Returns a description for this layer as defined in the data provider.
Definition: qgsvectorlayer.cpp:398
QgsAbstractVectorLayerLabeling::create
static QgsAbstractVectorLayerLabeling * create(const QDomElement &element, const QgsReadWriteContext &context)
Try to create instance of an implementation based on the XML data.
Definition: qgsvectorlayerlabeling.cpp:27
QgsMapLayerFactory::typeToString
static QString typeToString(QgsMapLayerType type)
Converts a map layer type to a string value.
Definition: qgsmaplayerfactory.cpp:51
QgsVectorDataProvider::EditingCapabilities
static const int EditingCapabilities
Bitmask of all provider's editing capabilities.
Definition: qgsvectordataprovider.h:104
QgsMapLayer::metadata
QgsLayerMetadata metadata
Definition: qgsmaplayer.h:78
QgsReadWriteContextCategoryPopper
Allows entering a context category and takes care of leaving this category on deletion of the class....
Definition: qgsreadwritecontext.h:178
QgsExpression::hasEvalError
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
Definition: qgsexpression.cpp:378
QgsVectorDataProvider::aggregate
virtual QVariant aggregate(QgsAggregateCalculator::Aggregate aggregate, int index, const QgsAggregateCalculator::AggregateParameters &parameters, QgsExpressionContext *context, bool &ok, QgsFeatureIds *fids=nullptr) const
Calculates an aggregated value from the layer's features.
Definition: qgsvectordataprovider.cpp:500
QgsVectorLayer::featureBlendModeChanged
void featureBlendModeChanged(QPainter::CompositionMode blendMode)
Signal emitted when setFeatureBlendMode() is called.
qgsexpressioncontext.h
QgsDataProvider::reloadData
virtual void reloadData()
Reloads the data from the source for providers with data caches to synchronize, changes in the data s...
Definition: qgsdataprovider.cpp:45
qgsrulebasedlabeling.h
QgsVectorDataProvider::minimumValue
QVariant minimumValue(int index) const override
Returns the minimum value of an attribute.
Definition: qgsvectordataprovider.cpp:431
QgsMapLayer::mValid
bool mValid
Indicates if the layer is valid and can be drawn.
Definition: qgsmaplayer.h:1938
QgsReadWriteContext::projectTranslator
const QgsProjectTranslator * projectTranslator() const
Returns the project translator.
Definition: qgsreadwritecontext.h:128
QgsVectorLayer::endEditCommand
void endEditCommand()
Finish edit command and add it to undo/redo stack.
Definition: qgsvectorlayer.cpp:3868
QgsVectorLayer::removeFieldConstraint
void removeFieldConstraint(int index, QgsFieldConstraints::Constraint constraint)
Removes a constraint for a specified field index.
Definition: qgsvectorlayer.cpp:5691
QgsVectorLayer::committedAttributeValuesChanges
void committedAttributeValuesChanges(const QString &layerId, const QgsChangedAttributesMap &changedAttributesValues)
Emitted when attribute value changes are saved to the provider if not in transaction mode.
QgsVectorLayer::decodedSource
QString decodedSource(const QString &source, const QString &provider, const QgsReadWriteContext &context) const FINAL
Called by readLayerXML(), used by derived classes to decode provider's specific data source from proj...
Definition: qgsvectorlayer.cpp:2090
QgsMapLayer::setExtent
virtual void setExtent(const QgsRectangle &rect)
Sets the extent.
Definition: qgsmaplayer.cpp:2151
QgsReadWriteContext::enterCategory
MAYBE_UNUSED NODISCARD QgsReadWriteContextCategoryPopper enterCategory(const QString &category, const QString &details=QString()) const
Push a category to the stack.
Definition: qgsreadwritecontext.cpp:62
Qgis::GeometryOperationResult::SelectionIsEmpty
@ SelectionIsEmpty
No features were selected.
QgsDiagramLayerSettings::readXml
void readXml(const QDomElement &elem)
Reads the diagram settings from a DOM element.
Definition: qgsdiagramrenderer.cpp:122
QgsVectorLayer::commitChanges
Q_INVOKABLE bool commitChanges(bool stopEditing=true)
Attempts to commit to the underlying data provider any buffered changes made since the last to call t...
Definition: qgsvectorlayer.cpp:3485
Qgis::LabelPlacement::Horizontal
@ Horizontal
Arranges horizontal candidates scattered throughout a polygon feature. Applies to polygon layers only...
QgsVectorLayer::setFieldConfigurationFlags
void setFieldConfigurationFlags(int index, QgsField::ConfigurationFlags flags)
Sets the configuration flags of the field at given index.
Definition: qgsvectorlayer.cpp:5740
qgsstoredexpressionmanager.h
QgsVectorLayer::addTopologicalPoints
int addTopologicalPoints(const QgsGeometry &geom)
Adds topological points for every vertex of the geometry.
Definition: qgsvectorlayer.cpp:1450
QgsVectorLayer::temporalProperties
QgsMapLayerTemporalProperties * temporalProperties() override
Returns the layer's temporal properties.
Definition: qgsvectorlayer.cpp:686
QgsDataSourceUri::username
QString username() const
Returns the username stored in the URI.
Definition: qgsdatasourceuri.cpp:260
QgsWkbTypes::Unknown
@ Unknown
Definition: qgswkbtypes.h:71
QgsVectorLayerEditBuffer::deleteFeature
virtual bool deleteFeature(QgsFeatureId fid)
Delete a feature from the layer (but does not commit it)
Definition: qgsvectorlayereditbuffer.cpp:163
QgsVectorLayerEditBuffer::featureDeleted
void featureDeleted(QgsFeatureId fid)
QgsVectorLayer::commitErrors
QStringList commitErrors() const
Returns a list containing any error messages generated when attempting to commit changes to the layer...
Definition: qgsvectorlayer.cpp:3559
QgsFeature::setGeometry
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Definition: qgsfeature.cpp:170
QgsVectorLayerEditUtils::translateFeature
int translateFeature(QgsFeatureId featureId, double dx, double dy)
Translates feature by dx, dy.
Definition: qgsvectorlayereditutils.cpp:267
qgsproviderregistry.h
QgsVectorLayerEditUtils::moveVertex
bool moveVertex(double x, double y, QgsFeatureId atFeatureId, int atVertex)
Moves the vertex at the given position number, ring and item (first number is index 0),...
Definition: qgsvectorlayereditutils.cpp:73
QgsTemporalProperty::isActive
bool isActive() const
Returns true if the temporal property is active.
Definition: qgstemporalproperty.cpp:36
QgsRelationManager::referencedRelations
QList< QgsRelation > referencedRelations(const QgsVectorLayer *layer=nullptr) const
Gets all relations where this layer is the referenced part (i.e.
Definition: qgsrelationmanager.cpp:157
QgsVectorLayerEditBuffer::deletedAttributeIds
QgsAttributeList deletedAttributeIds() const
Returns a list of deleted attributes fields which are not committed.
Definition: qgsvectorlayereditbuffer.h:152
QgsVectorLayerEditBuffer::committedAttributeValuesChanges
void committedAttributeValuesChanges(const QString &layerId, const QgsChangedAttributesMap &changedAttributesValues)
QgsVectorLayerJoinBuffer::changeAttributeValues
bool changeAttributeValues(QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues=QgsAttributeMap())
Changes attributes' values in joined layers.
Definition: qgsvectorlayerjoinbuffer.cpp:674
qgsvectorlayerjoinbuffer.h
QgsExpression::parserErrorString
QString parserErrorString() const
Returns parser error.
Definition: qgsexpression.cpp:211
saveStyle_t
bool saveStyle_t(const QString &uri, const QString &qmlStyle, const QString &sldStyle, const QString &styleName, const QString &styleDescription, const QString &uiFileContent, bool useAsDefault, QString &errCause)
Definition: qgsvectorlayer.cpp:122
qgsdatasourceuri.h
QgsVectorLayer::setExtent
void setExtent(const QgsRectangle &rect) FINAL
Sets the extent.
Definition: qgsvectorlayer.cpp:869
QgsDataProvider::FlagLoadDefaultStyle
@ FlagLoadDefaultStyle
Reset the layer's style to the default for the datasource.
Definition: qgsdataprovider.h:125
qgsactionmanager.h
QgsVectorLayer::reselect
void reselect()
Reselects the previous set of selected features.
Definition: qgsvectorlayer.cpp:668
Qgis::VertexMarkerType
VertexMarkerType
Editing vertex markers, used for showing vertices during a edit operation.
Definition: qgis.h:806
QgsVectorLayer::writeCustomSymbology
void writeCustomSymbology(QDomElement &element, QDomDocument &doc, QString &errorMessage) const
Signal emitted whenever the symbology (QML-file) for this layer is being written.
QgsVectorLayer::deleteSelectedFeatures
Q_INVOKABLE bool deleteSelectedFeatures(int *deletedCount=nullptr, QgsVectorLayer::DeleteContext *context=nullptr)
Deletes the selected features.
Definition: qgsvectorlayer.cpp:1220
QgsXmlUtils::readVariant
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
Definition: qgsxmlutils.cpp:251
QgsFeature::isValid
bool isValid() const
Returns the validity of this feature.
Definition: qgsfeature.cpp:216
QgsVectorLayer::selectionChanged
void selectionChanged(const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect)
Emitted when selection was changed.
QgsVectorLayer::rollBack
Q_INVOKABLE bool rollBack(bool deleteBuffer=true)
Stops a current editing operation and discards any uncommitted edits.
Definition: qgsvectorlayer.cpp:3564
QgsVectorLayer::weakRelations
QList< QgsWeakRelation > weakRelations() const
Returns the layer's weak relations as specified in the layer's style.
Definition: qgsvectorlayer.cpp:5414
QgsFieldConstraints::constraints
Constraints constraints
Definition: qgsfieldconstraints.h:36
QgsMapLayer::readStyleManager
void readStyleManager(const QDomNode &layerNode)
Read style manager's configuration (if any). To be called by subclasses.
Definition: qgsmaplayer.cpp:800
QgsFeatureIterator::close
bool close()
Definition: qgsfeatureiterator.h:412
QgsVectorLayer::vectorJoins
const QList< QgsVectorLayerJoinInfo > vectorJoins() const
Definition: qgsvectorlayer.cpp:3921
QgsVectorLayerEditBuffer::featureAdded
void featureAdded(QgsFeatureId fid)
QgsMapLayer::writeCommonStyle
void writeCommonStyle(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write style data common to all layer types.
Definition: qgsmaplayer.cpp:679
QgsVectorLayer::sourceExtent
QgsRectangle sourceExtent() const FINAL
Returns the extent of all geometries from the source.
Definition: qgsvectorlayer.cpp:987
QgsVectorLayer::addRing
Q_DECL_DEPRECATED Qgis::GeometryOperationResult addRing(const QVector< QgsPointXY > &ring, QgsFeatureId *featureId=nullptr)
Adds a ring to polygon/multipolygon features.
Definition: qgsvectorlayer.cpp:1264
QgsVectorLayer::QgsVectorLayerEditBuffer
friend class QgsVectorLayerEditBuffer
Definition: qgsvectorlayer.h:2954
QgsVectorLayerEditUtils::addRing
Q_DECL_DEPRECATED Qgis::GeometryOperationResult addRing(const QVector< QgsPointXY > &ring, const QgsFeatureIds &targetFeatureIds=QgsFeatureIds(), QgsFeatureId *modifiedFeatureId=nullptr)
Adds a ring to polygon/multipolygon features.
Definition: qgsvectorlayereditutils.cpp:121
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
QgsFields::OriginUnknown
@ OriginUnknown
It has not been specified where the field comes from.
Definition: qgsfields.h:50
QgsDataProvider::enterUpdateMode
virtual bool enterUpdateMode()
Enter update mode.
Definition: qgsdataprovider.h:469
QgsMapLayer::styleChanged
void styleChanged()
Signal emitted whenever a change affects the layer's style.
QgsGeometry::equals
bool equals(const QgsGeometry &geometry) const
Test if this geometry is exactly equal to another geometry.
Definition: qgsgeometry.cpp:1340
QgsAttributeTableConfig::writeXml
void writeXml(QDomNode &node) const
Serialize to XML on layer save.
Definition: qgsattributetableconfig.cpp:260
QgsMapLayer::repaintRequested
void repaintRequested(bool deferredUpdate=false)
By emitting this signal the layer tells that either appearance or content have been changed and any v...
QgsVectorLayerFeatureIterator
Definition: qgsvectorlayerfeatureiterator.h:129
QgsVectorLayer::labeling
const QgsAbstractVectorLayerLabeling * labeling() const
Access to const labeling configuration.
Definition: qgsvectorlayer.h:1656
QgsRelationManager::relationsLoaded
void relationsLoaded()
Emitted when the relations were loaded after reading a project.
QgsVectorLayer::translateFeature
Q_INVOKABLE int translateFeature(QgsFeatureId featureId, double dx, double dy)
Translates feature by dx, dy.
Definition: qgsvectorlayer.cpp:1401
QgsMapLayer::extent
virtual QgsRectangle extent() const
Returns the extent of the layer.
Definition: qgsmaplayer.cpp:305
qgsprofilerequest.h
QgsFieldConstraints::ConstraintOriginLayer
@ ConstraintOriginLayer
Constraint was set by layer.
Definition: qgsfieldconstraints.h:58
QgsStoredExpressionManager::readXml
bool readXml(const QDomNode &layerNode)
Reads the stored expressions in in XML format.
Definition: qgsstoredexpressionmanager.cpp:132
qgsmaplayerutils.h
QgsVectorLayer::readOnlyChanged
void readOnlyChanged()
Emitted when the read only state of this layer is changed.
QgsMapLayer::generalHtmlMetadata
QString generalHtmlMetadata() const
Returns an HTML fragment containing general metadata information, for use in the htmlMetadata() metho...
Definition: qgsmaplayer.cpp:2303
QgsVectorLayer::invertSelectionInRectangle
Q_INVOKABLE void invertSelectionInRectangle(QgsRectangle &rect)
Inverts selection of features found within the search rectangle (in layer's coordinates)
Definition: qgsvectorlayer.cpp:629
QgsMapLayerLegend::defaultVectorLegend
static QgsMapLayerLegend * defaultVectorLegend(QgsVectorLayer *vl)
Create new legend implementation for vector layer.
Definition: qgsmaplayerlegend.cpp:54
QgsSettings::flagValue
T flagValue(const QString &key, const T &defaultValue, const Section section=NoSection)
Returns the setting value for a setting based on a flag.
Definition: qgssettings.h:360
QgsVectorLayerEditBuffer::changedAttributeValues
QgsChangedAttributesMap changedAttributeValues() const
Returns a map of features with changed attributes values which are not committed.
Definition: qgsvectorlayereditbuffer.h:138
QgsVectorDataProvider::dependencies
virtual QSet< QgsMapLayerDependency > dependencies() const
Gets the list of layer ids on which this layer depends.
Definition: qgsvectordataprovider.cpp:771
QgsVectorLayer::attributeValueChanged
void attributeValueChanged(QgsFeatureId fid, int idx, const QVariant &value)
Emitted whenever an attribute value change is done in the edit buffer.
QgsFeatureSource::SpatialIndexPresence
SpatialIndexPresence
Enumeration of spatial index presence states.
Definition: qgsfeaturesource.h:187
QgsVectorLayerJoinBuffer
Manages joined fields for a vector layer.
Definition: qgsvectorlayerjoinbuffer.h:37
QgsVectorLayer::selectedFeatureIds
const Q_INVOKABLE QgsFeatureIds & selectedFeatureIds() const
Returns a list of the selected features IDs in this layer.
Definition: qgsvectorlayer.cpp:3621
QgsPainting::getCompositionMode
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
Definition: qgspainting.cpp:20
QgsMapLayer::mDependencies
QSet< QgsMapLayerDependency > mDependencies
List of layers that may modify this layer on modification.
Definition: qgsmaplayer.h:1969
QgsActionManager::actions
QList< QgsAction > actions(const QString &actionScope=QString()) const
Returns a list of actions that are available in the given action scope.
Definition: qgsactionmanager.cpp:170
QgsMapLayer::setMaximumScale
void setMaximumScale(double scale)
Sets the maximum map scale (i.e.
Definition: qgsmaplayer.cpp:883
QgsEditFormConfig::writeXml
void writeXml(QDomNode &node, const QgsReadWriteContext &context) const
Write XML information Serialize on project save.
Definition: qgseditformconfig.cpp:545
Qgis::VectorEditResult::InvalidLayer
@ InvalidLayer
Edit failed due to invalid layer.
QgsField::defaultValueDefinition
QgsDefaultValue defaultValueDefinition
Definition: qgsfield.h:62
QgsMapLayer::Forms
@ Forms
Feature form.
Definition: qgsmaplayer.h:165
QgsVectorLayer::constraintDescription
QString constraintDescription(int index) const
Returns the descriptive name for the constraint expression for a specified field index.
Definition: qgsvectorlayer.cpp:5716
QgsFeatureRenderer::toSld
virtual void toSld(QDomDocument &doc, QDomElement &element, const QVariantMap &props=QVariantMap()) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
Definition: qgsrenderer.h:326
QgsVectorLayer::afterRollBack
void afterRollBack()
Emitted after changes are rolled back.
QgsApplication::taskManager
static QgsTaskManager * taskManager()
Returns the application's task manager, used for managing application wide background task handling.
Definition: qgsapplication.cpp:2300
QgsVectorLayer::DeleteContext::mHandledFeatures
QMap< QgsVectorLayer *, QgsFeatureIds > mHandledFeatures
Definition: qgsvectorlayer.h:516
QgsVectorLayer::uniqueValues
QSet< QVariant > uniqueValues(int fieldIndex, int limit=-1) const FINAL
Calculates a list of unique values contained within an attribute in the layer.
Definition: qgsvectorlayer.cpp:4161
QgsMapLayer::setOpacity
virtual void setOpacity(double opacity)
Sets the opacity for the layer, where opacity is a value between 0 (totally transparent) and 1....
Definition: qgsmaplayer.cpp:325
RENDERER_TAG_NAME
#define RENDERER_TAG_NAME
Definition: qgsrenderer.h:50
QgsPalLayerSettings::setFormat
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
Definition: qgspallabeling.h:849
QgsField::comment
QString comment
Definition: qgsfield.h:59
Qgis::GeometryOperationResult
GeometryOperationResult
Success or failure of a geometry operation.
Definition: qgis.h:901
QgsVectorLayer::~QgsVectorLayer
~QgsVectorLayer() override
Definition: qgsvectorlayer.cpp:239
QgsFields::size
int size() const
Returns number of items.
Definition: qgsfields.cpp:138
QgsFields::fieldOrigin
FieldOrigin fieldOrigin(int fieldIdx) const
Returns the field's origin (value from an enumeration).
Definition: qgsfields.cpp:189
qgsrendercontext.h
qgsvectordataprovider.h
QgsVectorLayer::reload
void reload() FINAL
Synchronises with changes in the datasource.
Definition: qgsvectorlayer.cpp:417
QgsExpressionFieldBuffer::addExpression
void addExpression(const QString &exp, const QgsField &fld)
Add an expression to the buffer.
Definition: qgsexpressionfieldbuffer.cpp:23
QgsFeatureList
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:882
QgsAttributeMap
QMap< int, QVariant > QgsAttributeMap
Definition: qgsattributes.h:38
QgsVectorLayer::setTransformContext
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext) override
Sets the coordinate transform context to transformContext.
Definition: qgsvectorlayer.cpp:1526
QgsVectorLayerEditBuffer::attributeDeleted
void attributeDeleted(int idx)
qgspainting.h
QgsVectorLayer::referencingRelations
QList< QgsRelation > referencingRelations(int idx) const
Returns the layer's relations, where the foreign key is on this layer.
Definition: qgsvectorlayer.cpp:5409
QgsVectorLayerTemporalProperties::setDefaultsFromDataProviderTemporalCapabilities
void setDefaultsFromDataProviderTemporalCapabilities(const QgsDataProviderTemporalCapabilities *capabilities) override
Sets the layers temporal settings to appropriate defaults based on a provider's temporal capabilities...
Definition: qgsvectorlayertemporalproperties.cpp:332
QgsDiagramLayerSettings
Stores the settings for rendering of all diagrams for a layer.
Definition: qgsdiagramrenderer.h:61
QgsVectorLayerEditBuffer::committedFeaturesRemoved
void committedFeaturesRemoved(const QString &layerId, const QgsFeatureIds &deletedFeatureIds)
QgsMapLayer::loadDefaultStyle
virtual QString loadDefaultStyle(bool &resultFlag)
Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record...
Definition: qgsmaplayer.cpp:1050
QgsFieldConstraints::ConstraintUnique
@ ConstraintUnique
Field must have a unique value.
Definition: qgsfieldconstraints.h:46
QgsMessageLog::logMessage
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Definition: qgsmessagelog.cpp:27
QgsVectorLayerJoinBuffer::addFeatures
bool addFeatures(QgsFeatureList &features, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) override
Adds a list of features in joined layers.
Definition: qgsvectorlayerjoinbuffer.cpp:559
QgsCoordinateReferenceSystem::isValid
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Definition: qgscoordinatereferencesystem.cpp:977
QgsVectorLayerElevationProperties
Vector layer specific subclass of QgsMapLayerElevationProperties.
Definition: qgsvectorlayerelevationproperties.h:38
qgsvectorlayerutils.h
Qgis::LabelPlacement::OverPoint
@ OverPoint
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point....
QgsStoredExpressionManager::writeXml
bool writeXml(QDomNode &layerNode) const
Writes the stored expressions out in XML format.
Definition: qgsstoredexpressionmanager.cpp:115
QgsVectorLayer::readExtentFromXml
bool readExtentFromXml() const
Returns true if the extent is read from the XML document when data source has no metadata,...
Definition: qgsvectorlayer.cpp:5838
QgsVectorLayerTemporalProperties
Implementation of map layer temporal properties for vector layers.
Definition: qgsvectorlayertemporalproperties.h:70
QgsApplication::profiler
static QgsRuntimeProfiler * profiler()
Returns the application runtime profiler.
Definition: qgsapplication.cpp:549
QgsLogger::warning
static void warning(const QString &msg)
Goes to qWarning.
Definition: qgslogger.cpp:122
QgsVectorLayer::removeExpressionField
void removeExpressionField(int index)
Removes an expression field.
Definition: qgsvectorlayer.cpp:3936
QgsVectorLayerJoinBuffer::vectorJoins
const QgsVectorJoinList & vectorJoins() const
Definition: qgsvectorlayerjoinbuffer.h:83
QgsPropertyDefinition
Definition for a property.
Definition: qgsproperty.h:46
QgsVectorDataProvider::createRenderer
virtual QgsFeatureRenderer * createRenderer(const QVariantMap &configuration=QVariantMap()) const
Creates a new vector layer feature renderer, using provider backend specific information.
Definition: qgsvectordataprovider.cpp:754
QgsProfileRequest
Encapsulates properties and constraints relating to fetching elevation profiles from different source...
Definition: qgsprofilerequest.h:37
QgsVectorDataProvider::storageType
virtual QString storageType() const
Returns the permanent storage type for this layer as a friendly name.
Definition: qgsvectordataprovider.cpp:46
qgscoordinatetransform.h
QgsAuxiliaryLayer::joinInfo
QgsVectorLayerJoinInfo joinInfo() const
Returns information to use for joining with primary key and so on.
Definition: qgsauxiliarystorage.cpp:130
QgsPalLayerSettings::lineSettings
const QgsLabelLineSettings & lineSettings() const
Returns the label line settings, which contain settings related to how the label engine places and fo...
Definition: qgspallabeling.h:879
qgssymbollayer.h
QgsFeature::attribute
QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
Definition: qgsfeature.cpp:327
QgsVectorLayer::maximumValue
QVariant maximumValue(int index) const FINAL
Returns the maximum value for an attribute column or an invalid variant in case of error.
Definition: qgsvectorlayer.cpp:4377
QgsVectorSimplifyMethod::threshold
float threshold() const
Gets the simplification threshold of the vector layer managed.
Definition: qgsvectorsimplifymethod.h:89
QgsLayerMetadata::combine
void combine(const QgsAbstractMetadataBase *other) override
Combines the metadata from this object with the metadata from an other object.
Definition: qgslayermetadata.cpp:344
QgsVectorLayerEditBuffer::rollBack
virtual void rollBack()
Stop editing and discard the edits.
Definition: qgsvectorlayereditbuffer.cpp:434
QgsTask::taskTerminated
void taskTerminated()
Will be emitted by task if it has terminated for any reason other then completion (e....
QgsFeatureRequest::setFilterFids
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Sets the feature IDs that should be fetched.
Definition: qgsfeaturerequest.cpp:148
QgsVectorLayer::removeFeatureRendererGenerator
void removeFeatureRendererGenerator(const QString &id)
Removes the feature renderer with matching id from the layer.
Definition: qgsvectorlayer.cpp:3832
QgsDiagramRenderer
Evaluates and returns the diagram settings relating to a diagram for a specific feature.
Definition: qgsdiagramrenderer.h:684
qgsvectorlayerfeatureiterator.h
QgsVectorLayer::actions
QgsActionManager * actions()
Returns all layer actions defined on this layer.
Definition: qgsvectorlayer.h:741
QgsMapLayerTemporalProperties
Base class for storage of map layer temporal properties.
Definition: qgsmaplayertemporalproperties.h:42
QgsMapLayer::mDataSource
QString mDataSource
Data source description string, varies by layer type.
Definition: qgsmaplayer.h:1941
QgsVectorLayer::splitParts
Q_DECL_DEPRECATED Qgis::GeometryOperationResult splitParts(const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
Splits parts cut by the given line.
Definition: qgsvectorlayer.cpp:1414
QgsVectorLayer::setDisplayExpression
void setDisplayExpression(const QString &displayExpression)
Set the preview expression, used to create a human readable preview string.
Definition: qgsvectorlayer.cpp:3699
QgsVectorLayerEditBuffer::editBufferGroup
QgsVectorLayerEditBufferGroup * editBufferGroup() const
Returns the parent edit buffer group for this edit buffer, or nullptr if not part of a group.
Definition: qgsvectorlayereditbuffer.cpp:83
QgsVectorLayer::writeSld
bool writeSld(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QVariantMap &props=QVariantMap()) const
Writes the symbology of the layer into the document provided in SLD 1.1 format.
Definition: qgsvectorlayer.cpp:3010
QgsExpressionFieldBuffer::expressions
QList< QgsExpressionFieldBuffer::ExpressionField > expressions() const
Definition: qgsexpressionfieldbuffer.h:119
QgsVectorLayerEditBuffer::attributeAdded
void attributeAdded(int idx)
QgsVectorLayer::primaryKeyAttributes
QgsAttributeList primaryKeyAttributes() const
Returns the list of attributes which make up the layer's primary keys.
Definition: qgsvectorlayer.cpp:3441
QgsSymbolLayerUtils::getSvgParameterList
static QgsStringMap getSvgParameterList(QDomElement &element)
Definition: qgssymbollayerutils.cpp:3076
QgsVectorSimplifyMethod::setMaximumScale
void setMaximumScale(float maximumScale)
Sets the maximum scale at which the layer should be simplified.
Definition: qgsvectorsimplifymethod.h:97
QgsVectorLayerJoinInfo
Defines left outer join from our vector layer to some other vector layer. The join is done based on [...
Definition: qgsvectorlayerjoininfo.h:33
QgsMapLayer::layerModified
void layerModified()
Emitted when modifications has been done on layer.
QgsExpressionFieldBuffer
Buffers information about expression fields for a vector layer.
Definition: qgsexpressionfieldbuffer.h:35
QgsProject::startEditing
bool startEditing(QgsVectorLayer *vectorLayer=nullptr)
Makes the layer editable.
Definition: qgsproject.cpp:686
QgsMapLayer::hasScaleBasedVisibility
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
Definition: qgsmaplayer.cpp:839
QgsMapLayer::exportNamedStyle
virtual void exportNamedStyle(QDomDocument &doc, QString &errorMsg, const QgsReadWriteContext &context=QgsReadWriteContext(), QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const
Export the properties of this layer as named style in a QDomDocument.
Definition: qgsmaplayer.cpp:1288
QgsRectangle::xMinimum
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:188
QgsFieldConstraints::constraintStrength
ConstraintStrength constraintStrength(Constraint constraint) const
Returns the strength of a field constraint, or ConstraintStrengthNotSet if the constraint is not pres...
Definition: qgsfieldconstraints.cpp:27
QgsVectorLayerEditBuffer::renameAttribute
virtual bool renameAttribute(int attr, const QString &newName)
Renames an attribute field (but does not commit it)
Definition: qgsvectorlayereditbuffer.cpp:315
qgsrenderer.h
QgsVectorLayer::hasSpatialIndex
QgsFeatureSource::SpatialIndexPresence hasSpatialIndex() const override
Definition: qgsvectorlayer.cpp:1532
QgsFieldConstraints::constraintDescription
QString constraintDescription() const
Returns the descriptive name for the constraint expression.
Definition: qgsfieldconstraints.h:133
QgsVectorDataProvider::vectorLayerTypeFlags
virtual Qgis::VectorLayerTypeFlags vectorLayerTypeFlags() const
Returns the vector layer type flags.
Definition: qgsvectordataprovider.cpp:69
QgsVectorLayer::readSld
bool readSld(const QDomNode &node, QString &errorMessage) FINAL
Definition: qgsvectorlayer.cpp:2980
QgsVectorLayer::QgsVectorLayerEditPassthrough
friend class QgsVectorLayerEditPassthrough
Definition: qgsvectorlayer.h:2956
Qgis::GeometryOperationResult::AddRingNotInExistingFeature
@ AddRingNotInExistingFeature
The input ring doesn't have any existing ring to fit into.
QgsFeatureMap
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
Definition: qgsvectorlayereditbuffer.h:31
QgsTextBufferSettings
Container for settings relating to a text buffer.
Definition: qgstextbuffersettings.h:42
QgsVectorLayer::selectedFeatures
Q_INVOKABLE QgsFeatureList selectedFeatures() const
Returns a copy of the user-selected features.
Definition: qgsvectorlayer.cpp:3626
QgsVectorLayer::excludeAttributesWfs
Q_DECL_DEPRECATED QSet< QString > excludeAttributesWfs() const
A set of attributes that are not advertised in WFS requests with QGIS server.
Definition: qgsvectorlayer.cpp:3282
QgsVectorLayer::mapTipTemplateChanged
void mapTipTemplateChanged()
Emitted when the map tip changes.
Qgis::VectorEditResult::Success
@ Success
Edit operation was successful.
QgsMapLayer::removeCustomProperty
void removeCustomProperty(const QString &key)
Remove a custom property from layer.
Definition: qgsmaplayer.cpp:2004
QgsDiagramRenderer::diagramSettings
virtual QList< QgsDiagramSettings > diagramSettings() const =0
Returns list with all diagram settings in the renderer.
QgsVectorLayer::saveStyleToDatabase
virtual void saveStyleToDatabase(const QString &name, const QString &description, bool useAsDefault, const QString &uiFileContent, QString &msgError, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Saves named and sld style of the layer to the style table in the db.
Definition: qgsvectorlayer.cpp:5435
qgsdiagramrenderer.h
QgsFeatureRequest::setNoAttributes
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
Definition: qgsfeaturerequest.cpp:235
QgsExpression::prepare
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
Definition: qgsexpression.cpp:327
qgsrelationmanager.h
QgsDataSourceUri::host
QString host() const
Returns the host name stored in the URI.
Definition: qgsdatasourceuri.cpp:275
QgsFeatureIds
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:37
QgsMapLayer::minimumScale
double minimumScale() const
Returns the minimum map scale (i.e.
Definition: qgsmaplayer.cpp:904
QgsMapLayer::rendererChanged
void rendererChanged()
Signal emitted when renderer is changed.
QgsEditFormConfig
Contains configuration settings for an editor form.
Definition: qgseditformconfig.h:39
QgsVectorSimplifyMethod::forceLocalOptimization
bool forceLocalOptimization() const
Gets where the simplification executes, after fetch the geometries from provider, or when supported,...
Definition: qgsvectorsimplifymethod.h:94
QgsFeature::attributes
QgsAttributes attributes
Definition: qgsfeature.h:69
QgsVectorLayer::defaultValueDefinition
QgsDefaultValue defaultValueDefinition(int index) const
Returns the definition of the expression used when calculating the default value for a field.
Definition: qgsvectorlayer.cpp:4153
QgsMapLayer::maximumScale
double maximumScale() const
Returns the maximum map scale (i.e.
Definition: qgsmaplayer.cpp:888
QgsVectorLayer::removeJoin
bool removeJoin(const QString &joinLayerId)
Removes a vector layer join.
Definition: qgsvectorlayer.cpp:3916
QgsMapLayer::QgsVectorLayer
friend class QgsVectorLayer
Definition: qgsmaplayer.h:2129
QgsDiagramRenderer::writeXml
virtual void writeXml(QDomElement &layerElem, QDomDocument &doc, const QgsReadWriteContext &context) const =0
Writes diagram state to a DOM element.
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsVectorLayer::fieldConstraints
QgsFieldConstraints::Constraints fieldConstraints(int fieldIndex) const
Returns any constraints which are present for a specified field index.
Definition: qgsvectorlayer.cpp:5637
QgsExpression::evaluate
QVariant evaluate()
Evaluate the feature and return the result.
Definition: qgsexpression.cpp:350
QgsEditorWidgetSetup::isNull
bool isNull() const
Definition: qgseditorwidgetsetup.h:69
QgsVectorLayer::invertSelection
Q_INVOKABLE void invertSelection()
Selects not selected features and deselects selected ones.
Definition: qgsvectorlayer.cpp:617
QgsAbstractVectorLayerLabeling
Abstract base class - its implementations define different approaches to the labeling of a vector lay...
Definition: qgsvectorlayerlabeling.h:41
qgsxmlutils.h
QgsExpressionContextScope
Single scope for storing variables and functions for use within a QgsExpressionContext....
Definition: qgsexpressioncontext.h:113
QgsVectorLayer::raiseError
void raiseError(const QString &msg)
Signals an error related to this vector layer.
QgsVectorLayer::simplifyMethod
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings for fast rendering of features.
Definition: qgsvectorlayer.h:2311
QgsAction
Utility class that encapsulates an action based on vector attributes.
Definition: qgsaction.h:34
QgsMapLayerDependency::FromUser
@ FromUser
Definition: qgsmaplayerdependency.h:64
QgsVectorLayer::minimumValue
QVariant minimumValue(int index) const FINAL
Returns the minimum value for an attribute column or an invalid variant in case of error.
Definition: qgsvectorlayer.cpp:4370
qgsclipper.h
qgsstyle.h
QgsUnitTypes::RenderPixels
@ RenderPixels
Pixels.
Definition: qgsunittypes.h:171
QgsSymbolLayerUtils::decodeSldUom
static QgsUnitTypes::RenderUnit decodeSldUom(const QString &str, double *scaleFactor=nullptr)
Decodes a SLD unit of measure string to a render unit.
Definition: qgssymbollayerutils.cpp:740
QgsVectorLayerFeatureCounter::symbolFeatureCountMap
QHash< QString, long long > symbolFeatureCountMap() const
Returns the count for each symbol.
Definition: qgsvectorlayerfeaturecounter.cpp:122
QgsPalLayerSettings::upsidedownLabels
Qgis::UpsideDownLabelHandling upsidedownLabels
Controls whether upside down labels are displayed and how they are handled.
Definition: qgspallabeling.h:653
QgsVectorLayer::extent
QgsRectangle extent() const FINAL
Returns the extent of the layer.
Definition: qgsvectorlayer.cpp:894
QgsActionManager::readXml
bool readXml(const QDomNode &layer_node)
Reads the actions in in XML format.
Definition: qgsactionmanager.cpp:252
QgsRectangle::toString
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
Definition: qgsrectangle.cpp:127
QgsExpressionContext::appendScope
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
Definition: qgsexpressioncontext.cpp:494
QgsLinearlyInterpolatedDiagramRenderer
Definition: qgsdiagramrenderer.h:855
qgsvectorlayer.h
QgsVectorLayer::vectorLayerTypeFlags
Qgis::VectorLayerTypeFlags vectorLayerTypeFlags() const
Returns the vector layer type flags.
Definition: qgsvectorlayer.cpp:393
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
QgsMapLayer::Diagrams
@ Diagrams
Diagrams.
Definition: qgsmaplayer.h:168
QgsVectorLayer::beforeAddingExpressionField
void beforeAddingExpressionField(const QString &fieldName)
Will be emitted, when an expression field is going to be added to this vector layer.
QgsVectorLayerEditBuffer::committedAttributesDeleted
void committedAttributesDeleted(const QString &layerId, const QgsAttributeList &deletedAttributes)
Signals emitted after committing changes.
QgsAttributeTableConfig::isEmpty
bool isEmpty() const
Returns true if the configuration is empty, ie it contains no columns.
Definition: qgsattributetableconfig.cpp:25
QgsCurve::clone
QgsCurve * clone() const override=0
Clones the geometry by performing a deep copy.
QgsVectorLayer::getSelectedFeatures
QgsFeatureIterator getSelectedFeatures(QgsFeatureRequest request=QgsFeatureRequest()) const
Returns an iterator of the selected features.
Definition: qgsvectorlayer.cpp:3642
QgsVectorLayerProfileGenerator
Implementation of QgsAbstractProfileGenerator for vector layers.
Definition: qgsvectorlayerprofilegenerator.h:102
QgsMapLayer::dataChanged
void dataChanged()
Data of layer changed.
QgsProviderRegistry::loadStyle
QString loadStyle(const QString &providerKey, const QString &uri, QString &errCause)
Loads a layer style defined by uri.
Definition: qgsproviderregistry.cpp:697
QgsVectorLayer::readXml
bool readXml(const QDomNode &layer_node, QgsReadWriteContext &context) FINAL
Reads vector layer specific state from project file Dom node.
Definition: qgsvectorlayer.cpp:1550
QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition: qgspropertycollection.h:318
QgsVectorLayer::deselect
void deselect(QgsFeatureId featureId)
Deselects feature by its ID.
Definition: qgsvectorlayer.cpp:469
Qgis::SelectBehavior
SelectBehavior
Specifies how a selection should be applied.
Definition: qgis.h:777
QgsVectorLayerEditBufferGroup::commitChanges
bool commitChanges(QStringList &commitErrors, bool stopEditing=true)
Attempts to commit any changes to disk.
Definition: qgsvectorlayereditbuffergroup.cpp:115
QgsVectorLayer::LayerOptions
Setting options for loading vector layers.
Definition: qgsvectorlayer.h:408
qgstransaction.h
QgsVectorLayerEditBuffer::deletedFeatureIds
QgsFeatureIds deletedFeatureIds() const
Returns a list of deleted feature IDs which are not committed.
Definition: qgsvectorlayereditbuffer.h:185
QgsVectorLayer::diagramLayerSettings
const QgsDiagramLayerSettings * diagramLayerSettings() const
Definition: qgsvectorlayer.h:895
QgsSingleCategoryDiagramRenderer
Renders the diagrams for all features with the same settings.
Definition: qgsdiagramrenderer.h:820
QgsDataProvider::setTransformContext
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext)
Sets data coordinate transform context to transformContext.
Definition: qgsdataprovider.cpp:87
QgsMapLayer::publicSource
QString publicSource() const
Gets a version of the internal layer definition that has sensitive bits removed (for example,...
Definition: qgsmaplayer.cpp:292
QgsFeatureSource::FeatureAvailability
FeatureAvailability
Possible return value for hasFeatures() to determine if a source is empty.
Definition: qgsfeaturesource.h:50
QgsPathResolver::readPath
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
Definition: qgspathresolver.cpp:37
QgsFeature::setAttribute
bool setAttribute(int field, const QVariant &attr)
Sets an attribute's value by field index.
Definition: qgsfeature.cpp:262
QgsVectorLayer::displayExpressionChanged
void displayExpressionChanged()
Emitted when the display expression changes.
QgsMapLayer::source
QString source() const
Returns the source for the layer.
Definition: qgsmaplayer.cpp:300
QgsVectorLayer::editCommandDestroyed
void editCommandDestroyed()
Signal emitted, when an edit command is destroyed.
QgsVectorLayerElevationProperties::clone
QgsVectorLayerElevationProperties * clone() const override
Creates a clone of the properties.
Definition: qgsvectorlayerelevationproperties.cpp:143
QgsWkbTypes::LineGeometry
@ LineGeometry
Definition: qgswkbtypes.h:143
QgsMapLayer::setDataSource
void setDataSource(const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag=false)
Updates the data source of the layer.
Definition: qgsmaplayer.cpp:1803
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:2781
QgsWkbTypes::PointGeometry
@ PointGeometry
Definition: qgswkbtypes.h:142
QgsMapLayer::writeStyleManager
void writeStyleManager(QDomNode &layerNode, QDomDocument &doc) const
Write style manager's configuration (if exists). To be called by subclasses.
Definition: qgsmaplayer.cpp:809
QgsTextFormat::setBuffer
void setBuffer(const QgsTextBufferSettings &bufferSettings)
Sets the text's buffer settings.
Definition: qgstextformat.cpp:118
QgsPalLayerSettings::fieldName
QString fieldName
Name of field (or an expression) to use for label text.
Definition: qgspallabeling.h:354
QgsMapLayer::setScaleBasedVisibility
void setScaleBasedVisibility(bool enabled)
Sets whether scale based visibility is enabled for the layer.
Definition: qgsmaplayer.cpp:899
QgsMapLayer::Legend
@ Legend
Legend settings (since QGIS 3.16)
Definition: qgsmaplayer.h:175
QgsVectorSimplifyMethod::SimplifyAlgorithm
SimplifyAlgorithm
Types of local simplification algorithms that can be used.
Definition: qgsvectorsimplifymethod.h:67
QgsVectorSimplifyMethod::setSimplifyAlgorithm
void setSimplifyAlgorithm(SimplifyAlgorithm simplifyAlgorithm)
Sets the local simplification algorithm of the vector layer managed.
Definition: qgsvectorsimplifymethod.h:77
QgsVectorLayer::DeleteContext::project
QgsProject * project
Definition: qgsvectorlayer.h:518
QgsVectorLayer::setCoordinateSystem
void setCoordinateSystem()
Setup the coordinate system transformation for the layer.
Definition: qgsvectorlayer.cpp:3682
QgsRectangle::yMaximum
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:193
QgsVectorLayerEditUtils::splitFeatures
Q_DECL_DEPRECATED Qgis::GeometryOperationResult splitFeatures(const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
Splits features cut by the given line.
Definition: qgsvectorlayereditutils.cpp:286
QgsVectorLayer::mapTipTemplate
QString mapTipTemplate
Definition: qgsvectorlayer.h:397
QgsMapLayer::customProperty
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
Definition: qgsmaplayer.cpp:1999
QgsMapLayer::transformContext
QgsCoordinateTransformContext transformContext() const
Returns the layer data provider coordinate transform context or a default transform context if the la...
Definition: qgsmaplayer.cpp:951
qgsgeometry.h
QgsVectorLayerSimpleLabeling
Basic implementation of the labeling interface.
Definition: qgsvectorlayerlabeling.h:163
QgsConditionalLayerStyles::readXml
bool readXml(const QDomNode &node, const QgsReadWriteContext &context)
Reads the condition styles state from a DOM node.
Definition: qgsconditionalstyle.cpp:101
QgsFields::OriginExpression
@ OriginExpression
Field is calculated from an expression.
Definition: qgsfields.h:54
QgsAggregateCalculator::Aggregate
Aggregate
Available aggregates to calculate.
Definition: qgsaggregatecalculator.h:67
QgsFeatureRenderer
Definition: qgsrenderer.h:101
QgsProviderRegistry::saveStyle
bool saveStyle(const QString &providerKey, const QString &uri, const QString &qmlStyle, const QString &sldStyle, const QString &styleName, const QString &styleDescription, const QString &uiFileContent, bool useAsDefault, QString &errCause)
Saves a layer style to provider.
Definition: qgsproviderregistry.cpp:681
QgsVectorLayerFeatureCounter::cancel
void cancel() override
Notifies the task that it should terminate.
Definition: qgsvectorlayerfeaturecounter.cpp:115
QgsWkbTypes::GeometryType
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:140
QgsSymbolLayerUtils::fillFromSld
static bool fillFromSld(QDomElement &element, Qt::BrushStyle &brushStyle, QColor &color)
Definition: qgssymbollayerutils.cpp:2173
qgsexpressionnodeimpl.h
QgsVectorLayer::setAttributeTableConfig
void setAttributeTableConfig(const QgsAttributeTableConfig &attributeTableConfig)
Sets the attribute table configuration object.
Definition: qgsvectorlayer.cpp:5194
qgsvectorlayerelevationproperties.h
QgsFeatureIterator::nextFeature
bool nextFeature(QgsFeature &f)
Definition: qgsfeatureiterator.h:399
QgsVectorLayer::deleteFeatures
bool deleteFeatures(const QgsFeatureIds &fids, DeleteContext *context=nullptr)
Deletes a set of features from the layer (but does not commit it)
Definition: qgsvectorlayer.cpp:3420
QgsPropertyDefinition::Boolean
@ Boolean
Boolean value.
Definition: qgsproperty.h:53
QgsVectorLayerJoinBuffer::addJoin
bool addJoin(const QgsVectorLayerJoinInfo &joinInfo)
Joins another vector layer to this layer.
Definition: qgsvectorlayerjoinbuffer.cpp:64
QgsVectorLayer::listStylesInDatabase
virtual int listStylesInDatabase(QStringList &ids, QStringList &names, QStringList &descriptions, QString &msgError)
Lists all the style in db split into related to the layer and not related to.
Definition: qgsvectorlayer.cpp:5419
QgsPointSequence
QVector< QgsPoint > QgsPointSequence
Definition: qgsabstractgeometry.h:52
qgscurve.h
QgsVectorLayer::attributeDisplayName
QString attributeDisplayName(int index) const
Convenience function that returns the attribute alias if defined or the field name else.
Definition: qgsvectorlayer.cpp:3245
listStyles_t
int listStyles_t(const QString &uri, QStringList &ids, QStringList &names, QStringList &descriptions, QString &errCause)
Definition: qgsvectorlayer.cpp:138
c
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
Definition: porting_processing.dox:1
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsDiagramRenderer::readXml
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)=0
Reads diagram state from a DOM element.
QgsVectorLayer::setExcludeAttributesWfs
Q_DECL_DEPRECATED void setExcludeAttributesWfs(const QSet< QString > &att)
A set of attributes that are not advertised in WFS requests with QGIS server.
Definition: qgsvectorlayer.cpp:3296
QgsWeakRelation::Referencing
@ Referencing
The layer is referencing.
Definition: qgsweakrelation.h:48
QgsVectorLayer::destroyEditCommand
void destroyEditCommand()
Destroy active command and reverts all changes in it.
Definition: qgsvectorlayer.cpp:3888
qgsVariantEqual
bool qgsVariantEqual(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether they are equal, two NULL values are always treated a...
Definition: qgis.cpp:266
QgsFeatureSource::SpatialIndexUnknown
@ SpatialIndexUnknown
Spatial index presence cannot be determined, index may or may not exist.
Definition: qgsfeaturesource.h:189
QgsMapLayer::setName
void setName(const QString &name)
Set the display name of the layer.
Definition: qgsmaplayer.cpp:174
QgsVectorDataProvider::createLabeling
virtual QgsAbstractVectorLayerLabeling * createLabeling(const QVariantMap &configuration=QVariantMap()) const
Creates labeling settings, using provider backend specific information.
Definition: qgsvectordataprovider.cpp:759
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsFeature::hasGeometry
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Definition: qgsfeature.cpp:230
QgsRectangle::width
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Definition: qgsrectangle.h:223
QgsVectorLayer::DeleteContext::handledLayers
QList< QgsVectorLayer * > handledLayers(bool includeAuxiliaryLayers=true) const
Returns a list of all layers affected by the delete operation.
Definition: qgsvectorlayer.cpp:5852
QgsVectorLayer::committedAttributesDeleted
void committedAttributesDeleted(const QString &layerId, const QgsAttributeList &deletedAttributes)
Emitted when attributes are deleted from the provider if not in transaction mode.
QgsVectorLayerEditUtils::insertVertex
bool insertVertex(double x, double y, QgsFeatureId atFeatureId, int beforeVertex)
Insert a new vertex before the given vertex number, in the given ring, item (first number is index 0)...
Definition: qgsvectorlayereditutils.cpp:39
QgsRuleBasedLabeling::Rule::appendChild
void appendChild(QgsRuleBasedLabeling::Rule *rule)
add child rule, take ownership, sets this as parent
Definition: qgsrulebasedlabeling.cpp:180
QgsVectorLayer::geometryChanged
void geometryChanged(QgsFeatureId fid, const QgsGeometry &geometry)
Emitted whenever a geometry change is done in the edit buffer.
QgsVectorLayer::editFormConfig
QgsEditFormConfig editFormConfig
Definition: qgsvectorlayer.h:398
QgsVectorLayer::setReadOnly
bool setReadOnly(bool readonly=true)
Makes layer read-only (editing disabled) or not.
Definition: qgsvectorlayer.cpp:3744
QgsVectorDataProvider::maximumValue
QVariant maximumValue(int index) const override
Returns the maximum value of an attribute.
Definition: qgsvectordataprovider.cpp:447
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsRelationManager::referencingRelations
QList< QgsRelation > referencingRelations(const QgsVectorLayer *layer=nullptr, int fieldIdx=-2) const
Gets all relations where the specified layer (and field) is the referencing part (i....
Definition: qgsrelationmanager.cpp:119
QgsVectorLayer::editCommandStarted
void editCommandStarted(const QString &text)
Signal emitted when a new edit command has been started.
QgsVectorLayer::setExcludeAttributesWms
Q_DECL_DEPRECATED void setExcludeAttributesWms(const QSet< QString > &att)
A set of attributes that are not advertised in WMS requests with QGIS server.
Definition: qgsvectorlayer.cpp:3272
QgsMapLayerDependency
This class models dependencies with or between map layers.
Definition: qgsmaplayerdependency.h:37
QgsDataSourceUri::setConnection
void setConnection(const QString &aHost, const QString &aPort, const QString &aDatabase, const QString &aUsername, const QString &aPassword, SslMode sslmode=SslPrefer, const QString &authConfigId=QString())
Sets all connection related members at once.
Definition: qgsdatasourceuri.cpp:682
Qgis::GeometryOperationResult::Success
@ Success
Operation succeeded.
QgsFeatureRenderer::setReferenceScale
void setReferenceScale(double scale)
Sets the symbology reference scale.
Definition: qgsrenderer.h:482
QgsDataProvider::extent
virtual QgsRectangle extent() const =0
Returns the extent of the layer.
QgsVectorLayer::attributeTableConfig
QgsAttributeTableConfig attributeTableConfig() const
Returns the attribute table configuration object.
Definition: qgsvectorlayer.cpp:5184
QgsMapLayerDependency::DataDependency
@ DataDependency
Definition: qgsmaplayerdependency.h:70
QgsVectorLayer::getGeometry
QgsGeometry getGeometry(QgsFeatureId fid) const
Queries the layer for the geometry at the given id.
Definition: qgsvectorlayer.cpp:1060
QgsDefaultValue::expression
QString expression
Definition: qgsdefaultvalue.h:66
Qgis::VectorEditResult
VectorEditResult
Specifies the result of a vector layer edit operation.
Definition: qgis.h:791
QgsVectorLayerEditBuffer::changeAttributeValue
virtual bool changeAttributeValue(QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue=QVariant())
Changed an attribute value (but does not commit it)
Definition: qgsvectorlayereditbuffer.cpp:248
QgsTransaction::dirtied
void dirtied(const QString &sql, const QString &name)
Emitted if a sql query is executed and the underlying data is modified.
qgssettings.h
QgsVectorLayerEditBuffer::changedGeometries
QgsGeometryMap changedGeometries() const
Returns a map of features with changed geometries which are not committed.
Definition: qgsvectorlayereditbuffer.h:171
qgsEnumKeyToValue
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
Definition: qgis.h:2459
QgsWeakRelation::readXml
static QgsWeakRelation readXml(const QgsVectorLayer *layer, WeakRelationType type, const QDomNode &node, const QgsPathResolver resolver)
Returns a weak relation for the given layer.
Definition: qgsweakrelation.cpp:80
QgsTextBufferSettings::setSize
void setSize(double size)
Sets the size of the buffer.
Definition: qgstextbuffersettings.cpp:87
QgsMapLayer::Symbology
@ Symbology
Symbology.
Definition: qgsmaplayer.h:161
QgsMapLayer::recalculateExtents
void recalculateExtents() const
This is used to send a request that any mapcanvas using this layer update its extents.
QgsPalLayerSettings::maxCurvedCharAngleIn
double maxCurvedCharAngleIn
Maximum angle between inside curved label characters (valid range 20.0 to 60.0).
Definition: qgspallabeling.h:584
QgsVectorLayer::setFieldConfigurationFlag
void setFieldConfigurationFlag(int index, QgsField::ConfigurationFlag flag, bool active)
Sets the given configuration flag for the field at given index to be active or not.
Definition: qgsvectorlayer.cpp:5749
QgsFieldConstraints::ConstraintExpression
@ ConstraintExpression
Field has an expression constraint set. See constraintExpression().
Definition: qgsfieldconstraints.h:47
qgslayermetadataformatter.h
QgsVectorDataProvider::capabilitiesString
QString capabilitiesString() const
Returns the above in friendly format.
Definition: qgsvectordataprovider.cpp:252
QgsMapLayer::name
QString name
Definition: qgsmaplayer.h:76
QgsVectorLayer::select
void select(QgsFeatureId featureId)
Selects feature by its ID.
Definition: qgsvectorlayer.cpp:453
QgsStoredExpressionManager
Manages stored expressions regarding creation, modification and storing in the project.
Definition: qgsstoredexpressionmanager.h:93
QgsWkbTypes::UnknownGeometry
@ UnknownGeometry
Definition: qgswkbtypes.h:145
QgsVectorLayer::conditionalStyles
QgsConditionalLayerStyles * conditionalStyles() const
Returns the conditional styles that are set for this layer.
Definition: qgsvectorlayer.cpp:1047
Qgis::VertexMarkerType::Cross
@ Cross
Cross marker.
QgsExpression::quotedColumnRef
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
Definition: qgsexpression.cpp:68
QgsVectorLayer::setDependencies
bool setDependencies(const QSet< QgsMapLayerDependency > &layers) FINAL
Sets the list of dependencies.
Definition: qgsvectorlayer.cpp:5583
QgsPalLayerSettings::isExpression
bool isExpression
true if this label is made from a expression string, e.g., FieldName || 'mm'
Definition: qgspallabeling.h:360
qgsmaplayerlegend.h
QgsMapLayer::Relations
@ Relations
Relations.
Definition: qgsmaplayer.h:173
QgsDataSourceUri::database
QString database() const
Returns the database name stored in the URI.
Definition: qgsdatasourceuri.cpp:280
QgsVectorLayer::hasFeatures
FeatureAvailability hasFeatures() const FINAL
Determines if this vector layer has features.
Definition: qgsvectorlayer.cpp:3466
QgsFields::fieldOriginIndex
int fieldOriginIndex(int fieldIdx) const
Returns the field's origin index (its meaning is specific to each type of origin).
Definition: qgsfields.cpp:197
QgsField::constraints
QgsFieldConstraints constraints
Definition: qgsfield.h:63
QgsVectorLayerEditBuffer::commitChanges
virtual bool commitChanges(QStringList &commitErrors)
Attempts to commit any changes to disk.
Definition: qgsvectorlayereditbuffer.cpp:338
QgsWkbTypes::geometryType
static GeometryType geometryType(Type type) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
Definition: qgswkbtypes.h:968
QgsMapLayer::styleLoaded
void styleLoaded(QgsMapLayer::StyleCategories categories)
Emitted when a style has been loaded.
QgsVectorLayer::symbolFeatureCountMapChanged
void symbolFeatureCountMapChanged()
Emitted when the feature count for symbols on this layer has been recalculated.
QgsVectorLayer::beforeModifiedCheck
void beforeModifiedCheck() const
Emitted when the layer is checked for modifications. Use for last-minute additions.
QgsTextBufferSettings::setColor
void setColor(const QColor &color)
Sets the color for the buffer.
Definition: qgstextbuffersettings.cpp:117
QgsMapLayer::LayerConfiguration
@ LayerConfiguration
General configuration: identifiable, removable, searchable, display expression, read-only.
Definition: qgsmaplayer.h:160
QgsRelation
Definition: qgsrelation.h:42
QgsVectorLayerJoinBuffer::containsJoins
bool containsJoins() const
Quick way to test if there is any join at all.
Definition: qgsvectorlayerjoinbuffer.h:81
QgsAuxiliaryStorage
Class providing some utility methods to manage auxiliary storage.
Definition: qgsauxiliarystorage.h:291
QgsVectorLayer::countSymbolFeatures
QgsVectorLayerFeatureCounter * countSymbolFeatures(bool storeSymbolFids=false)
Count features for symbols.
Definition: qgsvectorlayer.cpp:827
QgsVectorLayerEditUtils::addPart
Q_DECL_DEPRECATED Qgis::GeometryOperationResult addPart(const QVector< QgsPointXY > &ring, QgsFeatureId featureId)
Adds a new part polygon to a multipart feature.
Definition: qgsvectorlayereditutils.cpp:186
QgsPalLayerSettings::offsetUnits
QgsUnitTypes::RenderUnit offsetUnits
Units for offsets of label.
Definition: qgspallabeling.h:550
QgsVectorLayer::supportsEditingChanged
void supportsEditingChanged()
Emitted when the read only state or the data provider of this layer is changed.
QgsWeakRelation::Referenced
@ Referenced
The layer is referenced.
Definition: qgsweakrelation.h:49
QgsDataSourceUri::uri
QString uri(bool expandAuthConfig=true) const
Returns the complete URI as a string.
Definition: qgsdatasourceuri.cpp:540
QgsVectorLayerJoinBuffer::deleteFeature
bool deleteFeature(QgsFeatureId fid, QgsVectorLayer::DeleteContext *context=nullptr) const
Deletes a feature from joined layers.
Definition: qgsvectorlayerjoinbuffer.cpp:693
QgsMapLayer::undoStack
QUndoStack * undoStack()
Returns pointer to layer's undo stack.
Definition: qgsmaplayer.cpp:1961
QgsExpression::needsGeometry
bool needsGeometry() const
Returns true if the expression uses feature geometry for some computation.
Definition: qgsexpression.cpp:270
QgsMapLayer::CustomProperties
@ CustomProperties
Custom properties (by plugins for instance)
Definition: qgsmaplayer.h:171
QgsMapLayer::setMinimumScale
void setMinimumScale(double scale)
Sets the minimum map scale (i.e.
Definition: qgsmaplayer.cpp:894
QgsVectorLayer::setEditFormConfig
void setEditFormConfig(const QgsEditFormConfig &editFormConfig)
Sets the editFormConfig (configuration) of the form used to represent this vector layer.
Definition: qgsvectorlayer.cpp:5160
QgsVectorLayer::storageType
QString storageType() const
Returns the permanent storage type for this layer as a friendly name.
Definition: qgsvectorlayer.cpp:369
QgsTextFormat::setSizeUnit
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the size of rendered text.
Definition: qgstextformat.cpp:269
QgsVectorLayer::splitFeatures
Q_DECL_DEPRECATED Qgis::GeometryOperationResult splitFeatures(const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
Splits features cut by the given line.
Definition: qgsvectorlayer.cpp:1428
QgsVectorLayer::subsetString
QString subsetString
Definition: qgsvectorlayer.h:395
QgsGeometry::boundingBox
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Definition: qgsgeometry.cpp:1080
QgsVectorLayer::selectByRect
Q_INVOKABLE void selectByRect(QgsRectangle &rect, Qgis::SelectBehavior behavior=Qgis::SelectBehavior::SetSelection)
Selects features found within the search rectangle (in layer's coordinates)
Definition: qgsvectorlayer.cpp:485
QgsTransaction::createSavepoint
QString createSavepoint(QString &error)
creates a save point returns empty string on error returns the last created savepoint if it's not dir...
Definition: qgstransaction.cpp:221
QgsAttributes
A vector of attributes. Mostly equal to QVector<QVariant>.
Definition: qgsattributes.h:57
QgsVectorSimplifyMethod::simplifyHints
SimplifyHints simplifyHints() const
Gets the simplification hints of the vector layer managed.
Definition: qgsvectorsimplifymethod.h:64
QgsVectorDataProvider
This is the base class for vector data providers.
Definition: qgsvectordataprovider.h:58
Qgis::SelectBehavior::SetSelection
@ SetSelection
Set selection, removing any existing selection.
QgsFeature::fields
QgsFields fields
Definition: qgsfeature.h:70
qgsexception.h
QgsMapLayer::project
QgsProject * project() const
Returns the parent project if this map layer is added to a project.
Definition: qgsmaplayer.cpp:2237
QgsField::displayName
QString displayName() const
Returns the name to use when displaying this field.
Definition: qgsfield.cpp:89
QgsVectorLayer::deleteAttribute
virtual bool deleteAttribute(int attr)
Deletes an attribute field (but does not commit it).
Definition: qgsvectorlayer.cpp:3306
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsVectorLayer::boundingBoxOfSelected
Q_INVOKABLE QgsRectangle boundingBoxOfSelected() const
Returns the bounding box of the selected features. If there is no selection, QgsRectangle(0,...
Definition: qgsvectorlayer.cpp:730
QgsSettings::NoSection
@ NoSection
Definition: qgssettings.h:69
QgsVectorLayer::featureRendererGenerators
QList< const QgsFeatureRendererGenerator * > featureRendererGenerators() const
Returns a list of the feature renderer generators owned by the layer.
Definition: qgsvectorlayer.cpp:3844
QgsPropertyCollection::setProperty
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
Definition: qgspropertycollection.cpp:187
QgsVectorLayer::deleteFeature
bool deleteFeature(QgsFeatureId fid, DeleteContext *context=nullptr)
Deletes a feature from the layer (but does not commit it).
Definition: qgsvectorlayer.cpp:3405
QgsDataProvider::leaveUpdateMode
virtual bool leaveUpdateMode()
Leave update mode.
Definition: qgsdataprovider.h:488
QgsExpression::isField
bool isField() const
Checks whether an expression consists only of a single field reference.
Definition: qgsexpression.cpp:1360
QgsDataProvider::subsetString
virtual QString subsetString() const
Returns the subset definition string (typically sql) currently in use by the layer and used by the pr...
Definition: qgsdataprovider.h:282
QgsVectorLayer::aggregate
QVariant aggregate(QgsAggregateCalculator::Aggregate aggregate, const QString &fieldOrExpression, const QgsAggregateCalculator::AggregateParameters &parameters=QgsAggregateCalculator::AggregateParameters(), QgsExpressionContext *context=nullptr, bool *ok=nullptr, QgsFeatureIds *fids=nullptr, QgsFeedback *feedback=nullptr, QString *error=nullptr) const
Calculates an aggregated value from the layer's features.
Definition: qgsvectorlayer.cpp:4543
loadStyle_t
QString loadStyle_t(const QString &uri, QString &errCause)
Definition: qgsvectorlayer.cpp:133
QgsVectorLayer::readSymbology
bool readSymbology(const QDomNode &layerNode, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) FINAL
Definition: qgsvectorlayer.cpp:2194
qgsvectorlayerlabeling.h
QgsActionManager
Storage and management of actions associated with a layer.
Definition: qgsactionmanager.h:52
Qgis::LabelPlacement::PerimeterCurved
@ PerimeterCurved
Arranges candidates following the curvature of a polygon's boundary. Applies to polygon layers only.
QgsVectorLayer::writeSymbology
bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const FINAL
Definition: qgsvectorlayer.cpp:2705
QgsDataProvider::layerMetadata
virtual QgsLayerMetadata layerMetadata() const
Returns layer metadata collected from the provider's source.
Definition: qgsdataprovider.h:573
qgsgeometryoptions.h
QgsVectorLayer::isModified
bool isModified() const override
Returns true if the provider has been modified since the last commit.
Definition: qgsvectorlayer.cpp:3763
QgsVectorLayerJoinBuffer::changeAttributeValue
bool changeAttributeValue(QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue=QVariant())
Changes attribute value in joined layers.
Definition: qgsvectorlayerjoinbuffer.cpp:646
QgsExpression::hasParserError
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
Definition: qgsexpression.cpp:206
QgsVectorLayer::updatedFields
void updatedFields()
Emitted whenever the fields available from this layer have been changed.
QgsVectorLayer::getFeature
QgsFeature getFeature(QgsFeatureId fid) const
Queries the layer for the feature with the given id.
Definition: qgsvectorlayer.h:1187
QgsFieldConstraints::ConstraintOriginProvider
@ ConstraintOriginProvider
Constraint was set at data provider.
Definition: qgsfieldconstraints.h:57
QgsVectorLayer::attributeAdded
void attributeAdded(int idx)
Will be emitted, when a new attribute has been added to this vector layer.
QgsVectorLayer::selectedFeatureCount
int selectedFeatureCount() const
Returns the number of features that are selected in this layer.
Definition: qgsvectorlayer.cpp:3616
QgsVectorLayerEditUtils
Definition: qgsvectorlayereditutils.h:31
QgsSettings::enumValue
T enumValue(const QString &key, const T &defaultValue, const Section section=NoSection)
Returns the setting value for a setting based on an enum.
Definition: qgssettings.h:282
qgslogger.h
qgsvectorlayerprofilegenerator.h
QgsDiagramLayerSettings::PositionX
@ PositionX
X-coordinate data defined diagram position.
Definition: qgsdiagramrenderer.h:95
QgsFieldConstraints::ConstraintStrength
ConstraintStrength
Strength of constraints.
Definition: qgsfieldconstraints.h:64
QgsVectorLayer::deleteAttributes
bool deleteAttributes(const QList< int > &attrs)
Deletes a list of attribute fields (but does not commit it)
Definition: qgsvectorlayer.cpp:3323
QgsExpression::expressionToLayerFieldIndex
static int expressionToLayerFieldIndex(const QString &expression, const QgsVectorLayer *layer)
Attempts to resolve an expression to a field index from the given layer.
Definition: qgsexpression.cpp:1365
QgsDefaultValue::applyOnUpdate
bool applyOnUpdate
Definition: qgsdefaultvalue.h:67
QgsTextFormat::setSize
void setSize(double size)
Sets the size for rendered text.
Definition: qgstextformat.cpp:291
QgsLayerMetadataFormatter::extentSectionHtml
QString extentSectionHtml(const bool showSpatialExtent=true) const
Formats the "Extents" section according to a metadata object (extent and temporal).
Definition: qgslayermetadataformatter.cpp:110
QgsCurve::isClosed
virtual bool isClosed() const SIP_HOLDGIL
Returns true if the curve is closed.
Definition: qgscurve.cpp:53
QgsFields::lookupField
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
Definition: qgsfields.cpp:349
QgsRenderContext::rendererScale
double rendererScale() const
Returns the renderer map scale.
Definition: qgsrendercontext.h:344
QgsVectorLayer::allowCommit
bool allowCommit() const
Controls, if the layer is allowed to commit changes.
Definition: qgsvectorlayer.cpp:5814
Qgis::LabelPlacement::Line
@ Line
Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon'...
QgsMapLayer::setValid
void setValid(bool valid)
Sets whether layer is valid or not.
Definition: qgsmaplayer.cpp:2061
QgsField::editorWidgetSetup
QgsEditorWidgetSetup editorWidgetSetup() const
Gets the editor widget setup for the field.
Definition: qgsfield.cpp:602
QgsVectorLayer::createExpressionContext
QgsExpressionContext createExpressionContext() const FINAL
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Definition: qgsvectorlayer.cpp:5203
QgsFields::at
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
Definition: qgsfields.cpp:163
QgsExpressionFieldBuffer::renameExpression
void renameExpression(int index, const QString &name)
Renames an expression field at a given index.
Definition: qgsexpressionfieldbuffer.cpp:33
QgsExpression
Class for parsing and evaluation of expressions (formerly called "search strings")....
Definition: qgsexpression.h:102
QgsVectorLayer::LayerOptions::fallbackWkbType
QgsWkbTypes::Type fallbackWkbType
Fallback geometry type.
Definition: qgsvectorlayer.h:459
QgsVectorLayer::addPart
Q_DECL_DEPRECATED Qgis::GeometryOperationResult addPart(const QList< QgsPointXY > &ring)
Adds a new part polygon to a multipart feature.
Definition: qgsvectorlayer.cpp:1330
QgsVectorLayer::updateFeature
bool updateFeature(QgsFeature &feature, bool skipDefaultValues=false)
Updates an existing feature in the layer, replacing the attributes and geometry for the feature with ...
Definition: qgsvectorlayer.cpp:1096
QgsVectorLayer::displayExpression
QString displayExpression
Definition: qgsvectorlayer.h:396
Qgis::SelectBehavior::RemoveFromSelection
@ RemoveFromSelection
Remove from current selection.
QgsVectorDataProvider::uniqueStringsMatching
virtual QStringList uniqueStringsMatching(int index, const QString &substring, int limit=-1, QgsFeedback *feedback=nullptr) const
Returns unique string values of an attribute which contain a specified subset string.
Definition: qgsvectordataprovider.cpp:464
QgsVectorLayer::sourceCrs
QgsCoordinateReferenceSystem sourceCrs() const FINAL
Returns the coordinate reference system for features in the source.
Definition: qgsvectorlayer.cpp:407
QgsXmlUtils::writeVariant
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
Definition: qgsxmlutils.cpp:106
QgsGeometry::type
QgsWkbTypes::GeometryType type
Definition: qgsgeometry.h:128
QgsVectorLayerEditBuffer::updateFields
void updateFields(QgsFields &fields)
Updates fields.
Definition: qgsvectorlayereditbuffer.cpp:61
QgsMapLayer::mBlockStyleChangedSignal
int mBlockStyleChangedSignal
If non-zero, the styleChanged signal should not be emitted.
Definition: qgsmaplayer.h:2008
QgsFeatureIterator
Wrapper for iterator of features from vector data provider or vector layer.
Definition: qgsfeatureiterator.h:289
QgsVectorLayer::displayField
QString displayField() const
This is a shorthand for accessing the displayExpression if it is a simple field.
Definition: qgsvectorlayer.cpp:3688
QgsVectorLayer::clone
QgsVectorLayer * clone() const override
Returns a new instance equivalent to this one.
Definition: qgsvectorlayer.cpp:265
QgsFeatureRenderer::loadSld
static QgsFeatureRenderer * loadSld(const QDomNode &node, QgsWkbTypes::GeometryType geomType, QString &errorMessage)
Create a new renderer according to the information contained in the UserStyle element of a SLD style ...
Definition: qgsrenderer.cpp:222
QgsVectorLayer::geometryType
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
Definition: qgsvectorlayer.cpp:720
QgsVectorLayer::addFeature
bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) FINAL
Adds a single feature to the sink.
Definition: qgsvectorlayer.cpp:1070
qgsfeedback.h
QgsVectorLayer::modifySelection
Q_INVOKABLE void modifySelection(const QgsFeatureIds &selectIds, const QgsFeatureIds &deselectIds)
Modifies the current selection on this layer.
Definition: qgsvectorlayer.cpp:602
QgsAbstractVectorLayerLabeling::accept
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the labeling...
Definition: qgsvectorlayerlabeling.cpp:44
QgsProviderRegistry::instance
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
Definition: qgsproviderregistry.cpp:73
MathUtils::angle
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Definition: MathUtils.cpp:786
QgsLayerMetadataFormatter::accessSectionHtml
QString accessSectionHtml() const
Formats the "Access" section according to a metadata object.
Definition: qgslayermetadataformatter.cpp:27
QgsField::ConfigurationFlag::HideFromWfs
@ HideFromWfs
Field is not available if layer is served as WFS from QGIS server.
QgsMapLayerDependency::PresenceDependency
@ PresenceDependency
Definition: qgsmaplayerdependency.h:69
QgsMapLayer::exportSldStyle
virtual void exportSldStyle(QDomDocument &doc, QString &errorMsg) const
Export the properties of this layer as SLD style in a QDomDocument.
Definition: qgsmaplayer.cpp:1581
QgsRenderContext::useRenderingOptimization
bool useRenderingOptimization() const
Returns true if the rendering optimization (geometry simplification) can be executed.
Definition: qgsrendercontext.cpp:340
QgsMapLayer::loadNamedStyle
virtual QString loadNamedStyle(const QString &uri, bool &resultFlag, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Retrieve a named style for this layer if one exists (either as a .qml file on disk or as a record in ...
Definition: qgsmaplayer.cpp:1116
QgsVectorLayerJoinBuffer::joinedFieldsChanged
void joinedFieldsChanged()
Emitted whenever the list of joined fields changes (e.g.
QgsMapLayer::setProviderType
void setProviderType(const QString &providerType)
Sets the providerType (provider key)
Definition: qgsmaplayer.cpp:2192
QgsVectorLayer::resolveReferences
void resolveReferences(QgsProject *project) FINAL
Resolves references to other layers (kept as layer IDs after reading XML) into layer objects.
Definition: qgsvectorlayer.cpp:2187
QgsVectorLayer::createMapRenderer
QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext) FINAL
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context.
Definition: qgsvectorlayer.cpp:426
QgsVectorLayerEditBuffer::changeAttributeValues
virtual bool changeAttributeValues(QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues)
Changes values of attributes (but does not commit it).
Definition: qgsvectorlayereditbuffer.cpp:230
qgscoordinatereferencesystem.h
QgsVectorLayerJoinBuffer::removeJoin
bool removeJoin(const QString &joinLayerId)
Removes a vector layer join.
Definition: qgsvectorlayerjoinbuffer.cpp:104
QgsFeatureRequest::setFlags
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
Definition: qgsfeaturerequest.cpp:222
Qgis::GeometryOperationResult::LayerNotEditable
@ LayerNotEditable
Cannot edit layer.
QgsLabelPlacementSettings::setOverlapHandling
void setOverlapHandling(Qgis::LabelOverlapHandling handling)
Sets the technique used to handle overlapping labels.
Definition: qgslabelplacementsettings.h:48
Qgis::GeometryOperationResult::InvalidInputGeometryType
@ InvalidInputGeometryType
The input geometry (ring, part, split line, etc.) has not the correct geometry type.
QgsExpression::expression
QString expression() const
Returns the original, unmodified expression string.
Definition: qgsexpression.cpp:60
QgsEditFormConfig::readXml
void readXml(const QDomNode &node, QgsReadWriteContext &context)
Read XML information Deserialize on project load.
Definition: qgseditformconfig.cpp:352
QgsVectorLayer::expressionField
QString expressionField(int index) const
Returns the expression used for a given expression field.
Definition: qgsvectorlayer.cpp:3945
QgsPathResolver
Resolves relative paths into absolute paths and vice versa. Used for writing.
Definition: qgspathresolver.h:31
QgsVectorLayer::selectByExpression
Q_INVOKABLE void selectByExpression(const QString &expression, Qgis::SelectBehavior behavior=Qgis::SelectBehavior::SetSelection, QgsExpressionContext *context=nullptr)
Selects matching features using an expression.
Definition: qgsvectorlayer.cpp:507
QgsAttributeTableConfig::readXml
void readXml(const QDomNode &node)
Deserialize to XML on layer load.
Definition: qgsattributetableconfig.cpp:144
QgsVectorLayerEditBuffer::addedFeatures
QgsFeatureMap addedFeatures() const
Returns a map of new features which are not committed.
Definition: qgsvectorlayereditbuffer.h:116
QgsVectorLayer::LayerOptions::skipCrsValidation
bool skipCrsValidation
Controls whether the layer is allowed to have an invalid/unknown CRS.
Definition: qgsvectorlayer.h:487
QgsRectangle::isNull
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
Definition: qgsrectangle.h:479
QgsVectorLayerElevationProperties::setDefaultsFromLayer
void setDefaultsFromLayer(QgsMapLayer *layer) override
Sets default properties based on sensible choices for the given map layer.
Definition: qgsvectorlayerelevationproperties.cpp:117
QgsVectorDataProvider::CreateLabeling
@ CreateLabeling
Provider can set labeling settings using backend-specific formatting information. Since QGIS 3....
Definition: qgsvectordataprovider.h:96
QgsMapLayer::Actions
@ Actions
Actions.
Definition: qgsmaplayer.h:166
qgsproject.h
QgsField::ConfigurationFlag::HideFromWms
@ HideFromWms
Field is not available if layer is served as WMS from QGIS server.
QgsMapLayer::setLegend
void setLegend(QgsMapLayerLegend *legend)
Assign a legend controller to the map layer.
Definition: qgsmaplayer.cpp:2070
QgsFields::indexFromName
int indexFromName(const QString &fieldName) const
Gets the field index from the field name.
Definition: qgsfields.cpp:202
QgsVectorLayer::fieldConfigurationFlags
QgsField::ConfigurationFlags fieldConfigurationFlags(int index) const
Returns the configuration flags of the field at given index.
Definition: qgsvectorlayer.cpp:5758
QgsVectorLayer::loadDefaultStyle
QString loadDefaultStyle(bool &resultFlag) FINAL
Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record...
Definition: qgsvectorlayer.cpp:1754
Qgis::LabelPlacement::AroundPoint
@ AroundPoint
Arranges candidates in a circle around a point (or centroid of a polygon). Applies to point or polygo...
qgsvectorlayereditbuffer.h
QgsVectorLayerUtils::guessFriendlyIdentifierField
static QString guessFriendlyIdentifierField(const QgsFields &fields, bool *foundFriendly=nullptr)
Given a set of fields, attempts to pick the "most useful" field for user-friendly identification of f...
Definition: qgsvectorlayerutils.cpp:1148
QgsVectorLayer::setProviderEncoding
void setProviderEncoding(const QString &encoding)
Sets the text encoding of the data provider.
Definition: qgsvectorlayer.cpp:703
QgsVectorLayer::QgsVectorLayerFeatureSource
friend class QgsVectorLayerFeatureSource
Definition: qgsvectorlayer.h:3010
QgsVectorLayerEditUtils::splitParts
Q_DECL_DEPRECATED Qgis::GeometryOperationResult splitParts(const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
Splits parts cut by the given line.
Definition: qgsvectorlayereditutils.cpp:416
QgsFields::OriginJoin
@ OriginJoin
Field comes from a joined layer (originIndex / 1000 = index of the join, originIndex % 1000 = index w...
Definition: qgsfields.h:52
QgsVectorLayerEditBuffer::addFeatures
virtual bool addFeatures(QgsFeatureList &features)
Insert a copy of the given features into the layer (but does not commit it)
Definition: qgsvectorlayereditbuffer.cpp:146
QgsVectorLayer::setFieldAlias
void setFieldAlias(int index, const QString &aliasString)
Sets an alias (a display name) for attributes to display in dialogs.
Definition: qgsvectorlayer.cpp:3224
QgsVectorDataProvider::wkbType
QgsWkbTypes::Type wkbType() const override=0
Returns the geometry type which is returned by this layer.
qgspointxy.h
qgsvectorlayereditpassthrough.h
QgsVectorLayerJoinBuffer::resolveReferences
void resolveReferences(QgsProject *project)
Resolves layer IDs of joined layers using given project's available layers.
Definition: qgsvectorlayerjoinbuffer.cpp:385
QgsDataProvider::isValid
virtual bool isValid() const =0
Returns true if this is a valid layer.
QgsDataProvider::updateExtents
virtual void updateExtents()
Update the extents of the layer.
Definition: qgsdataprovider.h:250
QgsVectorLayer::loadAuxiliaryLayer
bool loadAuxiliaryLayer(const QgsAuxiliaryStorage &storage, const QString &key=QString())
Loads the auxiliary layer for this vector layer.
Definition: qgsvectorlayer.cpp:5468
QgsVectorLayer::labelsEnabled
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
Definition: qgsvectorlayer.cpp:789
QgsMapLayerLegend::readXml
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads configuration from a DOM element previously written by writeXml()
Definition: qgsmaplayerlegend.cpp:41
QgsProjectTranslator::translate
virtual QString translate(const QString &context, const QString &sourceText, const char *disambiguation=nullptr, int n=-1) const =0
The derived translate() translates with QTranslator and qm file the sourceText.
QgsVectorLayerRenderer
Implementation of threaded rendering for vector layers.
Definition: qgsvectorlayerrenderer.h:58
QgsLayerMetadataFormatter::identificationSectionHtml
QString identificationSectionHtml() const
Formats the "Identification" section according to a metadata object.
Definition: qgslayermetadataformatter.cpp:180
QgsVectorLayer::committedFeaturesRemoved
void committedFeaturesRemoved(const QString &layerId, const QgsFeatureIds &deletedFeatureIds)
Emitted when features are deleted from the provider if not in transaction mode.
QgsFieldConstraints::constraintOrigin
ConstraintOrigin constraintOrigin(Constraint constraint) const
Returns the origin of a field constraint, or ConstraintOriginNotSet if the constraint is not present ...
Definition: qgsfieldconstraints.cpp:19
QgsVectorLayer::addFeatureRendererGenerator
void addFeatureRendererGenerator(QgsFeatureRendererGenerator *generator)
Adds a new feature renderer generator to the layer.
Definition: qgsvectorlayer.cpp:3824
QgsAbstractPropertyCollection::writeXml
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
Definition: qgspropertycollection.cpp:99
QgsVectorLayer::committedGeometriesChanges
void committedGeometriesChanges(const QString &layerId, const QgsGeometryMap &changedGeometries)
Emitted when geometry changes are saved to the provider if not in transaction mode.
QgsVectorLayer::setFeatureBlendMode
void setFeatureBlendMode(QPainter::CompositionMode blendMode)
Sets the blending mode used for rendering each feature.
Definition: qgsvectorlayer.cpp:4595
getStyleById_t
QString getStyleById_t(const QString &uri, QString styleID, QString &errCause)
Definition: qgsvectorlayer.cpp:146
Qgis::TransactionMode::BufferedGroups
@ BufferedGroups
Buffered transactional editing means that all editable layers in the buffered transaction group are t...
QgsFields::names
QStringList names() const
Returns a list with field names.
Definition: qgsfields.cpp:143
QgsFields::indexOf
int indexOf(const QString &fieldName) const
Gets the field index from the field name.
Definition: qgsfields.cpp:207
qgssimplifymethod.h
QgsReadWriteContext::pathResolver
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
Definition: qgsreadwritecontext.cpp:47
QgsVectorLayer::setSubsetString
virtual bool setSubsetString(const QString &subset)
Sets the string (typically sql) used to define a subset of the layer.
Definition: qgsvectorlayer.cpp:1002
QgsVectorLayer::attributeAliases
QgsStringMap attributeAliases() const
Returns a map of field name to attribute alias.
Definition: qgsvectorlayer.cpp:3253
QgsVectorLayer::writeStyle
bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const FINAL
Definition: qgsvectorlayer.cpp:2894
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28
QgsVectorLayer::editCommandEnded
void editCommandEnded()
Signal emitted, when an edit command successfully ended.
QgsAbstractVectorLayerLabeling::save
virtual QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) const =0
Returns labeling configuration as XML element.
qgsmessagelog.h
QgsDataProvider::crs
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
QgsVectorLayer::setSimplifyMethod
void setSimplifyMethod(const QgsVectorSimplifyMethod &simplifyMethod)
Sets the simplification settings for fast rendering of features.
Definition: qgsvectorlayer.h:2305
QgsField::alias
QString alias
Definition: qgsfield.h:61
QgsExpressionContext::setFeature
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Definition: qgsexpressioncontext.cpp:525
QgsVectorLayer::renderer
QgsFeatureRenderer * renderer()
Returns the feature renderer used for rendering the features in the layer in 2D map views.
Definition: qgsvectorlayer.h:903
QgsVectorLayer::addAttribute
bool addAttribute(const QgsField &field)
Add an attribute field (but does not commit it) returns true if the field was added.
Definition: qgsvectorlayer.cpp:3161
QgsMapLayer::error
virtual QgsError error() const
Gets current status error.
Definition: qgsmaplayer.cpp:2014
QgsXmlUtils::readRectangle
static QgsRectangle readRectangle(const QDomElement &element)
Definition: qgsxmlutils.cpp:39
QgsVectorLayer::readCustomSymbology
void readCustomSymbology(const QDomElement &element, QString &errorMessage)
Signal emitted whenever the symbology (QML-file) for this layer is being read.
QgsVectorLayer::addJoin
bool addJoin(const QgsVectorLayerJoinInfo &joinInfo)
Joins another vector layer to this layer.
Definition: qgsvectorlayer.cpp:3910
QgsField
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:50
QgsVectorLayer::elevationProperties
QgsMapLayerElevationProperties * elevationProperties() override
Returns the layer's elevation properties.
Definition: qgsvectorlayer.cpp:691
Qgis::LabelPlacement::Curved
@ Curved
Arranges candidates following the curvature of a line feature. Applies to line layers only.
QgsAttributeTableConfig::update
void update(const QgsFields &fields)
Update the configuration with the given fields.
Definition: qgsattributetableconfig.cpp:55
QgsMapLayer::type
QgsMapLayerType type
Definition: qgsmaplayer.h:80
QgsVectorLayer::featureAdded
void featureAdded(QgsFeatureId fid)
Emitted when a new feature has been added to the layer.