QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
59  bool convertToOfflineProject( const QString& offlineDataPath, const QString& offlineDbFile, const QStringList& layerIds, bool onlySelected = false );
60 
62  bool isOfflineProject() const;
63 
65  void synchronize();
66 
67  signals:
69  void progressStarted();
70 
75  void layerProgressUpdated( int layer, int numLayers );
76 
81  void progressModeSet( QgsOfflineEditing::ProgressMode mode, int maximum );
82 
86  void progressUpdated( int progress );
87 
89  void progressStopped();
90 
96  void warning( const QString& title, const QString& message );
97 
98  private:
99  void initializeSpatialMetadata( sqlite3 *sqlite_handle );
100  bool createSpatialiteDB( const QString& offlineDbPath );
101  void createLoggingTables( sqlite3* db );
102  QgsVectorLayer* copyVectorLayer( QgsVectorLayer* layer, sqlite3* db, const QString& offlineDbPath, bool onlySelected );
103 
104  void applyAttributesAdded( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId, int commitNo );
105  void applyFeaturesAdded( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer, sqlite3* db, int layerId );
106  void applyFeaturesRemoved( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId );
107  void applyAttributeValueChanges( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer, sqlite3* db, int layerId, int commitNo );
108  void applyGeometryChanges( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId, int commitNo );
109  void updateFidLookup( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId );
110  void copySymbology( QgsVectorLayer* sourceLayer, QgsVectorLayer* targetLayer );
114  void updateRelations( QgsVectorLayer* sourceLayer, QgsVectorLayer* targetLayer );
118  void updateVisibilityPresets( QgsVectorLayer* sourceLayer, QgsVectorLayer* targetLayer );
119 
120  QMap<int, int> attributeLookup( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer );
121 
122  void showWarning( const QString& message );
123 
124  sqlite3* openLoggingDb();
125  int getOrCreateLayerId( sqlite3* db, const QString& qgisLayerId );
126  int getCommitNo( sqlite3* db );
127  void increaseCommitNo( sqlite3* db );
128  void addFidLookup( sqlite3* db, int layerId, QgsFeatureId offlineFid, QgsFeatureId remoteFid );
129  QgsFeatureId remoteFid( sqlite3* db, int layerId, QgsFeatureId offlineFid );
130  QgsFeatureId offlineFid( sqlite3* db, int layerId, QgsFeatureId remoteFid );
131  bool isAddedFeature( sqlite3* db, int layerId, QgsFeatureId fid );
132 
133  int sqlExec( sqlite3* db, const QString& sql );
134  int sqlQueryInt( sqlite3* db, const QString& sql, int defaultValue );
135  QList<int> sqlQueryInts( sqlite3* db, const QString& sql );
136 
137  QList<QgsField> sqlQueryAttributesAdded( sqlite3* db, const QString& sql );
138  QgsFeatureIds sqlQueryFeaturesRemoved( sqlite3* db, const QString& sql );
139 
140  struct AttributeValueChange
141  {
142  QgsFeatureId fid;
143  int attr;
144  QString value;
145  };
147  AttributeValueChanges sqlQueryAttributeValueChanges( sqlite3* db, const QString& sql );
148 
149  struct GeometryChange
150  {
151  QgsFeatureId fid;
152  QString geom_wkt;
153  };
155  GeometryChanges sqlQueryGeometryChanges( sqlite3* db, const QString& sql );
159  bool syncError;
160 
161 
162  private slots:
163  void layerAdded( QgsMapLayer* layer );
164  void committedAttributesAdded( const QString& qgisLayerId, const QList<QgsField>& addedAttributes );
165  void committedFeaturesAdded( const QString& qgisLayerId, const QgsFeatureList& addedFeatures );
166  void committedFeaturesRemoved( const QString& qgisLayerId, const QgsFeatureIds& deletedFeatureIds );
167  void committedAttributeValuesChanges( const QString& qgisLayerId, const QgsChangedAttributesMap& changedAttrsMap );
168  void committedGeometriesChanges( const QString& qgisLayerId, const QgsGeometryMap& changedGeometries );
169  void startListenFeatureChanges();
170  void stopListenFeatureChanges();
171 };
172 
173 #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.