QGIS API Documentation  2.7.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 
57  bool changeGeometry( QgsFeatureId fid, QgsGeometry* geom );
58 
60  bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() );
61 
64  bool addAttribute( const QgsField &field );
65 
67  bool deleteAttribute( int attr );
68 
69 
85  bool commitChanges( QStringList& commitErrors );
86 
88  void rollBack();
89 
90 
91 
93  inline const QgsFeatureMap& addedFeatures() { return mAddedFeatures; }
94 
96  inline const QgsChangedAttributesMap& changedAttributeValues() { return mChangedAttributeValues; }
97 
99  inline const QgsAttributeList& deletedAttributeIds() { return mDeletedAttributeIds; }
100 
102  inline const QList<QgsField>& addedAttributes() { return mAddedAttributes; }
103 
105  inline const QgsGeometryMap& changedGeometries() { return mChangedGeometries; }
106 
107  inline const QgsFeatureIds deletedFeatureIds() { return mDeletedFeatureIds; }
108  //QString dumpEditBuffer();
109 
110  protected slots:
111  void undoIndexChanged( int index );
112 
113  signals:
115  void layerModified();
116 
117  void featureAdded( QgsFeatureId fid );
118  void featureDeleted( QgsFeatureId fid );
119  void geometryChanged( QgsFeatureId fid, QgsGeometry &geom );
120  void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant & );
121  void attributeAdded( int idx );
122  void attributeDeleted( int idx );
123 
125  void committedAttributesDeleted( const QString& layerId, const QgsAttributeList& deletedAttributes );
126  void committedAttributesAdded( const QString& layerId, const QList<QgsField>& addedAttributes );
127  void committedFeaturesAdded( const QString& layerId, const QgsFeatureList& addedFeatures );
128  void committedFeaturesRemoved( const QString& layerId, const QgsFeatureIds& deletedFeatureIds );
129  void committedAttributeValuesChanges( const QString& layerId, const QgsChangedAttributesMap& changedAttributesValues );
130  void committedGeometriesChanges( const QString& layerId, const QgsGeometryMap& changedGeometries );
131 
132  protected:
133 
134  void updateFields( QgsFields& fields );
135 
137  void updateFeatureGeometry( QgsFeature &f );
138 
140  void updateChangedAttributes( QgsFeature &f );
141 
143  void handleAttributeAdded( int index );
144 
146  void handleAttributeDeleted( int index );
147 
148 
150  void updateAttributeMapIndex( QgsAttributeMap& attrs, int index, int offset ) const;
151 
152  void updateLayerFields();
153 
154  protected:
156  friend class QgsVectorLayer;
157 
165 
171 
174 
177 
180 
182  QList<QgsField> mAddedAttributes;
183 
186 
187 };
188 
189 #endif // QGSVECTORLAYEREDITBUFFER_H
const QgsGeometryMap & changedGeometries()
Changed geometries which are not commited.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:315
static unsigned index
QMap< int, QVariant > QgsAttributeMap
Definition: qgsfeature.h:98
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:317
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:322
const QgsChangedAttributesMap & changedAttributeValues()
Changed attributes values which are not commited.
Container of fields for a vector layer.
Definition: qgsfield.h:172
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:33
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:312
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.