"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/gui/ogr/qgsvectorlayersaveasdialog.cpp" between
QGIS-final-3_10_5.tar.gz and QGIS-final-3_10_6.tar.gz

About: QGIS (Quantum GIS) is a Geographic Information System that supports vector, raster, and database formats. Long-term release (3.10.x series).

qgsvectorlayersaveasdialog.cpp  (QGIS-final-3_10_5):qgsvectorlayersaveasdialog.cpp  (QGIS-final-3_10_6)
skipping to change at line 22 skipping to change at line 22
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by * * it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or * * the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. * * (at your option) any later version. *
* * * *
***************************************************************************/ ***************************************************************************/
#include "qgslogger.h" #include "qgslogger.h"
#include "qgsvectorlayersaveasdialog.h" #include "qgsvectorlayersaveasdialog.h"
#include "qgsprojectionselectiondialog.h" #include "qgsprojectionselectiondialog.h"
#include "qgsvectordataprovider.h" #include "qgsvectordataprovider.h"
#include "qgsogrdataitems.h"
#include "qgscoordinatereferencesystem.h" #include "qgscoordinatereferencesystem.h"
#include "qgseditorwidgetfactory.h" #include "qgseditorwidgetfactory.h"
#include "qgseditorwidgetregistry.h" #include "qgseditorwidgetregistry.h"
#include "qgssettings.h" #include "qgssettings.h"
#include "qgsmapcanvas.h" #include "qgsmapcanvas.h"
#include "qgsgui.h" #include "qgsgui.h"
#include "qgsapplication.h" #include "qgsapplication.h"
#include <QMessageBox> #include <QMessageBox>
#include <QFileDialog> #include <QFileDialog>
#include <QTextCodec> #include <QTextCodec>
skipping to change at line 277 skipping to change at line 278
} }
void QgsVectorLayerSaveAsDialog::accept() void QgsVectorLayerSaveAsDialog::accept()
{ {
if ( QFile::exists( filename() ) ) if ( QFile::exists( filename() ) )
{ {
QgsVectorFileWriter::EditionCapabilities caps = QgsVectorFileWriter::EditionCapabilities caps =
QgsVectorFileWriter::editionCapabilities( filename() ); QgsVectorFileWriter::editionCapabilities( filename() );
bool layerExists = QgsVectorFileWriter::targetLayerExists( filename(), bool layerExists = QgsVectorFileWriter::targetLayerExists( filename(),
layername() ); layername() );
QMessageBox msgBox;
msgBox.setIcon( QMessageBox::Question );
msgBox.setWindowTitle( tr( "Save Vector Layer As" ) );
QPushButton *overwriteFileButton = msgBox.addButton( tr( "Overwrite File" ),
QMessageBox::ActionRole );
QPushButton *overwriteLayerButton = msgBox.addButton( tr( "Overwrite Layer"
), QMessageBox::ActionRole );
QPushButton *appendToLayerButton = msgBox.addButton( tr( "Append to Layer" )
, QMessageBox::ActionRole );
msgBox.setStandardButtons( QMessageBox::Cancel );
msgBox.setDefaultButton( QMessageBox::Cancel );
overwriteFileButton->hide();
overwriteLayerButton->hide();
appendToLayerButton->hide();
if ( layerExists ) if ( layerExists )
{ {
if ( !( caps & QgsVectorFileWriter::CanAppendToExistingLayer ) && if ( !( caps & QgsVectorFileWriter::CanAppendToExistingLayer ) &&
( caps & QgsVectorFileWriter::CanDeleteLayer ) && ( caps & QgsVectorFileWriter::CanDeleteLayer ) &&
( caps & QgsVectorFileWriter::CanAddNewLayer ) ) ( caps & QgsVectorFileWriter::CanAddNewLayer ) )
{ {
QMessageBox msgBox;
msgBox.setIcon( QMessageBox::Question );
msgBox.setWindowTitle( tr( "Save Vector Layer As" ) );
msgBox.setText( tr( "The layer already exists. Do you want to overwrite the whole file or overwrite the layer?" ) ); msgBox.setText( tr( "The layer already exists. Do you want to overwrite the whole file or overwrite the layer?" ) );
QPushButton *overwriteFileButton = msgBox.addButton( tr( "Overwrite File overwriteFileButton->setVisible( true );
" ), QMessageBox::ActionRole ); overwriteLayerButton->setVisible( true );
QPushButton *overwriteLayerButton = msgBox.addButton( tr( "Overwrite Lay
er" ), QMessageBox::ActionRole );
msgBox.setStandardButtons( QMessageBox::Cancel );
msgBox.setDefaultButton( QMessageBox::Cancel );
int ret = msgBox.exec();
if ( ret == QMessageBox::Cancel )
return;
if ( msgBox.clickedButton() == overwriteFileButton )
mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteFile;
else if ( msgBox.clickedButton() == overwriteLayerButton )
mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteLayer;
} }
else if ( !( caps & QgsVectorFileWriter::CanAppendToExistingLayer ) ) else if ( !( caps & QgsVectorFileWriter::CanAppendToExistingLayer ) )
{ {
if ( QMessageBox::question( this, msgBox.setText( tr( "The file already exists. Do you want to overwrite i
tr( "Save Vector Layer As" ), t?" ) );
tr( "The file already exists. Do you want to overwriteFileButton->setVisible( true );
overwrite it?" ) ) == QMessageBox::NoButton )
{
return;
}
mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteFile;
} }
else if ( ( caps & QgsVectorFileWriter::CanDeleteLayer ) && else if ( ( caps & QgsVectorFileWriter::CanDeleteLayer ) &&
( caps & QgsVectorFileWriter::CanAddNewLayer ) ) ( caps & QgsVectorFileWriter::CanAddNewLayer ) )
{ {
QMessageBox msgBox;
msgBox.setIcon( QMessageBox::Question );
msgBox.setWindowTitle( tr( "Save Vector Layer As" ) );
msgBox.setText( tr( "The layer already exists. Do you want to overwrite the whole file, overwrite the layer or append features to the layer?" ) ); msgBox.setText( tr( "The layer already exists. Do you want to overwrite the whole file, overwrite the layer or append features to the layer?" ) );
QPushButton *overwriteFileButton = msgBox.addButton( tr( "Overwrite File appendToLayerButton->setVisible( true );
" ), QMessageBox::ActionRole ); overwriteFileButton->setVisible( true );
QPushButton *overwriteLayerButton = msgBox.addButton( tr( "Overwrite Lay overwriteLayerButton->setVisible( true );
er" ), QMessageBox::ActionRole );
QPushButton *appendToLayerButton = msgBox.addButton( tr( "Append to Laye
r" ), QMessageBox::ActionRole );
msgBox.setStandardButtons( QMessageBox::Cancel );
msgBox.setDefaultButton( QMessageBox::Cancel );
int ret = msgBox.exec();
if ( ret == QMessageBox::Cancel )
return;
if ( msgBox.clickedButton() == overwriteFileButton )
mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteFile;
else if ( msgBox.clickedButton() == overwriteLayerButton )
mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteLayer;
else if ( msgBox.clickedButton() == appendToLayerButton )
mActionOnExistingFile = QgsVectorFileWriter::AppendToLayerNoNewFields;
} }
else else
{ {
QMessageBox msgBox;
msgBox.setIcon( QMessageBox::Question );
msgBox.setWindowTitle( tr( "Save Vector Layer As" ) );
msgBox.setText( tr( "The layer already exists. Do you want to overwrite the whole file or append features to the layer?" ) ); msgBox.setText( tr( "The layer already exists. Do you want to overwrite the whole file or append features to the layer?" ) );
QPushButton *overwriteFileButton = msgBox.addButton( tr( "Overwrite File appendToLayerButton->setVisible( true );
" ), QMessageBox::ActionRole ); overwriteFileButton->setVisible( true );
QPushButton *appendToLayerButton = msgBox.addButton( tr( "Append to Laye
r" ), QMessageBox::ActionRole );
msgBox.setStandardButtons( QMessageBox::Cancel );
msgBox.setDefaultButton( QMessageBox::Cancel );
int ret = msgBox.exec();
if ( ret == QMessageBox::Cancel )
return;
if ( msgBox.clickedButton() == overwriteFileButton )
mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteFile;
else if ( msgBox.clickedButton() == appendToLayerButton )
mActionOnExistingFile = QgsVectorFileWriter::AppendToLayerNoNewFields;
}
if ( mActionOnExistingFile == QgsVectorFileWriter::AppendToLayerNoNewField
s )
{
if ( QgsVectorFileWriter::areThereNewFieldsToCreate( filename(),
layername(),
mLayer,
selectedAttributes() ) )
{
if ( QMessageBox::question( this,
tr( "Save Vector Layer As" ),
tr( "The existing layer has different fiel
ds. Do you want to add the missing fields to the layer?" ) ) == QMessageBox::Yes
)
{
mActionOnExistingFile = QgsVectorFileWriter::AppendToLayerAddFields;
}
}
} }
int ret = msgBox.exec();
if ( ret == QMessageBox::Cancel )
return;
if ( msgBox.clickedButton() == overwriteFileButton )
mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteFile;
else if ( msgBox.clickedButton() == overwriteLayerButton )
mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteLayer;
else if ( msgBox.clickedButton() == appendToLayerButton )
mActionOnExistingFile = QgsVectorFileWriter::AppendToLayerNoNewFields;
} }
else else // !layerExists
{ {
if ( ( caps & QgsVectorFileWriter::CanAddNewLayer ) ) if ( ( caps & QgsVectorFileWriter::CanAddNewLayer ) )
{ {
mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteLayer; mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteLayer;
} }
else else
{ {
// should not reach here, layer does not exist and cannot add new layer
if ( QMessageBox::question( this, if ( QMessageBox::question( this,
tr( "Save Vector Layer As" ), tr( "Save Vector Layer As" ),
tr( "The file already exists. Do you want to overwrite it?" ) ) == QMessageBox::NoButton ) tr( "The file already exists. Do you want to overwrite it?" ) ) == QMessageBox::NoButton )
{ {
return; return;
} }
mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteFile; mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteFile;
} }
} }
} }
if ( mActionOnExistingFile == QgsVectorFileWriter::AppendToLayerNoNewFields )
{
if ( QgsVectorFileWriter::areThereNewFieldsToCreate( filename(), layername()
, mLayer, selectedAttributes() ) )
{
if ( QMessageBox::question( this,
tr( "Save Vector Layer As" ),
tr( "The existing layer has additional fields.
Do you want to add the missing fields to the layer?" ) ) == QMessageBox::Yes )
{
mActionOnExistingFile = QgsVectorFileWriter::AppendToLayerAddFields;
}
}
}
else if ( mActionOnExistingFile == QgsVectorFileWriter::CreateOrOverwriteFile
)
{
const QList<QgsOgrDbLayerInfo *> subLayers = QgsOgrLayerItem::subLayers( fil
ename(), format() );
QStringList layerList;
for ( const QgsOgrDbLayerInfo *layer : subLayers )
{
layerList.append( layer->name() );
}
qDeleteAll( subLayers );
if ( layerList.length() > 1 )
{
layerList.sort( Qt::CaseInsensitive );
QMessageBox msgBox;
msgBox.setIcon( QMessageBox::Warning );
msgBox.setWindowTitle( tr( "Overwrite File" ) );
msgBox.setText( tr( "This file contains %1 layers that will be lost!\n" ).
arg( QString::number( layerList.length() ) ) );
msgBox.setDetailedText( tr( "The following layers will be permanently lost
:\n\n%1" ).arg( layerList.join( "\n" ) ) );
msgBox.setStandardButtons( QMessageBox::Ok | QMessageBox::Cancel );
if ( msgBox.exec() == QMessageBox::Cancel )
return;
}
}
QgsSettings settings; QgsSettings settings;
settings.setValue( QStringLiteral( "UI/lastVectorFileFilterDir" ), QFileInfo( filename() ).absolutePath() ); settings.setValue( QStringLiteral( "UI/lastVectorFileFilterDir" ), QFileInfo( filename() ).absolutePath() );
settings.setValue( QStringLiteral( "UI/lastVectorFormat" ), format() ); settings.setValue( QStringLiteral( "UI/lastVectorFormat" ), format() );
settings.setValue( QStringLiteral( "UI/encoding" ), encoding() ); settings.setValue( QStringLiteral( "UI/encoding" ), encoding() );
QDialog::accept(); QDialog::accept();
} }
void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int idx ) void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int idx )
{ {
Q_UNUSED( idx ) Q_UNUSED( idx )
 End of changes. 13 change blocks. 
80 lines changed or deleted 77 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)