25 #include "qgssettings.h" 
   29 #include "qgsogrdataitems.h" 
   30 #include <QMessageBox> 
   31 #include <QFileDialog> 
   34 #include <QRegularExpression> 
   39 static const int COLUMN_IDX_NAME = 0;
 
   40 static const int COLUMN_IDX_TYPE = 1;
 
   41 static const int COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE = 2;
 
   44   : QDialog( parent, fl )
 
   46   , mAttributeTableItemChangedSlotEnabled( true )
 
   47   , mReplaceRawFieldValuesStateChangedSlotEnabled( true )
 
   54   : QDialog( parent, fl )
 
   56   , mAttributeTableItemChangedSlotEnabled( true )
 
   57   , mReplaceRawFieldValuesStateChangedSlotEnabled( true )
 
   63     mSelectedCrs = layer->
crs();
 
   64     mLayerExtent = layer->
extent();
 
   70     mSymbologyExportLabel->hide();
 
   71     mSymbologyExportComboBox->hide();
 
   81   if ( !( mOptions & 
Fields ) )
 
   82     mAttributesSelection->hide();
 
   85     mSelectedOnly->hide();
 
   91     mGeometryGroupBox->hide();
 
   93   if ( !( mOptions & 
Extent ) )
 
   94     mExtentGroupBox->hide();
 
   98     mCheckPersistMetadata->setChecked( 
false );
 
   99     mCheckPersistMetadata->hide();
 
  103   mButtonBox->button( QDialogButtonBox::Ok )->setDisabled( 
true );
 
  106 void QgsVectorLayerSaveAsDialog::setup()
 
  111   connect( mFormatComboBox, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged );
 
  113   connect( mSymbologyExportComboBox, &QComboBox::currentTextChanged, 
this, &QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged );
 
  114   connect( mGeometryTypeComboBox, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged );
 
  115   connect( mSelectAllAttributes, &QPushButton::clicked, 
this, &QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked );
 
  116   connect( mDeselectAllAttributes, &QPushButton::clicked, 
this, &QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked );
 
  117   connect( mReplaceRawFieldValues, &QCheckBox::stateChanged, 
this, &QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged );
 
  118   connect( mAttributeTable, &QTableWidget::itemChanged, 
this, &QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged );
 
  121   mHelpButtonBox->setVisible( 
false );
 
  122   mButtonBox->addButton( QDialogButtonBox::Help );
 
  123   connect( mButtonBox, &QDialogButtonBox::helpRequested, 
this, &QgsVectorLayerSaveAsDialog::showHelp );
 
  125   connect( mHelpButtonBox, &QDialogButtonBox::helpRequested, 
this, &QgsVectorLayerSaveAsDialog::showHelp );
 
  127   connect( mButtonBox, &QDialogButtonBox::accepted, 
this, &QgsVectorLayerSaveAsDialog::accept );
 
  128   connect( mButtonBox, &QDialogButtonBox::rejected, 
this, &QgsVectorLayerSaveAsDialog::reject );
 
  131   mFormatComboBox->blockSignals( 
true );
 
  134     mFormatComboBox->addItem( driver.longName, driver.driverName );
 
  137   QgsSettings settings;
 
  138   QString 
