QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
27 
28  if ( mBackend->addFeature( layer, defaultValues, defaultGeometry, f ) )
29  {
30  mAddedFeatures[layer].insert( f->id() );
31  if ( !feature )
32  delete f;
33  return true;
34  }
35  else
36  {
37  if ( !feature )
38  delete f;
39  return false;
40  }
41 }
42 
44 {
45  return mBackend->startEditing( layer );
46 }
47 
48 bool QgsTrackedVectorLayerTools::stopEditing( QgsVectorLayer *layer, bool allowCancel ) const
49 {
50  return mBackend->stopEditing( layer, allowCancel );
51 }
52 
54 {
55  return mBackend->saveEdits( layer );
56 }
57 
58 bool QgsTrackedVectorLayerTools::copyMoveFeatures( QgsVectorLayer *layer, QgsFeatureRequest &request, double dx, double dy, QString *errorMsg, const bool topologicalEditing, QgsVectorLayer *topologicalLayer ) const
59 {
60  return mBackend->copyMoveFeatures( layer, request, dx, dy, errorMsg, topologicalEditing, topologicalLayer );
61 }
62 
64 {
65  mBackend = tools;
66 }
67 
69 {
70  QMapIterator<QgsVectorLayer *, QgsFeatureIds> it( mAddedFeatures );
71  while ( it.hasNext() )
72  {
73  it.next();
74  it.key()->deleteFeatures( it.value() );
75  }
76 
77  mAddedFeatures.clear();
78 }
QgsVectorLayerTools::addFeature
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.
QgsVectorLayerTools::forceSuppressFormPopup
bool forceSuppressFormPopup() const
Returns force suppress form popup status.
Definition: qgsvectorlayertools.cpp:110
QgsVectorLayerTools::copyMoveFeatures
virtual bool copyMoveFeatures(QgsVectorLayer *layer, QgsFeatureRequest &request, double dx=0, double dy=0, QString *errorMsg=nullptr, const bool topologicalEditing=false, QgsVectorLayer *topologicalLayer=nullptr) const
Copy and move features with defined translation.
Definition: qgsvectorlayertools.cpp:28
QgsVectorLayerTools
Definition: qgsvectorlayertools.h:39
QgsTrackedVectorLayerTools::setVectorLayerTools
void setVectorLayerTools(const QgsVectorLayerTools *tools)
Set the vector layer tools that will be used to interact with the data.
Definition: qgstrackedvectorlayertools.cpp:63
QgsVectorLayerTools::setForceSuppressFormPopup
void setForceSuppressFormPopup(bool forceSuppressFormPopup)
Sets force suppress form popup status to forceSuppressFormPopup.
Definition: qgsvectorlayertools.cpp:115
QgsTrackedVectorLayerTools::addFeature
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.
Definition: qgstrackedvectorlayertools.cpp:20
QgsTrackedVectorLayerTools::copyMoveFeatures
bool copyMoveFeatures(QgsVectorLayer *layer, QgsFeatureRequest &request, double dx=0, double dy=0, QString *errorMsg=nullptr, const bool topologicalEditing=false, QgsVectorLayer *topologicalLayer=nullptr) const override
Copy and move features with defined translation.
Definition: qgstrackedvectorlayertools.cpp:58
QgsTrackedVectorLayerTools::startEditing
bool startEditing(QgsVectorLayer *layer) const override
This will be called, whenever a vector layer should be switched to edit mode.
Definition: qgstrackedvectorlayertools.cpp:43
QgsTrackedVectorLayerTools::stopEditing
bool stopEditing(QgsVectorLayer *layer, bool allowCancel) const override
Will be called, when an editing session is ended and the features should be committed.
Definition: qgstrackedvectorlayertools.cpp:48
QgsFeature::id
QgsFeatureId id
Definition: qgsfeature.h:68
QgsFeatureRequest
Definition: qgsfeaturerequest.h:75
QgsVectorLayerTools::saveEdits
virtual bool saveEdits(QgsVectorLayer *layer) const =0
Should be called, when the features should be committed but the editing session is not ended.
QgsAttributeMap
QMap< int, QVariant > QgsAttributeMap
Definition: qgsattributes.h:38
QgsTrackedVectorLayerTools::saveEdits
bool saveEdits(QgsVectorLayer *layer) const override
Should be called, when the features should be committed but the editing session is not ended.
Definition: qgstrackedvectorlayertools.cpp:53
qgsvectorlayer.h
QgsGeometry
Definition: qgsgeometry.h:122
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsVectorLayerTools::stopEditing
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.
QgsFeature
Definition: qgsfeature.h:55
qgstrackedvectorlayertools.h
QgsVectorLayerTools::startEditing
virtual bool startEditing(QgsVectorLayer *layer) const =0
This will be called, whenever a vector layer should be switched to edit mode.
QgsTrackedVectorLayerTools::rollback
void rollback()
Delete all features which have been added via this object.
Definition: qgstrackedvectorlayertools.cpp:68