Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
only selected features
should be exported to sqlite / gpkg
  • Loading branch information
signedav committed Jul 5, 2018
1 parent b1cd2fd commit f80f4ec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
19 changes: 11 additions & 8 deletions src/core/qgsofflineediting.cpp
Expand Up @@ -138,8 +138,7 @@ bool QgsOfflineEditing::convertToOfflineProject( const QString &offlineDataPath,
if ( vl )
{
QString origLayerId = vl->id();
QgsVectorLayer *newLayer;
newLayer = copyVectorLayer( vl, database.get(), dbPath, onlySelected, gpkg );
QgsVectorLayer *newLayer = copyVectorLayer( vl, database.get(), dbPath, onlySelected, gpkg );
if ( newLayer )
{
layerIdMapping.insert( origLayerId, newLayer );
Expand Down Expand Up @@ -171,6 +170,7 @@ bool QgsOfflineEditing::convertToOfflineProject( const QString &offlineDataPath,
}
}


emit progressStopped();

// save offline project
Expand Down Expand Up @@ -406,6 +406,7 @@ bool QgsOfflineEditing::createSpatialiteDB( const QString &offlineDbPath, bool g
// creating/opening the new database
QString dbPath = newDb.fileName();

// creating geopackage
if ( gpkg )
{
OGRSFDriverH hGpkgDriver = OGRGetDriverByName( "GPKG" );
Expand Down Expand Up @@ -600,13 +601,15 @@ QgsVectorLayer *QgsOfflineEditing::copyVectorLayer( QgsVectorLayer *layer, sqlit
rc = sqlExec( db, sqlCreateIndex );
}
}
if ( rc != SQLITE_OK )
{
showWarning( tr( "Filling SpatiaLite for layer %1 failed" ).arg( layer->name() ) );
return nullptr;
}
}

if ( rc != SQLITE_OK )
{
showWarning( tr( "Filling SpatiaLite for layer %1 failed" ).arg( layer->name() ) );
return nullptr;
}

// add new layer
QString connectionString = QStringLiteral( "dbname='%1' table='%2'%3 sql=" )
.arg( offlineDbPath,
tableName, layer->isSpatial() ? "(Geometry)" : "" );
Expand Down Expand Up @@ -760,6 +763,7 @@ QgsVectorLayer *QgsOfflineEditing::copyVectorLayer( QgsVectorLayer *layer, sqlit
updateLayerOrder( layer, newLayer );



}
return newLayer;
}
Expand Down Expand Up @@ -1352,7 +1356,6 @@ void QgsOfflineEditing::committedFeaturesAdded( const QString &qgisLayerId, cons
// only store feature ids
QString sql = QStringLiteral( "SELECT ROWID FROM '%1' ORDER BY ROWID DESC LIMIT %2" ).arg( tableName ).arg( addedFeatures.size() );
QList<int> newFeatureIds = sqlQueryInts( database.get(), sql );

for ( int i = newFeatureIds.size() - 1; i >= 0; i-- )
{
QString sql = QStringLiteral( "INSERT INTO 'log_added_features' VALUES ( %1, %2 )" )
Expand Down
3 changes: 1 addition & 2 deletions src/core/qgsofflineediting.h
Expand Up @@ -107,10 +107,9 @@ class CORE_EXPORT QgsOfflineEditing : public QObject

private:
void initializeSpatialMetadata( sqlite3 *sqlite_handle );
bool createSpatialiteDB( const QString &offlineDbPath, bool gpkg );
bool createSpatialiteDB( const QString &offlineDbPath, bool gpkg = false );
void createLoggingTables( sqlite3 *db );

QgsVectorLayer *copyVectorLayerGpkg( QgsVectorLayer *layer, sqlite3 *db, const QString &offlineDbPath );
QgsVectorLayer *copyVectorLayer( QgsVectorLayer *layer, sqlite3 *db, const QString &offlineDbPath, bool onlySelected, bool gpkg );

void applyAttributesAdded( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
Expand Down
1 change: 0 additions & 1 deletion src/plugins/offline_editing/offline_editing_plugin_gui.cpp
Expand Up @@ -106,7 +106,6 @@ QgsOfflineEditingPluginGui::QgsOfflineEditingPluginGui( QWidget *parent, Qt::Win

restoreState();

mOnlySelectedCheckBox->setDisabled( true );
mOfflineDbFile = QStringLiteral( "offline.gpkg" );
mOfflineDataPathLineEdit->setText( QDir( mOfflineDataPath ).absoluteFilePath( mOfflineDbFile ) );

Expand Down

0 comments on commit f80f4ec

Please sign in to comment.