QGIS API Documentation  3.17.0-Master (a035f434f4)
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 
69  bool convertToOfflineProject( const QString &offlineDataPath, const QString &offlineDbFile, const QStringList &layerIds, bool onlySelected = false, ContainerType containerType = SpatiaLite, const QString &layerNameSuffix = QStringLiteral( " (offline)" ) );
70 
72  bool isOfflineProject() const;
73 
75  void synchronize();
76 
77  signals:
78 
82  void progressStarted();
83 
90  void layerProgressUpdated( int layer, int numLayers );
91 
98  void progressModeSet( QgsOfflineEditing::ProgressMode mode, int maximum );
99 
104  void progressUpdated( int progress );
105 
107  void progressStopped();
108 
114  void warning( const QString &title, const QString &message );
115 
116  private:
117  void initializeSpatialMetadata( sqlite3 *sqlite_handle );
118  bool createOfflineDb( const QString &offlineDbPath, ContainerType containerType = SpatiaLite );
119  void createLoggingTables( sqlite3 *db );
120 
121  QgsVectorLayer *copyVectorLayer( QgsVectorLayer *layer, sqlite3 *db, const QString &offlineDbPath, bool onlySelected, ContainerType containerType = SpatiaLite, const QString &layerNameSuffix = QStringLiteral( " (offline)" ) );
122 
123  void applyAttributesAdded( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
124  void applyFeaturesAdded( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
125  void applyFeaturesRemoved( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
126  void applyAttributeValueChanges( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
127  void applyGeometryChanges( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
128  void updateFidLookup( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
129  void copySymbology( QgsVectorLayer *sourceLayer, QgsVectorLayer *targetLayer );
130 
134  void updateRelations( QgsVectorLayer *sourceLayer, QgsVectorLayer *targetLayer );
135 
139  void updateMapThemes( QgsVectorLayer *sourceLayer, QgsVectorLayer *targetLayer );
140 
144  void updateLayerOrder( QgsVectorLayer *sourceLayer, QgsVectorLayer *targetLayer );
145 
146  QMap<int, int> attributeLookup( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer );
147 
148  void showWarning( const QString &message );
149 
150  sqlite3_database_unique_ptr openLoggingDb();
151  int getOrCreateLayerId( sqlite3 *db, const QString &qgisLayerId );
152  int getCommitNo( sqlite3 *db );
153  void increaseCommitNo( sqlite3 *db );
154  void addFidLookup( sqlite3 *db, int layerId, QgsFeatureId offlineFid, QgsFeatureId remoteFid );
155  QgsFeatureId remoteFid( sqlite3 *db, int layerId, QgsFeatureId offlineFid );
156  QgsFeatureId offlineFid( sqlite3 *db, int layerId, QgsFeatureId remoteFid );
157  bool isAddedFeature( sqlite3 *db, int layerId, QgsFeatureId fid );
158 
159  int sqlExec( sqlite3 *db, const QString &sql );
160  int sqlQueryInt( sqlite3 *db, const QString &sql, int defaultValue );
161  QList<int> sqlQueryInts( sqlite3 *db, const QString &sql );
162 
163  QList<QgsField> sqlQueryAttributesAdded( sqlite3 *db, const QString &sql );
164  QgsFeatureIds sqlQueryFeaturesRemoved( sqlite3 *db, const QString &sql );
165 
166  struct AttributeValueChange
167  {
168  QgsFeatureId fid;
169  int attr;
170  QString value;
171  };
172  typedef QList<AttributeValueChange> AttributeValueChanges;
173  AttributeValueChanges sqlQueryAttributeValueChanges( sqlite3 *db, const QString &sql );
174 
175  struct GeometryChange
176  {
177  QgsFeatureId fid;
178  QString geom_wkt;
179  };
180  typedef QList<GeometryChange> GeometryChanges;
181  GeometryChanges sqlQueryGeometryChanges( sqlite3 *db, const QString &sql );
182 
183  private slots:
184  void layerAdded( QgsMapLayer *layer );
185  void committedAttributesAdded( const QString &qgisLayerId, const QList<QgsField> &addedAttributes );
186  void committedFeaturesAdded( const QString &qgisLayerId, const QgsFeatureList &addedFeatures );
187  void committedFeaturesRemoved( const QString &qgisLayerId, const QgsFeatureIds &deletedFeatureIds );
188  void committedAttributeValuesChanges( const QString &qgisLayerId, const QgsChangedAttributesMap &changedAttrsMap );
189  void committedGeometriesChanges( const QString &qgisLayerId, const QgsGeometryMap &changedGeometries );
190  void startListenFeatureChanges();
191  void stopListenFeatureChanges();
192 };
193 
194 #endif // QGS_OFFLINE_EDITING_H
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:578
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:37
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:583
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features ...
Definition: qgsfeatureid.h:28
ContainerType
Type of offline database container file.
struct sqlite3 sqlite3
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Definition: qgsfeature.h:569
Represents a vector layer which manages a vector based data sets.