mirror of
				https://github.com/qgis/QGIS.git
				synced 2025-11-04 00:04:25 -05:00 
			
		
		
		
	layer name suffix passed to convertToOfflineProject with ' (offline)' as default
it's written into custom property so in synchronize it can get it from the offline project
This commit is contained in:
		
							parent
							
								
									b33b79244d
								
							
						
					
					
						commit
						9f2a41258e
					
				@ -36,7 +36,7 @@ class QgsOfflineEditing : QObject
 | 
			
		||||
 | 
			
		||||
    QgsOfflineEditing();
 | 
			
		||||
 | 
			
		||||
    bool convertToOfflineProject( const QString &offlineDataPath, const QString &offlineDbFile, const QStringList &layerIds, bool onlySelected = false, ContainerType containerType = SpatiaLite );
 | 
			
		||||
    bool convertToOfflineProject( const QString &offlineDataPath, const QString &offlineDbFile, const QStringList &layerIds, bool onlySelected = false, ContainerType containerType = SpatiaLite, const QString &layerNameSuffix = QStringLiteral( " (offline)" ) );
 | 
			
		||||
%Docstring
 | 
			
		||||
Convert current project for offline editing
 | 
			
		||||
 | 
			
		||||
@ -45,6 +45,7 @@ Convert current project for offline editing
 | 
			
		||||
:param layerIds: List of layer names to convert
 | 
			
		||||
:param onlySelected: Only copy selected features from layers where a selection is present
 | 
			
		||||
:param containerType: defines the SQLite file container type like SpatiaLite or GPKG
 | 
			
		||||
:param layerNameSuffix: Suffix string added to the offline layer name
 | 
			
		||||
%End
 | 
			
		||||
 | 
			
		||||
    bool isOfflineProject() const;
 | 
			
		||||
 | 
			
		||||
@ -61,6 +61,7 @@ extern "C"
 | 
			
		||||
#define CUSTOM_PROPERTY_REMOTE_PROVIDER "remoteProvider"
 | 
			
		||||
#define CUSTOM_SHOW_FEATURE_COUNT "showFeatureCount"
 | 
			
		||||
#define CUSTOM_PROPERTY_ORIGINAL_LAYERID "remoteLayerId"
 | 
			
		||||
#define CUSTOM_PROPERTY_LAYERNAME_SUFFIX "layerNameSuffix"
 | 
			
		||||
#define PROJECT_ENTRY_SCOPE_OFFLINE "OfflineEditingPlugin"
 | 
			
		||||
#define PROJECT_ENTRY_KEY_OFFLINE_DB_PATH "/OfflineDbPath"
 | 
			
		||||
 | 
			
		||||
@ -85,7 +86,7 @@ QgsOfflineEditing::QgsOfflineEditing()
 | 
			
		||||
 * - remove remote layers
 | 
			
		||||
 * - mark as offline project
 | 
			
		||||
 */
 | 
			
		||||
bool QgsOfflineEditing::convertToOfflineProject( const QString &offlineDataPath, const QString &offlineDbFile, const QStringList &layerIds, bool onlySelected, ContainerType containerType )
 | 
			
		||||
