QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
82 
89  void layerProgressUpdated( int layer, int numLayers );
90 
98 
103  void progressUpdated( int progress );
104 
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:569
QgsOfflineEditing::warning
void warning(const QString &title, const QString &message)
Emitted when a warning needs to be displayed.
QgsOfflineEditing::UpdateFeatures
@ UpdateFeatures
Definition: qgsofflineediting.h:47
QgsOfflineEditing::SpatiaLite
@ SpatiaLite
Definition: qgsofflineediting.h:54
QgsOfflineEditing::progressStarted
void progressStarted()
Emitted when the process has started.
QgsOfflineEditing::AddFields
@ AddFields
Definition: qgsofflineediting.h:44
QgsOfflineEditing
Definition: qgsofflineediting.h:36
QgsOfflineEditing::AddFeatures
@ AddFeatures
Definition: qgsofflineediting.h:45
QgsFeatureList
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:583
QgsOfflineEditing::progressStopped
void progressStopped()
Emitted when the processing of all layers has finished.
QgsFeatureIds
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:37
QgsOfflineEditing::RemoveFeatures
@ RemoveFeatures
Definition: qgsofflineediting.h:46
QgsOfflineEditing::ContainerType
ContainerType
Type of offline database container file.
Definition: qgsofflineediting.h:53
QgsOfflineEditing::ProcessFeatures
@ ProcessFeatures
Definition: qgsofflineediting.h:43
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QgsOfflineEditing::layerProgressUpdated
void layerProgressUpdated(int layer, int numLayers)
Emitted whenever a new layer is being processed.
qgssqliteutils.h
QgsOfflineEditing::progressUpdated
void progressUpdated(int progress)
Emitted with the progress of the current mode.
QgsGeometryMap
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:578
sqlite3_database_unique_ptr
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
Definition: qgssqliteutils.h:119
QgsOfflineEditing::ProgressMode
ProgressMode
Definition: qgsofflineediting.h:41
QgsOfflineEditing::progressModeSet
void progressModeSet(QgsOfflineEditing::ProgressMode mode, int maximum)
Emitted when the mode for the progress of the current operation is set.
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28