QGIS API Documentation  3.2.0-Bonn (bc43194)
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 "qgsvectorlayer.h"
25 #include "qgssqliteutils.h"
26 
27 #include <QObject>
28 #include <QString>
29 
30 class QgsMapLayer;
31 class QgsVectorLayer;
32 
36 class CORE_EXPORT QgsOfflineEditing : public QObject
37 {
38  Q_OBJECT
39 
40  public:
42  {
43  CopyFeatures = 0,
49  UpdateGeometries
50  };
51 
53 
61  bool convertToOfflineProject( const QString &offlineDataPath, const QString &offlineDbFile, const QStringList &layerIds, bool onlySelected = false );
62 
64  bool isOfflineProject() const;
65 
67  void synchronize();
68 
69  signals:
70 
74  void progressStarted();
75 
82  void layerProgressUpdated( int layer, int numLayers );
83 
90  void progressModeSet( QgsOfflineEditing::ProgressMode mode, int maximum );
91 
96  void progressUpdated( int progress );
97 
99  void progressStopped();
100 
106  void warning( const QString &title, const QString &message );
107 
108  private:
109  void initializeSpatialMetadata( sqlite3 *sqlite_handle );
110  bool createSpatialiteDB( const QString &offlineDbPath );
111  void createLoggingTables( sqlite3 *db );
112  QgsVectorLayer *copyVectorLayer( QgsVectorLayer *layer, sqlite3 *db, const QString &offlineDbPath, bool onlySelected );
113 
114  void applyAttributesAdded( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
115  void applyFeaturesAdded( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
116  void applyFeaturesRemoved( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
117  void applyAttributeValueChanges( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
118  void applyGeometryChanges( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
119  void updateFidLookup( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
120  void copySymbology( QgsVectorLayer *sourceLayer, QgsVectorLayer *targetLayer );
121 
125  void updateRelations( QgsVectorLayer *sourceLayer, QgsVectorLayer *targetLayer );
126 
130  void updateMapThemes( QgsVectorLayer *sourceLayer, QgsVectorLayer *targetLayer );
131 
135  void updateLayerOrder( QgsVectorLayer *sourceLayer, QgsVectorLayer *targetLayer );
136 
137  QMap<int, int> attributeLookup( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer );
138 
139  void showWarning( const QString &message );
140 
141  sqlite3_database_unique_ptr openLoggingDb();
142  int getOrCreateLayerId( sqlite3 *db, const QString &qgisLayerId );
143  int getCommitNo( sqlite3 *db );
144  void increaseCommitNo( sqlite3 *db );
145  void addFidLookup( sqlite3 *db, int layerId, QgsFeatureId offlineFid, QgsFeatureId remoteFid );
146  QgsFeatureId remoteFid( sqlite3 *db, int layerId, QgsFeatureId offlineFid );
147  QgsFeatureId offlineFid( sqlite3 *db, int layerId, QgsFeatureId remoteFid );
148  bool isAddedFeature( sqlite3 *db, int layerId, QgsFeatureId fid );
149 
150  int sqlExec( sqlite3 *db, const QString &sql );
151  int sqlQueryInt( sqlite3 *db, const QString &sql, int defaultValue );
152  QList<int> sqlQueryInts( sqlite3 *db, const QString &sql );
153 
154  QList<QgsField> sqlQueryAttributesAdded( sqlite3 *db, const QString &sql );
155  QgsFeatureIds sqlQueryFeaturesRemoved( sqlite3 *db, const QString &sql );
156 
157  struct AttributeValueChange
158  {
159  QgsFeatureId fid;
160  int attr;
161  QString value;
162  };
163  typedef QList<AttributeValueChange> AttributeValueChanges;
164  AttributeValueChanges sqlQueryAttributeValueChanges( sqlite3 *db, const QString &sql );
165 
166  struct GeometryChange
167  {
168  QgsFeatureId fid;
169  QString geom_wkt;
170  };
171  typedef QList<GeometryChange> GeometryChanges;
172  GeometryChanges sqlQueryGeometryChanges( sqlite3 *db, const QString &sql );
173 
174  private slots:
175  void layerAdded( QgsMapLayer *layer );
176  void committedAttributesAdded( const QString &qgisLayerId, const QList<QgsField> &addedAttributes );
177  void committedFeaturesAdded( const QString &qgisLayerId, const QgsFeatureList &addedFeatures );
178  void committedFeaturesRemoved( const QString &qgisLayerId, const QgsFeatureIds &deletedFeatureIds );
179  void committedAttributeValuesChanges( const QString &qgisLayerId, const QgsChangedAttributesMap &changedAttrsMap );
180  void committedGeometriesChanges( const QString &qgisLayerId, const QgsGeometryMap &changedGeometries );
181  void startListenFeatureChanges();
182  void stopListenFeatureChanges();
183 };
184 
185 #endif // QGS_OFFLINE_EDITING_H
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:537
Base class for all map layer types.
Definition: qgsmaplayer.h:61
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:544
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:549
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:528
qint64 QgsFeatureId
Definition: qgsfeature.h:37
Represents a vector layer which manages a vector based data sets.