QGIS API Documentation  2.99.0-Master (7d4f81d)
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:
68 
72  void progressStarted();
73 
80  void layerProgressUpdated( int layer, int numLayers );
81 
88  void progressModeSet( QgsOfflineEditing::ProgressMode mode, int maximum );
89 
93  void progressUpdated( int progress );
94 
96  void progressStopped();
97 
103  void warning( const QString &title, const QString &message );
104 
105  private:
106  void initializeSpatialMetadata( sqlite3 *sqlite_handle );
107  bool createSpatialiteDB( const QString &offlineDbPath );
108  void createLoggingTables( sqlite3 *db );
109  QgsVectorLayer *copyVectorLayer( QgsVectorLayer *layer, sqlite3 *db, const QString &offlineDbPath, bool onlySelected );
110 
111  void applyAttributesAdded( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
112  void applyFeaturesAdded( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
113  void applyFeaturesRemoved( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
114  void applyAttributeValueChanges( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
115  void applyGeometryChanges( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
116  void updateFidLookup( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
117  void copySymbology( QgsVectorLayer *sourceLayer, QgsVectorLayer *targetLayer );
118 
122  void updateRelations( QgsVectorLayer *sourceLayer, QgsVectorLayer *targetLayer );
123 
127  void updateMapThemes( QgsVectorLayer *sourceLayer, QgsVectorLayer *targetLayer );
128 
132  void updateLayerOrder( QgsVectorLayer *sourceLayer, QgsVectorLayer *targetLayer );
133 
134  QMap<int, int> attributeLookup( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer );
135 
136  void showWarning( const QString &message );
137 
138  sqlite3 *openLoggingDb();
139  int getOrCreateLayerId( sqlite3 *db, const QString &qgisLayerId );
140  int getCommitNo( sqlite3 *db );
141  void increaseCommitNo( sqlite3 *db );
142  void addFidLookup( sqlite3 *db, int layerId, QgsFeatureId offlineFid, QgsFeatureId remoteFid );
143  QgsFeatureId remoteFid( sqlite3 *db, int layerId, QgsFeatureId offlineFid );
144  QgsFeatureId offlineFid( sqlite3 *db, int layerId, QgsFeatureId remoteFid );
145  bool isAddedFeature( sqlite3 *db, int layerId, QgsFeatureId fid );
146 
147  int sqlExec( sqlite3 *db, const QString &sql );
148  int sqlQueryInt( sqlite3 *db, const QString &sql, int defaultValue );
149  QList<int> sqlQueryInts( sqlite3 *db, const QString &sql );
150 
151  QList<QgsField> sqlQueryAttributesAdded( sqlite3 *db, const QString &sql );
152  QgsFeatureIds sqlQueryFeaturesRemoved( sqlite3 *db, const QString &sql );
153 
154  struct AttributeValueChange
155  {
156  QgsFeatureId fid;
157  int attr;
158  QString value;
159  };
160  typedef QList<AttributeValueChange> AttributeValueChanges;
161  AttributeValueChanges sqlQueryAttributeValueChanges( sqlite3 *db, const QString &sql );
162 
163  struct GeometryChange
164  {
165  QgsFeatureId fid;
166  QString geom_wkt;
167  };
168  typedef QList<GeometryChange> GeometryChanges;
169  GeometryChanges sqlQueryGeometryChanges( sqlite3 *db, const QString &sql );
170 
171  private slots:
172  void layerAdded( QgsMapLayer *layer );
173  void committedAttributesAdded( const QString &qgisLayerId, const QList<QgsField> &addedAttributes );
174  void committedFeaturesAdded( const QString &qgisLayerId, const QgsFeatureList &addedFeatures );
175  void committedFeaturesRemoved( const QString &qgisLayerId, const QgsFeatureIds &deletedFeatureIds );
176  void committedAttributeValuesChanges( const QString &qgisLayerId, const QgsChangedAttributesMap &changedAttrsMap );
177  void committedGeometriesChanges( const QString &qgisLayerId, const QgsGeometryMap &changedGeometries );
178  void startListenFeatureChanges();
179  void stopListenFeatureChanges();
180 };
181 
182 #endif // QGS_OFFLINE_EDITING_H
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:512
Base class for all map layer types.
Definition: qgsmaplayer.h:54
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:519
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:524
struct sqlite3 sqlite3
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Definition: qgsfeature.h:503
qint64 QgsFeatureId
Definition: qgsfeature.h:37
Represents a vector layer which manages a vector based data sets.