QGIS API Documentation 4.3.0-Master (91d4a333d5d)
Loading...
Searching...
No Matches
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 : matthias@opengis.ch
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 ***************************************************************************/
16
18
19#include "qgsvectorlayer.h"
21
22#include "moc_qgstrackedvectorlayertools.cpp"
23
25 QgsVectorLayer *layer, const QgsAttributeMap &defaultValues, const QgsGeometry &defaultGeometry, QgsFeature *feature, const QgsVectorLayerToolsContext &context
26) const
27{
28 QgsFeature *f = feature;
29 if ( !feature )
30 f = new QgsFeature();
31
33 if ( mBackend->addFeatureV2( layer, defaultValues, defaultGeometry, f, context ) )
34 {
35 connect( layer, &QgsVectorLayer::willBeDeleted, this, &QgsTrackedVectorLayerTools::layerWillBeDeleted, Qt::UniqueConnection );
36 mAddedFeatures[layer->id()].insert( f->id() );
37 if ( !feature )
38 delete f;
39 return true;
40 }
41 else
42 {
43 if ( !feature )
44 delete f;
45 return false;
46 }
47}
48
50{
51 return mBackend->startEditing( layer );
52}
53
54bool QgsTrackedVectorLayerTools::stopEditing( QgsVectorLayer *layer, bool allowCancel ) const
55{
56 return mBackend->stopEditing( layer, allowCancel );
57}
58
60{
61 return mBackend->saveEdits( layer );
62}
63
65 QgsVectorLayer *layer, QgsFeatureRequest &request, double dx, double dy, QString *errorMsg, const bool topologicalEditing, QgsVectorLayer *topologicalLayer, QString *childrenInfoMsg
66) const
67{
68 return mBackend->copyMoveFeatures( layer, request, dx, dy, errorMsg, topologicalEditing, topologicalLayer, childrenInfoMsg );
69}
70
72{
73 mBackend = tools;
74}
75
77{
78 QgsProject *p = project();
79 if ( !p )
80 return;
81
82 for ( auto it = mAddedFeatures.constBegin(); it != mAddedFeatures.constEnd(); ++it )
83 {
84 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( p->mapLayer( it.key() ) ) )
85 {
86 layer->deleteFeatures( it.value() );
87 }
88 }
89 mAddedFeatures.clear();
90}
91
92void QgsTrackedVectorLayerTools::layerWillBeDeleted()
93{
94 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( sender() ) )
95 {
96 // make sure there's no dangling references left to a layer which will be deleted
97 mAddedFeatures.remove( layer->id() );
98 }
99}
Wraps a request for features to a vector layer (or directly its vector data provider).
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
QgsFeatureId id
Definition qgsfeature.h:63
A geometry is the spatial representation of a feature.
QString id
Definition qgsmaplayer.h:87
void willBeDeleted()
Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid...
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:114
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
bool startEditing(QgsVectorLayer *layer) const override
This will be called, whenever a vector layer should be switched to edit mode.
bool copyMoveFeatures(QgsVectorLayer *layer, QgsFeatureRequest &request, double dx=0, double dy=0, QString *errorMsg=nullptr, const bool topologicalEditing=false, QgsVectorLayer *topologicalLayer=nullptr, QString *childrenInfoMsg=nullptr) const override
Copy and move features with defined translation.
bool addFeatureV2(QgsVectorLayer *layer, const QgsAttributeMap &defaultValues, const QgsGeometry &defaultGeometry, QgsFeature *feature, const QgsVectorLayerToolsContext &context) const override
This method calls the addFeature method of the backend QgsVectorLayerTools.
void setVectorLayerTools(const QgsVectorLayerTools *tools)
Set the vector layer tools that will be used to interact with the data.
void rollback()
Delete all features which have been added via this object.
bool stopEditing(QgsVectorLayer *layer, bool allowCancel) const override
Will be called, when an editing session is ended and the features should be committed.
bool saveEdits(QgsVectorLayer *layer) const override
Should be called, when the features should be committed but the editing session is not ended.
Contains settings which reflect the context in which vector layer tool operations should be considere...
bool forceSuppressFormPopup() const
Returns force suppress form popup status.
void setForceSuppressFormPopup(bool forceSuppressFormPopup)
Sets force suppress form popup status to forceSuppressFormPopup.
QgsProject * project() const
Returns the project to be used by operations when needed.
Represents a vector layer which manages a vector based dataset.
QMap< int, QVariant > QgsAttributeMap