29 #include <QMessageBox> 
   30 #include <QFileDialog> 
   33 #include <QRegularExpression> 
   40 static const int COLUMN_IDX_NAME = 0;
 
   41 static const int COLUMN_IDX_TYPE = 1;
 
   42 static const int COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE = 2;
 
   45   : QDialog( parent, fl )
 
   47   , mAttributeTableItemChangedSlotEnabled( true )
 
   48   , mReplaceRawFieldValuesStateChangedSlotEnabled( true )
 
   55   : QDialog( parent, fl )
 
   57   , mAttributeTableItemChangedSlotEnabled( true )
 
   58   , mReplaceRawFieldValuesStateChangedSlotEnabled( true )
 
   64     mSelectedCrs = layer->
crs();
 
   65     mLayerExtent = layer->
extent();
 
   71     mSymbologyExportLabel->hide();
 
   72     mSymbologyExportComboBox->hide();
 
   82   if ( !( mOptions & 
Fields ) )
 
   83     mAttributesSelection->hide();
 
   86     mSelectedOnly->hide();
 
   92     mGeometryGroupBox->hide();
 
   94   if ( !( mOptions & 
Extent ) )
 
   95     mExtentGroupBox->hide();
 
   99     mCheckPersistMetadata->setChecked( 
false );
 
  100     mCheckPersistMetadata->hide();
 
  104   mButtonBox->button( QDialogButtonBox::Ok )->setDisabled( 
true );
 
  107 void QgsVectorLayerSaveAsDialog::setup()
 
  112   connect( mFormatComboBox, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged );
 
  114   connect( mSymbologyExportComboBox, &QComboBox::currentTextChanged, 
this, &QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged );
 
  115   connect( mGeometryTypeComboBox, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged );
 
  116   connect( mSelectAllAttributes, &QPushButton::clicked, 
this, &QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked );
 
  117   connect( mDeselectAllAttributes, &QPushButton::clicked, 
this, &QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked );
 
  118   connect( mReplaceRawFieldValues, &QCheckBox::stateChanged, 
this, &QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged );
 
  119   connect( mAttributeTable, &QTableWidget::itemChanged, 
this, &QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged );
 
  122   mHelpButtonBox->setVisible( 
false );
 
  123   mButtonBox->addButton( QDialogButtonBox::Help );
 
  124   connect( mButtonBox, &QDialogButtonBox::helpRequested, 
this, &QgsVectorLayerSaveAsDialog::showHelp );
 
  126   connect( mHelpButtonBox, &QDialogButtonBox::helpRequested, 
this, &QgsVectorLayerSaveAsDialog::showHelp );
 
  128   connect( mButtonBox, &QDialogButtonBox::accepted, 
this, &QgsVectorLayerSaveAsDialog::accept );
 
  129   connect( mButtonBox, &QDialogButtonBox::rejected, 
this, &QgsVectorLayerSaveAsDialog::reject );
 
  132   mFormatComboBox->blockSignals( 
true );
 
  135     mFormatComboBox->addItem( driver.longName, driver.driverName );
 
  139   QString 
format = settings.
value( QStringLiteral( 
"UI/lastVectorFormat" ), 
"GPKG" ).toString();
 
  140   mFormatComboBox->setCurrentIndex( mFormatComboBox->findData( 
format ) );
 
  141   mFormatComboBox->blockSignals( 
false );
 
  149   mGeometryTypeComboBox->addItem( tr( 
"Automatic" ), -1 );
 
  155   mGeometryTypeComboBox->setCurrentIndex( mGeometryTypeComboBox->findData( -1 ) );
 
  159   QString enc = settings.
