QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
qgsvectorlayereditbuffer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorlayereditbuffer.h
3  ---------------------
4  begin : Dezember 2012
5  copyright : (C) 2012 by Martin Dobias
6  email : wonder dot sk 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 #ifndef QGSVECTORLAYEREDITBUFFER_H
16 #define QGSVECTORLAYEREDITBUFFER_H
17 
18 #include <QList>
19 #include <QSet>
20 
21 #include "qgsgeometry.h"
22 #include "qgsfeature.h"
23 #include "qgsfield.h"
24 #include "qgsrectangle.h"
25 #include "qgssnapper.h"
26 
28 
29 typedef QList<int> QgsAttributeList;
30 typedef QSet<int> QgsAttributeIds;
31 typedef QMap<QgsFeatureId, QgsFeature> QgsFeatureMap;
32 
33 class CORE_EXPORT QgsVectorLayerEditBuffer : public QObject
34 {
35  Q_OBJECT
36  public:
39 
41  bool isModified() const;
42 
43 
48  bool addFeature( QgsFeature& f );
49 
51  bool addFeatures( QgsFeatureList& features );
52 
54  bool deleteFeature( QgsFeatureId fid );
55 
58  bool changeGeometry( QgsFeatureId fid, QgsGeometry* geom );
59 
61  bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() );
62 
66  bool addAttribute( const QgsField &field );
67 
69  bool deleteAttribute( int attr );
70 
71 
87  bool commitChanges( QStringList& commitErrors );
88 
90  void rollBack();
91 
92 
93 
95  inline const QgsFeatureMap& addedFeatures() { return mAddedFeatures; }
96 
98  inline const QgsChangedAttributesMap& changedAttributeValues() { return mChangedAttributeValues; }
99 
101  inline const QgsAttributeList& deletedAttributeIds() { return mDeletedAttributeIds; }
102 
104  inline const QList<QgsField>& addedAttributes() { return mAddedAttributes; }
105 
107  inline const QgsGeometryMap& changedGeometries() { return mChangedGeometries; }
108 
109  inline const QgsFeatureIds deletedFeatureIds() { return mDeletedFeatureIds; }
110  //QString dumpEditBuffer();
111 
112  protected slots:
113  void undoIndexChanged( int index );
114 
115  signals:
117  void layerModified();
118 
119  void featureAdded( QgsFeatureId fid );
120  void featureDeleted( QgsFeatureId fid );
121  void geometryChanged( QgsFeatureId fid, QgsGeometry &geom );
122  void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant & );
123  void attributeAdded( int idx );
124  void attributeDeleted( int idx );
125 
128  void committedAttributesDeleted( const QString& layerId, const QgsAttributeList& deletedAttributes );
129  void committedAttributesAdded( const QString& layerId, const QList<QgsField>& addedAttributes );
130  void committedFeaturesAdded( const QString& layerId, const QgsFeatureList& addedFeatures );
131  void committedFeaturesRemoved( const QString& layerId, const QgsFeatureIds& deletedFeatureIds );
132  void committedAttributeValuesChanges( const QString& layerId, const QgsChangedAttributesMap& changedAttributesValues );
133  void committedGeometriesChanges( const QString& layerId, const QgsGeometryMap& changedGeometries );
134 
135  protected:
136 
137  void updateFields( QgsFields& fields );
138 
140  void updateFeatureGeometry( QgsFeature &f );
141 
143  void updateChangedAttributes( QgsFeature &f );
144 
146  void handleAttributeAdded( int index );
147 
149  void handleAttributeDeleted( int index );
150 
151 
153  void updateAttributeMapIndex( QgsAttributeMap& attrs, int index, int offset ) const;
154 
155  void updateLayerFields();
156 
157  protected:
159  friend class QgsVectorLayer;
160 
168 
174 
177 
180 
183 
185  QList<QgsField> mAddedAttributes;
186 
189 
190 };
191 
192 #endif // QGSVECTORLAYEREDITBUFFER_H
const QgsGeometryMap & changedGeometries()
Changed geometries which are not commited.
Definition: qgsvectorlayereditbuffer.h:107
Definition: qgsvectorlayerundocommand.h:128
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:323
static unsigned index
Definition: mersenne-twister.cpp:36
Definition: qgsvectorlayerundocommand.h:66
QMap< int, QVariant > QgsAttributeMap
Definition: qgsfeature.h:98
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:325
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:330
const QgsChangedAttributesMap & changedAttributeValues()
Changed attributes values which are not commited.
Definition: qgsvectorlayereditbuffer.h:98
Definition: qgsvectorlayerundocommand.h:35
Container of fields for a vector layer.
Definition: qgsfield.h:172
Definition: qgsvectorlayerundocommand.h:98
Definition: qgsgeometry.h:69
QgsChangedAttributesMap mChangedAttributeValues
Changed attributes values which are not commited.
Definition: qgsvectorlayereditbuffer.h:179
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
Definition: qgsvectorlayerundocommand.h:53
Definition: qgsvectorlayerundocommand.h:80
QSet< int > QgsAttributeIds
Definition: qgsvectorlayereditbuffer.h:30
QgsVectorLayer * L
Definition: qgsvectorlayereditbuffer.h:158
QgsGeometryMap mChangedGeometries
Changed geometries which are not commited.
Definition: qgsvectorlayereditbuffer.h:188
QList< int > QgsAttributeList
Definition: qgsfeaturerequest.h:26
const QgsFeatureIds deletedFeatureIds()
Definition: qgsvectorlayereditbuffer.h:109
QList< int > QgsAttributeList
Definition: qgsvectorlayereditbuffer.h:27
QgsFeatureIds mDeletedFeatureIds
Deleted feature IDs which are not commited.
Definition: qgsvectorlayereditbuffer.h:173
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:33
const QList< QgsField > & addedAttributes()
added attributes fields which are not commited
Definition: qgsvectorlayereditbuffer.h:104
Definition: qgsvectorlayerundocommand.h:114
const QgsFeatureMap & addedFeatures()
New features which are not commited.
Definition: qgsvectorlayereditbuffer.h:95
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
Definition: qgsvectorlayereditbuffer.h:31
QList< QgsField > mAddedAttributes
added attributes fields which are not commited
Definition: qgsvectorlayereditbuffer.h:185
Definition: qgsvectorlayereditbuffer.h:33
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Definition: qgsfeature.h:320
qint64 QgsFeatureId
Definition: qgsfeature.h:30
QgsFeatureMap mAddedFeatures
New features which are not commited.
Definition: qgsvectorlayereditbuffer.h:176
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:470
const QgsAttributeList & deletedAttributeIds()
deleted attributes fields which are not commited.
Definition: qgsvectorlayereditbuffer.h:101
QgsAttributeList mDeletedAttributeIds
deleted attributes fields which are not commited.
Definition: qgsvectorlayereditbuffer.h:182