format = settings.value( QStringLiteral( 
"UI/lastVectorFormat" ), 
"GPKG" ).toString();
 
  139   mFormatComboBox->setCurrentIndex( mFormatComboBox->findData( 
format ) );
 
  140   mFormatComboBox->blockSignals( 
false );
 
  148   mGeometryTypeComboBox->addItem( tr( 
"Automatic" ), -1 );
 
  154   mGeometryTypeComboBox->setCurrentIndex( mGeometryTypeComboBox->findData( -1 ) );
 
  158   QString enc = settings.value( QStringLiteral( 
"UI/encoding" ), 
"System" ).toString();
 
  159   int idx = mEncodingComboBox->findText( enc );
 
  162     mEncodingComboBox->insertItem( 0, enc );
 
  166   mCrsSelector->setCrs( mSelectedCrs );
 
  167   mCrsSelector->setLayerCrs( mSelectedCrs );
 
  168   mCrsSelector->setMessage( tr( 
"Select the coordinate reference system for the vector file. " 
  169                                 "The data points will be transformed from the layer coordinate reference system." ) );
 
  171   mEncodingComboBox->setCurrentIndex( idx );
 
  172   mFormatComboBox_currentIndexChanged( mFormatComboBox->currentIndex() );
 
  178   mSymbologyExportComboBox_currentIndexChanged( mSymbologyExportComboBox->currentText() );
 
  181   mExtentGroupBox->setOutputCrs( mSelectedCrs );
 
  182   mExtentGroupBox->setOriginalExtent( mLayerExtent, mSelectedCrs );
 
  183   mExtentGroupBox->setOutputExtentFromOriginal();
 
  184   mExtentGroupBox->setCheckable( 
true );
 
  185   mExtentGroupBox->setChecked( 
false );
 
  186   mExtentGroupBox->setCollapsed( 
true );
 
  189   mFilename->setDialogTitle( tr( 
"Save Layer As" ) );
 
  190   mFilename->setDefaultRoot( settings.value( QStringLiteral( 
"UI/lastVectorFileFilterDir" ), QDir::homePath() ).toString() );
 
  191   mFilename->setConfirmOverwrite( 
false );
 
  194     QgsSettings settings;
 
  195     QFileInfo tmplFileInfo( filePath );
 
  196     settings.setValue( QStringLiteral( 
"UI/lastVectorFileFilterDir" ), tmplFileInfo.absolutePath() );
 
  197     if ( !filePath.isEmpty() && leLayername->isEnabled() )
 
  199       QFileInfo fileInfo( filePath );
 
  200       leLayername->setText( fileInfo.completeBaseName() );
 
  202     mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( !filePath.isEmpty() );
 
  210       mCrsSelector->setSourceEnsemble( ensemble.
name() );
 
  217   mCrsSelector->setShowAccuracyWarnings( 
true );
 
  220 QList<QPair<QLabel *, QWidget *> > QgsVectorLayerSaveAsDialog::createControls( 
const QMap<QString, QgsVectorFileWriter::Option *> &options )
 
  222   QList<QPair<QLabel *, QWidget *> > controls;
 
  223   QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
 
  225   for ( it = options.constBegin(); it != options.constEnd(); ++it )
 
  228     QLabel *label = 
new QLabel( it.key() );
 
  229     QWidget *control = 
nullptr;
 
  230     switch ( option->
type )
 
  237           QSpinBox *sb = 
new QSpinBox();
 
  238           sb->setObjectName( it.key() );
 
  250           QComboBox *cb = 