value( QStringLiteral( 
"UI/encoding" ), 
"System" ).toString();
 
  160   int idx = mEncodingComboBox->findText( enc );
 
  163     mEncodingComboBox->insertItem( 0, enc );
 
  167   mCrsSelector->setCrs( mSelectedCrs );
 
  168   mCrsSelector->setLayerCrs( mSelectedCrs );
 
  169   mCrsSelector->setMessage( tr( 
"Select the coordinate reference system for the vector file. " 
  170                                 "The data points will be transformed from the layer coordinate reference system." ) );
 
  172   mEncodingComboBox->setCurrentIndex( idx );
 
  173   mFormatComboBox_currentIndexChanged( mFormatComboBox->currentIndex() );
 
  179   mSymbologyExportComboBox_currentIndexChanged( mSymbologyExportComboBox->currentText() );
 
  182   mExtentGroupBox->setOutputCrs( mSelectedCrs );
 
  183   mExtentGroupBox->setOriginalExtent( mLayerExtent, mSelectedCrs );
 
  184   mExtentGroupBox->setOutputExtentFromOriginal();
 
  185   mExtentGroupBox->setCheckable( 
true );
 
  186   mExtentGroupBox->setChecked( 
false );
 
  187   mExtentGroupBox->setCollapsed( 
true );
 
  190   mFilename->setDialogTitle( tr( 
"Save Layer As" ) );
 
  191   mFilename->setDefaultRoot( settings.
value( QStringLiteral( 
"UI/lastVectorFileFilterDir" ), QDir::homePath() ).toString() );
 
  192   mFilename->setConfirmOverwrite( 
false );
 
  196     QFileInfo tmplFileInfo( filePath );
 
  197     settings.
setValue( QStringLiteral( 
"UI/lastVectorFileFilterDir" ), tmplFileInfo.absolutePath() );
 
  198     if ( !filePath.isEmpty() && leLayername->isEnabled() )
 
  200       QFileInfo fileInfo( filePath );
 
  201       leLayername->setText( fileInfo.completeBaseName() );
 
  203     mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( !filePath.isEmpty() );
 
  211       mCrsSelector->setSourceEnsemble( ensemble.
name() );
 
  218   mCrsSelector->setShowAccuracyWarnings( 
true );
 
  221 QList<QPair<QLabel *, QWidget *> > QgsVectorLayerSaveAsDialog::createControls( 
const QMap<QString, QgsVectorFileWriter::Option *> &options )
 
  223   QList<QPair<QLabel *, QWidget *> > controls;
 
  224   QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
 
  226   for ( it = options.constBegin(); it != options.constEnd(); ++it )
 
  229     QLabel *label = 
new QLabel( it.key() );
 
  230     QWidget *control = 
nullptr;
 
  231     switch ( option->
type )
 
  238           QSpinBox *sb = 
new QSpinBox();
 
  239           sb->setObjectName( it.key() );
 
  251           QComboBox *cb = 
