QGIS API Documentation  master-3f58142
src/core/qgsofflineediting.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     offline_editing.h
00003 
00004     Offline Editing Plugin
00005     a QGIS plugin
00006      --------------------------------------
00007     Date                 : 22-Jul-2010
00008     Copyright            : (C) 2010 by Sourcepole
00009     Email                : info at sourcepole.ch
00010  ***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 
00019 #ifndef QGS_OFFLINE_EDITING_H
00020 #define QGS_OFFLINE_EDITING_H
00021 
00022 #include <qgsfeature.h>
00023 #include <qgsvectorlayer.h>
00024 
00025 #include <QObject>
00026 #include <QString>
00027 
00028 class QgsMapLayer;
00029 class QgsVectorLayer;
00030 struct sqlite3;
00031 
00032 class CORE_EXPORT QgsOfflineEditing : public QObject
00033 {
00034     Q_OBJECT
00035 
00036   public:
00037     enum ProgressMode
00038     {
00039       CopyFeatures = 0,
00040       ProcessFeatures,
00041       AddFields,
00042       AddFeatures,
00043       RemoveFeatures,
00044       UpdateFeatures,
00045       UpdateGeometries
00046     };
00047 
00048     QgsOfflineEditing();
00049     ~QgsOfflineEditing();
00050 
00056     bool convertToOfflineProject( const QString& offlineDataPath, const QString& offlineDbFile, const QStringList& layerIds );
00057 
00059     bool isOfflineProject();
00060 
00062     void synchronize();
00063 
00064   signals:
00066     void progressStarted();
00067 
00072     void layerProgressUpdated( int layer, int numLayers );
00073 
00078     void progressModeSet( QgsOfflineEditing::ProgressMode mode, int maximum );
00079 
00083     void progressUpdated( int progress );
00084 
00086     void progressStopped();
00087 
00088   private:
00089     void initializeSpatialMetadata( sqlite3 *sqlite_handle );
00090     bool createSpatialiteDB( const QString& offlineDbPath );
00091     void createLoggingTables( sqlite3* db );
00092     void copyVectorLayer( QgsVectorLayer* layer, sqlite3* db, const QString& offlineDbPath );
00093 
00094     void applyAttributesAdded( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId, int commitNo );
00095     void applyFeaturesAdded( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer, sqlite3* db, int layerId );
00096     void applyFeaturesRemoved( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId );
00097     void applyAttributeValueChanges( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer, sqlite3* db, int layerId, int commitNo );
00098     void applyGeometryChanges( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId, int commitNo );
00099     void updateFidLookup( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId );
00100     void copySymbology( const QgsVectorLayer* sourceLayer, QgsVectorLayer* targetLayer );
00101     QMap<int, int> attributeLookup( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer );
00102 
00103     void showWarning( const QString& message );
00104 
00105     sqlite3* openLoggingDb();
00106     int getOrCreateLayerId( sqlite3* db, const QString& qgisLayerId );
00107     int getCommitNo( sqlite3* db );
00108     void increaseCommitNo( sqlite3* db );
00109     void addFidLookup( sqlite3* db, int layerId, QgsFeatureId offlineFid, QgsFeatureId remoteFid );
00110     QgsFeatureId remoteFid( sqlite3* db, int layerId, QgsFeatureId offlineFid );
00111     QgsFeatureId offlineFid( sqlite3* db, int layerId, QgsFeatureId remoteFid );
00112     bool isAddedFeature( sqlite3* db, int layerId, QgsFeatureId fid );
00113 
00114     int sqlExec( sqlite3* db, const QString& sql );
00115     int sqlQueryInt( sqlite3* db, const QString& sql, int defaultValue );
00116     QList<int> sqlQueryInts( sqlite3* db, const QString& sql );
00117 
00118     QList<QgsField> sqlQueryAttributesAdded( sqlite3* db, const QString& sql );
00119     QgsFeatureIds sqlQueryFeaturesRemoved( sqlite3* db, const QString& sql );
00120 
00121     struct AttributeValueChange
00122     {
00123       QgsFeatureId fid;
00124       int attr;
00125       QString value;
00126     };
00127     typedef QList<AttributeValueChange> AttributeValueChanges;
00128     AttributeValueChanges sqlQueryAttributeValueChanges( sqlite3* db, const QString& sql );
00129 
00130     struct GeometryChange
00131     {
00132       QgsFeatureId fid;
00133       QString geom_wkt;
00134     };
00135     typedef QList<GeometryChange> GeometryChanges;
00136     GeometryChanges sqlQueryGeometryChanges( sqlite3* db, const QString& sql );
00137 
00138   private slots:
00139     void layerAdded( QgsMapLayer* layer );
00140     void committedAttributesAdded( const QString& qgisLayerId, const QList<QgsField>& addedAttributes );
00141     void committedFeaturesAdded( const QString& qgisLayerId, const QgsFeatureList& addedFeatures );
00142     void committedFeaturesRemoved( const QString& qgisLayerId, const QgsFeatureIds& deletedFeatureIds );
00143     void committedAttributeValuesChanges( const QString& qgisLayerId, const QgsChangedAttributesMap& changedAttrsMap );
00144     void committedGeometriesChanges( const QString& qgisLayerId, const QgsGeometryMap& changedGeometries );
00145 };
00146 
00147 #endif // QGS_OFFLINE_EDITING_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines