QGIS API Documentation 3.41.0-Master (cea29feecf2)
qgsvectorlayereditpassthrough.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsvectorlayereditpassthrough.cpp
3 ---------------------
4 begin : Jan 12 2015
5 copyright : (C) 2015 by Sandro Mani
6 email : manisandro at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17#include "moc_qgsvectorlayereditpassthrough.cpp"
18#include "qgsvectorlayer.h"
21#include "qgstransaction.h"
22
24 : mModified( false )
25{
26 L = layer;
27}
28
30{
31 return mModified;
32}
33
34bool QgsVectorLayerEditPassthrough::modify( QgsVectorLayerUndoPassthroughCommand *cmd )
35{
36 L->undoStack()->push( cmd ); // push takes ownership -> no need for cmd to be a smart ptr
37 if ( cmd->hasError() )
38 return false;
39
40 if ( !mModified )
41 {
42 mModified = true;
43 emit layerModified();
44 }
45
46 return true;
47}
48
50{
52 if ( !modify( cmd ) ) // modify takes owneship -> no need for cmd to be a smart ptr
53 return false;
54
55 const QgsFeatureList features = cmd->features();
56 f = features.at( features.count() - 1 );
57 return true;
58}
59
61{
63 if ( !modify( cmd ) ) // modify takes owneship -> no need for cmd to be a smart ptr
64 return false;
65
66 features = cmd->features();
67 return true;
68}
69
74
79
81{
82 return modify( new QgsVectorLayerUndoPassthroughCommandChangeGeometry( this, fid, geom ) );
83}
84
85bool QgsVectorLayerEditPassthrough::changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &/*oldValue*/ )
86{
87 return modify( new QgsVectorLayerUndoPassthroughCommandChangeAttribute( this, fid, field, newValue ) );
88}
89
91{
92 return modify( new QgsVectorLayerUndoPassthroughCommandChangeAttributes( this, fid, newValues, oldValues ) );
93}
94
96{
97 return modify( new QgsVectorLayerUndoPassthroughCommandAddAttribute( this, field ) );
98}
99
101{
102 return modify( new QgsVectorLayerUndoPassthroughCommandDeleteAttribute( this, attr ) );
103}
104
105bool QgsVectorLayerEditPassthrough::renameAttribute( int attr, const QString &newName )
106{
107 return modify( new QgsVectorLayerUndoPassthroughCommandRenameAttribute( this, attr, newName ) );
108}
109
110bool QgsVectorLayerEditPassthrough::commitChanges( QStringList & /*commitErrors*/ )
111{
112 mModified = false;
113 return true;
114}
115
117{
118 mModified = false;
119}
120
121bool QgsVectorLayerEditPassthrough::update( QgsTransaction *tr, const QString &sql, const QString &name )
122{
123 return modify( new QgsVectorLayerUndoPassthroughCommandUpdate( this, tr, sql, name ) );
124}
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:53
A geometry is the spatial representation of a feature.
QUndoStack * undoStack()
Returns pointer to layer's undo stack.
This class allows including a set of layers in a database-side transaction, provided the layer data p...
friend class QgsVectorLayerUndoPassthroughCommandChangeGeometry
friend class QgsVectorLayerUndoPassthroughCommandDeleteFeatures
friend class QgsVectorLayerUndoPassthroughCommandUpdate
friend class QgsVectorLayerUndoPassthroughCommandAddAttribute
friend class QgsVectorLayerUndoPassthroughCommandRenameAttribute
friend class QgsVectorLayerUndoPassthroughCommandChangeAttributes
friend class QgsVectorLayerUndoPassthroughCommandChangeAttribute
friend class QgsVectorLayerUndoPassthroughCommandDeleteAttribute
void layerModified()
Emitted when modifications has been done on layer.
friend class QgsVectorLayerUndoPassthroughCommandAddFeatures
bool addFeature(QgsFeature &f) override
Adds a feature.
bool renameAttribute(int attr, const QString &newName) override
Renames an attribute field (but does not commit it)
void rollBack() override
Stop editing and discard the edits.
bool changeAttributeValue(QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue=QVariant()) override
Changed an attribute value (but does not commit it)
bool addFeatures(QgsFeatureList &features) override
Insert a copy of the given features into the layer (but does not commit it)
bool commitChanges(QStringList &commitErrors) override
Attempts to commit any changes to disk.
bool deleteFeatures(const QgsFeatureIds &fids) override
Deletes a set of features from the layer (but does not commit it)
bool deleteAttribute(int attr) override
Deletes an attribute field (but does not commit it)
bool changeAttributeValues(QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues) override
Changes values of attributes (but does not commit it).
bool isModified() const override
Returns true if the provider has been modified since the last commit.
bool deleteFeature(QgsFeatureId fid) override
Delete a feature from the layer (but does not commit it)
bool changeGeometry(QgsFeatureId fid, const QgsGeometry &geom) override
Change feature's geometry.
bool update(QgsTransaction *transaction, const QString &sql, const QString &name)
Update underlying data with a SQL query embedded in a transaction.
bool addAttribute(const QgsField &field) override
Adds an attribute field (but does not commit it) returns true if the field was added.
Undo command for adding a feature to a vector layer in transaction group mode.
QgsFeatureList features() const
List of features (added feaures can be modified by default values from database)
Undo command for vector layer in transaction group mode.
Represents a vector layer which manages a vector based data sets.
QMap< int, QVariant > QgsAttributeMap
QList< QgsFeature > QgsFeatureList
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features