new QComboBox();
 
  252           cb->setObjectName( it.key() );
 
  253           for ( 
const QString &val : std::as_const( opt->
values ) )
 
  255             cb->addItem( val, val );
 
  258             cb->addItem( tr( 
"<Default>" ), QVariant( QVariant::String ) );
 
  261             idx = cb->findData( QVariant( QVariant::String ) );
 
  262           cb->setCurrentIndex( idx );
 
  274           le->setObjectName( it.key() );
 
  288       label->setToolTip( QStringLiteral( 
"<p>%1</p>" ).arg( option->
docString.toHtmlEscaped() ) );
 
  289       control->setToolTip( QStringLiteral( 
"<p>%1</p>" ).arg( option->
docString.toHtmlEscaped() ) );
 
  291       controls << QPair<QLabel *, QWidget *>( label, control );
 
  298 void QgsVectorLayerSaveAsDialog::accept()
 
  302     QgsVectorFileWriter::EditionCapabilities caps =
 
  307     msgBox.setIcon( QMessageBox::Question );
 
  308     msgBox.setWindowTitle( tr( 
"Save Vector Layer As" ) );
 
  309     QPushButton *overwriteFileButton = msgBox.addButton( tr( 
"Overwrite File" ), QMessageBox::ActionRole );
 
  310     QPushButton *overwriteLayerButton = msgBox.addButton( tr( 
"Overwrite Layer" ), QMessageBox::ActionRole );
 
  311     QPushButton *appendToLayerButton = msgBox.addButton( tr( 
"Append to Layer" ), QMessageBox::ActionRole );
 
  312     msgBox.setStandardButtons( QMessageBox::Cancel );
 
  313     msgBox.setDefaultButton( QMessageBox::Cancel );
 
  314     overwriteFileButton->hide();
 
  315     overwriteLayerButton->hide();
 
  316     appendToLayerButton->hide();
 
  323         msgBox.setText( tr( 
"The layer already exists. Do you want to overwrite the whole file or overwrite the layer?" ) );
 
  324         overwriteFileButton->setVisible( 
true );
 
  325         overwriteLayerButton->setVisible( 
true );
 
  329         msgBox.setText( tr( 
"The file already exists. Do you want to overwrite it?" ) );
 
  330         overwriteFileButton->setVisible( 
true );
 
  335         msgBox.setText( tr( 
"The layer already exists. Do you want to overwrite the whole file, overwrite the layer or append features to the layer?" ) );
 
  336         appendToLayerButton->setVisible( 
true );
 
  337         overwriteFileButton->setVisible( 
true );
 
  338         overwriteLayerButton->setVisible( 
true );
 
  342         msgBox.setText( tr( 
"The layer already exists. Do you want to overwrite the whole file or append features to the layer?" ) );
 
  343         appendToLayerButton->setVisible( 
true );
 
  344         overwriteFileButton->setVisible( 
true );
 
  347       int ret = msgBox.exec();
 
  348       if ( ret == QMessageBox::Cancel )
 
  350       if ( msgBox.clickedButton() == overwriteFileButton )
 
  352       else if ( msgBox.clickedButton() == overwriteLayerButton )
 
  354       else if ( msgBox.clickedButton() == appendToLayerButton )
 
  366         if ( QMessageBox::question( 
this,
 
  367                                     tr( 
"Save Vector Layer As" ),
 
  368                                     tr( 
"The file already exists. Do you want to overwrite it?" ) ) == QMessageBox::NoButton )
 
  381       if ( QMessageBox::question( 
this,
 
  382                                   tr( 
"Save Vector Layer As" ),
 
  383                                   tr( 
"The existing layer has additional fields. Do you want to add the missing fields to the layer?" ) ) == QMessageBox::Yes )
 
  392     QStringList layerList;
 
  393     layerList.reserve( sublayers.size() );
 
  396       layerList.append( sublayer.name() );
 
  398     if ( layerList.length() > 1 )
 
  400       layerList.sort( Qt::CaseInsensitive );
 
  402       msgBox.setIcon( QMessageBox::Warning );
 
  403       msgBox.setWindowTitle( tr( 
"Overwrite File" ) );
 
  404       msgBox.setText( tr( 
"This file contains %1 layers that will be lost!\n" ).arg( QLocale().toString( layerList.length() ) ) );
 
  405       msgBox.setDetailedText( tr( 
"The following layers will be permanently lost:\n\n%1" ).arg( layerList.join( 
"\n" ) ) );
 
  406       msgBox.setStandardButtons( QMessageBox::Ok | QMessageBox::Cancel );
 
  407       if ( msgBox.exec() == QMessageBox::Cancel )
 
  413   settings.
setValue( QStringLiteral( 
"UI/lastVectorFileFilterDir" ), QFileInfo( 
filename() ).absolutePath() );
 
  414   settings.
setValue( QStringLiteral( 
"UI/lastVectorFormat" ), 
format() );
 
  419 void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( 
int idx )
 
  423   mFilename->setEnabled( 
true );
 
  428   if ( !mFilename->filePath().isEmpty() )
 
  430     QRegularExpression rx( 
"\\.(.*?)[\\s]" );
 
  433     if ( !ext.isEmpty() )
 
  435       QFileInfo fi( mFilename->filePath() );
 
  436       mFilename->setFilePath( QStringLiteral( 
"%1/%2.%3" ).arg( fi.path() ).arg( fi.baseName() ).arg( ext ) );
 
  440   bool selectAllFields = 
