@@ -79,7 +79,7 @@ QgsOfflineEditing::~QgsOfflineEditing()
79
79
* - remove remote layers
80
80
* - mark as offline project
81
81
*/
82
- bool QgsOfflineEditing::convertToOfflineProject ( const QString& offlineDataPath, const QString& offlineDbFile, const QStringList& layerIds )
82
+ bool QgsOfflineEditing::convertToOfflineProject ( const QString& offlineDataPath, const QString& offlineDbFile, const QStringList& layerIds, bool onlySelected )
83
83
{
84
84
if ( layerIds.isEmpty () )
85
85
{
@@ -104,9 +104,9 @@ bool QgsOfflineEditing::convertToOfflineProject( const QString& offlineDataPath,
104
104
QMap<QString, QgsVectorJoinList > joinInfoBuffer;
105
105
QMap<QString, QgsVectorLayer*> layerIdMapping;
106
106
107
- for ( int i = 0 ; i < layerIds. count (); i++ )
107
+ Q_FOREACH ( const QString& layerId, layerIds )
108
108
{
109
- QgsMapLayer* layer = QgsMapLayerRegistry::instance ()->mapLayer ( layerIds. at ( i ) );
109
+ QgsMapLayer* layer = QgsMapLayerRegistry::instance ()->mapLayer ( layerId );
110
110
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( layer );
111
111
if ( !vl )
112
112
continue ;
@@ -116,17 +116,17 @@ bool QgsOfflineEditing::convertToOfflineProject( const QString& offlineDataPath,
116
116
// Join fields are prefixed with the layer name and we do not want the
117
117
// field name to change so we stabilize the field name by defining a
118
118
// custom prefix with the layername without _offline suffix.
119
- QgsVectorJoinList::iterator it = joins.begin ();
120
- while ( it != joins.end () )
119
+ QgsVectorJoinList::iterator joinIt = joins.begin ();
120
+ while ( joinIt != joins.end () )
121
121
{
122
- if (( *it ). prefix .isNull () )
122
+ if ( joinIt-> prefix .isNull () )
123
123
{
124
- QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance ()->mapLayer (( *it ). joinLayerId ) );
124
+ QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance ()->mapLayer ( joinIt-> joinLayerId ) );
125
125
126
126
if ( vl )
127
- ( *it ). prefix = vl->name () + ' _' ;
127
+ joinIt-> prefix = vl->name () + ' _' ;
128
128
}
129
- ++it ;
129
+ ++joinIt ;
130
130
}
131
131
joinInfoBuffer.insert ( vl->id (), joins );
132
132
}
@@ -141,7 +141,7 @@ bool QgsOfflineEditing::convertToOfflineProject( const QString& offlineDataPath,
141
141
if ( vl )
142
142
{
143
143
QString origLayerId = vl->id ();
144
- QgsVectorLayer* newLayer = copyVectorLayer ( vl, db, dbPath );
144
+ QgsVectorLayer* newLayer = copyVectorLayer ( vl, db, dbPath, onlySelected );
145
145
146
146
if ( newLayer )
147
147
{
@@ -197,7 +197,7 @@ bool QgsOfflineEditing::convertToOfflineProject( const QString& offlineDataPath,
197
197
return false ;
198
198
}
199
199
200
- bool QgsOfflineEditing::isOfflineProject ()
200
+ bool QgsOfflineEditing::isOfflineProject () const
201
201
{
202
202
return !QgsProject::instance ()->readEntry ( PROJECT_ENTRY_SCOPE_OFFLINE, PROJECT_ENTRY_KEY_OFFLINE_DB_PATH ).isEmpty ();
203
203
}
@@ -228,7 +228,7 @@ void QgsOfflineEditing::synchronize()
228
228
QgsDebugMsgLevel ( QString ( " Found %1 offline layers" ).arg ( offlineLayers.count () ), 4 );
229
229
for ( int l = 0 ; l < offlineLayers.count (); l++ )
230
230
{
231
- QgsMapLayer* layer = offlineLayers[l] ;
231
+ QgsMapLayer* layer = offlineLayers. at ( l ) ;
232
232
233
233
emit layerProgressUpdated ( l + 1 , offlineLayers.count () );
234
234
@@ -254,8 +254,7 @@ void QgsOfflineEditing::synchronize()
254
254
QgsVectorLayer* offlineLayer = qobject_cast<QgsVectorLayer*>( layer );
255
255
256
256
// register this layer with the central layers registry
257
- QgsMapLayerRegistry::instance ()->addMapLayers (
258
- QList<QgsMapLayer *>() << remoteLayer, true );
257
+ QgsMapLayerRegistry::instance ()->addMapLayers ( QList<QgsMapLayer *>() << remoteLayer, true );
259
258
260
259
// copy style
261
260
copySymbology ( offlineLayer, remoteLayer );
@@ -317,8 +316,7 @@ void QgsOfflineEditing::synchronize()
317
316
// again with the same path
318
317
offlineLayer->dataProvider ()->invalidateConnections ( QgsDataSourceUri ( offlineLayer->source () ).database () );
319
318
// remove offline layer
320
- QgsMapLayerRegistry::instance ()->removeMapLayers (
321
- ( QStringList () << qgisLayerId ) );
319
+ QgsMapLayerRegistry::instance ()->removeMapLayers ( QStringList () << qgisLayerId );
322
320
323
321
324
322
// disable offline project
@@ -486,7 +484,7 @@ void QgsOfflineEditing::createLoggingTables( sqlite3* db )
486
484
*/
487
485
}
488
486
489
- QgsVectorLayer* QgsOfflineEditing::copyVectorLayer ( QgsVectorLayer* layer, sqlite3* db, const QString& offlineDbPath )
487
+ QgsVectorLayer* QgsOfflineEditing::copyVectorLayer ( QgsVectorLayer* layer, sqlite3* db, const QString& offlineDbPath , bool onlySelected )
490
488
{
491
489
if ( !layer )
492
490
return nullptr ;
@@ -626,12 +624,18 @@ QgsVectorLayer* QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlit
626
624
627
625
QgsFeatureIterator fit = layer->dataProvider ()->getFeatures ();
628
626
627
+ QgsFeatureIds selectedFids = layer->selectedFeaturesIds ();
628
+
629
629
emit progressModeSet ( QgsOfflineEditing::CopyFeatures, layer->dataProvider ()->featureCount () );
630
630
int featureCount = 1 ;
631
631
632
632
QList<QgsFeatureId> remoteFeatureIds;
633
633
while ( fit.nextFeature ( f ) )
634
634
{
635
+ // Check if we only want selected feature, if the selection is not empty and the current feature is not selected: dismiss it
636
+ if ( onlySelected && !selectedFids.isEmpty () && !selectedFids.contains ( f.id () ) )
637
+ continue ;
638
+
635
639
remoteFeatureIds << f.id ();
636
640
637
641
// NOTE: Spatialite provider ignores position of geometry column
0 commit comments