QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsofflineediting.h
Go to the documentation of this file.
1 /***************************************************************************
2  offline_editing.h
3 
4  Offline Editing Plugin
5  a QGIS plugin
6  --------------------------------------
7  Date : 22-Jul-2010
8  Copyright : (C) 2010 by Sourcepole
9  Email : info at sourcepole.ch
10  ***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 #ifndef QGS_OFFLINE_EDITING_H
20 #define QGS_OFFLINE_EDITING_H
21 
22 #include <qgsfeature.h>
23 #include <qgsvectorlayer.h>
24 
25 #include <QObject>
26 #include <QString>
27 
28 class QgsMapLayer;
29 class QgsVectorLayer;
30 struct sqlite3;
31 
32 class CORE_EXPORT QgsOfflineEditing : public QObject
33 {
34  Q_OBJECT
35 
36  public:
38  {
39  CopyFeatures = 0,
45  UpdateGeometries
46  };
47 
50 
56  bool convertToOfflineProject( const QString& offlineDataPath, const QString& offlineDbFile, const QStringList& layerIds );
57 
59  bool isOfflineProject();
60 
62  void synchronize();
63 
64  signals:
66  void progressStarted();
67 
72  void layerProgressUpdated( int layer, int numLayers );
73 
78  void progressModeSet( QgsOfflineEditing::ProgressMode mode, int maximum );
79 
83  void progressUpdated( int progress );
84 
86  void progressStopped();
87 
88  private:
89  void initializeSpatialMetadata( sqlite3 *sqlite_handle );
90  bool createSpatialiteDB( const QString& offlineDbPath );
91  void createLoggingTables( sqlite3* db );
92  void copyVectorLayer( QgsVectorLayer* layer, sqlite3* db, const QString& offlineDbPath );
93 
94  void applyAttributesAdded( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId, int commitNo );
95  void applyFeaturesAdded( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer, sqlite3* db, int layerId );
96  void applyFeaturesRemoved( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId );
97  void applyAttributeValueChanges( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer, sqlite3* db, int layerId, int commitNo );
98  void applyGeometryChanges( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId, int commitNo );
99  void updateFidLookup( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId );
100  void copySymbology( const QgsVectorLayer* sourceLayer, QgsVectorLayer* targetLayer );
101  QMap<int, int> attributeLookup( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer );
102 
103  void showWarning( const QString& message );
104 
105  sqlite3* openLoggingDb();
106  int getOrCreateLayerId( sqlite3* db, const QString& qgisLayerId );
107  int getCommitNo( sqlite3* db );
108  void increaseCommitNo( sqlite3* db );
109  void addFidLookup( sqlite3* db, int layerId, QgsFeatureId offlineFid, QgsFeatureId remoteFid );
110  QgsFeatureId remoteFid( sqlite3* db, int layerId, QgsFeatureId offlineFid );
111  QgsFeatureId offlineFid( sqlite3* db, int layerId, QgsFeatureId remoteFid );
112  bool isAddedFeature( sqlite3* db, int layerId, QgsFeatureId fid );
113 
114  int sqlExec( sqlite3* db, const QString& sql );
115  int sqlQueryInt( sqlite3* db, const QString& sql, int defaultValue );
116  QList<int> sqlQueryInts( sqlite3* db, const QString& sql );
117 
118  QList<QgsField> sqlQueryAttributesAdded( sqlite3* db, const QString& sql );
119  QgsFeatureIds sqlQueryFeaturesRemoved( sqlite3* db, const QString& sql );
120 
121  struct AttributeValueChange
122  {
123  QgsFeatureId fid;
124  int attr;
125  QString value;
126  };
127  typedef QList<AttributeValueChange> AttributeValueChanges;
128  AttributeValueChanges sqlQueryAttributeValueChanges( sqlite3* db, const QString& sql );
129 
130  struct GeometryChange
131  {
132  QgsFeatureId fid;
133  QString geom_wkt;
134  };
135  typedef QList<GeometryChange> GeometryChanges;
136  GeometryChanges sqlQueryGeometryChanges( sqlite3* db, const QString& sql );
137 
138  private slots:
139  void layerAdded( QgsMapLayer* layer );
140  void committedAttributesAdded( const QString& qgisLayerId, const QList<QgsField>& addedAttributes );
141  void committedFeaturesAdded( const QString& qgisLayerId, const QgsFeatureList& addedFeatures );
142  void committedFeaturesRemoved( const QString& qgisLayerId, const QgsFeatureIds& deletedFeatureIds );
143  void committedAttributeValuesChanges( const QString& qgisLayerId, const QgsChangedAttributesMap& changedAttrsMap );
144  void committedGeometriesChanges( const QString& qgisLayerId, const QgsGeometryMap& changedGeometries );
145  void startListenFeatureChanges();
146  void stopListenFeatureChanges();
147 };
148 
149 #endif // QGS_OFFLINE_EDITING_H