QGIS API Documentation  2.99.0-Master (b8fd1fd)
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 
26 #include <QObject>
27 #include <QString>
28 
29 class QgsMapLayer;
30 class QgsVectorLayer;
31 struct sqlite3;
32 
35 class CORE_EXPORT QgsOfflineEditing : public QObject
36 {
37  Q_OBJECT
38 
39  public:
41  {
42  CopyFeatures = 0,
48  UpdateGeometries
49  };
50 
52 
59  bool convertToOfflineProject( const QString &offlineDataPath, const QString &offlineDbFile, const QStringList &layerIds, bool onlySelected = false );
60 
62  bool isOfflineProject() const;
63 
65  void synchronize();
66 
67  signals:
69  void progressStarted();
70 
75  void layerProgressUpdated( int layer, int numLayers );
76 
81  void progressModeSet( QgsOfflineEditing::ProgressMode mode, int maximum );
82 
86  void progressUpdated( int progress );
87 
89  void progressStopped();
90 
96  void warning( const QString &title, const QString &message );
97 
98  private:
99  void initializeSpatialMetadata( sqlite3 *sqlite_handle );
100  bool createSpatialiteDB( const QString &offlineDbPath );
101  void createLoggingTables( sqlite3 *db );
102  QgsVectorLayer *copyVectorLayer( QgsVectorLayer *layer, sqlite3 *db, const QString &offlineDbPath, bool onlySelected );
103 
104  void applyAttributesAdded( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
105  void applyFeaturesAdded( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
106  void applyFeaturesRemoved( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
107  void applyAttributeValueChanges( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
108  void applyGeometryChanges( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
109  void updateFidLookup( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
110  void copySymbology( QgsVectorLayer *sourceLayer, QgsVectorLayer *targetLayer );
111 
115  void updateRelations( QgsVectorLayer *sourceLayer, QgsVectorLayer *targetLayer );
116 
120  void updateMapThemes( QgsVectorLayer *sourceLayer, QgsVectorLayer *targetLayer );
121 
122  QMap<int, int> attributeLookup( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer );
123 
124  void showWarning( const QString &message );
125 
126  sqlite3 *openLoggingDb();
127  int getOrCreateLayerId( sqlite3 *db, const QString &qgisLayerId );
128  int getCommitNo( sqlite3 *db );
129  void increaseCommitNo( sqlite3 *db );
130  void addFidLookup( sqlite3 *db, int layerId, QgsFeatureId offlineFid, QgsFeatureId remoteFid );
131  QgsFeatureId remoteFid( sqlite3 *db, int layerId, QgsFeatureId offlineFid );
132  QgsFeatureId offlineFid( sqlite3 *db, int layerId, QgsFeatureId remoteFid );
133  bool isAddedFeature( sqlite3 *db, int layerId, QgsFeatureId fid );
134 
135  int sqlExec( sqlite3 *db, const QString &sql );
136  int sqlQueryInt( sqlite3 *db, const QString &sql, int defaultValue );
137  QList<int> sqlQueryInts( sqlite3 *db, const QString &sql );
138 
139  QList<QgsField> sqlQueryAttributesAdded( sqlite3 *db, const QString &sql );
140  QgsFeatureIds sqlQueryFeaturesRemoved( sqlite3 *db, const QString &sql );
141 
142  struct AttributeValueChange
143  {
144  QgsFeatureId fid;
145  int attr;
146  QString value;
147  };
148  typedef QList<AttributeValueChange> AttributeValueChanges;
149  AttributeValueChanges sqlQueryAttributeValueChanges( sqlite3 *db, const QString &sql );
150 
151  struct GeometryChange
152  {
153  QgsFeatureId fid;
154  QString geom_wkt;
155  };
156  typedef QList<GeometryChange> GeometryChanges;
157  GeometryChanges sqlQueryGeometryChanges( sqlite3 *db, const QString &sql );
158 
159  private slots:
160  void layerAdded( QgsMapLayer *layer );
161  void committedAttributesAdded( const QString &qgisLayerId, const QList<QgsField> &addedAttributes );
162  void committedFeaturesAdded( const QString &qgisLayerId, const QgsFeatureList &addedFeatures );
163  void committedFeaturesRemoved( const QString &qgisLayerId, const QgsFeatureIds &deletedFeatureIds );
164  void committedAttributeValuesChanges( const QString &qgisLayerId, const QgsChangedAttributesMap &changedAttrsMap );
165  void committedGeometriesChanges( const QString &qgisLayerId, const QgsGeometryMap &changedGeometries );
166  void startListenFeatureChanges();
167  void stopListenFeatureChanges();
168 };
169 
170 #endif // QGS_OFFLINE_EDITING_H
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:356
Base class for all map layer types.
Definition: qgsmaplayer.h:52
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:358
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:363
struct sqlite3 sqlite3
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Definition: qgsfeature.h:353
qint64 QgsFeatureId
Definition: qgsfeature.h:33
Represents a vector layer which manages a vector based data sets.