true;
 
  445   bool isFormatForFieldsAsDisplayedValues = 
false;
 
  447   const QString sFormat( 
format() );
 
  448   if ( sFormat == QLatin1String( 
"DXF" ) || sFormat == QLatin1String( 
"DGN" ) )
 
  450     mAttributesSelection->setVisible( 
false );
 
  451     selectAllFields = 
false;
 
  457       mAttributesSelection->setVisible( 
true );
 
  458       isFormatForFieldsAsDisplayedValues = ( sFormat == QLatin1String( 
"CSV" ) ||
 
  459                                              sFormat == QLatin1String( 
"XLS" ) ||
 
  460                                              sFormat == QLatin1String( 
"XLSX" ) ||
 
  461                                              sFormat == QLatin1String( 
"ODS" ) );
 
  468     mSymbologyExportLabel->setVisible( 
true );
 
  469     mSymbologyExportComboBox->setVisible( 
true );
 
  470     mScaleLabel->setVisible( 
true );
 
  471     mScaleWidget->setVisible( 
true );
 
  475     mSymbologyExportLabel->hide();
 
  476     mSymbologyExportComboBox->hide();
 
  478     mScaleWidget->hide();
 
  481   leLayername->setEnabled( sFormat == QLatin1String( 
"KML" ) ||
 
  482                            sFormat == QLatin1String( 
"GPKG" ) ||
 
  483                            sFormat == QLatin1String( 
"XLSX" ) ||
 
  484                            sFormat == QLatin1String( 
"ODS" ) ||
 
  485                            sFormat == QLatin1String( 
"FileGDB" ) ||
 
  486                            sFormat == QLatin1String( 
"SQLite" ) ||
 
  487                            sFormat == QLatin1String( 
"SpatiaLite" ) );
 
  489   if ( sFormat == QLatin1String( 
"XLSX" ) )
 
  490     leLayername->setMaxLength( 31 );
 
  491   else if ( leLayername->isEnabled() )
 
  492     leLayername->setMaxLength( 32767 ); 
 
  494   if ( !leLayername->isEnabled() )
 
  495     leLayername->setText( QString() );
 
  496   else if ( leLayername->text().isEmpty() &&
 
  497             !mFilename->filePath().isEmpty() )
 
  499     QString layerName = QFileInfo( mFilename->filePath() ).baseName();
 
  500     leLayername->setText( layerName );
 
  505     mAttributeTable->setRowCount( mLayer->
fields().
count() );
 
  507     bool foundFieldThatCanBeExportedAsDisplayedValue = 
