33
33
#include " qgsexception.h"
34
34
#include " qgssettings.h"
35
35
#include " qgsgeometryengine.h"
36
+ #include " qgsproviderregistry.h"
36
37
37
38
#include < QFile>
38
39
#include < QFileInfo>
@@ -2422,6 +2423,7 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::prepareWriteAsVectorFormat
2422
2423
details.dataSourceUri = layer->dataProvider ()->dataSourceUri ();
2423
2424
details.storageType = layer->storageType ();
2424
2425
details.selectedFeatureIds = layer->selectedFeatureIds ();
2426
+ details.providerUriParams = QgsProviderRegistry::instance ()->decodeUri ( layer->providerType (), layer->dataProvider ()->dataSourceUri () );
2425
2427
2426
2428
if ( details.storageType == QLatin1String ( " ESRI Shapefile" ) )
2427
2429
{
@@ -2554,26 +2556,21 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::writeAsVectorFormat( Prepa
2554
2556
if ( details.providerType == QLatin1String ( " ogr" ) && !details.dataSourceUri .isEmpty () )
2555
2557
{
2556
2558
QStringList theURIParts = details.dataSourceUri .split ( ' |' );
2557
- QString srcFileName = theURIParts[0 ];
2558
2559
QgsStringMap srcUriParams;
2560
+ QString srcFileName;
2559
2561
if ( theURIParts.length () > 0 )
2560
2562
{
2561
- for ( int i = 1 ; i < theURIParts.length (); ++i )
2562
- {
2563
- QStringList parts ( theURIParts[i].split ( ' =' ) );
2564
- if ( parts.length () == 2 )
2565
- srcUriParams[parts[0 ]] = parts[1 ];
2566
- }
2563
+ srcFileName = theURIParts[0 ];
2567
2564
}
2568
2565
2569
2566
if ( QFile::exists ( srcFileName ) && QFileInfo ( fileName ).canonicalFilePath () == QFileInfo ( srcFileName ).canonicalFilePath () )
2570
2567
{
2571
- // Check the layer name too if it's a GPKG/SpatiaLite/SQLite OGR driver
2568
+ // Check the layer name too if it's a GPKG/SpatiaLite/SQLite OGR driver (pay attention: camel case in layerName)
2572
2569
QgsDataSourceUri uri ( details.dataSourceUri );
2573
2570
if ( !( ( options.driverName == QLatin1String ( " GPKG" ) ||
2574
2571
options.driverName == QLatin1String ( " SpatiaLite" ) ||
2575
2572
options.driverName == QLatin1String ( " SQLite" ) ) &&
2576
- options.layerName != srcUriParams[ " layername " ] ) )
2573
+ options.layerName != details. providerUriParams . value ( QLatin1String ( " layerName " ) ) ) )
2577
2574
{
2578
2575
if ( errorMessage )
2579
2576
*errorMessage = QObject::tr ( " Cannot overwrite a OGR layer in place" );
@@ -2596,7 +2593,7 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::writeAsVectorFormat( Prepa
2596
2593
if ( options.feedback )
2597
2594
{
2598
2595
// dedicate first 5% of progress bar to this scan
2599
- int newProgress = ( 5.0 * scanned ) / total;
2596
+ int newProgress = static_cast < int >( ( 5.0 * scanned ) / total ) ;
2600
2597
if ( newProgress != lastProgressReport )
2601
2598
{
2602
2599
lastProgressReport = newProgress;
@@ -2694,7 +2691,7 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::writeAsVectorFormat( Prepa
2694
2691
if ( options.feedback )
2695
2692
{
2696
2693
// avoid spamming progress reports
2697
- int newProgress = initialProgress + ( ( 100.0 - initialProgress ) * saved ) / total;
2694
+ int newProgress = static_cast < int >( initialProgress + ( ( 100.0 - initialProgress ) * saved ) / total ) ;
2698
2695
if ( newProgress < 100 && newProgress != lastProgressReport )
2699
2696
{
2700
2697
lastProgressReport = newProgress;
0 commit comments