42#include <QRegularExpression>
45using namespace Qt::StringLiterals;
49 std::unique_ptr<QgsExpression> expression;
56 expression = std::make_unique<QgsExpression>( fieldOrExpression );
59 if ( expression->hasParserError() || !expression->prepare( &context ) )
68 lst.insert( fieldOrExpression );
70 lst = expression->referencedColumns();
88 QList<QVariant> values;
92 std::unique_ptr<QgsExpression> expression;
99 expression = std::make_unique<QgsExpression>( fieldOrExpression );
109 QVariant v = expression->evaluate( &context );
132 if ( attrNum != -1 && !selectedOnly )
147 std::unique_ptr<QgsExpression> expression;
152 expression = std::make_unique<QgsExpression>( fieldOrExpression );
162 newValue = expression->evaluate( &context );
169 if ( !newValue.isNull() )
188 QList<double> values;
193 const QList<QVariant> variantValues =
getValues( layer, fieldOrExpression, ok, selectedOnly, feedback );
198 for (
const QVariant &value : variantValues )
200 double val = value.toDouble( &convertOk );
224 if ( fieldIndex < 0 || fieldIndex >= fields.
count() )
237 int srcFieldIndex = -1;
243 fieldIndex = srcFieldIndex;
252 QString fieldName = fields.
at( fieldIndex ).
name();
260 int limit = ignoreIds.size() + 1;
269 if ( ignoreIds.contains( feat.
id() ) )
285 if ( fieldIndex < 0 || fieldIndex >= fields.
count() )
293 QVariant newVar( maxVal.toLongLong() + 1 );
301 switch ( field.
type() )
303 case QMetaType::Type::QString:
306 if ( seed.isValid() )
307 base = seed.toString();
309 if ( !base.isEmpty() )
312 const thread_local QRegularExpression rx( u
"(.*)_\\d+"_s );
313 QRegularExpressionMatch match = rx.match( base );
314 if ( match.hasMatch() )
316 base = match.captured( 1 );
328 base = f.
attribute( fieldIndex ).toString();
335 if ( !base.isEmpty() && !vals.contains( base ) )
338 for (
int i = 1; i < 10000; ++i )
340 QString testVal = base +
'_' + QString::number( i );
341 if ( !vals.contains( testVal ) )
365 if ( fieldIndex < 0 || fieldIndex >= fields.
count() )
372 QVariant maxVal = existingValues.isEmpty()
374 : *std::max_element( existingValues.begin(), existingValues.end(), [](
const QVariant &a,
const QVariant &b ) { return a.toLongLong() < b.toLongLong(); } );
375 QVariant newVar( maxVal.toLongLong() + 1 );
383 switch ( field.
type() )
385 case QMetaType::Type::QString:
388 if ( seed.isValid() )
389 base = seed.toString();
391 if ( !base.isEmpty() )
394 const thread_local QRegularExpression rx( u
"(.*)_\\d+"_s );
395 QRegularExpressionMatch match = rx.match( base );
396 if ( match.hasMatch() )
398 base = match.captured( 1 );
405 base = existingValues.isEmpty() ? QString() : existingValues.constBegin()->toString();
410 for (
const auto &v : std::as_const( existingValues ) )
412 if ( v.toString().startsWith( base ) )
413 vals.push_back( v.toString() );
417 if ( !base.isEmpty() && !vals.contains( base ) )
420 for (
int i = 1; i < 10000; ++i )
422 QString testVal = base +
'_' + QString::number( i );
423 if ( !vals.contains( testVal ) )
445 if ( attributeIndex < 0 || attributeIndex >= layer->
fields().
count() )
463 if ( attributeIndex < 0 || attributeIndex >= layer->
fields().
count() )
468 const QVariant value = feature.
attribute( attributeIndex );
484 valid = expr.
evaluate( &context ).toBool();
492 errors << QObject::tr(
"evaluation error: %1" ).arg( expr.
evalErrorString() );
500 bool notNullConstraintViolated {
false };
516 valid = valid && !isNullOrUnset;
520 errors << QObject::tr(
"value is NULL" );
521 notNullConstraintViolated =
true;
527 if ( !notNullConstraintViolated )
543 valid = valid && !alreadyExists;
547 errors << QObject::tr(
"value is not unique" );
559 return features.isEmpty() ?
QgsFeature() : features.first();
568 result.reserve( featuresData.length() );
571 std::unique_ptr< QgsExpressionContext > tempContext;
576 evalContext = tempContext.get();
582 QMap<int, QSet<QVariant>> uniqueValueCache;
584 auto checkUniqueValue = [&](
const int fieldIdx,
const QVariant &value ) {
585 if ( !uniqueValueCache.contains( fieldIdx ) )
590 std::unique_ptr<QgsVectorLayer> unfilteredClone { layer->
clone() };
591 unfilteredClone->setSubsetString( QString() );
592 uniqueValueCache[fieldIdx] = unfilteredClone->uniqueValues( fieldIdx );
596 uniqueValueCache[fieldIdx] = layer->
uniqueValues( fieldIdx );
599 return uniqueValueCache[fieldIdx].contains( value );
602 for (
const auto &fd : std::as_const( featuresData ) )
612 QList<int> deferredFieldIndexes;
613 QList<int> fieldIndexes( fields.
count() );
614 std::iota( fieldIndexes.begin(), fieldIndexes.end(), 0 );
615 while ( !fieldIndexes.isEmpty() )
617 const int idx = fieldIndexes.takeFirst();
620 bool checkUnique =
true;
625 if ( fd.attributes().contains( idx ) )
627 v = fd.attributes().value( idx );
636 if ( defaultValueExpression.
referencedColumns().isEmpty() || deferredFieldIndexes.contains( idx ) )
641 v = layer->
defaultValue( idx, newFeature, evalContext );
646 deferredFieldIndexes << idx;
658 if ( !providerDefault.isEmpty() )
682 v = fd.attributes().value( idx );
690 if ( checkUnique && hasUniqueConstraint )
692 if ( checkUniqueValue( idx, v ) )
696 if ( uniqueValue.isValid() )
700 if ( hasUniqueConstraint )
702 uniqueValueCache[idx].insert( v );
707 result.append( newFeature );
729 for (
int fieldIdx = 0; fieldIdx < fieldCount; ++fieldIdx )
739 attributeMap.insert( fieldIdx, feature.
attribute( fieldIdx ) );
752 referencedLayersBranch << layer;
754 const int effectiveMaxDepth = maxDepth > 0 ? maxDepth : 100;
765 while ( relatedFeaturesIt.
nextFeature( childFeature ) )
768 relation.referencingLayer()->startEditing();
770 const auto pairs = relation.fieldPairs();
776 childFeatureIds.insert(
duplicateFeature( relation.referencingLayer(), childFeature, project, duplicateFeatureContext, maxDepth, depth + 1, referencedLayersBranch ).
id() );
780 duplicateFeatureContext.setDuplicatedFeatures( relation.referencingLayer(), childFeatureIds );
790 std::unique_ptr<QgsVectorLayerFeatureSource> featureSource;
792 auto getFeatureSource = [layer = std::move( layer ), &featureSource, feedback] {
793 Q_ASSERT( QThread::currentThread() == qApp->thread() || feedback );
798 featureSource = std::make_unique<QgsVectorLayerFeatureSource>( lyr );
804 return featureSource;
812 attributes.reserve( fields.
size() );
814 for (
const QgsField &field : fields )
825 if ( lengthDiff > 0 )
831 else if ( lengthDiff < 0 )
835 attributes.reserve( fields.
count() );
837 for (
int i = attributeCount; i < fields.
count(); ++i )
859 for (
int index : pkIndexes )
871 if ( ( newFHasGeom && !layerHasGeom ) || !newFHasGeom )
875 resultFeatures.append( _f );
882 if ( geometries.count() != 1 )
885 for (
int j = 0; j < newF.
fields().count(); j++ )
889 resultFeatures.reserve( geometries.size() );
893 resultFeatures.append( _f );
899 resultFeatures.append( newF );
902 return resultFeatures;
911 for (
const auto &_f : features )
913 resultFeatures.append( _f );
916 return resultFeatures;
921 QList<QgsVectorLayer *>
layers;
922 QMap<QgsVectorLayer *, QgsFeatureIds>::const_iterator i;
923 for ( i = mDuplicatedFeatures.begin(); i != mDuplicatedFeatures.end(); ++i )
930 return mDuplicatedFeatures[layer];
935 if ( mDuplicatedFeatures.contains( layer ) )
936 mDuplicatedFeatures[layer] += ids;
938 mDuplicatedFeatures.insert( layer, ids );
1035 if ( !joinedFeature.
isValid() )
1047 const QgsVectorLayer *layer,
const QHash< QString, QgsSelectiveMaskingSourceSet > &selectiveMaskingSourceSets,
const QVector<QgsVectorLayer *> &allRenderedVectorLayers
1067 const QgsTextMaskSettings &maskSettings = labelSettingsEntity->settings().format().mask();
1075 QgsMaskedLayer &maskedLayer = maskedLayers[currentLabelRuleId][r.layerId()];
1084 QHash<QString, QgsMaskedLayers> maskedLayers;
1086 QString currentLabelRuleId;
1089 LabelMasksVisitor visitor;
1101 bool visitSymbol(
const QgsSymbol *symbol )
1109 if ( it != selectiveMaskingSourceSets.constEnd() )
1111 const QVector<QgsSelectiveMaskSource> maskingSources = it.value().sources();
1116 QgsMaskedLayer &maskedLayer = maskedLayers[maskSource.sourceId()][maskedLayerId];
1126 visitSymbol( subSymbol );
1138 if ( symbolEntity->symbol() )
1139 visitSymbol( symbolEntity->symbol() );
1144 QHash<QString, QgsMaskedLayers> maskedLayers;
1145 QString maskingLayerId;
1146 QString maskedLayerId;
1147 QHash< QString, QgsSelectiveMaskingSourceSet > selectiveMaskingSourceSets;
1150 LabelSelectiveMaskingSetVisitor selectiveMaskingSetVisitor;
1151 selectiveMaskingSetVisitor.maskingLayerId = layer->
id();
1152 selectiveMaskingSetVisitor.maskedLayers = std::move( visitor.maskedLayers );
1153 selectiveMaskingSetVisitor.selectiveMaskingSourceSets = selectiveMaskingSourceSets;
1158 selectiveMaskingSetVisitor.maskedLayerId = layer->
id();
1163 return std::move( selectiveMaskingSetVisitor.maskedLayers );
1167 const QgsVectorLayer *layer,
const QHash< QString, QgsSelectiveMaskingSourceSet > &selectiveMaskingSourceSets,
const QVector<QgsVectorLayer *> &allRenderedVectorLayers
1179 bool visitSymbol(
const QgsSymbol *symbol )
1183 bool symbolHasEffect = symbol->
opacity() < 1;
1188 symbolHasEffect |= slHasEffects;
1194 slHasEffects = visitSymbol( subSymbol ) || slHasEffects;
1199 QgsMaskedLayer &maskedLayer = maskedLayers[thingToMask.layerId()];
1205 return symbolHasEffect;
1213 if ( symbolEntity->symbol() )
1214 visitSymbol( symbolEntity->symbol() );
1221 SymbolLayerVisitor visitor;
1231 bool visitSymbol(
const QgsSymbol *symbol )
1239 if ( it != selectiveMaskingSourceSets.constEnd() )
1241 const QVector<QgsSelectiveMaskSource> maskingSources = it.value().sources();
1256 visitSymbol( subSymbol );
1268 if ( symbolEntity->symbol() )
1269 visitSymbol( symbolEntity->symbol() );
1274 QString maskingLayerId;
1275 QString maskedLayerId;
1276 QHash< QString, QgsSelectiveMaskingSourceSet > selectiveMaskingSourceSets;
1279 SymbolLayerSelectiveMaskingSetVisitor selectiveMaskingSetVisitor;
1280 selectiveMaskingSetVisitor.maskingLayerId = layer->
id();
1281 selectiveMaskingSetVisitor.maskedLayers = visitor.maskedLayers;
1282 selectiveMaskingSetVisitor.selectiveMaskingSourceSets = selectiveMaskingSourceSets;
1287 selectiveMaskingSetVisitor.maskedLayerId = layer->
id();
1292 return selectiveMaskingSetVisitor.maskedLayers;
1302 QString displayString = exp.
evaluate( &context ).toString();
1304 return displayString;
1315 switch ( relation.strength() )
1321 const auto constFids = fids;
1327 while ( relatedFeaturesIt.
nextFeature( childFeature ) )
1329 childFeatureIds.insert( childFeature.
id() );
1333 if ( childFeatureIds.count() > 0 )
1335 if ( context.
layers().contains( relation.referencingLayer() ) )
1339 handledFeatureIds.unite( childFeatureIds );
1340 context.setDuplicatedFeatures( relation.referencingLayer(), handledFeatureIds );
1345 context.setDuplicatedFeatures( relation.referencingLayer(), childFeatureIds );
1364 if ( info.isEditable() && info.hasCascadedDelete() )
1367 const auto constFids = fids;
1372 joinFeatureIds.insert( joinFeature.
id() );
1375 if ( joinFeatureIds.count() > 0 )
1377 if ( context.
layers().contains( info.joinLayer() ) )
1381 handledFeatureIds.unite( joinFeatureIds );
1382 context.setDuplicatedFeatures( info.joinLayer(), handledFeatureIds );
1387 context.setDuplicatedFeatures( info.joinLayer(), joinFeatureIds );
1394 return !context.
layers().isEmpty();
1399 if ( foundFriendly )
1400 *foundFriendly =
false;
1412 static QStringList sCandidates {
1433 static QStringList sAntiCandidates {
1443 QString bestCandidateName;
1444 QString bestCandidateContainsName;
1445 QString bestCandidateContainsNameWithAntiCandidate;
1447 for (
const QString &candidate : sCandidates )
1449 for (
const QgsField &field : fields )
1451 const QString fldName = field.name();
1453 if ( fldName.compare( candidate, Qt::CaseInsensitive ) == 0 )
1455 bestCandidateName = fldName;
1457 else if ( fldName.contains( candidate, Qt::CaseInsensitive ) )
1459 bool isAntiCandidate =
false;
1460 for (
const QString &antiCandidate : sAntiCandidates )
1462 if ( fldName.contains( antiCandidate, Qt::CaseInsensitive ) )
1464 isAntiCandidate =
true;
1469 if ( isAntiCandidate )
1471 if ( bestCandidateContainsNameWithAntiCandidate.isEmpty() )
1473 bestCandidateContainsNameWithAntiCandidate = fldName;
1478 if ( bestCandidateContainsName.isEmpty() )
1480 bestCandidateContainsName = fldName;
1486 if ( !bestCandidateName.isEmpty() )
1490 QString candidateName = bestCandidateName;
1491 if ( candidateName.isEmpty() )
1493 candidateName = bestCandidateContainsName.isEmpty() ? bestCandidateContainsNameWithAntiCandidate : bestCandidateContainsName;
1496 if ( !candidateName.isEmpty() )
1505 if ( candidateName ==
"gml_name"_L1 && fields.
indexOf(
"id"_L1 ) >= 0 )
1507 candidateName.clear();
1509 for (
const QgsField &field : std::as_const( fields ) )
1511 const QString fldName = field.name();
1512 if ( fldName !=
"gml_name"_L1 && fldName.endsWith(
"_name"_L1 ) )
1514 candidateName = fldName;
1518 if ( candidateName.isEmpty() )
1521 candidateName = u
"id"_s;
1525 if ( foundFriendly )
1526 *foundFriendly =
true;
1527 return candidateName;
1532 for (
const QgsField &field : fields )
1534 if ( field.type() == QMetaType::Type::QString )
1535 return field.name();
1539 return fields.at( 0 ).name();
1543template<
typename T,
typename ConverterFunc>
void populateFieldDataArray(
const QVector<QVariant> &values,
const QVariant &nullValue, QByteArray &res, ConverterFunc converter )
1545 res.resize( values.size() *
sizeof( T ) );
1546 T *data =
reinterpret_cast<T *
>( res.data() );
1547 for (
const QVariant &val : values )
1551 *data++ = converter( nullValue );
1555 *data++ = converter( val );
1562 const int fieldIndex = fields.
lookupField( fieldName );
1563 if ( fieldIndex < 0 )
1564 return QByteArray();
1566 QVector< QVariant > values;
1570 values.append( f.
attribute( fieldIndex ) );
1573 const QgsField field = fields.
at( fieldIndex );
1575 switch ( field.
type() )
1577 case QMetaType::Int:
1583 case QMetaType::UInt:
1589 case QMetaType::LongLong:
1595 case QMetaType::ULongLong:
1601 case QMetaType::Double:
1607 case QMetaType::Long:
1613 case QMetaType::Short:
1619 case QMetaType::ULong:
1625 case QMetaType::UShort:
1631 case QMetaType::Float:
1649 if ( featureIds.isEmpty() )
1659 validIds.reserve( featureIds.size() );
1665 validIds.insert( feat.
id() );
@ AddFeatures
Allows adding features.
@ ChangeAttributeValues
Allows modification of attribute values.
@ Composition
Fix relation, related elements are part of the parent and a parent copy will copy any children or del...
@ Association
Loose relation, related elements are not part of the parent and a parent copy will not copy any child...
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
@ NoFlags
No flags are set.
@ Label
A mask generated from a labeling provider.
@ SymbolLayer
A mask generated from a symbol layer.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
@ UnsetField
Clears the field value so that the data provider backend will populate using any backend triggers or ...
@ DefaultValue
Use default field value.
@ Duplicate
Duplicate original value.
@ Provider
Field originates from the underlying data provider of the vector layer.
@ Join
Field originates from a joined layer.
WkbType
The WKB type describes the number of dimensions a geometry has.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the labeling...
Provides a container for managing client side default values for fields.
bool isValid() const
Returns if this default value should be applied.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
Handles parsing and evaluation of expressions (formerly called "search strings").
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
static QString quotedValue(const QVariant &value)
Returns a string representation of a literal value, including appropriate quotations where required.
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
QString evalErrorString() const
Returns evaluation error.
QString parserErrorString() const
Returns parser error.
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes).
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
QVariant evaluate()
Evaluate the feature and return the result.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
Wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(Qgis::FeatureRequestFlags flags)
Sets flags that affect how features will be fetched.
QgsFeatureRequest & setLimit(long long limit)
Set the maximum number of features to request.
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Sets the feature IDs that should be fetched.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
QFlags< SinkFlag > SinkFlags
@ RegeneratePrimaryKey
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Q_INVOKABLE bool setAttribute(int field, const QVariant &attr)
Sets an attribute's value by field index.
void initAttributes(int fieldCount)
Initialize this feature with the given number of fields.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
void setFields(const QgsFields &fields, bool initAttributes=false)
Assigns a field map with the feature to allow attribute access by attribute name.
int attributeCount() const
Returns the number of attributes attached to the feature.
void setValid(bool validity)
Sets the validity of the feature.
bool isValid() const
Returns the validity of this feature.
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
bool isCanceled() const
Tells whether the operation has been canceled already.
Stores information about constraints which may be present on a field.
ConstraintStrength
Strength of constraints.
@ ConstraintStrengthNotSet
Constraint is not set.
ConstraintOrigin
Origin of constraints.
@ ConstraintOriginNotSet
Constraint is not set.
@ ConstraintOriginProvider
Constraint was set at data provider.
ConstraintStrength constraintStrength(Constraint constraint) const
Returns the strength of a field constraint, or ConstraintStrengthNotSet if the constraint is not pres...
ConstraintOrigin constraintOrigin(Constraint constraint) const
Returns the origin of a field constraint, or ConstraintOriginNotSet if the constraint is not present ...
QString constraintExpression() const
Returns the constraint expression for the field, if set.
@ ConstraintNotNull
Field may not be null.
@ ConstraintUnique
Field must have a unique value.
@ ConstraintExpression
Field has an expression constraint set. See constraintExpression().
QString constraintDescription() const
Returns the descriptive name for the constraint expression.
Encapsulate a field in an attribute table or data source.
bool convertCompatible(QVariant &v, QString *errorMessage=nullptr) const
Converts the provided variant to a compatible format.
Qgis::FieldDuplicatePolicy duplicatePolicy() const
Returns the field's duplicate policy, which indicates how field values should be handled during a dup...
QgsFieldConstraints constraints
Container of fields for a vector layer.
Q_INVOKABLE int indexOf(const QString &fieldName) const
Gets the field index from the field name.
Qgis::FieldOrigin fieldOrigin(int fieldIdx) const
Returns the field's origin (value from an enumeration).
int size() const
Returns number of items.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
int fieldOriginIndex(int fieldIdx) const
Returns the field's origin index (its meaning is specific to each type of origin).
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
A geometry is the spatial representation of a feature.
QVector< QgsGeometry > coerceToType(Qgis::WkbType type, double defaultZ=0, double defaultM=0, bool avoidDuplicates=true) const
Attempts to coerce this geometry into the specified destination type.
Qgis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.).
bool enabled() const
Returns whether the effect is enabled.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
QgsRelationManager * relationManager
QList< QgsRelation > referencedRelations(const QgsVectorLayer *layer=nullptr) const
Gets all relations where this layer is the referenced part (i.e.
Defines a relation between matching fields of the two involved tables of a relation.
Represents a relationship between two vector layers.
Encapsulates a single source for selective masking (e.g.
virtual QgsStyle::StyleEntity type() const =0
Returns the type of style entity.
An interface for classes which can visit style entity (e.g.
@ SymbolRule
Rule based symbology or label child rule.
A label settings entity for QgsStyle databases.
A symbol entity for QgsStyle databases.
@ LabelSettingsEntity
Label settings.
Type used to refer to a specific symbol layer in a symbol of a layer.
Abstract base class for symbol layers.
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the layer.
QString selectiveMaskingSourceSetId() const
Returns the selective masking source set ID for this symbol layer.
QString id() const
Returns symbol layer identifier This id is unique in the whole project.
virtual QList< QgsSymbolLayerReference > masks() const
Returns masks defined by this symbol layer.
Abstract base class for all rendered symbols.
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
qreal opacity() const
Returns the opacity for the symbol.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
Container for settings relating to a selective masking around a text.
QList< QgsSymbolLayerReference > maskedSymbolLayers() const
Returns a list of references to symbol layers that are masked by this buffer.
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the mask.
double opacity() const
Returns the mask's opacity.
bool enabled() const
Returns whether the mask is enabled.
static bool runOnMainThread(const Func &func, QgsFeedback *feedback=nullptr)
Guarantees that func is executed on the main thread.
Represents a default, "not-specified" value for a feature attribute.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
static QVariant createNullVariant(QMetaType::Type metaType)
Helper method to properly create a null QVariant from a metaType Returns the created QVariant.
static bool isUnsetAttributeValue(const QVariant &variant)
Check if the variant is a QgsUnsetAttributeValue.
virtual Q_INVOKABLE Qgis::VectorProviderCapabilities capabilities() const
Returns flags containing the supported capabilities.
virtual QgsAttributeList pkAttributeIndexes() const
Returns list of indexes of fields that make up the primary key.
virtual QString defaultValueClause(int fieldIndex) const
Returns any default value clauses which are present at the provider for a specified field index.
virtual QVariant defaultValue(int fieldIndex) const
Returns any literal default values which are present at the provider for a specified field index.
virtual bool skipConstraintCheck(int fieldIndex, QgsFieldConstraints::Constraint constraint, const QVariant &value=QVariant()) const
Returns true if a constraint check should be skipped for a specified field (e.g., if the value return...
const QgsVectorLayerJoinInfo * joinForFieldIndex(int index, const QgsFields &fields, int &sourceFieldIndex) const
Finds the vector join for a layer field index.
bool containsJoins() const
Quick way to test if there is any join at all.
QgsFeature joinedFeatureOf(const QgsVectorLayerJoinInfo *info, const QgsFeature &feature) const
Returns the joined feature corresponding to the feature.
const QgsVectorJoinList & vectorJoins() const
Defines left outer join from our vector layer to some other vector layer.
bool hasUpsertOnEdit() const
Returns whether a feature created on the target layer has to impact the joined layer by creating a ne...
bool isEditable() const
Returns whether joined fields may be edited through the form of the target layer.
QgsVectorLayer * joinLayer() const
Returns joined layer (may be nullptr if the reference was set by layer ID and not resolved yet).
Contains mainly the QMap with QgsVectorLayer and QgsFeatureIds which list all the duplicated features...
QgsFeatureIds duplicatedFeatures(QgsVectorLayer *layer) const
Returns the duplicated features in the given layer.
QList< QgsVectorLayer * > layers() const
Returns all the layers on which features have been duplicated.
Encapsulate geometry and attributes for new features, to be passed to createFeatures.
QgsGeometry geometry() const
Returns geometry.
QgsAttributeMap attributes() const
Returns attributes.
QgsFeatureData(const QgsGeometry &geometry=QgsGeometry(), const QgsAttributeMap &attributes=QgsAttributeMap())
Constructs a new QgsFeatureData with given geometry and attributes.
static QByteArray fieldToDataArray(const QgsFields &fields, const QString &fieldName, QgsFeatureIterator &it, const QVariant &nullValue)
Converts field values from an iterator to an array of data.
static QgsFeature duplicateFeature(QgsVectorLayer *layer, const QgsFeature &feature, QgsProject *project, QgsDuplicateFeatureContext &duplicateFeatureContext, const int maxDepth=0, int depth=0, QList< QgsVectorLayer * > referencedLayersBranch=QList< QgsVectorLayer * >())
Duplicates a feature and it's children (one level deep).
QList< QgsVectorLayerUtils::QgsFeatureData > QgsFeaturesDataList
Alias for list of QgsFeatureData.
static QgsMaskedLayers collectObjectsMaskedBySymbolLayersFromLayer(const QgsVectorLayer *layer, const QHash< QString, QgsSelectiveMaskingSourceSet > &selectiveMaskingSourceSets, const QVector< QgsVectorLayer * > &allRenderedVectorLayers)
Returns all objects that will be masked by the symbol layers for a given vector layer.
static bool valueExists(const QgsVectorLayer *layer, int fieldIndex, const QVariant &value, const QgsFeatureIds &ignoreIds=QgsFeatureIds())
Returns true if the specified value already exists within a field.
static QgsFeatureList makeFeatureCompatible(const QgsFeature &feature, const QgsVectorLayer *layer, QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags())
Converts input feature to be compatible with the given layer.
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...
static bool fieldIsEditable(const QgsVectorLayer *layer, int fieldIndex, const QgsFeature &feature, QgsVectorLayerUtils::FieldIsEditableFlags flags=QgsVectorLayerUtils::FieldIsEditableFlags())
Tests whether a field is editable for a particular feature.
static QList< QVariant > uniqueValues(const QgsVectorLayer *layer, const QString &fieldOrExpression, bool &ok, bool selectedOnly=false, int limit=-1, QgsFeedback *feedback=nullptr)
Fetches all unique values from a specified field name or expression.
static QgsFeatureIterator getValuesIterator(const QgsVectorLayer *layer, const QString &fieldOrExpression, bool &ok, bool selectedOnly)
Create a feature iterator for a specified field name or expression.
static bool fieldEditabilityDependsOnFeature(const QgsVectorLayer *layer, int fieldIndex)
Returns true if the editability of the field at index fieldIndex from layer may vary feature by featu...
static QgsFeatureList makeFeaturesCompatible(const QgsFeatureList &features, const QgsVectorLayer *layer, QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags())
Converts input features to be compatible with the given layer.
static QHash< QString, QgsMaskedLayers > collectObjectsMaskedByLabelsFromLayer(const QgsVectorLayer *layer, const QHash< QString, QgsSelectiveMaskingSourceSet > &selectiveMaskingSourceSets, const QVector< QgsVectorLayer * > &allRenderedVectorLayers)
Returns all objects that will be masked by the labels for a given vector layer.
static std::unique_ptr< QgsVectorLayerFeatureSource > getFeatureSource(QPointer< QgsVectorLayer > layer, QgsFeedback *feedback=nullptr)
Gets the feature source from a QgsVectorLayer pointer.
static QString getFeatureDisplayString(const QgsVectorLayer *layer, const QgsFeature &feature)
Returns a descriptive string for a feature, suitable for displaying to the user.
static QgsFeature createFeature(const QgsVectorLayer *layer, const QgsGeometry &geometry=QgsGeometry(), const QgsAttributeMap &attributes=QgsAttributeMap(), QgsExpressionContext *context=nullptr)
Creates a new feature ready for insertion into a layer.
QFlags< FieldIsEditableFlag > FieldIsEditableFlags
static bool attributeHasConstraints(const QgsVectorLayer *layer, int attributeIndex)
Returns true if a feature attribute has active constraints.
static QList< double > getDoubleValues(const QgsVectorLayer *layer, const QString &fieldOrExpression, bool &ok, bool selectedOnly=false, int *nullCount=nullptr, QgsFeedback *feedback=nullptr)
Fetches all double values from a specified field name or expression.
@ IgnoreLayerEditability
Ignores the vector layer's editable state.
QFlags< CascadedFeatureFlag > CascadedFeatureFlags
static bool fieldIsReadOnly(const QgsVectorLayer *layer, int fieldIndex)
Returns true if the field at index fieldIndex from layer is editable, false if the field is read only...
static QgsFeatureIds filterValidFeatureIds(const QgsVectorLayer *layer, const QgsFeatureIds &featureIds)
Filters a set of feature IDs to only include those that exist in the layer.
static QgsFeatureList createFeatures(const QgsVectorLayer *layer, const QgsFeaturesDataList &featuresData, QgsExpressionContext *context=nullptr)
Creates a set of new features ready for insertion into a layer.
static QVariant createUniqueValue(const QgsVectorLayer *layer, int fieldIndex, const QVariant &seed=QVariant())
Returns a new attribute value for the specified field index which is guaranteed to be unique.
static bool impactsCascadeFeatures(const QgsVectorLayer *layer, const QgsFeatureIds &fids, const QgsProject *project, QgsDuplicateFeatureContext &context, QgsVectorLayerUtils::CascadedFeatureFlags flags=QgsVectorLayerUtils::CascadedFeatureFlags())
Returns true if at least one feature of the fids on layer is connected as parent in at least one comp...
static QList< QVariant > getValues(const QgsVectorLayer *layer, const QString &fieldOrExpression, bool &ok, bool selectedOnly=false, QgsFeedback *feedback=nullptr)
Fetches all values from a specified field name or expression.
static QVariant createUniqueValueFromCache(const QgsVectorLayer *layer, int fieldIndex, const QSet< QVariant > &existingValues, const QVariant &seed=QVariant())
Returns a new attribute value for the specified field index which is guaranteed to be unique within r...
static bool validateAttribute(const QgsVectorLayer *layer, const QgsFeature &feature, int attributeIndex, QStringList &errors, QgsFieldConstraints::ConstraintStrength strength=QgsFieldConstraints::ConstraintStrengthNotSet, QgsFieldConstraints::ConstraintOrigin origin=QgsFieldConstraints::ConstraintOriginNotSet)
Tests a feature attribute value to check whether it passes all constraints which are present on the c...
static void matchAttributesToFields(QgsFeature &feature, const QgsFields &fields)
Matches the attributes in feature to the specified fields.
@ IgnoreAuxiliaryLayers
Ignore auxiliary layers.
Represents a vector layer which manages a vector based dataset.
bool isEditable() const final
Returns true if the provider is in editing mode.
Q_INVOKABLE QVariant maximumValue(int index) const final
Returns the maximum value for an attribute column or an invalid variant in case of error.
QgsExpressionContext createExpressionContext() const final
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QgsDefaultValue defaultValueDefinition(int index) const
Returns the definition of the expression used when calculating the default value for a field.
Q_INVOKABLE Qgis::WkbType wkbType() const final
Returns the WKBType or WKBUnknown in case of error.
const QgsAbstractVectorLayerLabeling * labeling() const
Access to const labeling configuration.
QgsFeatureRenderer * renderer()
Returns the feature renderer used for rendering the features in the layer in 2D map views.
QString displayExpression
QgsFeatureIterator getSelectedFeatures(QgsFeatureRequest request=QgsFeatureRequest()) const
Returns an iterator of the selected features.
QgsVectorLayerJoinBuffer * joinBuffer()
Returns the join buffer object.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const final
Queries the layer for features specified in request.
QgsVectorLayer * clone() const override
Returns a new instance equivalent to this one.
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.
QVariant defaultValue(int index, const QgsFeature &feature=QgsFeature(), QgsExpressionContext *context=nullptr) const
Returns the calculated default value for the specified field index.
QgsEditFormConfig editFormConfig
Q_INVOKABLE QSet< QVariant > uniqueValues(int fieldIndex, int limit=-1) const final
Calculates a list of unique values contained within an attribute in the layer.
bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) final
Adds a single feature to the sink.
Q_INVOKABLE QgsFeature getFeature(QgsFeatureId fid) const
Queries the layer for the feature with the given id.
QgsVectorDataProvider * dataProvider() final
Returns the layer's data provider, it may be nullptr.
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
QMap< int, QVariant > QgsAttributeMap
QList< QgsFeature > QgsFeatureList
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QList< int > QgsAttributeList
QList< QgsVectorLayerJoinInfo > QgsVectorJoinList
bool fieldIsEditablePrivate(const QgsVectorLayer *layer, int fieldIndex, const QgsFeature &feature, QgsVectorLayerUtils::FieldIsEditableFlags flags=QgsVectorLayerUtils::FieldIsEditableFlags())
void populateFieldDataArray(const QVector< QVariant > &values, const QVariant &nullValue, QByteArray &res, ConverterFunc converter)
QHash< QString, QgsMaskedLayer > QgsMaskedLayers
masked layers where key is the layer id of the layer that WILL be masked
QSet< QString > symbolLayerIdsToMask
Contains information relating to a node (i.e.
QString identifier
A string identifying the node.
QgsStyleEntityVisitorInterface::NodeType type
Node type.
Contains information relating to the style entity currently being visited.
const QgsStyleEntityInterface * entity
Reference to style entity being visited.