QGIS API Documentation  2.4.0-Chugiak
 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, 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.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:323
static unsigned index
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.
Container of fields for a vector layer.
Definition: qgsfield.h:161
QgsChangedAttributesMap mChangedAttributeValues
Changed attributes values which are not commited.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
QSet< int > QgsAttributeIds
QgsGeometryMap mChangedGeometries
Changed geometries which are not commited.
QList< int > QgsAttributeList
const QgsFeatureIds deletedFeatureIds()
QList< int > QgsAttributeList
QgsFeatureIds mDeletedFeatureIds
Deleted feature IDs which are not commited.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:31
const QList< QgsField > & addedAttributes()
added attributes fields which are not commited
const QgsFeatureMap & addedFeatures()
New features which are not commited.
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
QList< QgsField > mAddedAttributes
added attributes fields which are not commited
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Definition: qgsfeature.h:320
qint64 QgsFeatureId
Definition: qgsfeature.h:30
QgsFeatureMap mAddedFeatures
New features which are not commited.
Represents a vector layer which manages a vector based data sets.
const QgsAttributeList & deletedAttributeIds()
deleted attributes fields which are not commited.
QgsAttributeList mDeletedAttributeIds
deleted attributes fields which are not commited.