new QComboBox();
 
  251           cb->setObjectName( it.key() );
 
  252           for ( 
const QString &val : std::as_const( opt->
values ) )
 
  254             cb->addItem( val, val );
 
  257             cb->addItem( tr( 
"<Default>" ), QVariant( QVariant::String ) );
 
  260             idx = cb->findData( QVariant( QVariant::String ) );
 
  261           cb->setCurrentIndex( idx );
 
  273           le->setObjectName( it.key() );
 
  287       label->setToolTip( QStringLiteral( 
"<p>%1</p>" ).arg( option->
docString ) );
 
  288       control->setToolTip( QStringLiteral( 
"<p>%1</p>" ).arg( option->
docString ) );
 
  290       controls << QPair<QLabel *, QWidget *>( label, control );
 
  297 void QgsVectorLayerSaveAsDialog::accept()
 
  301     QgsVectorFileWriter::EditionCapabilities caps =
 
  306     msgBox.setIcon( QMessageBox::Question );
 
  307     msgBox.setWindowTitle( tr( 
"Save Vector Layer As" ) );
 
  308     QPushButton *overwriteFileButton = msgBox.addButton( tr( 
"Overwrite File" ), QMessageBox::ActionRole );
 
  309     QPushButton *overwriteLayerButton = msgBox.addButton( tr( 
"Overwrite Layer" ), QMessageBox::ActionRole );
 
  310     QPushButton *appendToLayerButton = msgBox.addButton( tr( 
"Append to Layer" ), QMessageBox::ActionRole );
 
  311     msgBox.setStandardButtons( QMessageBox::Cancel );
 
  312     msgBox.setDefaultButton( QMessageBox::Cancel );
 
  313     overwriteFileButton->hide();
 
  314     overwriteLayerButton->hide();
 
  315     appendToLayerButton->hide();
 
  322         msgBox.setText( tr( 
"The layer already exists. Do you want to overwrite the whole file or overwrite the layer?" ) );
 
  323         overwriteFileButton->setVisible( 
true );
 
  324         overwriteLayerButton->setVisible( 
true );
 
  328         msgBox.setText( tr( 
"The file already exists. Do you want to overwrite it?" ) );
 
  329         overwriteFileButton->setVisible( 
true );
 
  334         msgBox.setText( tr( 
"The layer already exists. Do you want to overwrite the whole file, overwrite the layer or append features to the layer?" ) );
 
  335         appendToLayerButton->setVisible( 
true );
 
  336         overwriteFileButton->setVisible( 
true );
 
  337         overwriteLayerButton->setVisible( 
true );
 
  341         msgBox.setText( tr( 
"The layer already exists. Do you want to overwrite the whole file or append features to the layer?" ) );
 
  342         appendToLayerButton->setVisible( 
true );
 
  343         overwriteFileButton->setVisible( 
true );
 
  346       int ret = msgBox.exec();
 
  347       if ( ret == QMessageBox::Cancel )
 
  349       if ( msgBox.clickedButton() == overwriteFileButton )
 
  351       else if ( msgBox.clickedButton() == overwriteLayerButton )
 
  353       else if ( msgBox.clickedButton() == appendToLayerButton )
 
  365         if ( QMessageBox::question( 
this,
 
  366                                     tr( 
"Save Vector Layer As" ),
 
  367                                     tr( 
"The file already exists. Do you want to overwrite it?" ) ) == QMessageBox::NoButton )
 
  380       if ( QMessageBox::question( 
this,
 
  381                                   tr( 
"Save Vector Layer As" ),
 
  382                                   tr( 
"The existing layer has additional fields. Do you want to add the missing fields to the layer?" ) ) == QMessageBox::Yes )
 
  392       const QList<QgsOgrDbLayerInfo *> subLayers = QgsOgrLayerItem::subLayers( 
filename(), 
format() );
 
  393       QStringList layerList;
 
  394       for ( 
const QgsOgrDbLayerInfo *layer : subLayers )
 
  396         layerList.append( layer->name() );
 
  398       qDeleteAll( subLayers );
 
  399       if ( layerList.length() > 1 )
 
  401         layerList.sort( Qt::CaseInsensitive );
 
  403         msgBox.setIcon( QMessageBox::Warning );
 
  404         msgBox.setWindowTitle( tr( 
"Overwrite File" ) );
 
  405         msgBox.setText( tr( 
"This file contains %1 layers that will be lost!\n" ).arg( QString::number( layerList.length() ) ) );
 
  406         msgBox.setDetailedText( tr( 
"The following layers will be permanently lost:\n\n%1" ).arg( layerList.join( 
"\n" ) ) );
 
  407         msgBox.setStandardButtons( QMessageBox::Ok | QMessageBox::Cancel );
 
  408         if ( msgBox.exec() == QMessageBox::Cancel )
 
  412     catch ( QgsOgrLayerNotValidException &ex )
 
  414       QMessageBox::critical( 
this,
 
  415                              tr( 
"Save Vector Layer As" ),
 
  416                              tr( 
"Error opening destination file: %1" ).arg( ex.what() ) );
 
  421   QgsSettings settings;
 
  422   settings.setValue( QStringLiteral( 
"UI/lastVectorFileFilterDir" ), QFileInfo( 
filename() ).absolutePath() );
 
  423   settings.setValue( QStringLiteral( 
"UI/lastVectorFormat" ), 
format() );
 
  424   settings.setValue( QStringLiteral( 
"UI/encoding" ), 
encoding() );
 
  428 void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( 
int idx )
 
  432   mFilename->setEnabled( 
true );
 
  437   if ( !mFilename->filePath().isEmpty() )
 
  439     QRegularExpression rx( 
"\\.(.*?)[\\s]" );
 
  442     if ( !ext.isEmpty() )
 
  444       QFileInfo fi( mFilename->filePath() );
 
  445       mFilename->setFilePath( QStringLiteral( 
"%1/%2.%3" ).arg( fi.path() ).arg( fi.baseName() ).arg( ext ) );
 
  449   bool selectAllFields = 
true;
 
  454   bool isFormatForFieldsAsDisplayedValues = 
false;
 
  456   const QString sFormat( 
format() );
 
  457   if ( sFormat == QLatin1String( 
"DXF" ) || sFormat == QLatin1String( 
"DGN" ) )
 
  459     mAttributesSelection->setVisible( 
false );
 
  460     selectAllFields = 
