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