false;
 
  508     for ( 
int i = 0; i < mLayer->
fields().size(); ++i )
 
  511       if ( setup.
type() != QLatin1String( 
"TextEdit" ) &&
 
  514         foundFieldThatCanBeExportedAsDisplayedValue = 
true;
 
  518     if ( foundFieldThatCanBeExportedAsDisplayedValue )
 
  520       mAttributeTable->setColumnCount( 3 );
 
  521       mAttributeTable->setHorizontalHeaderLabels( QStringList() << tr( 
"Name" ) << tr( 
"Type" ) << tr( 
"Replace with displayed values" ) );
 
  525       mAttributeTable->setColumnCount( 2 );
 
  526       mAttributeTable->setHorizontalHeaderLabels( QStringList() << tr( 
"Name" ) << tr( 
"Type" ) );
 
  529     mAttributeTableItemChangedSlotEnabled = 
false;
 
  531     bool checkReplaceRawFieldValues = selectAllFields && isFormatForFieldsAsDisplayedValues;
 
  532     for ( 
int i = 0; i < mLayer->
fields().size(); ++i )
 
  535       Qt::ItemFlags flags = mLayer->
providerType() != QLatin1String( 
"oracle" ) || !fld.
typeName().contains( QLatin1String( 
"SDO_GEOMETRY" ) ) ? Qt::ItemIsEnabled : Qt::NoItemFlags;
 
  536       QTableWidgetItem *item = 
nullptr;
 
  537       item = 
new QTableWidgetItem( fld.
name() );
 
  538       item->setFlags( flags | Qt::ItemIsUserCheckable );
 
  539       item->setCheckState( ( selectAllFields ) ? Qt::Checked : Qt::Unchecked );
 
  540       mAttributeTable->setItem( i, COLUMN_IDX_NAME, item );
 
  542       item = 
new QTableWidgetItem( fld.
typeName() );
 
  543       item->setFlags( flags );
 
  544       mAttributeTable->setItem( i, COLUMN_IDX_TYPE, item );
 
  546       if ( foundFieldThatCanBeExportedAsDisplayedValue )
 
  550         const QString widgetId( setup.
type() );
 
  551         if ( flags == Qt::ItemIsEnabled &&
 
  552              widgetId != QLatin1String( 
"TextEdit" ) &&
 
  555           item = 
new QTableWidgetItem( tr( 
"Use %1" ).arg( factory->
name() ) );
 
  556           item->setFlags( ( selectAllFields ) ? ( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable ) : Qt::ItemIsUserCheckable );
 
  557           const bool checkItem = ( selectAllFields && isFormatForFieldsAsDisplayedValues &&
 
  558                                    ( widgetId == QLatin1String( 
"ValueMap" ) ||
 
  559                                      widgetId == QLatin1String( 
"ValueRelation" ) ||
 
  560                                      widgetId == QLatin1String( 
"CheckBox" ) ||
 
  561                                      widgetId == QLatin1String( 
"RelationReference" ) ) );
 
  562           checkReplaceRawFieldValues &= checkItem;
 
  563           item->setCheckState( checkItem ?
 
  564                                Qt::Checked : Qt::Unchecked );
 
  565           mAttributeTable->setItem( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE, item );
 
  569           item = 
new QTableWidgetItem();
 
  570           item->setFlags( Qt::NoItemFlags );
 
  571           mAttributeTable->setItem( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE, item );
 
  576     mAttributeTableItemChangedSlotEnabled = 
true;
 
  578     mReplaceRawFieldValuesStateChangedSlotEnabled = 
false;
 
  579     mReplaceRawFieldValues->setChecked( checkReplaceRawFieldValues );
 
  580     mReplaceRawFieldValuesStateChangedSlotEnabled = 
true;
 
  581     mReplaceRawFieldValues->setEnabled( selectAllFields );
 
  582     mReplaceRawFieldValues->setVisible( foundFieldThatCanBeExportedAsDisplayedValue );
 
  584     mAttributeTable->resizeColumnsToContents();
 
  589   while ( mDatasourceOptionsGroupBox->layout()->count() )
 
  591     QLayoutItem *item = mDatasourceOptionsGroupBox->layout()->takeAt( 0 );
 
  592     delete item->widget();
 
  596   while ( mLayerOptionsGroupBox->layout()->count() )
 
  598     QLayoutItem *item = mLayerOptionsGroupBox->layout()->takeAt( 0 );
 
  599     delete item->widget();
 
  603   typedef QPair<QLabel *, QWidget *> LabelControlPair;
 
  609       mDatasourceOptionsGroupBox->setVisible( 
true );
 
  610       QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.
driverOptions );
 
  612       QFormLayout *datasourceLayout = 
dynamic_cast<QFormLayout *
>( mDatasourceOptionsGroupBox->layout() );
 
  614       const auto constControls = controls;
 
  615       for ( LabelControlPair control : constControls )
 
  617         datasourceLayout->addRow( control.first, control.second );
 
  622       mDatasourceOptionsGroupBox->setVisible( 
false );
 
  627       mLayerOptionsGroupBox->setVisible( 
true );
 
  628       QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.
layerOptions );
 
  630       QFormLayout *layerOptionsLayout = 
