QGIS API Documentation  2.17.0-Master (0497e4a)
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 <qgsfeature.h>
23 #include <qgsvectorlayer.h>
24 
25 #include <QObject>
26 #include <QString>
27 
28 class QgsMapLayer;
29 class QgsVectorLayer;
30 struct sqlite3;
31 
34 class CORE_EXPORT QgsOfflineEditing : public QObject
35 {
36  Q_OBJECT
37 
38  public:
40  {
41  CopyFeatures = 0,
47  UpdateGeometries
48  };
49 
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  QMap<int, int> attributeLookup( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer );
112 
113  void showWarning( const QString& message );
114 
115  sqlite3* openLoggingDb();
116  int getOrCreateLayerId( sqlite3* db, const QString& qgisLayerId );
117  int getCommitNo( sqlite3* db );
118  void increaseCommitNo( sqlite3* db );
119  void addFidLookup( sqlite3* db, int layerId, QgsFeatureId offlineFid, QgsFeatureId remoteFid );
120  QgsFeatureId remoteFid( sqlite3* db, int layerId, QgsFeatureId offlineFid );
121  QgsFeatureId offlineFid( sqlite3* db, int layerId, QgsFeatureId remoteFid );
122  bool isAddedFeature( sqlite3* db, int layerId, QgsFeatureId fid );
123 
124  int sqlExec( sqlite3* db, const QString& sql );
125  int sqlQueryInt( sqlite3* db, const QString& sql, int defaultValue );
126  QList<int> sqlQueryInts( sqlite3* db, const QString& sql );
127 
128  QList<QgsField> sqlQueryAttributesAdded( sqlite3* db, const QString& sql );
129  QgsFeatureIds sqlQueryFeaturesRemoved( sqlite3* db, const QString& sql );
130 
131  struct AttributeValueChange
132  {
133  QgsFeatureId fid;
134  int attr;
135  QString value;
136  };
138  AttributeValueChanges sqlQueryAttributeValueChanges( sqlite3* db, const QString& sql );
139 
140  struct GeometryChange
141  {
142  QgsFeatureId fid;
143  QString geom_wkt;
144  };
146  GeometryChanges sqlQueryGeometryChanges( sqlite3* db, const QString& sql );
147 
148  private slots:
149  void layerAdded( QgsMapLayer* layer );
150  void committedAttributesAdded( const QString& qgisLayerId, const QList<QgsField>& addedAttributes );
151  void committedFeaturesAdded( const QString& qgisLayerId, const QgsFeatureList& addedFeatures );
152  void committedFeaturesRemoved( const QString& qgisLayerId, const QgsFeatureIds& deletedFeatureIds );
153  void committedAttributeValuesChanges( const QString& qgisLayerId, const QgsChangedAttributesMap& changedAttrsMap );
154  void committedGeometriesChanges( const QString& qgisLayerId, const QgsGeometryMap& changedGeometries );
155  void startListenFeatureChanges();
156  void stopListenFeatureChanges();
157 };
158 
159 #endif // QGS_OFFLINE_EDITING_H
Base class for all map layer types.
Definition: qgsmaplayer.h:49
struct sqlite3 sqlite3
qint64 QgsFeatureId
Definition: qgsfeature.h:31
Represents a vector layer which manages a vector based data sets.