QGIS API Documentation 4.3.0-Master (7d9941090cd)
Loading...
Searching...
No Matches
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 "qgsproject.h"
25#include "qgssqliteutils.h"
26
27#include <QObject>
28#include <QString>
29
30using namespace Qt::StringLiterals;
31
32class QgsMapLayer;
33class QgsVectorLayer;
34
39class CORE_EXPORT QgsOfflineEditing : public QObject
40{
41 Q_OBJECT
42
43 public:
54
61
62 // TODO QGIS 5.0 - remove default constructor
69
75 QgsOfflineEditing( QgsProject *project );
76
86 bool convertToOfflineProject(
87 const QString &offlineDataPath, const QString &offlineDbFile, const QStringList &layerIds, bool onlySelected = false, ContainerType containerType = SpatiaLite, const QString &layerNameSuffix = u" (offline)"_s
88 );
89
91 bool isOfflineProject() const;
92
93
98 void synchronize( bool useTransaction = false );
99
100 signals:
101
106
113 void layerProgressUpdated( int layer, int numLayers );
114
121 void progressModeSet( QgsOfflineEditing::ProgressMode mode, long long maximum );
122
127 void progressUpdated( long long progress );
128
131
137 void warning( const QString &title, const QString &message );
138
139 private:
140 void initializeSpatialMetadata( sqlite3 *sqlite_handle );
141 bool createOfflineDb( const QString &offlineDbPath, ContainerType containerType = SpatiaLite );
142 void createLoggingTables( sqlite3 *db );
143
144 void convertToOfflineLayer(
145 QgsVectorLayer *layer, sqlite3 *db, const QString &offlineDbPath, bool onlySelected, ContainerType containerType = SpatiaLite, const QString &layerNameSuffix = u" (offline)"_s
146 );
147
148 void applyAttributesAdded( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
149 void applyFeaturesAdded( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
150 void applyFeaturesRemoved( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
151 void applyAttributeValueChanges( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
152 void applyGeometryChanges( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
153 void updateFidLookup( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
154
158 int getLayerPkIdx( const QgsVectorLayer *layer ) const;
159
160 QMap<int, int> attributeLookup( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer );
161
162 void showWarning( const QString &message );
163
164 sqlite3_database_unique_ptr openLoggingDb();
165 int getOrCreateLayerId( sqlite3 *db, const QString &qgisLayerId );
166 int getCommitNo( sqlite3 *db );
167 void increaseCommitNo( sqlite3 *db );
168 void addFidLookup( sqlite3 *db, int layerId, QgsFeatureId offlineFid, QgsFeatureId remoteFid, const QString &remotePk );
169 QgsFeatureId remoteFid( sqlite3 *db, int layerId, QgsFeatureId offlineFid, QgsVectorLayer *remoteLayer );
170 QgsFeatureId offlineFid( sqlite3 *db, int layerId, QgsFeatureId remoteFid );
171 bool isAddedFeature( sqlite3 *db, int layerId, QgsFeatureId fid );
172
173 int sqlExec( sqlite3 *db, const QString &sql );
174 int sqlQueryInt( sqlite3 *db, const QString &sql, int defaultValue );
175 QString sqlQueryStr( sqlite3 *db, const QString &sql, QString &defaultValue );
176 QList<int> sqlQueryInts( sqlite3 *db, const QString &sql );
177 QString sqlEscape( QString value ) const;
178
179 QList<QgsField> sqlQueryAttributesAdded( sqlite3 *db, const QString &sql );
180 QgsFeatureIds sqlQueryFeaturesRemoved( sqlite3 *db, const QString &sql );
181
182 struct AttributeValueChange
183 {
184 QgsFeatureId fid;
185 int attr;
186 QString value;
187 };
188 typedef QList<AttributeValueChange> AttributeValueChanges;
189 AttributeValueChanges sqlQueryAttributeValueChanges( sqlite3 *db, const QString &sql );
190
191 struct GeometryChange
192 {
193 QgsFeatureId fid;
194 QString geom_wkt;
195 };
196 typedef QList<GeometryChange> GeometryChanges;
197 GeometryChanges sqlQueryGeometryChanges( sqlite3 *db, const QString &sql );
198
199 private slots:
200 void setupLayer( QgsMapLayer *layer );
201 void committedAttributesAdded( const QString &qgisLayerId, const QList<QgsField> &addedAttributes );
202 void committedFeaturesAdded( const QString &qgisLayerId, const QgsFeatureList &addedFeatures );
203 void committedFeaturesRemoved( const QString &qgisLayerId, const QgsFeatureIds &deletedFeatureIds );
204 void committedAttributeValuesChanges( const QString &qgisLayerId, const QgsChangedAttributesMap &changedAttrsMap );
205 void committedGeometriesChanges( const QString &qgisLayerId, const QgsGeometryMap &changedGeometries );
206 void startListenFeatureChanges();
207 void stopListenFeatureChanges();
208
209 private:
210 QgsProject *mProject = nullptr;
211};
212
213#endif // QGS_OFFLINE_EDITING_H
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:56
Base class for all map layer types.
Definition qgsmaplayer.h:83
Handles logic relating to synchronizing online and offline copies of layer data.
void progressModeSet(QgsOfflineEditing::ProgressMode mode, long long maximum)
Emitted when the mode for the progress of the current operation is set.
void progressUpdated(long long progress)
Emitted with the progress of the current mode.
void layerProgressUpdated(int layer, int numLayers)
Emitted whenever a new layer is being processed.
QgsOfflineEditing()
Default constructor – uses the QgsProject instance().
void warning(const QString &title, const QString &message)
Emitted when a warning needs to be displayed.
void progressStopped()
Emitted when the processing of all layers has finished.
ContainerType
Type of offline database container file.
void progressStarted()
Emitted when the process has started.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:114
Represents a vector layer which manages a vector based dataset.
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
#define SIP_DEPRECATED
Definition qgis_sip.h:113
struct sqlite3 sqlite3
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
QList< QgsFeature > QgsFeatureList
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features