only remove suffix when it's on the end

This commit is contained in:
signedav 2020-10-22 08:43:38 +02:00 committed by Nyall Dawson
parent 1cc9029b1f
commit da8c41a57d
2 changed files with 6 additions and 3 deletions

View File

@ -251,7 +251,8 @@ void QgsOfflineEditing::synchronize()
QString remoteProvider = layer->customProperty( CUSTOM_PROPERTY_REMOTE_PROVIDER, "" ).toString();
QString remoteName = layer->name();
QString remoteNameSuffix = layer->customProperty( CUSTOM_PROPERTY_LAYERNAME_SUFFIX, " (offline)" ).toString();
remoteName.remove( remoteNameSuffix );
if ( remoteName.endsWith( remoteNameSuffix ) )
remoteName.chop( remoteNameSuffix.size() );
const QgsVectorLayer::LayerOptions options { QgsProject::instance()->transformContext() };
QgsVectorLayer *remoteLayer = new QgsVectorLayer( remoteSource, remoteName, remoteProvider, options );
if ( remoteLayer->isValid() )

View File

@ -121,9 +121,10 @@ void TestQgsOfflineEditing::createSpatialiteAndSynchronizeBack_data()
QTest::addColumn<QString>( "suffix_input" );
QTest::addColumn<QString>( "suffix_result" );
QTest::newRow( "no suffix" ) << QString( "no suffix" ) << QStringLiteral( " (offline)" );
QTest::newRow( "no suffix" ) << QString( "no suffix" ) << QStringLiteral( " (offline)" ); //default value expected
QTest::newRow( "null suffix" ) << QString() << QString();
QTest::newRow( "empty suffix" ) << QStringLiteral( "" ) << QStringLiteral( "" );
QTest::newRow( "part of name suffix" ) << QStringLiteral( "point" ) << QStringLiteral( "point" );
QTest::newRow( "another suffix" ) << QStringLiteral( "another suffix" ) << QStringLiteral( "another suffix" );
}
@ -132,9 +133,10 @@ void TestQgsOfflineEditing::createGeopackageAndSynchronizeBack_data()
QTest::addColumn<QString>( "suffix_input" );
QTest::addColumn<QString>( "suffix_result" );
QTest::newRow( "no suffix" ) << QStringLiteral( "no suffix" ) << QStringLiteral( " (offline)" );
QTest::newRow( "no suffix" ) << QStringLiteral( "no suffix" ) << QStringLiteral( " (offline)" ); //default value expected
QTest::newRow( "null suffix" ) << QString() << QString();
QTest::newRow( "empty suffix" ) << QStringLiteral( "" ) << QStringLiteral( "" );
QTest::newRow( "part of name suffix" ) << QStringLiteral( "point" ) << QStringLiteral( "point" );
QTest::newRow( "another suffix" ) << QStringLiteral( "another suffix" ) << QStringLiteral( "another suffix" );
}