QGIS API Documentation  2.17.0-Master (8784312)
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 
34 class CORE_EXPORT QgsOfflineEditing : public QObject
35 {
36  Q_OBJECT
37 
38  public:
40  {
41  CopyFeatures = 0,
47  UpdateGeometries
48  };
49 
52 
58  bool convertToOfflineProject( const QString& offlineDataPath, const QString& offlineDbFile, const QStringList& layerIds );
59 
61  bool isOfflineProject();
62 
64  void synchronize();
65 
66  signals:
68  void progressStarted();
69 
74  void layerProgressUpdated( int layer, int numLayers );
75 
80  void progressModeSet( QgsOfflineEditing::ProgressMode mode, int maximum );
81 
85  void progressUpdated( int progress );
86 
88  void progressStopped();
89 
95  void warning( const QString& title, const QString& message );
96 
97  private:
98  void initializeSpatialMetadata( sqlite3 *sqlite_handle );
99  bool createSpatialiteDB( const QString& offlineDbPath );
100  void createLoggingTables( sqlite3* db );
101  QgsVectorLayer* copyVectorLayer( QgsVectorLayer* layer, sqlite3* db, const QString& offlineDbPath );
102 
103  void applyAttributesAdded( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId, int commitNo );
104  void applyFeaturesAdded( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer, sqlite3* db, int layerId );
105  void applyFeaturesRemoved( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId );
106  void applyAttributeValueChanges( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer, sqlite3* db, int layerId, int commitNo );
107  void applyGeometryChanges( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId, int commitNo );
108  void updateFidLookup( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId );
109  void copySymbology( QgsVectorLayer* sourceLayer, QgsVectorLayer* targetLayer );
110  QMap<int, int> attributeLookup( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer );
111 
112  void showWarning( const QString& message );
113 
114  sqlite3* openLoggingDb();
115  int getOrCreateLayerId( sqlite3* db, const QString& qgisLayerId );
116  int getCommitNo( sqlite3* db );
117  void increaseCommitNo( sqlite3* db );
118  void addFidLookup( sqlite3* db, int layerId, QgsFeatureId offlineFid, QgsFeatureId remoteFid );
119  QgsFeatureId remoteFid( sqlite3* db, int layerId, QgsFeatureId offlineFid );
120  QgsFeatureId offlineFid( sqlite3* db, int layerId, QgsFeatureId remoteFid );
121  bool isAddedFeature( sqlite3* db, int layerId, QgsFeatureId fid );
122 
123  int sqlExec( sqlite3* db, const QString& sql );
124  int sqlQueryInt( sqlite3* db, const QString& sql, int defaultValue );
125  QList<int> sqlQueryInts( sqlite3* db, const QString& sql );
126 
127  QList<QgsField> sqlQueryAttributesAdded( sqlite3* db, const QString& sql );
128  QgsFeatureIds sqlQueryFeaturesRemoved( sqlite3* db, const QString& sql );
129 
130  struct AttributeValueChange
131  {
132  QgsFeatureId fid;
133  int attr;
134  QString value;
135  };
137  AttributeValueChanges sqlQueryAttributeValueChanges( sqlite3* db, const QString& sql );
138 
139  struct GeometryChange
140  {
141  QgsFeatureId fid;
142  QString geom_wkt;
143  };
145  GeometryChanges sqlQueryGeometryChanges( sqlite3* db, const QString& sql );
146 
147  private slots:
148  void layerAdded( QgsMapLayer* layer );
149  void committedAttributesAdded( const QString& qgisLayerId, const QList<QgsField>& addedAttributes );
150  void committedFeaturesAdded( const QString& qgisLayerId, const QgsFeatureList& addedFeatures );
151  void committedFeaturesRemoved( const QString& qgisLayerId, const QgsFeatureIds& deletedFeatureIds );
152  void committedAttributeValuesChanges( const QString& qgisLayerId, const QgsChangedAttributesMap& changedAttrsMap );
153  void committedGeometriesChanges( const QString& qgisLayerId, const QgsGeometryMap& changedGeometries );
154  void startListenFeatureChanges();
155  void stopListenFeatureChanges();
156 };
157 
158 #endif // QGS_OFFLINE_EDITING_H
Base class for all map layer types.
Definition: qgsmaplayer.h:49
struct sqlite3 sqlite3
qint64 QgsFeatureId
Definition: qgsfeature.h:31
Represents a vector layer which manages a vector based data sets.