QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
83 
90  void layerProgressUpdated( int layer, int numLayers );
91 
99 
104  void progressUpdated( int progress );
105 
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
Base class for all map layer types.
Definition: qgsmaplayer.h:85
void layerProgressUpdated(int layer, int numLayers)
Emitted whenever a new layer is being processed.
void progressModeSet(QgsOfflineEditing::ProgressMode mode, int maximum)
Emitted when the mode for the progress of the current operation is set.
void warning(const QString &title, const QString &message)
Emitted when a warning needs to be displayed.
void progressStopped()
Emitted when the processing of all layers has finished.
void progressUpdated(int progress)
Emitted with the progress of the current mode.
ContainerType
Type of offline database container file.
void progressStarted()
Emitted when the process has started.
Represents a vector layer which manages a vector based data sets.
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
struct sqlite3 sqlite3
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:609
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Definition: qgsfeature.h:600
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:614
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:37
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28