dynamic_cast<QFormLayout *
>( mLayerOptionsGroupBox->layout() );
 
  632       const auto constControls = controls;
 
  633       for ( LabelControlPair control : constControls )
 
  635         layerOptionsLayout->addRow( control.first, control.second );
 
  640       mLayerOptionsGroupBox->setVisible( 
false );
 
  645       mEncodingComboBox->setEnabled( 
true );
 
  652         mEncodingComboBox->setCurrentIndex( idx );
 
  653         mEncodingComboBox->setDisabled( 
true );
 
  657         mEncodingComboBox->setEnabled( 
true );
 
  664     mEncodingComboBox->setEnabled( 
true );
 
  667   GDALDriverH hDriver = GDALGetDriverByName( 
format().toUtf8().constData() );
 
  670     mAddToCanvas->setEnabled( GDALGetMetadataItem( hDriver, GDAL_DCAP_OPEN, 
nullptr ) != 
nullptr );
 
  674 void QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged( 
int )
 
  676   if ( !mReplaceRawFieldValuesStateChangedSlotEnabled )
 
  678   if ( mAttributeTable->columnCount() != 3 )
 
  680   mReplaceRawFieldValuesStateChangedSlotEnabled = 
false;
 
  681   mAttributeTableItemChangedSlotEnabled = 
false;
 
  682   if ( mReplaceRawFieldValues->checkState() != Qt::PartiallyChecked )
 
  684     for ( 
int i = 0; i < mAttributeTable->rowCount(); i++ )
 
  686       if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked &&
 
  687            mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
 
  688            mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
 
  690         mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( mReplaceRawFieldValues->checkState() );
 
  694   mReplaceRawFieldValues->setTristate( 
false );
 
  695   mAttributeTableItemChangedSlotEnabled = 
true;
 
  696   mReplaceRawFieldValuesStateChangedSlotEnabled = 
true;
 
  699 void QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged( QTableWidgetItem *item )
 
  701   if ( !mAttributeTableItemChangedSlotEnabled )
 
  703   mReplaceRawFieldValuesStateChangedSlotEnabled = 
false;
 
  704   mAttributeTableItemChangedSlotEnabled = 
