mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-22 00:06:57 -04:00
literal defaults, and qgis expression defaults) and automatically handle unique value constraints on layers Add a new method QgsVectorLayerUtils::createFeature which returns a new feature which includes all relevant defaults. Any fields with unique value constraints will be guaranteed to have a value which is unique for the field. Currently only in use by the split feature tool. Sponsored by Canton of Zug and the QGEP project
52 lines
2.6 KiB
Plaintext
52 lines
2.6 KiB
Plaintext
|
|
/** \ingroup core
|
|
* \class QgsVectorLayerUtils
|
|
* \brief Contains utility methods for working with QgsVectorLayers.
|
|
*
|
|
* \note Added in version 3.0
|
|
*/
|
|
class QgsVectorLayerUtils
|
|
{
|
|
%TypeHeaderCode
|
|
#include <qgsvectorlayerutils.h>
|
|
%End
|
|
public:
|
|
|
|
/**
|
|
* Returns true if the specified value already exists within a field. This method can be used to test for uniqueness
|
|
* of values inside a layer's attributes. An optional list of ignored feature IDs can be provided, if so, any features
|
|
* with IDs within this list are ignored when testing for existance of the value.
|
|
* @see createUniqueValue()
|
|
*/
|
|
static bool valueExists( const QgsVectorLayer* layer, int fieldIndex, const QVariant& value, const QgsFeatureIds& ignoreIds = QgsFeatureIds() );
|
|
|
|
/**
|
|
* Returns a new attribute value for the specified field index which is guaranteed to be unique. The optional seed
|
|
* value can be used as a basis for generated values.
|
|
* @see valueExists()
|
|
*/
|
|
static QVariant createUniqueValue( const QgsVectorLayer* layer, int fieldIndex, const QVariant& seed = QVariant() );
|
|
|
|
/**
|
|
* Tests an attribute value to check whether it passes all constraints which are present on the corresponding field.
|
|
* Returns true if the attribute value is valid for the field. Any constraint failures will be reported in the errors argument.
|
|
* If the strength or origin parameter is set then only constraints with a matching strength/origin will be checked.
|
|
*/
|
|
static bool validateAttribute( const QgsVectorLayer* layer, const QgsFeature& feature, int attributeIndex, QStringList& errors /Out/,
|
|
QgsFieldConstraints::ConstraintStrength strength = QgsFieldConstraints::ConstraintStrengthNotSet,
|
|
QgsFieldConstraints::ConstraintOrigin origin = QgsFieldConstraints::ConstraintOriginNotSet );
|
|
|
|
/**
|
|
* Creates a new feature ready for insertion into a layer. Default values and constraints
|
|
* (eg unique constraints) will automatically be handled. An optional attribute map can be
|
|
* passed for the new feature to copy as many attribute values as possible from the map,
|
|
* assuming that they respect the layer's constraints. Note that the created feature is not
|
|
* automatically inserted into the layer.
|
|
*/
|
|
static QgsFeature createFeature( QgsVectorLayer* layer,
|
|
const QgsGeometry& geometry = QgsGeometry(),
|
|
const QgsAttributeMap& attributes = QgsAttributeMap(),
|
|
QgsExpressionContext* context = nullptr );
|
|
|
|
};
|