QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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(
73 const QString &offlineDataPath, const QString &offlineDbFile, const QStringList &layerIds, bool onlySelected = false, ContainerType containerType = SpatiaLite, const QString &layerNameSuffix = u" (offline)"_s
74 );
75
77 bool isOfflineProject() const;
78
79
84 void synchronize( bool useTransaction = false );
85
86 signals:
87
92
99 void layerProgressUpdated( int layer, int numLayers );
100
107 void progressModeSet( QgsOfflineEditing::ProgressMode mode, long long maximum );
108
113 void progressUpdated( long long progress );
114
117
123 void warning( const QString &title, const QString &message );
124
125 private:
126 void initializeSpatialMetadata( sqlite3 *sqlite_handle );
127 bool createOfflineDb( const QString &offlineDbPath, ContainerType containerType = SpatiaLite );
128 void createLoggingTables( sqlite3 *db );
129
130 void convertToOfflineLayer(
131 QgsVectorLayer *layer, sqlite3 *db, const QString &offlineDbPath, bool onlySelected, ContainerType containerType = SpatiaLite, const QString &layerNameSuffix = u" (offline)"_s
132 );
133
134 void applyAttributesAdded( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
135 void applyFeaturesAdded( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
136 void applyFeaturesRemoved( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
137 void applyAttributeValueChanges( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
138 void applyGeometryChanges( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
139 void updateFidLookup( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
140
144 int getLayerPkIdx( const QgsVectorLayer *layer ) const;
145
146 QMap<int, int> attributeLookup( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer );
147
148 void showWarning( const QString &message );
149
150 sqlite3_database_unique_ptr openLoggingDb();
151 int getOrCreateLayerId( sqlite3 *db, const QString &qgisLayerId );
152 int getCommitNo( sqlite3 *db );
153 void increaseCommitNo( sqlite3 *db );
154 void addFidLookup( sqlite3 *db, int layerId, QgsFeatureId offlineFid, QgsFeatureId remoteFid, const QString &remotePk );
155 QgsFeatureId remoteFid( sqlite3 *db, int layerId, QgsFeatureId offlineFid, QgsVectorLayer *remoteLayer );
156 QgsFeatureId offlineFid( sqlite3 *db, int layerId, QgsFeatureId remoteFid );
157 bool isAddedFeature( sqlite3 *db, int layerId, QgsFeatureId fid );
158
159 int sqlExec( sqlite3 *db, const QString &sql );
160 int sqlQueryInt( sqlite3 *db, const QString &sql, int defaultValue );
161 QString sqlQueryStr( sqlite3 *db, const QString &sql, QString &defaultValue );
162 QList<int> sqlQueryInts( sqlite3 *db, const QString &sql );
163 QString sqlEscape( QString value ) const;
164
165 QList<QgsField> sqlQueryAttributesAdded( sqlite3 *db, const QString &sql );
166 QgsFeatureIds sqlQueryFeaturesRemoved( sqlite3 *db, const QString &sql );
167
168 struct AttributeValueChange
169 {
170 QgsFeatureId fid;
171 int attr;
172 QString value;
173 };
174 typedef QList<AttributeValueChange> AttributeValueChanges;
175 AttributeValueChanges sqlQueryAttributeValueChanges( sqlite3 *db, const QString &sql );
176
177 struct GeometryChange
178 {
179 QgsFeatureId fid;
180 QString geom_wkt;
181 };
182 typedef QList<GeometryChange> GeometryChanges;
183 GeometryChanges sqlQueryGeometryChanges( sqlite3 *db, const QString &sql );
184
185 private slots:
186 void setupLayer( QgsMapLayer *layer );
187 void committedAttributesAdded( const QString &qgisLayerId, const QList<QgsField> &addedAttributes );
188 void committedFeaturesAdded( const QString &qgisLayerId, const QgsFeatureList &addedFeatures );
189 void committedFeaturesRemoved( const QString &qgisLayerId, const QgsFeatureIds &deletedFeatureIds );
190 void committedAttributeValuesChanges( const QString &qgisLayerId, const QgsChangedAttributesMap &changedAttrsMap );
191 void committedGeometriesChanges( const QString &qgisLayerId, const QgsGeometryMap &changedGeometries );
192 void startListenFeatureChanges();
193 void stopListenFeatureChanges();
194};
195
196#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