false;
 
  705   int row = item->row();
 
  706   int column = item->column();
 
  707   if ( column == COLUMN_IDX_NAME &&
 
  708        mAttributeTable->item( row, column )->checkState() == Qt::Unchecked &&
 
  709        mAttributeTable->columnCount() == 3 &&
 
  710        mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
 
  711        ( mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
 
  713     mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( Qt::Unchecked );
 
  714     mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable );
 
  715     bool checkBoxEnabled = 
false;
 
  716     for ( 
int i = 0; i < mAttributeTable->rowCount(); i++ )
 
  718       if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
 
  719            mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
 
  721         checkBoxEnabled = 
true;
 
  725     mReplaceRawFieldValues->setEnabled( checkBoxEnabled );
 
  726     if ( !checkBoxEnabled )
 
  727       mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
 
  729   else if ( column == COLUMN_IDX_NAME &&
 
  730             mAttributeTable->item( row, column )->checkState() == Qt::Checked &&
 
  731             mAttributeTable->columnCount() == 3 &&
 
  732             mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
 
  733             ( mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
 
  735     mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
 
  736     mReplaceRawFieldValues->setEnabled( 
true );
 
  738   else if ( column == COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE &&
 
  739             ( mAttributeTable->item( row, column )->flags() & Qt::ItemIsUserCheckable ) )
 
  741     bool allChecked = 
true;
 
  742     bool allUnchecked = 
true;
 
  743     for ( 
int i = 0; i < mAttributeTable->rowCount(); i++ )
 
  745       if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
 
  746            mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
 
  748         if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->checkState() == Qt::Unchecked )
 
  751           allUnchecked = 
false;
 
  754     mReplaceRawFieldValues->setCheckState( ( !allChecked && !allUnchecked ) ? Qt::PartiallyChecked : ( allChecked ) ? Qt::Checked : Qt::Unchecked );
 
  756   mAttributeTableItemChangedSlotEnabled = 
true;
 
  757   mReplaceRawFieldValuesStateChangedSlotEnabled = 
true;
 
  763   mExtentGroupBox->setOutputCrs( mSelectedCrs );
 
  768   return mFilename->filePath();
 
  773   return leLayername->text();
 
  778   return mEncodingComboBox->currentText();
 
  783   return mFormatComboBox->currentData().toString();
 
  788   return mSelectedCrs.
srsid();
 
  804     QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
 
  808       switch ( it.value()->type )
 
  813           QSpinBox *sb = mDatasourceOptionsGroupBox->findChild<QSpinBox *>( it.key() );
 
  815             options << QStringLiteral( 
"%1=%2" ).arg( it.key() ).arg( sb->value() );
 
  822           QComboBox *cb = mDatasourceOptionsGroupBox->findChild<QComboBox *>( it.key() );
 
  823           if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->
defaultValue )
 
  824             options << QStringLiteral( 
"%1=%2" ).arg( it.key(), cb->currentText() );
 
  831           QLineEdit *le = mDatasourceOptionsGroupBox->findChild<QLineEdit *>( it.key() );
 
  833             options << QStringLiteral( 
"%1=%2" ).arg( it.key(), le->text() );
 
  841           options << QStringLiteral( 
"%1=%2" ).arg( it.key(), opt->
mValue );
 
  848   QString plainText = mOgrDatasourceOptions->toPlainText().trimmed();
 
  849   if ( !plainText.isEmpty() )
 
  850     options += plainText.split( 
'\n' );
 
  863     QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
 
  867       switch ( it.value()->type )
 
  872           QSpinBox *sb = mLayerOptionsGroupBox->findChild<QSpinBox *>( it.key() );
 
  874             options << QStringLiteral( 
"%1=%2" ).arg( it.key() ).arg( sb->value() );
 
  881           QComboBox *cb = mLayerOptionsGroupBox->findChild<QComboBox *>( it.key() );
 
  882           if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->
defaultValue )
 
  883             options << QStringLiteral( 
"%1=%2" ).arg( it.key(), cb->currentText() );
 
  890           QLineEdit *le = mLayerOptionsGroupBox->findChild<QLineEdit *>( it.key() );
 
  892             options << QStringLiteral( 
"%1=%2" ).arg( it.key(), le->text() );
 
  900           options << QStringLiteral( 
"%1=%2" ).arg( it.key(), opt->
mValue );
 
  907   QString plainText = mOgrLayerOptions->toPlainText().trimmed();
 
  908   if ( !plainText.isEmpty() )
 
  909     options += plainText.split( 
'\n' );
 
  918   for ( 
int i = 0; i < mAttributeTable->rowCount(); i++ )
 
  920     if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked )
 
  922       attributes.append( i );
 
  933   for ( 
int i = 0; i < mAttributeTable->rowCount(); i++ )
 
  935     if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked &&
 
  936          mAttributeTable->columnCount() == 3 &&
 
  937          mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->checkState() == Qt::Checked )
 
  939       attributes.append( i );
 
  948   return mAddToCanvas->isChecked() && mAddToCanvas->isEnabled();
 
  953   mAddToCanvas->setChecked( enabled );
 
  958   return mSymbologyExportComboBox->currentData().toInt();
 
  963   return mScaleWidget->scale();
 
  969   mScaleWidget->setMapCanvas( canvas );
 
  970   mScaleWidget->setShowCurrentScaleButton( 
true );
 
  976   return mExtentGroupBox->isChecked();
 
  981   return mExtentGroupBox->outputExtent();
 
  991   return mSelectedOnly->isChecked();
 
  996   return mCheckPersistMetadata->isChecked();
 
 1001   int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
 
 1002   if ( currentIndexData == -1 )
 
 1013   int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
 
 1014   return currentIndexData == -1;
 
 1019   return mForceMultiCheckBox->isChecked();
 
 1024   mForceMultiCheckBox->setChecked( checked );
 
 1029   return mIncludeZCheckBox->isChecked();
 
 1034   return mActionOnExistingFile;
 
 1039   mIncludeZCheckBox->setChecked( checked );
 
 1042 void QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged( 
const QString &text )
 
 1044   bool scaleEnabled = 