false;
 
  466       mAttributesSelection->setVisible( 
true );
 
  467       isFormatForFieldsAsDisplayedValues = ( sFormat == QLatin1String( 
"CSV" ) ||
 
  468                                              sFormat == QLatin1String( 
"XLS" ) ||
 
  469                                              sFormat == QLatin1String( 
"XLSX" ) ||
 
  470                                              sFormat == QLatin1String( 
"ODS" ) );
 
  477     mSymbologyExportLabel->setVisible( 
true );
 
  478     mSymbologyExportComboBox->setVisible( 
true );
 
  479     mScaleLabel->setVisible( 
true );
 
  480     mScaleWidget->setVisible( 
true );
 
  484     mSymbologyExportLabel->hide();
 
  485     mSymbologyExportComboBox->hide();
 
  487     mScaleWidget->hide();
 
  490   leLayername->setEnabled( sFormat == QLatin1String( 
"KML" ) ||
 
  491                            sFormat == QLatin1String( 
"GPKG" ) ||
 
  492                            sFormat == QLatin1String( 
"XLSX" ) ||
 
  493                            sFormat == QLatin1String( 
"ODS" ) ||
 
  494                            sFormat == QLatin1String( 
"FileGDB" ) ||
 
  495                            sFormat == QLatin1String( 
"SQLite" ) ||
 
  496                            sFormat == QLatin1String( 
"SpatiaLite" ) );
 
  497   if ( !leLayername->isEnabled() )
 
  498     leLayername->setText( QString() );
 
  499   else if ( leLayername->text().isEmpty() &&
 
  500             !mFilename->filePath().isEmpty() )
 
  502     QString layerName = QFileInfo( mFilename->filePath() ).baseName();
 
  503     leLayername->setText( layerName );
 
  508     mAttributeTable->setRowCount( mLayer->
fields().
count() );
 
  510     bool foundFieldThatCanBeExportedAsDisplayedValue = 
false;
 
  511     for ( 
int i = 0; i < mLayer->
fields().size(); ++i )
 
  514       if ( setup.
type() != QLatin1String( 
"TextEdit" ) &&
 
  517         foundFieldThatCanBeExportedAsDisplayedValue = 
true;
 
  521     if ( foundFieldThatCanBeExportedAsDisplayedValue )
 
  523       mAttributeTable->setColumnCount( 3 );
 
  524       mAttributeTable->setHorizontalHeaderLabels( QStringList() << tr( 
"Name" ) << tr( 
"Type" ) << tr( 
"Replace with displayed values" ) );
 
  528       mAttributeTable->setColumnCount( 2 );
 
  529       mAttributeTable->setHorizontalHeaderLabels( QStringList() << tr( 
"Name" ) << tr( 
"Type" ) );
 
  532     mAttributeTableItemChangedSlotEnabled = 
false;
 
  534     bool checkReplaceRawFieldValues = selectAllFields && isFormatForFieldsAsDisplayedValues;
 
  535     for ( 
int i = 0; i < mLayer->
fields().size(); ++i )
 
  538       Qt::ItemFlags flags = mLayer->
providerType() != QLatin1String( 
"oracle" ) || !fld.
typeName().contains( QLatin1String( 
"SDO_GEOMETRY" ) ) ? Qt::ItemIsEnabled : Qt::NoItemFlags;
 
  539       QTableWidgetItem *item = 
nullptr;
 
  540       item = 
new QTableWidgetItem( fld.
name() );
 
  541       item->setFlags( flags | Qt::ItemIsUserCheckable );
 
  542       item->setCheckState( ( selectAllFields ) ? Qt::Checked : Qt::Unchecked );
 
  543       mAttributeTable->setItem( i, COLUMN_IDX_NAME, item );
 
  545       item = 
new QTableWidgetItem( fld.
typeName() );
 
  546       item->setFlags( flags );
 
  547       mAttributeTable->setItem( i, COLUMN_IDX_TYPE, item );
 
  549       if ( foundFieldThatCanBeExportedAsDisplayedValue )
 
  553         const QString widgetId( setup.
type() );
 
  554         if ( flags == Qt::ItemIsEnabled &&
 
  555              widgetId != QLatin1String( 
"TextEdit" ) &&
 
  558           item = 
new QTableWidgetItem( tr( 
"Use %1" ).arg( factory->
name() ) );
 
  559           item->setFlags( ( selectAllFields ) ? ( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable ) : Qt::ItemIsUserCheckable );
 
  560           const bool checkItem = ( selectAllFields && isFormatForFieldsAsDisplayedValues &&
 
  561                                    ( widgetId == QLatin1String( 
"ValueMap" ) ||
 
  562                                      widgetId == QLatin1String( 
"ValueRelation" ) ||
 
  563                                      widgetId == QLatin1String( 
"CheckBox" ) ||
 
  564                                      widgetId == QLatin1String( 
"RelationReference" ) ) );
 
  565           checkReplaceRawFieldValues &= checkItem;
 
  566           item->setCheckState( checkItem ?
 
  567                                Qt::Checked : Qt::Unchecked );
 
  568           mAttributeTable->setItem( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE, item );
 
  572           item = 
new QTableWidgetItem();
 
  573           item->setFlags( Qt::NoItemFlags );
 
  574           mAttributeTable->setItem( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE, item );
 
  579     mAttributeTableItemChangedSlotEnabled = 
true;
 
  581     mReplaceRawFieldValuesStateChangedSlotEnabled = 
false;
 
  582     mReplaceRawFieldValues->setChecked( checkReplaceRawFieldValues );
 
  583     mReplaceRawFieldValuesStateChangedSlotEnabled = 
true;
 
  584     mReplaceRawFieldValues->setEnabled( selectAllFields );
 
  585     mReplaceRawFieldValues->setVisible( foundFieldThatCanBeExportedAsDisplayedValue );
 
  587     mAttributeTable->resizeColumnsToContents();
 
  592   while ( mDatasourceOptionsGroupBox->layout()->count() )
 
  594     QLayoutItem *item = mDatasourceOptionsGroupBox->layout()->takeAt( 0 );
 
  595     delete item->widget();
 
  599   while ( mLayerOptionsGroupBox->layout()->count() )
 
  601     QLayoutItem *item = mLayerOptionsGroupBox->layout()->takeAt( 0 );
 
  602     delete item->widget();
 
  606   typedef QPair<QLabel *, QWidget *> LabelControlPair;
 
  612       mDatasourceOptionsGroupBox->setVisible( 
true );
 
  613       QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.
driverOptions );
 
  615       QFormLayout *datasourceLayout = 
dynamic_cast<QFormLayout *
>( mDatasourceOptionsGroupBox->layout() );
 
  617       const auto constControls = controls;
 
  618       for ( LabelControlPair control : constControls )
 
  620         datasourceLayout->addRow( control.first, control.second );
 
  625       mDatasourceOptionsGroupBox->setVisible( 
false );
 
  630       mLayerOptionsGroupBox->setVisible( 
true );
 
  631       QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.
layerOptions );
 
  633       QFormLayout *layerOptionsLayout = 
