QGIS API Documentation 3.99.0-Master (e9821da5c6b)
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
29using namespace Qt::StringLiterals;
30
31class QgsMapLayer;
32class QgsVectorLayer;
33
38class CORE_EXPORT QgsOfflineEditing : public QObject
39{
40 Q_OBJECT
41
42 public:
53
60
62
72 bool convertToOfflineProject( const QString &offlineDataPath, const QString &offlineDbFile, const QStringList &layerIds, bool onlySelected = false, ContainerType containerType = SpatiaLite, const QString &layerNameSuffix = u" (offline)"_s );
73
75 bool isOfflineProject() const;
76
77
82 void synchronize( bool useTransaction = false );
83
84 signals:
85
90
97 void layerProgressUpdated( int layer, int numLayers );
98
105 void progressModeSet( QgsOfflineEditing::ProgressMode mode, long long maximum );
106
111 void progressUpdated( long long progress );
112
115
121 void warning( const QString &title, const QString &message );
122
123 private:
124 void initializeSpatialMetadata( sqlite3 *sqlite_handle );
125 bool createOfflineDb( const QString &offlineDbPath, ContainerType containerType = SpatiaLite );
126 void createLoggingTables( sqlite3 *db );
127
128 void convertToOfflineLayer( QgsVectorLayer *layer, sqlite3 *db, const QString &offlineDbPath, bool onlySelected, ContainerType containerType = SpatiaLite, const QString &layerNameSuffix = u" (offline)"_s );
129
130 void applyAttributesAdded( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
131 void applyFeaturesAdded( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
132 void applyFeaturesRemoved( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
133 void applyAttributeValueChanges( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
134 void applyGeometryChanges( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
135 void updateFidLookup( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
136
140 int getLayerPkIdx( const QgsVectorLayer *layer ) const;
141
142 QMap<int, int> attributeLookup( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer );
143
144 void showWarning( const QString &message );
145
146 sqlite3_database_unique_ptr openLoggingDb();
147 int getOrCreateLayerId( sqlite3 *db, const QString &qgisLayerId );
148 int getCommitNo( sqlite3 *db );
149 void increaseCommitNo( sqlite3 *db );
150 void addFidLookup( sqlite3 *db, int layerId, QgsFeatureId offlineFid, QgsFeatureId remoteFid, const QString &remotePk );
151 QgsFeatureId remoteFid( sqlite3 *db, int layerId, QgsFeatureId offlineFid, QgsVectorLayer *remoteLayer );
152 QgsFeatureId offlineFid( sqlite3 *db, int layerId, QgsFeatureId remoteFid );
153 bool isAddedFeature( sqlite3 *db, int layerId, QgsFeatureId fid );
154
155 int sqlExec( sqlite3 *db, const QString &sql );
156 int sqlQueryInt( sqlite3 *db, const QString &sql, int defaultValue );
157 QString sqlQueryStr( sqlite3 *db, const QString &sql, QString &defaultValue );
158 QList<int> sqlQueryInts( sqlite3 *db, const QString &sql );
159 QString sqlEscape( QString value ) const;
160
161 QList<QgsField> sqlQueryAttributesAdded( sqlite3 *db, const QString &sql );
162 QgsFeatureIds sqlQueryFeaturesRemoved( sqlite3 *db, const QString &sql );
163
164 struct AttributeValueChange
165 {
166 QgsFeatureId fid;
167 int attr;
168 QString value;
169 };
170 typedef QList<AttributeValueChange> AttributeValueChanges;
171 AttributeValueChanges sqlQueryAttributeValueChanges( sqlite3 *db, const QString &sql );
172
173 struct GeometryChange
174 {
175 QgsFeatureId fid;
176 QString geom_wkt;
177 };
178 typedef QList<GeometryChange> GeometryChanges;
179 GeometryChanges sqlQueryGeometryChanges( sqlite3 *db, const QString &sql );
180
181 private slots:
182 void setupLayer( QgsMapLayer *layer );
183 void committedAttributesAdded( const QString &qgisLayerId, const QList<QgsField> &addedAttributes );
184 void committedFeaturesAdded( const QString &qgisLayerId, const QgsFeatureList &addedFeatures );
185 void committedFeaturesRemoved( const QString &qgisLayerId, const QgsFeatureIds &deletedFeatureIds );
186 void committedAttributeValuesChanges( const QString &qgisLayerId, const QgsChangedAttributesMap &changedAttrsMap );
187 void committedGeometriesChanges( const QString &qgisLayerId, const QgsGeometryMap &changedGeometries );
188 void startListenFeatureChanges();
189 void stopListenFeatureChanges();
190};
191
192#endif // QGS_OFFLINE_EDITING_H
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.
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 dataset.
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