true;
 
 1045   if ( text == tr( 
"No symbology" ) )
 
 1047     scaleEnabled = 
false;
 
 1049   mScaleWidget->setEnabled( scaleEnabled );
 
 1050   mScaleLabel->setEnabled( scaleEnabled );
 
 1053 void QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged( 
int index )
 
 1055   int currentIndexData = mGeometryTypeComboBox->itemData( index ).toInt();
 
 1059     mForceMultiCheckBox->setEnabled( 
true );
 
 1060     mIncludeZCheckBox->setEnabled( 
true );
 
 1064     mForceMultiCheckBox->setEnabled( 
false );
 
 1065     mForceMultiCheckBox->setChecked( 
false );
 
 1066     mIncludeZCheckBox->setEnabled( 
false );
 
 1067     mIncludeZCheckBox->setChecked( 
false );
 
 1071 void QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked()
 
 1073   mAttributeTableItemChangedSlotEnabled = 
false;
 
 1074   mReplaceRawFieldValuesStateChangedSlotEnabled = 
false;
 
 1075   for ( 
int i = 0; i < mAttributeTable->rowCount(); i++ )
 
 1077     if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->flags() & Qt::ItemIsEnabled )
 
 1079       if ( mAttributeTable->columnCount() == 3 &&
 
 1080            ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
 
 1082         mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
 
 1084       mAttributeTable->item( i, COLUMN_IDX_NAME )->setCheckState( Qt::Checked );
 
 1087   if ( mAttributeTable->columnCount() == 3 )
 
 1089     mReplaceRawFieldValues->setEnabled( 
true );
 
 1091   mAttributeTableItemChangedSlotEnabled = 
true;
 
 1092   mReplaceRawFieldValuesStateChangedSlotEnabled = 
true;
 
 1095 void QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked()
 
 1097   mAttributeTableItemChangedSlotEnabled = 
false;
 
 1098   mReplaceRawFieldValuesStateChangedSlotEnabled = 
false;
 
 1099   for ( 
int i = 0; i < mAttributeTable->rowCount(); i++ )
 
 1101     mAttributeTable->item( i, COLUMN_IDX_NAME )->setCheckState( Qt::Unchecked );
 
 1102     if ( mAttributeTable->columnCount() == 3 &&
 
 1103          ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
 
 1105       mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable );
 
 1106       mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( Qt::Unchecked );
 
 1109   if ( mAttributeTable->columnCount() == 3 )
 
 1111     mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
 
 1112     mReplaceRawFieldValues->setEnabled( 
false );
 
 1114   mAttributeTableItemChangedSlotEnabled = 
true;
 
 1115   mReplaceRawFieldValuesStateChangedSlotEnabled = 
true;
 
 1118 void QgsVectorLayerSaveAsDialog::showHelp()
 
 1120   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 output image size into account.
 
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.
 
QList< QgsProviderSublayerDetails > querySublayers(const QString &uri, Qgis::SublayerQueryFlags flags=Qgis::SublayerQueryFlags(), QgsFeedback *feedback=nullptr) const
Queries the specified uri and returns a list of any valid sublayers found in the dataset which can be...
 
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
 
Contains details about a sub layer available from a dataset.
 
A rectangle specified with double values.
 
This class is a composition of two QSettings instances:
 
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
 
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
 
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.