35 #include <QDomDocument> 38 #include <QMessageBox> 43 #include <spatialite.h> 50 #define CUSTOM_PROPERTY_IS_OFFLINE_EDITABLE "isOfflineEditable" 51 #define CUSTOM_PROPERTY_REMOTE_SOURCE "remoteSource" 52 #define CUSTOM_PROPERTY_REMOTE_PROVIDER "remoteProvider" 53 #define PROJECT_ENTRY_SCOPE_OFFLINE "OfflineEditingPlugin" 54 #define PROJECT_ENTRY_KEY_OFFLINE_DB_PATH "/OfflineDbPath" 87 if ( createSpatialiteDB( dbPath ) )
91 if ( rc != SQLITE_OK )
93 showWarning(
tr(
"Could not open the spatialite database" ) );
98 createLoggingTables( db );
105 for (
int i = 0; i < layerIds.
count(); i++ )
115 QgsVectorJoinList::iterator it = joins.
begin();
116 while ( it != joins.end() )
118 if (( *it ).prefix.isNull() )
123 ( *it ).prefix = vl->
name() +
'_';
127 joinInfoBuffer.
insert( vl->
id(), joins );
131 for (
int i = 0; i < layerIds.
count(); i++ )
142 layerIdMapping.
insert( origLayerId, newLayer );
160 if ( newJoinedLayer )
181 projectTitle +=
" (offline)";
214 offlineLayers << layer;
218 for (
int l = 0; l < offlineLayers.
count(); l++ )
241 copySymbology( offlineLayer, remoteLayer );
245 QString sql =
QString(
"SELECT \"id\" FROM 'log_layer_ids' WHERE \"qgis_id\" = '%1'" ).
arg( qgisLayerId );
246 int layerId = sqlQueryInt( db, sql, -1 );
252 int commitNo = getCommitNo( db );
253 for (
int i = 0; i < commitNo; i++ )
256 applyAttributesAdded( remoteLayer, db, layerId, i );
257 applyAttributeValueChanges( offlineLayer, remoteLayer, db, layerId, i );
258 applyGeometryChanges( remoteLayer, db, layerId, i );
261 applyFeaturesAdded( offlineLayer, remoteLayer, db, layerId );
262 applyFeaturesRemoved( remoteLayer, db, layerId );
267 updateFidLookup( remoteLayer, db, layerId );
270 sql =
QString(
"DELETE FROM 'log_added_attrs' WHERE \"layer_id\" = %1" ).
arg( layerId );
272 sql =
QString(
"DELETE FROM 'log_added_features' WHERE \"layer_id\" = %1" ).
arg( layerId );
274 sql =
QString(
"DELETE FROM 'log_removed_features' WHERE \"layer_id\" = %1" ).
arg( layerId );
276 sql =
QString(
"DELETE FROM 'log_feature_updates' WHERE \"layer_id\" = %1" ).
arg( layerId );
278 sql =
QString(
"DELETE FROM 'log_geometry_updates' WHERE \"layer_id\" = %1" ).
arg( layerId );
282 QString sql =
QString(
"UPDATE 'log_indices' SET 'last_index' = 0 WHERE \"name\" = 'commit_no'" );
312 void QgsOfflineEditing::initializeSpatialMetadata(
sqlite3 *sqlite_handle )
315 if ( !sqlite_handle )
320 int ret = sqlite3_get_table( sqlite_handle,
"select count(*) from sqlite_master", &results, &rows, &columns,
nullptr );
321 if ( ret != SQLITE_OK )
326 for (
int i = 1; i <= rows; i++ )
327 count = atoi( results[( i * columns ) + 0] );
330 sqlite3_free_table( results );
335 bool above41 =
false;
336 ret = sqlite3_get_table( sqlite_handle,
"select spatialite_version()", &results, &rows, &columns,
nullptr );
337 if ( ret == SQLITE_OK && rows == 1 && columns == 1 )
341 if ( parts.
size() >= 1 )
344 above41 = verparts.
size() >= 2 && ( verparts[0].toInt() > 4 || ( verparts[0].toInt() == 4 && verparts[1].toInt() >= 1 ) );
348 sqlite3_free_table( results );
351 char *errMsg =
nullptr;
352 ret = sqlite3_exec( sqlite_handle, above41 ?
"SELECT InitSpatialMetadata(1)" :
"SELECT InitSpatialMetadata()",
nullptr,
nullptr, &errMsg );
354 if ( ret != SQLITE_OK )
356 QString errCause =
tr(
"Unable to initialize SpatialMetadata:\n" );
358 showWarning( errCause );
359 sqlite3_free( errMsg );
362 spatial_ref_sys_init( sqlite_handle, 0 );
365 bool QgsOfflineEditing::createSpatialiteDB(
const QString& offlineDbPath )
369 char *errMsg =
nullptr;
370 QFile newDb( offlineDbPath );
390 QString errCause =
tr(
"Could not create a new database\n" );
392 sqlite3_close( sqlite_handle );
393 showWarning( errCause );
397 ret = sqlite3_exec( sqlite_handle,
"PRAGMA foreign_keys = 1",
nullptr,
nullptr, &errMsg );
398 if ( ret != SQLITE_OK )
400 showWarning(
tr(
"Unable to activate FOREIGN_KEY constraints" ) );
401 sqlite3_free( errMsg );
405 initializeSpatialMetadata( sqlite_handle );
413 void QgsOfflineEditing::createLoggingTables(
sqlite3* db )
416 QString sql =
"CREATE TABLE 'log_indices' ('name' TEXT, 'last_index' INTEGER)";
419 sql =
"INSERT INTO 'log_indices' VALUES ('commit_no', 0)";
422 sql =
"INSERT INTO 'log_indices' VALUES ('layer_id', 0)";
426 sql =
"CREATE TABLE 'log_layer_ids' ('id' INTEGER, 'qgis_id' TEXT)";
430 sql =
"CREATE TABLE 'log_fids' ('layer_id' INTEGER, 'offline_fid' INTEGER, 'remote_fid' INTEGER)";
434 sql =
"CREATE TABLE 'log_added_attrs' ('layer_id' INTEGER, 'commit_no' INTEGER, ";
435 sql +=
"'name' TEXT, 'type' INTEGER, 'length' INTEGER, 'precision' INTEGER, 'comment' TEXT)";
439 sql =
"CREATE TABLE 'log_added_features' ('layer_id' INTEGER, 'fid' INTEGER)";
443 sql =
"CREATE TABLE 'log_removed_features' ('layer_id' INTEGER, 'fid' INTEGER)";
447 sql =
"CREATE TABLE 'log_feature_updates' ('layer_id' INTEGER, 'commit_no' INTEGER, 'fid' INTEGER, 'attr' INTEGER, 'value' TEXT)";
451 sql =
"CREATE TABLE 'log_geometry_updates' ('layer_id' INTEGER, 'commit_no' INTEGER, 'fid' INTEGER, 'geom_wkt' TEXT)";
471 for (
int idx = 0; idx < fields.
count(); ++idx )
474 QVariant::Type type = fields[idx].type();
475 if ( type == QVariant::Int || type == QVariant::LongLong )
477 dataType =
"INTEGER";
479 else if ( type == QVariant::Double )
483 else if ( type == QVariant::String )
489 showWarning(
tr(
"%1: Unknown data type %2. Not using type affinity for the field." ).arg( fields[idx].
name(),
QVariant::typeToName( type ) ) );
492 sql += delim +
QString(
"'%1' %2" ).
arg( fields[idx].
name(), dataType );
497 int rc = sqlExec( db, sql );
509 geomType =
"MULTIPOINT";
512 geomType =
"LINESTRING";
515 geomType =
"MULTILINESTRING";
518 geomType =
"POLYGON";
521 geomType =
"MULTIPOLYGON";
524 showWarning(
tr(
"QGIS wkbType %1 not supported" ).arg( layer->
wkbType() ) );
527 QString sqlAddGeom =
QString(
"SELECT AddGeometryColumn('%1', 'Geometry', %2, '%3', 2)" )
533 QString sqlCreateIndex =
QString(
"SELECT CreateSpatialIndex('%1', 'Geometry')" ).
arg( tableName );
535 if ( rc == SQLITE_OK )
537 rc = sqlExec( db, sqlAddGeom );
538 if ( rc == SQLITE_OK )
540 rc = sqlExec( db, sqlCreateIndex );
545 if ( rc == SQLITE_OK )
548 QString connectionString =
QString(
"dbname='%1' table='%2'%3 sql=" )
552 layer->
name() +
" (offline)",
"spatialite" );
573 copySymbology( layer, newLayer );
579 if ( layerTreeLayer )
582 if ( parentTreeGroup )
587 if ( newLayerTreeLayer )
601 copySymbology( layer, newLayer );
614 int featureCount = 1;
619 remoteFeatureIds << f.
id();
626 for (
int it = 0; it < attrs.
count(); ++it )
628 newAttrs[column++] = attrs.
at( it );
642 int layerId = getOrCreateLayerId( db, newLayer->
id() );
648 offlineFeatureIds << f.
id();
652 sqlExec( db,
"BEGIN" );
653 int remoteCount = remoteFeatureIds.
size();
654 for (
int i = 0; i < remoteCount; i++ )
657 if ( i < offlineFeatureIds.count() )
659 addFidLookup( db, layerId, offlineFeatureIds.at( i ), remoteFeatureIds.
at( remoteCount - ( i + 1 ) ) );
663 showWarning(
QString(
"Feature cannot be copied to the offline layer, please check if the online layer '%1' is sill accessible." ).arg( layer->
name() ) );
668 sqlExec( db,
"COMMIT" );
680 void QgsOfflineEditing::applyAttributesAdded(
QgsVectorLayer* remoteLayer,
sqlite3* db,
int layerId,
int commitNo )
682 QString sql =
QString(
"SELECT \"name\", \"type\", \"length\", \"precision\", \"comment\" FROM 'log_added_attrs' WHERE \"layer_id\" = %1 AND \"commit_no\" = %2" ).
arg( layerId ).
arg( commitNo );
690 for (
int i = 0; i < nativeTypes.
size(); i++ )
698 for (
int i = 0; i < fields.
size(); i++ )
702 if ( typeNameLookup.contains( field.
type() ) )
710 showWarning(
QString(
"Could not add attribute '%1' of type %2" ).arg( field.
name() ).arg( field.
type() ) );
719 QString sql =
QString(
"SELECT \"fid\" FROM 'log_added_features' WHERE \"layer_id\" = %1" ).
arg( layerId );
720 QList<int> newFeatureIds = sqlQueryInts( db, sql );
725 for (
int i = 0; i < remoteFlds.
count(); ++i )
733 for (
int i = 0; i < newFeatureIds.
size(); i++ )
753 QMap<int, int> attrLookup = attributeLookup( offlineLayer, remoteLayer );
756 for (
int it = 0; it < attrs.
count(); ++it )
758 newAttrs[ attrLookup[ it ] ] = attrs.
at( it );
763 for (
int k = 0; k < newAttrs.
count(); ++k )
765 if ( newAttrs.
at( k ).isNull() && !defaultValues.at( k ).isNull() )
766 newAttrs[k] = defaultValues.
at( k );
777 void QgsOfflineEditing::applyFeaturesRemoved(
QgsVectorLayer* remoteLayer,
sqlite3* db,
int layerId )
779 QString sql =
QString(
"SELECT \"fid\" FROM 'log_removed_features' WHERE \"layer_id\" = %1" ).
arg( layerId );
796 QString sql =
QString(
"SELECT \"fid\", \"attr\", \"value\" FROM 'log_feature_updates' WHERE \"layer_id\" = %1 AND \"commit_no\" = %2 " ).
arg( layerId ).
arg( commitNo );
801 QMap<int, int> attrLookup = attributeLookup( offlineLayer, remoteLayer );
803 for (
int i = 0; i < values.
size(); i++ )
813 void QgsOfflineEditing::applyGeometryChanges(
QgsVectorLayer* remoteLayer,
sqlite3* db,
int layerId,
int commitNo )
815 QString sql =
QString(
"SELECT \"fid\", \"geom_wkt\" FROM 'log_geometry_updates' WHERE \"layer_id\" = %1 AND \"commit_no\" = %2" ).
arg( layerId ).
arg( commitNo );
820 for (
int i = 0; i < values.
size(); i++ )
845 if ( offlineFid( db, layerId, f.
id() ) == -1 )
847 newRemoteFids[ f.
id()] =
true;
855 QString sql =
QString(
"SELECT \"fid\" FROM 'log_added_features' WHERE \"layer_id\" = %1" ).
arg( layerId );
856 QList<int> newOfflineFids = sqlQueryInts( db, sql );
858 if ( newRemoteFids.size() != newOfflineFids.
size() )
866 sqlExec( db,
"BEGIN" );
869 addFidLookup( db, layerId, newOfflineFids.
at( i++ ), it.key() );
871 sqlExec( db,
"COMMIT" );
887 showWarning( error );
897 QMap <
int ,
int > attrLookup;
899 for (
int i = 0; i < remoteAttrs.
size(); i++ )
901 attrLookup.
insert( offlineAttrs.
at( i ), remoteAttrs.
at( i ) );
907 void QgsOfflineEditing::showWarning(
const QString& message )
909 emit
warning(
tr(
"Offline Editing Plugin" ), message );
912 sqlite3* QgsOfflineEditing::openLoggingDb()
919 if ( rc != SQLITE_OK )
921 showWarning(
tr(
"Could not open the spatialite logging database" ) );
929 int QgsOfflineEditing::getOrCreateLayerId(
sqlite3* db,
const QString& qgisLayerId )
931 QString sql =
QString(
"SELECT \"id\" FROM 'log_layer_ids' WHERE \"qgis_id\" = '%1'" ).
arg( qgisLayerId );
932 int layerId = sqlQueryInt( db, sql, -1 );
936 sql =
"SELECT \"last_index\" FROM 'log_indices' WHERE \"name\" = 'layer_id'";
937 int newLayerId = sqlQueryInt( db, sql, -1 );
940 sql =
QString(
"INSERT INTO 'log_layer_ids' VALUES (%1, '%2')" ).
arg( newLayerId ).
arg( qgisLayerId );
945 sql =
QString(
"UPDATE 'log_indices' SET 'last_index' = %1 WHERE \"name\" = 'layer_id'" ).
arg( newLayerId + 1 );
948 layerId = newLayerId;
954 int QgsOfflineEditing::getCommitNo(
sqlite3* db )
956 QString sql =
"SELECT \"last_index\" FROM 'log_indices' WHERE \"name\" = 'commit_no'";
957 return sqlQueryInt( db, sql, -1 );
960 void QgsOfflineEditing::increaseCommitNo(
sqlite3* db )
962 QString sql =
QString(
"UPDATE 'log_indices' SET 'last_index' = %1 WHERE \"name\" = 'commit_no'" ).
arg( getCommitNo( db ) + 1 );
968 QString sql =
QString(
"INSERT INTO 'log_fids' VALUES ( %1, %2, %3 )" ).
arg( layerId ).
arg( offlineFid ).
arg( remoteFid );
974 QString sql =
QString(
"SELECT \"remote_fid\" FROM 'log_fids' WHERE \"layer_id\" = %1 AND \"offline_fid\" = %2" ).
arg( layerId ).
arg( offlineFid );
975 return sqlQueryInt( db, sql, -1 );
980 QString sql =
QString(
"SELECT \"offline_fid\" FROM 'log_fids' WHERE \"layer_id\" = %1 AND \"remote_fid\" = %2" ).
arg( layerId ).
arg( remoteFid );
981 return sqlQueryInt( db, sql, -1 );
986 QString sql =
QString(
"SELECT COUNT(\"fid\") FROM 'log_added_features' WHERE \"layer_id\" = %1 AND \"fid\" = %2" ).
arg( layerId ).
arg( fid );
987 return ( sqlQueryInt( db, sql, 0 ) > 0 );
993 int rc = sqlite3_exec( db, sql.
toUtf8(),
nullptr,
nullptr, &errmsg );
994 if ( rc != SQLITE_OK )
996 showWarning( errmsg );
1001 int QgsOfflineEditing::sqlQueryInt(
sqlite3* db,
const QString& sql,
int defaultValue )
1003 sqlite3_stmt* stmt =
nullptr;
1004 if ( sqlite3_prepare_v2( db, sql.
toUtf8().
constData(), -1, &stmt, nullptr ) != SQLITE_OK )
1006 showWarning( sqlite3_errmsg( db ) );
1007 return defaultValue;
1010 int value = defaultValue;
1011 int ret = sqlite3_step( stmt );
1012 if ( ret == SQLITE_ROW )
1014 value = sqlite3_column_int( stmt, 0 );
1016 sqlite3_finalize( stmt );
1025 sqlite3_stmt* stmt =
nullptr;
1026 if ( sqlite3_prepare_v2( db, sql.
toUtf8().
constData(), -1, &stmt, nullptr ) != SQLITE_OK )
1028 showWarning( sqlite3_errmsg( db ) );
1032 int ret = sqlite3_step( stmt );
1033 while ( ret == SQLITE_ROW )
1035 values << sqlite3_column_int( stmt, 0 );
1037 ret = sqlite3_step( stmt );
1039 sqlite3_finalize( stmt );
1048 sqlite3_stmt* stmt =
nullptr;
1049 if ( sqlite3_prepare_v2( db, sql.
toUtf8().
constData(), -1, &stmt, nullptr ) != SQLITE_OK )
1051 showWarning( sqlite3_errmsg( db ) );
1055 int ret = sqlite3_step( stmt );
1056 while ( ret == SQLITE_ROW )
1058 QgsField field(
QString( reinterpret_cast< const char* >( sqlite3_column_text( stmt, 0 ) ) ),
1059 static_cast< QVariant::Type >( sqlite3_column_int( stmt, 1 ) ),
1061 sqlite3_column_int( stmt, 2 ),
1062 sqlite3_column_int( stmt, 3 ),
1063 QString( reinterpret_cast< const char* >( sqlite3_column_text( stmt, 4 ) ) ) );
1066 ret = sqlite3_step( stmt );
1068 sqlite3_finalize( stmt );
1077 sqlite3_stmt* stmt =
nullptr;
1078 if ( sqlite3_prepare_v2( db, sql.
toUtf8().
constData(), -1, &stmt, nullptr ) != SQLITE_OK )
1080 showWarning( sqlite3_errmsg( db ) );
1084 int ret = sqlite3_step( stmt );
1085 while ( ret == SQLITE_ROW )
1087 values << sqlite3_column_int( stmt, 0 );
1089 ret = sqlite3_step( stmt );
1091 sqlite3_finalize( stmt );
1100 sqlite3_stmt* stmt =
nullptr;
1101 if ( sqlite3_prepare_v2( db, sql.
toUtf8().
constData(), -1, &stmt, nullptr ) != SQLITE_OK )
1103 showWarning( sqlite3_errmsg( db ) );
1107 int ret = sqlite3_step( stmt );
1108 while ( ret == SQLITE_ROW )
1110 AttributeValueChange change;
1111 change.fid = sqlite3_column_int( stmt, 0 );
1112 change.attr = sqlite3_column_int( stmt, 1 );
1113 change.value =
QString( reinterpret_cast< const char* >( sqlite3_column_text( stmt, 2 ) ) );
1116 ret = sqlite3_step( stmt );
1118 sqlite3_finalize( stmt );
1127 sqlite3_stmt* stmt =
nullptr;
1128 if ( sqlite3_prepare_v2( db, sql.
toUtf8().
constData(), -1, &stmt, nullptr ) != SQLITE_OK )
1130 showWarning( sqlite3_errmsg( db ) );
1134 int ret = sqlite3_step( stmt );
1135 while ( ret == SQLITE_ROW )
1137 GeometryChange change;
1138 change.fid = sqlite3_column_int( stmt, 0 );
1139 change.geom_wkt =
QString( reinterpret_cast< const char* >( sqlite3_column_text( stmt, 1 ) ) );
1142 ret = sqlite3_step( stmt );
1144 sqlite3_finalize( stmt );
1149 void QgsOfflineEditing::committedAttributesAdded(
const QString& qgisLayerId,
const QList<QgsField>& addedAttributes )
1151 sqlite3* db = openLoggingDb();
1156 int layerId = getOrCreateLayerId( db, qgisLayerId );
1157 int commitNo = getCommitNo( db );
1162 QString sql =
QString(
"INSERT INTO 'log_added_attrs' VALUES ( %1, %2, '%3', %4, %5, %6, '%7' )" )
1166 .arg( field.
type() )
1173 increaseCommitNo( db );
1174 sqlite3_close( db );
1177 void QgsOfflineEditing::committedFeaturesAdded(
const QString& qgisLayerId,
const QgsFeatureList& addedFeatures )
1179 sqlite3* db = openLoggingDb();
1184 int layerId = getOrCreateLayerId( db, qgisLayerId );
1191 QString sql =
QString(
"SELECT ROWID FROM '%1' ORDER BY ROWID DESC LIMIT %2" ).
arg( uri.
table() ).arg( addedFeatures.
size() );
1192 QList<int> newFeatureIds = sqlQueryInts( db, sql );
1193 for (
int i = newFeatureIds.
size() - 1; i >= 0; i-- )
1195 QString sql =
QString(
"INSERT INTO 'log_added_features' VALUES ( %1, %2 )" )
1197 .
arg( newFeatureIds.
at( i ) );
1201 sqlite3_close( db );
1204 void QgsOfflineEditing::committedFeaturesRemoved(
const QString& qgisLayerId,
const QgsFeatureIds& deletedFeatureIds )
1206 sqlite3* db = openLoggingDb();
1211 int layerId = getOrCreateLayerId( db, qgisLayerId );
1215 if ( isAddedFeature( db, layerId, *it ) )
1218 QString sql =
QString(
"DELETE FROM 'log_added_features' WHERE \"layer_id\" = %1 AND \"fid\" = %2" ).
arg( layerId ).
arg( *it );
1223 QString sql =
QString(
"INSERT INTO 'log_removed_features' VALUES ( %1, %2)" )
1230 sqlite3_close( db );
1235 sqlite3* db = openLoggingDb();
1240 int layerId = getOrCreateLayerId( db, qgisLayerId );
1241 int commitNo = getCommitNo( db );
1243 for ( QgsChangedAttributesMap::const_iterator cit = changedAttrsMap.
begin(); cit != changedAttrsMap.
end(); ++cit )
1246 if ( isAddedFeature( db, layerId, fid ) )
1252 for ( QgsAttributeMap::const_iterator it = attrMap.
begin(); it != attrMap.
end(); ++it )
1254 QString sql =
QString(
"INSERT INTO 'log_feature_updates' VALUES ( %1, %2, %3, %4, '%5' )" )
1259 .arg( it.value().toString() );
1264 increaseCommitNo( db );
1265 sqlite3_close( db );
1268 void QgsOfflineEditing::committedGeometriesChanges(
const QString& qgisLayerId,
const QgsGeometryMap& changedGeometries )
1270 sqlite3* db = openLoggingDb();
1275 int layerId = getOrCreateLayerId( db, qgisLayerId );
1276 int commitNo = getCommitNo( db );
1278 for ( QgsGeometryMap::const_iterator it = changedGeometries.
begin(); it != changedGeometries.
end(); ++it )
1281 if ( isAddedFeature( db, layerId, fid ) )
1287 QString sql =
QString(
"INSERT INTO 'log_geometry_updates' VALUES ( %1, %2, %3, '%4' )" )
1297 increaseCommitNo( db );
1298 sqlite3_close( db );
1301 void QgsOfflineEditing::startListenFeatureChanges()
1320 void QgsOfflineEditing::stopListenFeatureChanges()
1339 void QgsOfflineEditing::layerAdded(
QgsMapLayer* layer )
1345 connect( vLayer, SIGNAL( editingStarted() ),
this, SLOT( startListenFeatureChanges() ) );
1346 connect( vLayer, SIGNAL( editingStopped() ),
this, SLOT( stopListenFeatureChanges() ) );
QgsFeatureId id() const
Get the feature ID for this feature.
virtual QString subsetString()
Get the string (typically sql) used to define a subset of the layer.
Layer tree group node serves as a container for layers and further groups.
Wrapper for iterator of features from vector data provider or vector layer.
void layerProgressUpdated(int layer, int numLayers)
Emit a signal that the next layer of numLayers has started processing.
bool addJoin(const QgsVectorJoinInfo &joinInfo)
Joins another vector layer to this layer.
Base class for all map layer types.
const QList< QgsVectorJoinInfo > vectorJoins() const
QgsAttributeList attributeList() const
Returns list of attribute indexes.
QString name() const
Get the display name of the layer.
#define PROJECT_ENTRY_KEY_OFFLINE_DB_PATH
bool convertToOfflineProject(const QString &offlineDataPath, const QString &offlineDbFile, const QStringList &layerIds)
Convert current project for offline editing.
QList< QgsMapLayer * > addMapLayers(const QList< QgsMapLayer * > &theMapLayers, bool addToLegend=true, bool takeOwnership=true)
Add a list of layers to the map of loaded layers.
bool deleteFeature(QgsFeatureId fid)
Delete a feature from the layer (but does not commit it)
QgsFields fields() const
Returns the list of fields of this layer.
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
#define CUSTOM_PROPERTY_IS_OFFLINE_EDITABLE
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
bool commitChanges()
Attempts to commit any changes to disk.
bool startEditing()
Make layer editable.
const_iterator constBegin() const
const T & at(int i) const
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
#define Q_NOWARN_DEPRECATED_PUSH
#define CUSTOM_PROPERTY_REMOTE_SOURCE
int precision() const
Gets the precision of the field.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
void removeChildNode(QgsLayerTreeNode *node)
Remove a child node from this group. The node will be deleted.
void removeMapLayers(const QStringList &theLayerIds)
Remove a set of layers from the registry.
QString source() const
Returns the source for the layer.
QString comment() const
Returns the field comment.
bool addFeature(QgsFeature &f, bool alsoUpdateExtent=true)
Adds a feature.
field comes from the underlying data provider of the vector layer (originIndex = index in provider's ...
QString join(const QString &separator) const
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QString & remove(int position, int n)
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QString tr(const char *sourceText, const char *disambiguation, int n)
static int sqlite3_close(sqlite3 *)
QgsMapLayer * mapLayer(const QString &theLayerId)
Retrieve a pointer to a loaded layer by id.
QGis::WkbType wkbType() const
Returns the WKBType or WKBUnknown in case of error.
int indexOf(const T &value, int from) const
bool isOfflineProject()
Return true if current project is offline.
long featureCount(QgsSymbolV2 *symbol)
Number of features rendered with specified symbol.
static int sqlite3_open(const char *filename, sqlite3 **ppDb)
const char * name() const
bool writeEntry(const QString &scope, const QString &key, bool value)
void progressUpdated(int progress)
Emit a signal with the progress of the current mode.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString::null, bool *ok=nullptr) const
QgsVectorLayerEditBuffer * editBuffer()
Buffer with uncommitted editing operations. Only valid after editing has been turned on...
int count(const T &value) const
QString fromUtf8(const char *str, int size)
void progressStopped()
Emit a signal that processing of all layers has finished.
QgsAttributes attributes() const
Returns the feature's attributes.
Q_DECL_DEPRECATED void title(const QString &title)
Every project has an associated title string.
void setTypeName(const QString &typeName)
Set the field type.
static int sqlite3_open_v2(const char *filename, sqlite3 **ppDb, int flags, const char *zVfs)
QString name() const
Gets the name of the field.
QgsLayerTreeNode * parent()
Get pointer to the parent. If parent is a null pointer, the node is a root node.
const_iterator constEnd() const
int fieldOriginIndex(int fieldIdx) const
Get field's origin index (its meaning is specific to each type of origin)
const char * constData() const
const QList< NativeType > & nativeTypes() const
Returns the names of the supported types.
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
virtual long featureCount() const =0
Number of features in the layer.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QList< int > QgsAttributeList
This class is a base class for nodes in a layer tree.
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())=0
Query the provider for features specified in request.
bool removeEntry(const QString &scope, const QString &key)
Remove the given key.
int count() const
Return number of items.
bool changeGeometry(QgsFeatureId fid, QgsGeometry *geom)
Change feature's geometry.
Encapsulate a field in an attribute table or data source.
virtual bool importNamedStyle(QDomDocument &doc, QString &errorMsg)
Import the properties of this layer from a QDomDocument.
QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QList< QgsLayerTreeNode * > children()
Get list of children of the node. Children are owned by the parent.
bool isValid()
Return the status of the layer.
#define PROJECT_ENTRY_SCOPE_OFFLINE
Q_DECL_DEPRECATED bool changeAttributeValue(QgsFeatureId fid, int field, const QVariant &value, bool emitSignal)
Changes an attribute value (but does not commit it)
const QStringList & commitErrors()
Class for storing the component parts of a PostgreSQL/RDBMS datasource URI.
virtual void reload() override
Synchronises with changes in the datasource.
const char * typeToName(Type typ)
#define Q_NOWARN_DEPRECATED_POP
const Key key(const T &value) const
long toLong(bool *ok, int base) const
virtual void exportNamedStyle(QDomDocument &doc, QString &errorMsg)
Export the properties of this layer as named style in a QDomDocument.
QString providerType() const
Return the provider type for this layer.
const T & at(int i) const
bool hasGeometryType() const
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
void warning(const QString &title, const QString &message)
Emitted when a warning needs to be displayed.
virtual const QgsFields & fields() const =0
Return a map of indexes with field names for this layer.
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
QString mid(int position, int n) const
virtual QVariant defaultValue(int fieldId)
Returns the default value for field specified by fieldId.
void insertChildNode(int index, QgsLayerTreeNode *node)
Insert existing node at specified position. The node must not have a parent yet. The node will be own...
QString absolutePath() const
void synchronize()
Synchronize to remote layers.
static QgsProject * instance()
access to canonical QgsProject instance
QString table() const
Returns the table.
int length() const
Gets the length of the field.
int count(const T &value) const
void setTitle(const QString &title)
Set project title.
Q_DECL_DEPRECATED bool hasLabelsEnabled() const
Label is on.
QString absoluteFilePath(const QString &fileName) const
FieldOrigin fieldOrigin(int fieldIdx) const
Get field's origin (value from an enumeration)
QString authid() const
Returns the authority identifier for the CRS, which includes both the authority (eg EPSG) and the CRS...
const QMap< QString, QgsMapLayer * > & mapLayers()
Retrieve the mapLayers collection (mainly intended for use by projection)
QStringList split(const QString &sep, const QString &str, bool allowEmptyEntries)
virtual bool setSubsetString(const QString &subset)
Set the string (typically sql) used to define a subset of the layer.
void progressModeSet(QgsOfflineEditing::ProgressMode mode, int maximum)
Emit a signal that sets the mode for the progress of the current operation.
QgsLayerTreeLayer * findLayer(const QString &layerId) const
Find layer node representing the map layer specified by its ID. Searches recursively the whole sub-tr...
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
iterator insert(const Key &key, const T &value)
static QgsGeometry * fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
QString exportToWkt(int precision=17) const
Exports the geometry to WKT.
QgsVectorDataProvider * dataProvider()
Returns the data provider.
bool nextFeature(QgsFeature &f)
This is the base class for vector data providers.
QgsLayerTreeGroup * layerTreeRoot() const
Return pointer to the root (invisible) node of the project's layer tree.
Geometry is not required. It may still be returned if e.g. required for a filter condition.
virtual void invalidateConnections(const QString &connection)
Invalidate connections corresponding to specified name.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Represents a vector layer which manages a vector based data sets.
bool addAttribute(const QgsField &field)
Add an attribute field (but does not commit it) returns true if the field was added.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
#define CUSTOM_PROPERTY_REMOTE_PROVIDER
QString joinLayerId
Source layer.
void progressStarted()
Emit a signal that processing has started.
virtual QgsLayerTreeLayer * clone() const override
Create a copy of the node. Returns new instance.
bool mkpath(const QString &dirPath) const
Layer tree node points to a map layer.
QVariant::Type type() const
Gets variant type of the field as it will be retrieved from data source.
const T value(const Key &key) const
QByteArray toUtf8() const