bool QgsOfflineEditing::convertToOfflineProject( const QString &offlineDataPath, const QString &offlineDbFile, const QStringList &layerIds, bool onlySelected, ContainerType containerType, const QString &layerNameSuffix )
 | 
			
		||||
{
 | 
			
		||||
  if ( layerIds.isEmpty() )
 | 
			
		||||
  {
 | 
			
		||||
@ -150,7 +151,7 @@ bool QgsOfflineEditing::convertToOfflineProject( const QString &offlineDataPath,
 | 
			
		||||
        if ( vl )
 | 
			
		||||
        {
 | 
			
		||||
          QString origLayerId = vl->id();
 | 
			
		||||
          QgsVectorLayer *newLayer = copyVectorLayer( vl, database.get(), dbPath, onlySelected, containerType );
 | 
			
		||||
          QgsVectorLayer *newLayer = copyVectorLayer( vl, database.get(), dbPath, onlySelected, containerType, layerNameSuffix );
 | 
			
		||||
          if ( newLayer )
 | 
			
		||||
          {
 | 
			
		||||
            layerIdMapping.insert( origLayerId, newLayer );
 | 
			
		||||
@ -249,7 +250,8 @@ void QgsOfflineEditing::synchronize()
 | 
			
		||||
    QString remoteSource = layer->customProperty( CUSTOM_PROPERTY_REMOTE_SOURCE, "" ).toString();
 | 
			
		||||
    QString remoteProvider = layer->customProperty( CUSTOM_PROPERTY_REMOTE_PROVIDER, "" ).toString();
 | 
			
		||||
    QString remoteName = layer->name();
 | 
			
		||||
    remoteName.remove( QRegExp( " \\(offline\\)$" ) );
 | 
			
		||||
    QString remoteNameSuffix = layer->customProperty( CUSTOM_PROPERTY_LAYERNAME_SUFFIX, " (offline)" ).toString();
 | 
			
		||||
    remoteName.remove( remoteNameSuffix );
 | 
			
		||||
    const QgsVectorLayer::LayerOptions options { QgsProject::instance()->transformContext() };
 | 
			
		||||
    QgsVectorLayer *remoteLayer = new QgsVectorLayer( remoteSource, remoteName, remoteProvider, options );
 | 
			
		||||
    if ( remoteLayer->isValid() )
 | 
			
		||||
@ -539,7 +541,7 @@ void QgsOfflineEditing::createLoggingTables( sqlite3 *db )
 | 
			
		||||
  */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QgsVectorLayer *QgsOfflineEditing::copyVectorLayer( QgsVectorLayer *layer, sqlite3 *db, const QString &offlineDbPath, bool onlySelected, ContainerType containerType )
 | 
			
		||||
QgsVectorLayer *QgsOfflineEditing::copyVectorLayer( QgsVectorLayer *layer, sqlite3 *db, const QString &offlineDbPath, bool onlySelected, ContainerType containerType, const QString &layerNameSuffix )
 | 
			
		||||
{
 | 
			
		||||
  if ( !layer )
 | 
			
		||||
    return nullptr;
 | 
			
		||||
@ -664,7 +666,7 @@ QgsVectorLayer *QgsOfflineEditing::copyVectorLayer( QgsVectorLayer *layer, sqlit
 | 
			
		||||
                                       tableName, layer->isSpatial() ? "(Geometry)" : "" );
 | 
			
		||||
      QgsVectorLayer::LayerOptions options { QgsProject::instance()->transformContext() };
 | 
			
		||||
      newLayer = new QgsVectorLayer( connectionString,
 | 
			
		||||
                                     layer->name() + " (offline)", QStringLiteral( "spatialite" ), options );
 | 
			
		||||
                                     layer->name() + layerNameSuffix, QStringLiteral( "spatialite" ), options );
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
    case GPKG:
 | 
			
		||||
@ -673,7 +675,7 @@ QgsVectorLayer *QgsOfflineEditing::copyVectorLayer( QgsVectorLayer *layer, sqlit
 | 
			
		||||
      char **options = nullptr;
 | 
			
		||||
 | 
			
		||||
      options = CSLSetNameValue( options, "OVERWRITE", "YES" );
 | 
			
		||||
      options = CSLSetNameValue( options, "IDENTIFIER", tr( "%1 (offline)" ).arg( layer->id() ).toUtf8().constData() );
 | 
			
		||||
      options = CSLSetNameValue( options, "IDENTIFIER", layer->id().toUtf8().constData() );
 | 
			
		||||
      options = CSLSetNameValue( options, "DESCRIPTION", layer->dataComment().toUtf8().constData() );
 | 
			
		||||
 | 
			
		||||
      //the FID-name should not exist in the original data
 | 
			
		||||
@ -768,7 +770,7 @@ QgsVectorLayer *QgsOfflineEditing::copyVectorLayer( QgsVectorLayer *layer, sqlit
 | 
			
		||||
 | 
			
		||||
      QString uri = QStringLiteral( "%1|layername=%2" ).arg( offlineDbPath,  tableName );
 | 
			
		||||
      QgsVectorLayer::LayerOptions layerOptions { QgsProject::instance()->transformContext() };
 | 
			
		||||
      newLayer = new QgsVectorLayer( uri, layer->name() + " (offline)", QStringLiteral( "ogr" ), layerOptions );
 | 
			
		||||
      newLayer = new QgsVectorLayer( uri, layer->name() + layerNameSuffix, QStringLiteral( "ogr" ), layerOptions );
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
@ -871,6 +873,7 @@ QgsVectorLayer *QgsOfflineEditing::copyVectorLayer( QgsVectorLayer *layer, sqlit
 | 
			
		||||
    newLayer->setCustomProperty( CUSTOM_PROPERTY_REMOTE_SOURCE, layer->source() );
 | 
			
		||||
    newLayer->setCustomProperty( CUSTOM_PROPERTY_REMOTE_PROVIDER, layer->providerType() );
 | 
			
		||||
    newLayer->setCustomProperty( CUSTOM_PROPERTY_ORIGINAL_LAYERID, layer->id() );
 | 
			
		||||
    newLayer->setCustomProperty( CUSTOM_PROPERTY_LAYERNAME_SUFFIX, layerNameSuffix );
 | 
			
		||||
 | 
			
		||||
    // register this layer with the central layers registry
 | 
			
		||||
    QgsProject::instance()->addMapLayers(
 | 
			
		||||
 | 
			
		||||
@ -64,8 +64,9 @@ class CORE_EXPORT QgsOfflineEditing : public QObject
 | 
			
		||||
     * \param layerIds List of layer names to convert
 | 
			
		||||
     * \param onlySelected Only copy selected features from layers where a selection is present
 | 
			
		||||
     * \param containerType defines the SQLite file container type like SpatiaLite or GPKG
 | 
			
		||||
     * \param layerNameSuffix Suffix string added to the offline layer name
 | 
			
		||||
     */
 | 
			
		||||
    bool convertToOfflineProject( const QString &offlineDataPath, const QString &offlineDbFile, const QStringList &layerIds, bool onlySelected = false, ContainerType containerType = SpatiaLite );
 | 
			
		||||
    bool convertToOfflineProject( const QString &offlineDataPath, const QString &offlineDbFile, const QStringList &layerIds, bool onlySelected = false, ContainerType containerType = SpatiaLite, const QString &layerNameSuffix = QStringLiteral( " (offline)" ) );
 | 
			
		||||
 | 
			
		||||
    //! Returns TRUE if current project is offline
 | 
			
		||||
    bool isOfflineProject() const;
 | 
			
		||||
@ -117,7 +118,7 @@ class CORE_EXPORT QgsOfflineEditing : public QObject
 | 
			
		||||
    bool createOfflineDb( const QString &offlineDbPath, ContainerType containerType = SpatiaLite );
 | 
			
		||||
    void createLoggingTables( sqlite3 *db );
 | 
			
		||||
 | 
			
		||||
    QgsVectorLayer *copyVectorLayer( QgsVectorLayer *layer, sqlite3 *db, const QString &offlineDbPath, bool onlySelected, ContainerType containerType = SpatiaLite );
 | 
			
		||||
    QgsVectorLayer *copyVectorLayer( QgsVectorLayer *layer, sqlite3 *db, const QString &offlineDbPath, bool onlySelected, ContainerType containerType = SpatiaLite, const QString &layerNameSuffix = QStringLiteral( " (offline)" ) );
 | 
			
		||||
 | 
			
		||||
    void applyAttributesAdded( QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId, int commitNo );
 | 
			
		||||
    void applyFeaturesAdded( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer, sqlite3 *db, int layerId );
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user