dynamic_cast<QFormLayout *
>( mLayerOptionsGroupBox->layout() );
 
  635       const auto constControls = controls;
 
  636       for ( LabelControlPair control : constControls )
 
  638         layerOptionsLayout->addRow( control.first, control.second );
 
  643       mLayerOptionsGroupBox->setVisible( 
false );
 
  648       mEncodingComboBox->setEnabled( 
true );
 
  655         mEncodingComboBox->setCurrentIndex( idx );
 
  656         mEncodingComboBox->setDisabled( 
true );
 
  660         mEncodingComboBox->setEnabled( 
true );
 
  667     mEncodingComboBox->setEnabled( 
true );
 
  670   GDALDriverH hDriver = GDALGetDriverByName( 
format().toUtf8().constData() );
 
  673     mAddToCanvas->setEnabled( GDALGetMetadataItem( hDriver, GDAL_DCAP_OPEN, 
nullptr ) != 
nullptr );
 
  677 void QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged( 
int )
 
  679   if ( !mReplaceRawFieldValuesStateChangedSlotEnabled )
 
  681   if ( mAttributeTable->columnCount() != 3 )
 
  683   mReplaceRawFieldValuesStateChangedSlotEnabled = 
false;
 
  684   mAttributeTableItemChangedSlotEnabled = 
false;
 
  685   if ( mReplaceRawFieldValues->checkState() != Qt::PartiallyChecked )
 
  687     for ( 
int i = 0; i < mAttributeTable->rowCount(); i++ )
 
  689       if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked &&
 
  690            mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
 
  691            mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
 
  693         mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( mReplaceRawFieldValues->checkState() );
 
  697   mReplaceRawFieldValues->setTristate( 
false );
 
  698   mAttributeTableItemChangedSlotEnabled = 
true;
 
  699   mReplaceRawFieldValuesStateChangedSlotEnabled = 
true;
 
  702 void QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged( QTableWidgetItem *item )
 
  704   if ( !mAttributeTableItemChangedSlotEnabled )
 
  706   mReplaceRawFieldValuesStateChangedSlotEnabled = 
false;
 
  707   mAttributeTableItemChangedSlotEnabled = 
