QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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, QVariant value );
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 
113  protected slots:
114  void undoIndexChanged( int index );
115 
116  signals:
118  void layerModified();
119 
120  void featureAdded( QgsFeatureId fid );
121  void featureDeleted( QgsFeatureId fid );
122  void geometryChanged( QgsFeatureId fid, QgsGeometry &geom );
123  void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant & );
124  void attributeAdded( int idx );
125  void attributeDeleted( int idx );
126 
129  void committedAttributesDeleted( const QString& layerId, const QgsAttributeList& deletedAttributes );
130  void committedAttributesAdded( const QString& layerId, const QList<QgsField>& addedAttributes );
131  void committedFeaturesAdded( const QString& layerId, const QgsFeatureList& addedFeatures );
132  void committedFeaturesRemoved( const QString& layerId, const QgsFeatureIds& deletedFeatureIds );
133  void committedAttributeValuesChanges( const QString& layerId, const QgsChangedAttributesMap& changedAttributesValues );
134  void committedGeometriesChanges( const QString& layerId, const QgsGeometryMap& changedGeometries );
135 
136  protected:
137 
138  void updateFields( QgsFields& fields );
139 
141  void updateFeatureGeometry( QgsFeature &f );
142 
144  void updateChangedAttributes( QgsFeature &f );
145 
147  void handleAttributeAdded( int index );
148 
150  void handleAttributeDeleted( int index );
151 
152 
154  void updateAttributeMapIndex( QgsAttributeMap& attrs, int index, int offset ) const;
155 
156  void updateLayerFields();
157 
158  protected:
160  friend class QgsVectorLayer;
161 
169 
175 
178 
181 
184 
186  QList<QgsField> mAddedAttributes;
187 
190 
191 };
192 
193 #endif // QGSVECTORLAYEREDITBUFFER_H