QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 <qgsfeature.h>
23 #include <qgsvectorlayer.h>
24 
25 #include <QObject>
26 #include <QString>
27 
28 class QgsMapLayer;
29 class QgsVectorLayer;
30 struct sqlite3;
31 
32 class CORE_EXPORT QgsOfflineEditing : public QObject
33 {
34  Q_OBJECT
35 
36  public:
38  {
39  CopyFeatures = 0,
45  UpdateGeometries
46  };
47 
50 
56  bool convertToOfflineProject( const QString& offlineDataPath, const QString& offlineDbFile, const QStringList& layerIds );
57 
59  bool isOfflineProject();
60 
62  void synchronize();
63 
64  signals:
66  void progressStarted();
67 
72  void layerProgressUpdated( int layer, int numLayers );
73 
78  void progressModeSet( QgsOfflineEditing::ProgressMode mode, int maximum );
79 
83  void progressUpdated( int progress );
84 
86  void progressStopped();
87 
93  void warning( const QString& title, const QString& message );
94 
95  private:
96  void initializeSpatialMetadata( sqlite3 *sqlite_handle );
97  bool createSpatialiteDB( const QString& offlineDbPath );
98  void createLoggingTables( sqlite3* db );
99  QgsVectorLayer* copyVectorLayer( QgsVectorLayer* layer, sqlite3* db, const QString& offlineDbPath );
100 
101  void applyAttributesAdded( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId, int commitNo );
102  void applyFeaturesAdded( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer, sqlite3* db, int layerId );
103  void applyFeaturesRemoved( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId );
104  void applyAttributeValueChanges( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer, sqlite3* db, int layerId, int commitNo );
105  void applyGeometryChanges( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId, int commitNo );
106  void updateFidLookup( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId );
107  void copySymbology( QgsVectorLayer* sourceLayer, QgsVectorLayer* targetLayer );
108  QMap<int, int> attributeLookup( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer );
109 
110  void showWarning( const QString& message );
111 
112  sqlite3* openLoggingDb();
113  int getOrCreateLayerId( sqlite3* db, const QString& qgisLayerId );
114  int getCommitNo( sqlite3* db );
115  void increaseCommitNo( sqlite3* db );
116  void addFidLookup( sqlite3* db, int layerId, QgsFeatureId offlineFid, QgsFeatureId remoteFid );
117  QgsFeatureId remoteFid( sqlite3* db, int layerId, QgsFeatureId offlineFid );
118  QgsFeatureId offlineFid( sqlite3* db, int layerId, QgsFeatureId remoteFid );
119  bool isAddedFeature( sqlite3* db, int layerId, QgsFeatureId fid );
120 
121  int sqlExec( sqlite3* db, const QString& sql );
122  int sqlQueryInt( sqlite3* db, const QString& sql, int defaultValue );
123  QList<int> sqlQueryInts( sqlite3* db, const QString& sql );
124 
125  QList<QgsField> sqlQueryAttributesAdded( sqlite3* db, const QString& sql );
126  QgsFeatureIds sqlQueryFeaturesRemoved( sqlite3* db, const QString& sql );
127 
128  struct AttributeValueChange
129  {
130  QgsFeatureId fid;
131  int attr;
132  QString value;
133  };
134  typedef QList<AttributeValueChange> AttributeValueChanges;
135  AttributeValueChanges sqlQueryAttributeValueChanges( sqlite3* db, const QString& sql );
136 
137  struct GeometryChange
138  {
139  QgsFeatureId fid;
140  QString geom_wkt;
141  };
142  typedef QList<GeometryChange> GeometryChanges;
143  GeometryChanges sqlQueryGeometryChanges( sqlite3* db, const QString& sql );
144 
145  private slots:
146  void layerAdded( QgsMapLayer* layer );
147  void committedAttributesAdded( const QString& qgisLayerId, const QList<QgsField>& addedAttributes );
148  void committedFeaturesAdded( const QString& qgisLayerId, const QgsFeatureList& addedFeatures );
149  void committedFeaturesRemoved( const QString& qgisLayerId, const QgsFeatureIds& deletedFeatureIds );
150  void committedAttributeValuesChanges( const QString& qgisLayerId, const QgsChangedAttributesMap& changedAttrsMap );
151  void committedGeometriesChanges( const QString& qgisLayerId, const QgsGeometryMap& changedGeometries );
152  void startListenFeatureChanges();
153  void stopListenFeatureChanges();
154 };
155 
156 #endif // QGS_OFFLINE_EDITING_H