QgsVectorLayerTools class
Methods in this class are used to handle basic operations on vector layers.
Contents
- Reference
With an implementation of this class, parts of the application can ask for an operation to be done and the implementation will then take care of it.
Reimplement this class, if you need to have custom checks or GUI elements in your application.
Public functions
- auto addFeature(QgsVectorLayer* layer, const QgsAttributeMap& defaultValues = QgsAttributeMap(), const QgsGeometry& defaultGeometry = QgsGeometry(), QgsFeature* feature = nullptr) const -> bool pure virtual
- This method should/will be called, whenever a new feature will be added to the layer.
- auto copyMoveFeatures(QgsVectorLayer* layer, QgsFeatureRequest& request, double dx = 0, double dy = 0, QString* errorMsg = nullptr) const -> bool virtual
- Copy and move features with defined translation.
- auto saveEdits(QgsVectorLayer* layer) const -> bool pure virtual
- Should be called, when the features should be committed but the editing session is not ended.
- auto startEditing(QgsVectorLayer* layer) const -> bool pure virtual
- This will be called, whenever a vector layer should be switched to edit mode.
- auto stopEditing(QgsVectorLayer* layer, bool allowCancel = true) const -> bool pure virtual
- Will be called, when an editing session is ended and the features should be committed.
Function documentation
bool QgsVectorLayerTools:: addFeature(QgsVectorLayer* layer,
const QgsAttributeMap& defaultValues = QgsAttributeMap(),
const QgsGeometry& defaultGeometry = QgsGeometry(),
QgsFeature* feature = nullptr) const pure virtual
This method should/will be called, whenever a new feature will be added to the layer.
| Parameters | |
|---|---|
| layer | The layer to which the feature should be added |
| defaultValues | Default values for the feature to add |
| defaultGeometry | A default geometry to add to the feature |
| feature | Updated feature after adding will be written back to this |
| Returns | True in case of success, False if the operation failed/was aborted |
TODO QGIS 3: remove const qualifier
bool QgsVectorLayerTools:: copyMoveFeatures(QgsVectorLayer* layer,
QgsFeatureRequest& request,
double dx = 0,
double dy = 0,
QString* errorMsg = nullptr) const virtual
Copy and move features with defined translation.
| Parameters | |
|---|---|
| layer | The layer |
| request | The request for the features to be moved. It will be assigned to a new feature request with the newly copied features. |
| dx | The translation on x |
| dy | The translation on y |
| errorMsg | If given, it will contain the error message |
| Returns | True if all features could be copied. |
TODO QGIS 3: remove const qualifier
bool QgsVectorLayerTools:: saveEdits(QgsVectorLayer* layer) const pure virtual
Should be called, when the features should be committed but the editing session is not ended.
| Parameters | |
|---|---|
| layer | The layer to commit |
| Returns | True if successful |
TODO QGIS 3: remove const qualifier
bool QgsVectorLayerTools:: startEditing(QgsVectorLayer* layer) const pure virtual
This will be called, whenever a vector layer should be switched to edit mode.
| Parameters | |
|---|---|
| layer | The layer on which to start an edit session |
| Returns | True, if the editing session was started |
Check the providers capability to edit in here. If successful layer->startEditing() will be called and true returned.
TODO QGIS 3: remove const qualifier
bool QgsVectorLayerTools:: stopEditing(QgsVectorLayer* layer,
bool allowCancel = true) const pure virtual
Will be called, when an editing session is ended and the features should be committed.
| Parameters | |
|---|---|
| layer | The layer to commit |
| allowCancel | True if a cancel button should be offered |
| Returns | True if successful |
Appropriate dialogs should be shown like
TODO QGIS 3: remove const qualifier