QGIS API Documentation  3.6.0-Noosa (5873452)
qgstrackedvectorlayertools.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgstrackedvectorlayertools.cpp - QgsTrackedVectorLayerTools
3 
4  ---------------------
5  begin : 16.5.2016
6  copyright : (C) 2016 by Matthias Kuhn, OPENGIS.ch
7  email : [email protected]
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
17 #include "qgsvectorlayer.h"
18 
19 
20 bool QgsTrackedVectorLayerTools::addFeature( QgsVectorLayer *layer, const QgsAttributeMap &defaultValues, const QgsGeometry &defaultGeometry, QgsFeature *feature ) const
21 {
22  QgsFeature *f = feature;
23  if ( !feature )
24  f = new QgsFeature();
25 
26  if ( mBackend->addFeature( layer, defaultValues, defaultGeometry, f ) )
27  {
28  mAddedFeatures[layer].insert( f->id() );
29  if ( !feature )
30  delete f;
31  return true;
32  }
33  else
34  {
35  if ( !feature )
36  delete f;
37  return false;
38  }
39 }
40 
42 {
43  return mBackend->startEditing( layer );
44 }
45 
46 bool QgsTrackedVectorLayerTools::stopEditing( QgsVectorLayer *layer, bool allowCancel ) const
47 {
48  return mBackend->stopEditing( layer, allowCancel );
49 }
50 
52 {
53  return mBackend->saveEdits( layer );
54 }
55 
56 bool QgsTrackedVectorLayerTools::copyMoveFeatures( QgsVectorLayer *layer, QgsFeatureRequest &request, double dx, double dy, QString *errorMsg ) const
57 {
58  return mBackend->copyMoveFeatures( layer, request, dx, dy, errorMsg );
59 }
60 
62 {
63  mBackend = tools;
64 }
65 
67 {
68  QMapIterator<QgsVectorLayer *, QgsFeatureIds> it( mAddedFeatures );
69  while ( it.hasNext() )
70  {
71  it.next();
72  it.key()->deleteFeatures( it.value() );
73  }
74 
75  mAddedFeatures.clear();
76 }
Methods in this class are used to handle basic operations on vector layers.
QgsFeatureId id
Definition: qgsfeature.h:64
virtual bool copyMoveFeatures(QgsVectorLayer *layer, QgsFeatureRequest &request, double dx=0, double dy=0, QString *errorMsg=nullptr) const
Copy and move features with defined translation.
virtual bool saveEdits(QgsVectorLayer *layer) const =0
Should be called, when the features should be committed but the editing session is not ended...
virtual bool startEditing(QgsVectorLayer *layer) const =0
This will be called, whenever a vector layer should be switched to edit mode.
bool stopEditing(QgsVectorLayer *layer, bool allowCancel) const override
Will be called, when an editing session is ended and the features should be committed.
bool copyMoveFeatures(QgsVectorLayer *layer, QgsFeatureRequest &request, double dx=0, double dy=0, QString *errorMsg=nullptr) const override
Copy and move features with defined translation.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:106
bool startEditing(QgsVectorLayer *layer) const override
This will be called, whenever a vector layer should be switched to edit mode.
virtual bool stopEditing(QgsVectorLayer *layer, bool allowCancel=true) const =0
Will be called, when an editing session is ended and the features should be committed.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
void setVectorLayerTools(const QgsVectorLayerTools *tools)
Set the vector layer tools that will be used to interact with the data.
QMap< int, QVariant > QgsAttributeMap
Definition: qgsattributes.h:38
bool addFeature(QgsVectorLayer *layer, const QgsAttributeMap &defaultValues, const QgsGeometry &defaultGeometry, QgsFeature *feature) const override
This method should/will be called, whenever a new feature will be added to the layer.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void rollback()
Delete all features which have been added via this object.
bool saveEdits(QgsVectorLayer *layer) const override
Should be called, when the features should be committed but the editing session is not ended...
virtual bool addFeature(QgsVectorLayer *layer, const QgsAttributeMap &defaultValues=QgsAttributeMap(), const QgsGeometry &defaultGeometry=QgsGeometry(), QgsFeature *feature=nullptr) const =0
This method should/will be called, whenever a new feature will be added to the layer.
Represents a vector layer which manages a vector based data sets.