QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 "qgis_core.h"
23 #include "qgsfeature.h"
24 #include "qgssqliteutils.h"
25 
26 #include <QObject>
27 #include <QString>
28 
29 class QgsMapLayer;
30 class QgsVectorLayer;
31 
35 class CORE_EXPORT QgsOfflineEditing : public QObject
36 {
37  Q_OBJECT
38 
39  public:
41  {
42  CopyFeatures = 0,
48  UpdateGeometries
49  };
50 
53  {
55  GPKG
56  };
57 
59 
68  bool convertToOfflineProject( const QString &offlineDataPath, const QString &offlineDbFile, const QStringList &layerIds, bool onlySelected = false, ContainerType containerType = SpatiaLite );
69 
71  bool isOfflineProject() const;
72 
74  void synchronize();
75 
76  signals:
77 
81  void progressStarted();
82 
89  void layerProgressUpdated( int layer, int numLayers );
90 
97  void progressModeSet( QgsOfflineEditing::ProgressMode mode, int maximum );
98 
103  void progressUpdated( int progress );
104 
106  void progressStopped();
107 
113  void warning( const QString &title, const QString &message );
114 
115  private:
116  void initializeSpatialMetadata( sqlite3 *sqlite_handle );
117  bool createOfflineDb( const QString &offlineDbPath, ContainerType containerType = SpatiaLite );
118  void createLoggingTables( sqlite3 *db );
119 
120  QgsVectorLayer *copyVectorLayer( QgsVectorLayer *layer, sqlite3 *db, const QString &offlineDbPath, bool onlySelected, ContainerType containerType = SpatiaLite );
121 
122  void applyAttributesAdded( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
123  void applyFeaturesAdded( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
124  void applyFeaturesRemoved( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
125  void applyAttributeValueChanges( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
126  void applyGeometryChanges( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
127  void updateFidLookup( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
128  void copySymbology( QgsVectorLayer *sourceLayer, QgsVectorLayer *targetLayer );
129 
133  void updateRelations( QgsVectorLayer *sourceLayer, QgsVectorLayer *targetLayer );
134 
138  void updateMapThemes( QgsVectorLayer *sourceLayer, QgsVectorLayer *targetLayer );
139 
143  void updateLayerOrder( QgsVectorLayer *sourceLayer, QgsVectorLayer *targetLayer );
144 
145  QMap<int, int> attributeLookup( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer );
146 
147  void showWarning( const QString &message );
148 
149  sqlite3_database_unique_ptr openLoggingDb();
150  int getOrCreateLayerId( sqlite3 *db, const QString &qgisLayerId );
151  int getCommitNo( sqlite3 *db );
152  void increaseCommitNo( sqlite3 *db );
153  void addFidLookup( sqlite3 *db, int layerId, QgsFeatureId offlineFid, QgsFeatureId remoteFid );
154  QgsFeatureId remoteFid( sqlite3 *db, int layerId, QgsFeatureId offlineFid );
155  QgsFeatureId offlineFid( sqlite3 *db, int layerId, QgsFeatureId remoteFid );
156  bool isAddedFeature( sqlite3 *db, int layerId, QgsFeatureId fid );
157 
158  int sqlExec( sqlite3 *db, const QString &sql );
159  int sqlQueryInt( sqlite3 *db, const QString &sql, int defaultValue );
160  QList<int> sqlQueryInts( sqlite3 *db, const QString &sql );
161 
162  QList<QgsField> sqlQueryAttributesAdded( sqlite3 *db, const QString &sql );
163  QgsFeatureIds sqlQueryFeaturesRemoved( sqlite3 *db, const QString &sql );
164 
165  struct AttributeValueChange
166  {
167  QgsFeatureId fid;
168  int attr;
169  QString value;
170  };
171  typedef QList<AttributeValueChange> AttributeValueChanges;
172  AttributeValueChanges sqlQueryAttributeValueChanges( sqlite3 *db, const QString &sql );
173 
174  struct GeometryChange
175  {
176  QgsFeatureId fid;
177  QString geom_wkt;
178  };
179  typedef QList<GeometryChange> GeometryChanges;
180  GeometryChanges sqlQueryGeometryChanges( sqlite3 *db, const QString &sql );
181 
182  private slots:
183  void layerAdded( QgsMapLayer *layer );
184  void committedAttributesAdded( const QString &qgisLayerId, const QList<QgsField> &addedAttributes );
185  void committedFeaturesAdded( const QString &qgisLayerId, const QgsFeatureList &addedFeatures );
186  void committedFeaturesRemoved( const QString &qgisLayerId, const QgsFeatureIds &deletedFeatureIds );
187  void committedAttributeValuesChanges( const QString &qgisLayerId, const QgsChangedAttributesMap &changedAttrsMap );
188  void committedGeometriesChanges( const QString &qgisLayerId, const QgsGeometryMap &changedGeometries );
189  void startListenFeatureChanges();
190  void stopListenFeatureChanges();
191 };
192 
193 #endif // QGS_OFFLINE_EDITING_H
sqlite3
struct sqlite3 sqlite3
Definition: qgscoordinatereferencesystem.h:55
qgsfeature.h
QgsChangedAttributesMap
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Definition: qgsfeature.h:558
QgsOfflineEditing::UpdateFeatures
@ UpdateFeatures
Definition: qgsofflineediting.h:47
QgsOfflineEditing::SpatiaLite
@ SpatiaLite
Definition: qgsofflineediting.h:54
QgsOfflineEditing::AddFields
@ AddFields
Definition: qgsofflineediting.h:44
QgsOfflineEditing
Definition: qgsofflineediting.h:35
QgsOfflineEditing::AddFeatures
@ AddFeatures
Definition: qgsofflineediting.h:45
QgsFeatureList
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:572
QgsFeatureIds
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:34
QgsOfflineEditing::RemoveFeatures
@ RemoveFeatures
Definition: qgsofflineediting.h:46
QgsOfflineEditing::ContainerType
ContainerType
Type of offline database container file.
Definition: qgsofflineediting.h:52
QgsOfflineEditing::ProcessFeatures
@ ProcessFeatures
Definition: qgsofflineediting.h:43
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsMapLayer
Definition: qgsmaplayer.h:81
qgssqliteutils.h
QgsGeometryMap
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:567
sqlite3_database_unique_ptr
Definition: qgssqliteutils.h:118
QgsOfflineEditing::ProgressMode
ProgressMode
Definition: qgsofflineediting.h:40
QgsFeatureId
qint64 QgsFeatureId
Definition: qgsfeatureid.h:25