QGIS API Documentation  2.6.0-Brighton
 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 
57  bool changeGeometry( QgsFeatureId fid, QgsGeometry* geom );
58 
60  bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() );
61 
65  bool addAttribute( const QgsField &field );
66 
68  bool deleteAttribute( int attr );
69 
70 
86  bool commitChanges( QStringList& commitErrors );
87 
89  void rollBack();
90 
91 
92 
94  inline const QgsFeatureMap& addedFeatures() { return mAddedFeatures; }
95 
97  inline const QgsChangedAttributesMap& changedAttributeValues() { return mChangedAttributeValues; }
98 
100  inline const QgsAttributeList& deletedAttributeIds() { return mDeletedAttributeIds; }
101 
103  inline const QList<QgsField>& addedAttributes() { return mAddedAttributes; }
104 
106  inline const QgsGeometryMap& changedGeometries() { return mChangedGeometries; }
107 
108  inline const QgsFeatureIds deletedFeatureIds() { return mDeletedFeatureIds; }
109  //QString dumpEditBuffer();
110 
111  protected slots:
112  void undoIndexChanged( int index );
113 
114  signals:
116  void layerModified();
117 
118  void featureAdded( QgsFeatureId fid );
119  void featureDeleted( QgsFeatureId fid );
120  void geometryChanged( QgsFeatureId fid, QgsGeometry &geom );
121  void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant & );
122  void attributeAdded( int idx );
123  void attributeDeleted( int idx );
124 
126  void committedAttributesDeleted( const QString& layerId, const QgsAttributeList& deletedAttributes );
127  void committedAttributesAdded( const QString& layerId, const QList<QgsField>& addedAttributes );
128  void committedFeaturesAdded( const QString& layerId, const QgsFeatureList& addedFeatures );
129  void committedFeaturesRemoved( const QString& layerId, const QgsFeatureIds& deletedFeatureIds );
130  void committedAttributeValuesChanges( const QString& layerId, const QgsChangedAttributesMap& changedAttributesValues );
131  void committedGeometriesChanges( const QString& layerId, const QgsGeometryMap& changedGeometries );
132 
133  protected:
134 
135  void updateFields( QgsFields& fields );
136 
138  void updateFeatureGeometry( QgsFeature &f );
139 
141  void updateChangedAttributes( QgsFeature &f );
142 
144  void handleAttributeAdded( int index );
145 
147  void handleAttributeDeleted( int index );
148 
149 
151  void updateAttributeMapIndex( QgsAttributeMap& attrs, int index, int offset ) const;
152 
153  void updateLayerFields();
154 
155  protected:
157  friend class QgsVectorLayer;
158 
166 
172 
175 
178 
181 
183  QList<QgsField> mAddedAttributes;
184 
187 
188 };
189 
190 #endif // QGSVECTORLAYEREDITBUFFER_H