QGIS API Documentation 3.41.0-Master (45a0abf3bec)
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 "qgssqliteutils.h"
25
26#include <QObject>
27#include <QString>
28
29class QgsMapLayer;
30class QgsVectorLayer;
31
36class CORE_EXPORT QgsOfflineEditing : public QObject
37{
38 Q_OBJECT
39
40 public:
51
54 {
56 GPKG
57 };
58
60
70 bool convertToOfflineProject( const QString &offlineDataPath, const QString &offlineDbFile, const QStringList &layerIds, bool onlySelected = false, ContainerType containerType = SpatiaLite, const QString &layerNameSuffix = QStringLiteral( " (offline)" ) );
71
73 bool isOfflineProject() const;
74
75
80 void synchronize( bool useTransaction = false );
81
82 signals:
83
88
95 void layerProgressUpdated( int layer, int numLayers );
96
103 void progressModeSet( QgsOfflineEditing::ProgressMode mode, long long maximum );
104
109 void progressUpdated( long long progress );
110
113
119 void warning( const QString &title, const QString &message );
120
121 private:
122 void initializeSpatialMetadata( sqlite3 *sqlite_handle );
123 bool createOfflineDb( const QString &offlineDbPath, ContainerType containerType = SpatiaLite );
124 void createLoggingTables( sqlite3 *db );
125
126 void convertToOfflineLayer( QgsVectorLayer *layer, sqlite3 *db, const QString &offlineDbPath, bool onlySelected, ContainerType containerType = SpatiaLite, const QString &layerNameSuffix = QStringLiteral( " (offline)" ) );
127
128 void applyAttributesAdded( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
129 void applyFeaturesAdded( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
130 void applyFeaturesRemoved( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
131 void applyAttributeValueChanges( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
132 void applyGeometryChanges( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
133 void updateFidLookup( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
134
138 int getLayerPkIdx( const QgsVectorLayer *layer ) const;
139
140 QMap<int, int> attributeLookup( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer );
141
142 void showWarning( const QString &message );
143
144 sqlite3_database_unique_ptr openLoggingDb();
145 int getOrCreateLayerId( sqlite3 *db, const QString &qgisLayerId );
146 int getCommitNo( sqlite3 *db );
147 void increaseCommitNo( sqlite3 *db );
148 void addFidLookup( sqlite3 *db, int layerId, QgsFeatureId offlineFid, QgsFeatureId remoteFid, const QString &remotePk );
149 QgsFeatureId remoteFid( sqlite3 *db, int layerId, QgsFeatureId offlineFid, QgsVectorLayer *remoteLayer );
150 QgsFeatureId offlineFid( sqlite3 *db, int layerId, QgsFeatureId remoteFid );
151 bool isAddedFeature( sqlite3 *db, int layerId, QgsFeatureId fid );
152
153 int sqlExec( sqlite3 *db, const QString &sql );
154 int sqlQueryInt( sqlite3 *db, const QString &sql, int defaultValue );
155 QString sqlQueryStr( sqlite3 *db, const QString &sql, QString &defaultValue );
156 QList<int> sqlQueryInts( sqlite3 *db, const QString &sql );
157 QString sqlEscape( QString value ) const;
158
159 QList<QgsField> sqlQueryAttributesAdded( sqlite3 *db, const QString &sql );
160 QgsFeatureIds sqlQueryFeaturesRemoved( sqlite3 *db, const QString &sql );
161
162 struct AttributeValueChange
163 {
164 QgsFeatureId fid;
165 int attr;
166 QString value;
167 };
168 typedef QList<AttributeValueChange> AttributeValueChanges;
169 AttributeValueChanges sqlQueryAttributeValueChanges( sqlite3 *db, const QString &sql );
170
171 struct GeometryChange
172 {
173 QgsFeatureId fid;
174 QString geom_wkt;
175 };
176 typedef QList<GeometryChange> GeometryChanges;
177 GeometryChanges sqlQueryGeometryChanges( sqlite3 *db, const QString &sql );
178
179 private slots:
180 void setupLayer( QgsMapLayer *layer );
181 void committedAttributesAdded( const QString &qgisLayerId, const QList<QgsField> &addedAttributes );
182 void committedFeaturesAdded( const QString &qgisLayerId, const QgsFeatureList &addedFeatures );
183 void committedFeaturesRemoved( const QString &qgisLayerId, const QgsFeatureIds &deletedFeatureIds );
184 void committedAttributeValuesChanges( const QString &qgisLayerId, const QgsChangedAttributesMap &changedAttrsMap );
185 void committedGeometriesChanges( const QString &qgisLayerId, const QgsGeometryMap &changedGeometries );
186 void startListenFeatureChanges();
187 void stopListenFeatureChanges();
188};
189
190#endif // QGS_OFFLINE_EDITING_H
Base class for all map layer types.
Definition qgsmaplayer.h:76
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.
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.
Represents a vector layer which manages a vector based data sets.
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
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