false;
 
  708   int row = item->row();
 
  709   int column = item->column();
 
  710   if ( column == COLUMN_IDX_NAME &&
 
  711        mAttributeTable->item( row, column )->checkState() == Qt::Unchecked &&
 
  712        mAttributeTable->columnCount() == 3 &&
 
  713        mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
 
  714        ( mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
 
  716     mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( Qt::Unchecked );
 
  717     mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable );
 
  718     bool checkBoxEnabled = 
false;
 
  719     for ( 
int i = 0; i < mAttributeTable->rowCount(); i++ )
 
  721       if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
 
  722            mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
 
  724         checkBoxEnabled = 
true;
 
  728     mReplaceRawFieldValues->setEnabled( checkBoxEnabled );
 
  729     if ( !checkBoxEnabled )
 
  730       mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
 
  732   else if ( column == COLUMN_IDX_NAME &&
 
  733             mAttributeTable->item( row, column )->checkState() == Qt::Checked &&
 
  734             mAttributeTable->columnCount() == 3 &&
 
  735             mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
 
  736             ( mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
 
  738     mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
 
  739     mReplaceRawFieldValues->setEnabled( 
true );
 
  741   else if ( column == COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE &&
 
  742             ( mAttributeTable->item( row, column )->flags() & Qt::ItemIsUserCheckable ) )
 
  744     bool allChecked = 
true;
 
  745     bool allUnchecked = 
true;
 
  746     for ( 
int i = 0; i < mAttributeTable->rowCount(); i++ )
 
  748       if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
 
  749            mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
 
  751         if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->checkState() == Qt::Unchecked )
 
  754           allUnchecked = 
false;
 
  757     mReplaceRawFieldValues->setCheckState( ( !allChecked && !allUnchecked ) ? Qt::PartiallyChecked : ( allChecked ) ? Qt::Checked : Qt::Unchecked );
 
  759   mAttributeTableItemChangedSlotEnabled = 
true;
 
  760   mReplaceRawFieldValuesStateChangedSlotEnabled = 
true;
 
  766   mExtentGroupBox->setOutputCrs( mSelectedCrs );
 
  771   return mFilename->filePath();
 
  776   return leLayername->text();
 
  781   return mEncodingComboBox->currentText();
 
  786   return mFormatComboBox->currentData().toString();
 
  791   return mSelectedCrs.
srsid();
 
  807     QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
 
  811       switch ( it.value()->type )
 
  816           QSpinBox *sb = mDatasourceOptionsGroupBox->findChild<QSpinBox *>( it.key() );
 
  818             options << QStringLiteral( 
"%1=%2" ).arg( it.key() ).arg( sb->value() );
 
  825           QComboBox *cb = mDatasourceOptionsGroupBox->findChild<QComboBox *>( it.key() );
 
  826           if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->
defaultValue )
 
  827             options << QStringLiteral( 
"%1=%2" ).arg( it.key(), cb->currentText() );
 
  834           QLineEdit *le = mDatasourceOptionsGroupBox->findChild<QLineEdit *>( it.key() );
 
  836             options << QStringLiteral( 
"%1=%2" ).arg( it.key(), le->text() );
 
  844           options << QStringLiteral( 
"%1=%2" ).arg( it.key(), opt->
mValue );
 
  851   QString plainText = mOgrDatasourceOptions->toPlainText().trimmed();
 
  852   if ( !plainText.isEmpty() )
 
  853     options += plainText.split( 
'\n' );
 
  866     QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
 
  870       switch ( it.value()->type )
 
  875           QSpinBox *sb = mLayerOptionsGroupBox->findChild<QSpinBox *>( it.key() );
 
  877             options << QStringLiteral( 
"%1=%2" ).arg( it.key() ).arg( sb->value() );
 
  884           QComboBox *cb = mLayerOptionsGroupBox->findChild<QComboBox *>( it.key() );
 
  885           if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->
defaultValue )
 
  886             options << QStringLiteral( 
"%1=%2" ).arg( it.key(), cb->currentText() );
 
  893           QLineEdit *le = mLayerOptionsGroupBox->findChild<QLineEdit *>( it.key() );
 
  895             options << QStringLiteral( 
"%1=%2" ).arg( it.key(), le->text() );
 
  903           options << QStringLiteral( 
"%1=%2" ).arg( it.key(), opt->
mValue );
 
  910   QString plainText = mOgrLayerOptions->toPlainText().trimmed();
 
  911   if ( !plainText.isEmpty() )
 
  912     options += plainText.split( 
'\n' );
 
  921   for ( 
int i = 0; i < mAttributeTable->rowCount(); i++ )
 
  923     if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked )
 
  925       attributes.append( i );
 
  936   for ( 
int i = 0; i < mAttributeTable->rowCount(); i++ )
 
  938     if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked &&
 
  939          mAttributeTable->columnCount() == 3 &&
 
  940          mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->checkState() == Qt::Checked )
 
  942       attributes.append( i );
 
  951   return mAddToCanvas->isChecked() && mAddToCanvas->isEnabled();
 
  956   mAddToCanvas->setChecked( enabled );
 
  961   return mSymbologyExportComboBox->currentData().toInt();
 
  966   return mScaleWidget->scale();
 
  972   mScaleWidget->setMapCanvas( canvas );
 
  973   mScaleWidget->setShowCurrentScaleButton( 
true );
 
  979   return mExtentGroupBox->isChecked();
 
  984   return mExtentGroupBox->outputExtent();
 
  994   return mSelectedOnly->isChecked();
 
  999   return mCheckPersistMetadata->isChecked();
 
 1004   int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
 
 1005   if ( currentIndexData == -1 )
 
 1016   int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
 
 1017   return currentIndexData == -1;
 
 1022   return mForceMultiCheckBox->isChecked();
 
 1027   mForceMultiCheckBox->setChecked( checked );
 
 1032   return mIncludeZCheckBox->isChecked();
 
 1037   return mActionOnExistingFile;
 
 1042   mIncludeZCheckBox->setChecked( checked );
 
 1045 void QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged( 
const QString &text )
 
 1047   bool scaleEnabled = 
