Quantum GIS API Documentation  master-693a1fe
src/core/qgsvectorlayereditbuffer.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     qgsvectorlayereditbuffer.h
00003     ---------------------
00004     begin                : Dezember 2012
00005     copyright            : (C) 2012 by Martin Dobias
00006     email                : wonder dot sk at gmail dot com
00007  ***************************************************************************
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  ***************************************************************************/
00015 #ifndef QGSVECTORLAYEREDITBUFFER_H
00016 #define QGSVECTORLAYEREDITBUFFER_H
00017 
00018 #include <QList>
00019 #include <QSet>
00020 
00021 #include "qgsgeometry.h"
00022 #include "qgsfeature.h"
00023 #include "qgsfield.h"
00024 #include "qgsrectangle.h"
00025 #include "qgssnapper.h"
00026 
00027 class QgsVectorLayer;
00028 
00029 typedef QList<int> QgsAttributeList;
00030 typedef QSet<int> QgsAttributeIds;
00031 typedef QMap<QgsFeatureId, QgsFeature> QgsFeatureMap;
00032 
00033 class CORE_EXPORT QgsVectorLayerEditBuffer : public QObject
00034 {
00035     Q_OBJECT
00036   public:
00037     QgsVectorLayerEditBuffer( QgsVectorLayer* layer );
00038     ~QgsVectorLayerEditBuffer();
00039 
00041     bool isModified() const;
00042 
00043 
00048     bool addFeature( QgsFeature& f );
00049 
00051     bool addFeatures( QgsFeatureList& features );
00052 
00054     bool deleteFeature( QgsFeatureId fid );
00055 
00058     bool changeGeometry( QgsFeatureId fid, QgsGeometry* geom );
00059 
00061     bool changeAttributeValue( QgsFeatureId fid, int field, QVariant value );
00062 
00066     bool addAttribute( const QgsField &field );
00067 
00069     bool deleteAttribute( int attr );
00070 
00071 
00087     bool commitChanges( QStringList& commitErrors );
00088 
00090     void rollBack();
00091 
00092 
00093 
00095     inline const QgsFeatureMap& addedFeatures() { return mAddedFeatures; }
00096 
00098     inline const QgsChangedAttributesMap& changedAttributeValues() { return mChangedAttributeValues; }
00099 
00101     inline const QgsAttributeList& deletedAttributeIds() { return mDeletedAttributeIds; }
00102 
00104     inline const QList<QgsField>& addedAttributes() { return mAddedAttributes; }
00105 
00107     inline const QgsGeometryMap& changedGeometries() { return mChangedGeometries; }
00108 
00109     //QString dumpEditBuffer();
00110 
00111 
00112   protected slots:
00113     void undoIndexChanged( int index );
00114 
00115   signals:
00117     void layerModified();
00118 
00119     void featureAdded( QgsFeatureId fid );
00120     void featureDeleted( QgsFeatureId fid );
00121     void geometryChanged( QgsFeatureId fid, QgsGeometry &geom );
00122     void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant & );
00123     void attributeAdded( int idx );
00124     void attributeDeleted( int idx );
00125 
00128     void committedAttributesDeleted( const QString& layerId, const QgsAttributeList& deletedAttributes );
00129     void committedAttributesAdded( const QString& layerId, const QList<QgsField>& addedAttributes );
00130     void committedFeaturesAdded( const QString& layerId, const QgsFeatureList& addedFeatures );
00131     void committedFeaturesRemoved( const QString& layerId, const QgsFeatureIds& deletedFeatureIds );
00132     void committedAttributeValuesChanges( const QString& layerId, const QgsChangedAttributesMap& changedAttributesValues );
00133     void committedGeometriesChanges( const QString& layerId, const QgsGeometryMap& changedGeometries );
00134 
00135   protected:
00136 
00137     void updateFields( QgsFields& fields );
00138 
00140     void updateFeatureGeometry( QgsFeature &f );
00141 
00143     void updateChangedAttributes( QgsFeature &f );
00144 
00146     void handleAttributeAdded( int index );
00147 
00149     void handleAttributeDeleted( int index );
00150 
00151 
00153     void updateAttributeMapIndex( QgsAttributeMap& attrs, int index, int offset ) const;
00154 
00155     void updateLayerFields();
00156 
00157   protected:
00158     QgsVectorLayer* L;
00159     friend class QgsVectorLayer;
00160     friend class QgsVectorLayerFeatureIterator;
00161 
00162     friend class QgsVectorLayerUndoCommand;
00163     friend class QgsVectorLayerUndoCommandAddFeature;
00164     friend class QgsVectorLayerUndoCommandDeleteFeature;
00165     friend class QgsVectorLayerUndoCommandChangeGeometry;
00166     friend class QgsVectorLayerUndoCommandChangeAttribute;
00167     friend class QgsVectorLayerUndoCommandAddAttribute;
00168     friend class QgsVectorLayerUndoCommandDeleteAttribute;
00169 
00174     QgsFeatureIds mDeletedFeatureIds;
00175 
00177     QgsFeatureMap mAddedFeatures;
00178 
00180     QgsChangedAttributesMap mChangedAttributeValues;
00181 
00183     QgsAttributeList mDeletedAttributeIds;
00184 
00186     QList<QgsField> mAddedAttributes;
00187 
00189     QgsGeometryMap mChangedGeometries;
00190 
00191 };
00192 
00193 #endif // QGSVECTORLAYEREDITBUFFER_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines