QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
20  : mBackend( nullptr )
21 {
22 }
23 
24 bool QgsTrackedVectorLayerTools::addFeature( QgsVectorLayer* layer, const QgsAttributeMap& defaultValues, const QgsGeometry& defaultGeometry, QgsFeature* feature ) const
25 {
26  QgsFeature* f = feature;
27  if ( !feature )
28  f = new QgsFeature();
29 
30  if ( mBackend->addFeature( layer, defaultValues, defaultGeometry, f ) )
31  {
32  mAddedFeatures[layer].insert( f->id() );
33  if ( !feature )
34  delete f;
35  return true;
36  }
37  else
38  {
39  if ( !feature )
40  delete f;
41  return false;
42  }
43 }
44 
46 {
47  return mBackend->startEditing( layer );
48 }
49 
50 bool QgsTrackedVectorLayerTools::stopEditing( QgsVectorLayer* layer, bool allowCancel ) const
51 {
52  return mBackend->stopEditing( layer, allowCancel );
53 }
54 
56 {
57  return mBackend->saveEdits( layer );
58 }
59 
61 {
62  mBackend = tools;
63 }
64 
66 {
68  while ( it.hasNext() )
69  {
70  it.next();
71  it.key()->deleteFeatures( it.value() );
72  }
73 
74  mAddedFeatures.clear();
75 }
Methods in this class are used to handle basic operations on vector layers.
virtual bool saveEdits(QgsVectorLayer *layer) const =0
Should be called, when the features should be commited 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 commited.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
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 commited.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
void setVectorLayerTools(const QgsVectorLayerTools *tools)
Set the vector layer tools that will be used to interact with the data.
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.
const Key & key() const
const T & value() const
void rollback()
Delete all features which have been added via this object.
QgsFeatureId id() const
Get the feature ID for this feature.
Definition: qgsfeature.cpp:65
bool saveEdits(QgsVectorLayer *layer) const override
Should be called, when the features should be commited 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.
bool hasNext() const