true;
 
 1048   if ( text == tr( 
"No symbology" ) )
 
 1050     scaleEnabled = 
false;
 
 1052   mScaleWidget->setEnabled( scaleEnabled );
 
 1053   mScaleLabel->setEnabled( scaleEnabled );
 
 1056 void QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged( 
int index )
 
 1058   int currentIndexData = mGeometryTypeComboBox->itemData( index ).toInt();
 
 1062     mForceMultiCheckBox->setEnabled( 
true );
 
 1063     mIncludeZCheckBox->setEnabled( 
true );
 
 1067     mForceMultiCheckBox->setEnabled( 
false );
 
 1068     mForceMultiCheckBox->setChecked( 
false );
 
 1069     mIncludeZCheckBox->setEnabled( 
false );
 
 1070     mIncludeZCheckBox->setChecked( 
false );
 
 1074 void QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked()
 
 1076   mAttributeTableItemChangedSlotEnabled = 
false;
 
 1077   mReplaceRawFieldValuesStateChangedSlotEnabled = 
false;
 
 1078   for ( 
int i = 0; i < mAttributeTable->rowCount(); i++ )
 
 1080     if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->flags() & Qt::ItemIsEnabled )
 
 1082       if ( mAttributeTable->columnCount() == 3 &&
 
 1083            ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
 
 1085         mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
 
 1087       mAttributeTable->item( i, COLUMN_IDX_NAME )->setCheckState( Qt::Checked );
 
 1090   if ( mAttributeTable->columnCount() == 3 )
 
 1092     mReplaceRawFieldValues->setEnabled( 
true );
 
 1094   mAttributeTableItemChangedSlotEnabled = 
true;
 
 1095   mReplaceRawFieldValuesStateChangedSlotEnabled = 
true;
 
 1098 void QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked()
 
 1100   mAttributeTableItemChangedSlotEnabled = 
false;
 
 1101   mReplaceRawFieldValuesStateChangedSlotEnabled = 
false;
 
 1102   for ( 
int i = 0; i < mAttributeTable->rowCount(); i++ )
 
 1104     mAttributeTable->item( i, COLUMN_IDX_NAME )->setCheckState( Qt::Unchecked );
 
 1105     if ( mAttributeTable->columnCount() == 3 &&
 
 1106          ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
 
 1108       mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable );
 
 1109       mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( Qt::Unchecked );
 
 1112   if ( mAttributeTable->columnCount() == 3 )
 
 1114     mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
 
 1115     mReplaceRawFieldValues->setEnabled( 
false );
 
 1117   mAttributeTableItemChangedSlotEnabled = 
true;
 
 1118   mReplaceRawFieldValuesStateChangedSlotEnabled = 
true;
 
 1121 void QgsVectorLayerSaveAsDialog::showHelp()
 
 1123   QgsHelp::openHelp( QStringLiteral( 
"managing_data_source/create_layers.html#creating-new-layers-from-an-existing-layer" ) );
 
This class represents a coordinate reference system (CRS).
QgsDatumEnsemble datumEnsemble() const SIP_THROW(QgsNotSupportedException)
Attempts to retrieve datum ensemble details from the CRS.
long srsid() const
Returns the internal CRS ID, if available.
Contains information about a datum ensemble.
bool isValid() const
Returns true if the datum ensemble is a valid object, or false if it is a null/invalid object.
QString name() const
Display name of datum ensemble.
Encapsulate a field in an attribute table or data source.
QString typeName() const
Gets the field type.
int count() const
Returns number of items.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
static QgsEditorWidgetRegistry * editorWidgetRegistry()
Returns the global editor widget registry, used for managing all known edit widget factories.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
static QIcon iconForWkbType(QgsWkbTypes::Type type)
Returns the icon for a vector layer whose geometry type is provided.
Map canvas is a class for displaying all GIS data types on a canvas.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
QString providerType() const
Returns the provider type (provider key) for this layer.
QgsCoordinateReferenceSystem crs
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
Custom exception class which is raised when an operation is not supported.
A rectangle specified with double values.
static QStringList availableEncodings()
Returns a list of available encodings.
QgsVectorFileWriter::OptionType type
A convenience class for writing vector layers to disk based formats (e.g.
@ CanAppendToExistingLayer
Flag to indicate that new features can be added to an existing layer.
@ CanAddNewLayer
Flag to indicate that a new layer can be added to the dataset.
@ CanDeleteLayer
Flag to indicate that an existing layer can be deleted.
static QgsVectorFileWriter::EditionCapabilities editionCapabilities(const QString &datasetName)
Returns edition capabilities for an existing dataset name.
static bool supportsFeatureStyles(const QString &driverName)
Returns true if the specified driverName supports feature styles.
static bool targetLayerExists(const QString &datasetName, const QString &layerName)
Returns whether the target layer already exists.
static bool driverMetadata(const QString &driverName, MetaData &driverMetadata)
static QString filterForDriver(const QString &driverName)
Creates a filter for an OGR driver key.
static bool areThereNewFieldsToCreate(const QString &datasetName, const QString &layerName, QgsVectorLayer *layer, const QgsAttributeList &attributes)
Returns whether there are among the attributes specified some that do not exist yet in the layer.
static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList(VectorFormatOptions options=SortRecommended)
Returns the driver list that can be used for dialogs.
ActionOnExistingFile
Combination of CanAddNewLayer, CanAppendToExistingLayer, CanAddNewFieldsToExistingLayer or CanDeleteL...
@ CreateOrOverwriteLayer
Create or overwrite layer.
@ CreateOrOverwriteFile
Create or overwrite file.
@ AppendToLayerNoNewFields
Append features to existing layer, but do not create new fields.
@ AppendToLayerAddFields
Append features to existing layer, and create new fields if needed.
bool onlySelected() const
Returns whether only selected features will be saved.
bool forceMulti() const
Returns true if force multi geometry type is checked.
QString filename() const
Returns the target filename.
QgsAttributeList selectedAttributes() const
Returns a list of attributes which are selected for saving.
QgsRectangle filterExtent() const
Determines the extent to be exported.
Q_DECL_DEPRECATED long crs() const
Returns the internal CRS ID.
QString format() const
The format in which the export should be written.
QStringList datasourceOptions() const
Returns a list of additional data source options which are passed to OGR.
bool persistMetadata() const
Returns true if the persist metadata (copy source metadata to destination layer) option is checked.
QString encoding() const
The encoding of the target file.
void setIncludeZ(bool checked)
Sets whether the include z dimension checkbox should be checked.
void setOnlySelected(bool onlySelected)
Sets whether only selected features will be saved.
@ DestinationCrs
Show destination CRS (reprojection) option.
@ AddToCanvas
Show add to map option.
@ Extent
Show extent group.
@ Symbology
Show symbology options.
@ SelectedOnly
Show selected features only option.
@ Fields
Show field customization group.
@ Metadata
Show metadata options.
@ GeometryType
Show geometry group.
bool automaticGeometryType() const
Returns true if geometry type is set to automatic.
QString layername() const
Returns the target layer name.
QgsWkbTypes::Type geometryType() const
Returns the selected flat geometry type for the export.
Q_DECL_DEPRECATED QgsVectorLayerSaveAsDialog(long srsid, QWidget *parent=nullptr, Qt::WindowFlags fl=Qt::WindowFlags())
Construct a new QgsVectorLayerSaveAsDialog.
bool includeZ() const
Returns true if include z dimension is checked.
QgsCoordinateReferenceSystem crsObject() const
Returns the CRS chosen for export.
QStringList layerOptions() const
Returns a list of additional layer options which are passed to OGR.
void setForceMulti(bool checked)
Sets whether the force multi geometry checkbox should be checked.
bool addToCanvas() const
Returns true if the "add to canvas" checkbox is checked.
void setMapCanvas(QgsMapCanvas *canvas)
Sets a map canvas to associate with the dialog.
QgsVectorFileWriter::ActionOnExistingFile creationActionOnExistingFile() const
Returns creation action.
int symbologyExport() const
Returns type of symbology export.
QgsAttributeList attributesAsDisplayedValues() const
Returns selected attributes that must be exported with their displayed values instead of their raw va...
double scale() const
Returns the specified map scale.
bool hasFilterExtent() const
Determines if filtering the export by an extent is activated.
void setAddToCanvas(bool checked)
Sets whether the "add to canvas" checkbox should be checked.
Represents a vector layer which manages a vector based data sets.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
int selectedFeatureCount() const
Returns the number of features that are selected in this layer.
QgsRectangle extent() const FINAL
Returns the extent of the layer.
static QString translatedDisplayString(Type type) SIP_HOLDGIL
Returns a translated display string type for a WKB type, e.g., the geometry name used in WKT geometry...
Type
The WKB type describes the number of dimensions a geometry has.
QList< int > QgsAttributeList
const QgsCoordinateReferenceSystem & crs
Details of available driver formats.