34#include <QRegularExpression>
43 : QDialog( parent, fl )
51 : QDialog( parent, fl )
58 mSelectedCrs = layer->
crs();
59 mLayerExtent = layer->
extent();
66 leLayername->setDefaultValue( mDefaultOutputLayerNameFromInputLayerName );
68 if ( leLayername->isEnabled() )
69 leLayername->setText( mDefaultOutputLayerNameFromInputLayerName );
74 mSymbologyExportLabel->hide();
75 mSymbologyExportComboBox->hide();
85 if ( !( mOptions &
Fields ) )
86 mAttributesSelection->hide();
89 mSelectedOnly->hide();
95 mGeometryGroupBox->hide();
97 if ( !( mOptions &
Extent ) )
98 mExtentGroupBox->hide();
102 mCheckPersistMetadata->setChecked(
false );
103 mCheckPersistMetadata->hide();
107 mButtonBox->button( QDialogButtonBox::Ok )->setDisabled(
true );
110void QgsVectorLayerSaveAsDialog::setup()
115 connect( mFormatComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged );
117 connect( mSymbologyExportComboBox, &QComboBox::currentTextChanged,
this, &QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged );
118 connect( mGeometryTypeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged );
119 connect( mSelectAllAttributes, &QPushButton::clicked,
this, &QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked );
120 connect( mDeselectAllAttributes, &QPushButton::clicked,
this, &QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked );
121 connect( mUseAliasesForExportedName, &QCheckBox::stateChanged,
this, &QgsVectorLayerSaveAsDialog::mUseAliasesForExportedName_stateChanged );
122 connect( mReplaceRawFieldValues, &QCheckBox::stateChanged,
this, &QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged );
123 connect( mAttributeTable, &QTableWidget::itemChanged,
this, &QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged );
126 mHelpButtonBox->setVisible(
false );
127 mButtonBox->addButton( QDialogButtonBox::Help );
128 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorLayerSaveAsDialog::showHelp );
130 connect( mHelpButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorLayerSaveAsDialog::showHelp );
132 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QgsVectorLayerSaveAsDialog::accept );
133 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsVectorLayerSaveAsDialog::reject );
136 mFormatComboBox->blockSignals(
true );
139 mFormatComboBox->addItem( driver.longName, driver.driverName );
143 QString
format = settings.
value( QStringLiteral(
"UI/lastVectorFormat" ),
"GPKG" ).toString();
144 mFormatComboBox->setCurrentIndex( mFormatComboBox->findData(
format ) );
145 mFormatComboBox->blockSignals(
false );
153 mGeometryTypeComboBox->addItem( tr(
"Automatic" ), -1 );
159 mGeometryTypeComboBox->setCurrentIndex( mGeometryTypeComboBox->findData( -1 ) );
163 QString enc = settings.
value( QStringLiteral(
"UI/encoding" ),
"System" ).toString();
164 int idx = mEncodingComboBox->findText( enc );
167 mEncodingComboBox->insertItem( 0, enc );
171 mCrsSelector->setCrs( mSelectedCrs );
172 mCrsSelector->setLayerCrs( mSelectedCrs );
173 mCrsSelector->setMessage( tr(
"Select the coordinate reference system for the vector file. "
174 "The data points will be transformed from the layer coordinate reference system." ) );
176 mEncodingComboBox->setCurrentIndex( idx );
177 mFormatComboBox_currentIndexChanged( mFormatComboBox->currentIndex() );
183 mSymbologyExportComboBox_currentIndexChanged( mSymbologyExportComboBox->currentText() );
186 mExtentGroupBox->setOutputCrs( mSelectedCrs );
187 mExtentGroupBox->setOriginalExtent( mLayerExtent, mSelectedCrs );
188 mExtentGroupBox->setOutputExtentFromOriginal();
189 mExtentGroupBox->setCheckable(
true );
190 mExtentGroupBox->setChecked(
false );
191 mExtentGroupBox->setCollapsed(
true );
194 mFilename->setDialogTitle( tr(
"Save Layer As" ) );
195 mFilename->setDefaultRoot( settings.
value( QStringLiteral(
"UI/lastVectorFileFilterDir" ), QDir::homePath() ).toString() );
196 mFilename->setConfirmOverwrite(
false );
200 QFileInfo tmplFileInfo( filePath );
201 settings.
setValue( QStringLiteral(
"UI/lastVectorFileFilterDir" ), tmplFileInfo.absolutePath() );
203 const QFileInfo fileInfo( filePath );
205 if ( mDefaultOutputLayerNameFromInputLayerName.isEmpty() )
206 leLayername->setDefaultValue( suggestedLayerName );
209 if ( leLayername->text().isEmpty() && !filePath.isEmpty() && leLayername->isEnabled() )
211 leLayername->setText( suggestedLayerName );
213 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( !filePath.isEmpty() );
221 mCrsSelector->setSourceEnsemble( ensemble.
name() );
228 mCrsSelector->setShowAccuracyWarnings(
true );
231QList<QPair<QLabel *, QWidget *> > QgsVectorLayerSaveAsDialog::createControls(
const QMap<QString, QgsVectorFileWriter::Option *> &options )
233 QList<QPair<QLabel *, QWidget *> > controls;
234 QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
236 for ( it = options.constBegin(); it != options.constEnd(); ++it )
239 QWidget *control =
nullptr;
240 switch ( option->
type )
247 QSpinBox *sb =
new QSpinBox();
248 sb->setObjectName( it.key() );
249 sb->setMaximum( std::numeric_limits<int>::max() );
261 QComboBox *cb =
new QComboBox();
262 cb->setObjectName( it.key() );
263 for (
const QString &val : std::as_const( opt->values ) )
265 cb->addItem( val, val );
268 cb->addItem( tr(
"<Default>" ), QVariant( QVariant::String ) );
271 idx = cb->findData( QVariant( QVariant::String ) );
272 cb->setCurrentIndex( idx );
284 le->setObjectName( it.key() );
297 QLabel *label =
new QLabel( it.key() );
300 label->setToolTip( QStringLiteral(
"<p>%1</p>" ).arg( option->
docString.toHtmlEscaped() ) );
301 control->setToolTip( QStringLiteral(
"<p>%1</p>" ).arg( option->
docString.toHtmlEscaped() ) );
303 controls << QPair<QLabel *, QWidget *>( label, control );
310void QgsVectorLayerSaveAsDialog::accept()
314 QgsVectorFileWriter::EditionCapabilities caps =
319 msgBox.setIcon( QMessageBox::Question );
320 msgBox.setWindowTitle( tr(
"Save Vector Layer As" ) );
321 QPushButton *overwriteFileButton = msgBox.addButton( tr(
"Overwrite File" ), QMessageBox::ActionRole );
322 QPushButton *overwriteLayerButton = msgBox.addButton( tr(
"Overwrite Layer" ), QMessageBox::ActionRole );
323 QPushButton *appendToLayerButton = msgBox.addButton( tr(
"Append to Layer" ), QMessageBox::ActionRole );
324 msgBox.setStandardButtons( QMessageBox::Cancel );
325 msgBox.setDefaultButton( QMessageBox::Cancel );
326 overwriteFileButton->hide();
327 overwriteLayerButton->hide();
328 appendToLayerButton->hide();
335 msgBox.setText( tr(
"The layer already exists. Do you want to overwrite the whole file or overwrite the layer?" ) );
336 overwriteFileButton->setVisible(
true );
337 overwriteLayerButton->setVisible(
true );
341 msgBox.setText( tr(
"The file already exists. Do you want to overwrite it?" ) );
342 overwriteFileButton->setVisible(
true );
347 msgBox.setText( tr(
"The layer already exists. Do you want to overwrite the whole file, overwrite the layer or append features to the layer?" ) );
348 appendToLayerButton->setVisible(
true );
349 overwriteFileButton->setVisible(
true );
350 overwriteLayerButton->setVisible(
true );
354 msgBox.setText( tr(
"The layer already exists. Do you want to overwrite the whole file or append features to the layer?" ) );
355 appendToLayerButton->setVisible(
true );
356 overwriteFileButton->setVisible(
true );
359 int ret = msgBox.exec();
360 if ( ret == QMessageBox::Cancel )
362 if ( msgBox.clickedButton() == overwriteFileButton )
364 else if ( msgBox.clickedButton() == overwriteLayerButton )
366 else if ( msgBox.clickedButton() == appendToLayerButton )
378 if ( QMessageBox::question(
this,
379 tr(
"Save Vector Layer As" ),
380 tr(
"The file already exists. Do you want to overwrite it?" ) ) == QMessageBox::NoButton )
393 if ( QMessageBox::question(
this,
394 tr(
"Save Vector Layer As" ),
395 tr(
"The existing layer has additional fields. Do you want to add the missing fields to the layer?" ) ) == QMessageBox::Yes )
404 QStringList layerList;
405 layerList.reserve( sublayers.size() );
408 layerList.append( sublayer.name() );
410 if ( layerList.length() > 1 )
412 layerList.sort( Qt::CaseInsensitive );
414 msgBox.setIcon( QMessageBox::Warning );
415 msgBox.setWindowTitle( tr(
"Overwrite File" ) );
416 msgBox.setText( tr(
"This file contains %1 layers that will be lost!\n" ).arg( QLocale().toString( layerList.length() ) ) );
417 msgBox.setDetailedText( tr(
"The following layers will be permanently lost:\n\n%1" ).arg( layerList.join(
"\n" ) ) );
418 msgBox.setStandardButtons( QMessageBox::Ok | QMessageBox::Cancel );
419 if ( msgBox.exec() == QMessageBox::Cancel )
425 settings.
setValue( QStringLiteral(
"UI/lastVectorFileFilterDir" ), QFileInfo(
filename() ).absolutePath() );
426 settings.
setValue( QStringLiteral(
"UI/lastVectorFormat" ),
format() );
431void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged(
int idx )
435 mFilename->setEnabled(
true );
443 if (
format() == QLatin1String(
"OpenFileGDB" ) ||
format() == QLatin1String(
"FileGDB" ) )
444 filter = QStringLiteral(
"%1 (*.gdb *.GDB gdb)" ).arg( tr(
"ESRI File Geodatabase" ) );
445 mFilename->setFilter( filter );
449 if ( !mFilename->filePath().isEmpty() )
451 const thread_local QRegularExpression rx(
"\\.(.*?)[\\s]" );
452 const QString ext = rx.match( filter ).captured( 1 );
453 if ( !ext.isEmpty() )
455 QFileInfo fi( mFilename->filePath() );
456 mFilename->setFilePath( QStringLiteral(
"%1/%2.%3" ).arg( fi.path() ).arg( fi.baseName() ).arg( ext ) );
460 bool selectAllFields =
true;
465 bool isFormatForFieldsAsDisplayedValues =
false;
467 const QString sFormat(
format() );
468 if ( sFormat == QLatin1String(
"DXF" ) || sFormat == QLatin1String(
"DGN" ) )
470 mAttributesSelection->setVisible(
false );
471 selectAllFields =
false;
477 mAttributesSelection->setVisible(
true );
478 isFormatForFieldsAsDisplayedValues = ( sFormat == QLatin1String(
"CSV" ) ||
479 sFormat == QLatin1String(
"XLS" ) ||
480 sFormat == QLatin1String(
"XLSX" ) ||
481 sFormat == QLatin1String(
"ODS" ) );
488 mSymbologyExportLabel->setVisible(
true );
489 mSymbologyExportComboBox->setVisible(
true );
490 mScaleLabel->setVisible(
true );
491 mScaleWidget->setVisible(
true );
495 mSymbologyExportLabel->hide();
496 mSymbologyExportComboBox->hide();
498 mScaleWidget->hide();
501 leLayername->setEnabled( sFormat == QLatin1String(
"KML" ) ||
502 sFormat == QLatin1String(
"GPKG" ) ||
503 sFormat == QLatin1String(
"XLSX" ) ||
504 sFormat == QLatin1String(
"ODS" ) ||
505 sFormat == QLatin1String(
"FileGDB" ) ||
506 sFormat == QLatin1String(
"OpenFileGDB" ) ||
507 sFormat == QLatin1String(
"SQLite" ) ||
508 sFormat == QLatin1String(
"SpatiaLite" ) );
510 if ( sFormat == QLatin1String(
"XLSX" ) )
511 leLayername->setMaxLength( 31 );
512 else if ( leLayername->isEnabled() )
513 leLayername->setMaxLength( 32767 );
515 if ( !leLayername->isEnabled() )
516 leLayername->setText( QString() );
517 else if ( leLayername->text().isEmpty() )
519 QString layerName = mDefaultOutputLayerNameFromInputLayerName;
520 if ( layerName.isEmpty() && !mFilename->filePath().isEmpty() )
522 layerName = QFileInfo( mFilename->filePath() ).baseName();
523 leLayername->setDefaultValue( layerName );
525 if ( layerName.isEmpty() )
526 layerName = tr(
"new_layer" );
527 leLayername->setText( layerName );
532 mAttributeTable->setRowCount( mLayer->
fields().
count() );
534 QStringList horizontalHeaders = QStringList() << tr(
"Name" ) << tr(
"Export name" ) << tr(
"Type" ) << tr(
"Replace with displayed values" );
535 mAttributeTable->setColumnCount( horizontalHeaders.size() );
536 mAttributeTable->setHorizontalHeaderLabels( horizontalHeaders );
538 bool foundFieldThatCanBeExportedAsDisplayedValue =
false;
539 for (
int i = 0; i < mLayer->
fields().size(); ++i )
542 if ( setup.
type() != QLatin1String(
"TextEdit" ) &&
545 foundFieldThatCanBeExportedAsDisplayedValue =
true;
549 mAttributeTable->setColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ),
550 ! foundFieldThatCanBeExportedAsDisplayedValue );
552 bool checkReplaceRawFieldValues = selectAllFields && isFormatForFieldsAsDisplayedValues;
553 const QSignalBlocker signalBlockerAttributeTable( mAttributeTable );
555 for (
int i = 0; i < mLayer->
fields().size(); ++i )
558 Qt::ItemFlags flags = mLayer->
providerType() != QLatin1String(
"oracle" ) || !fld.
typeName().contains( QLatin1String(
"SDO_GEOMETRY" ) ) ? Qt::ItemIsEnabled : Qt::NoItemFlags;
559 QTableWidgetItem *item =
nullptr;
560 item =
new QTableWidgetItem( fld.
name() );
561 item->setFlags( flags | Qt::ItemIsUserCheckable );
562 item->setCheckState( ( selectAllFields ) ? Qt::Checked : Qt::Unchecked );
563 mAttributeTable->setItem( i,
static_cast<int>( ColumnIndex::Name ), item );
565 item =
new QTableWidgetItem( fld.
name() );
566 item->setFlags( flags | Qt::ItemIsEditable );
568 mAttributeTable->setItem( i,
static_cast<int>( ColumnIndex::ExportName ), item );
570 item =
new QTableWidgetItem( fld.
typeName() );
571 item->setFlags( flags );
572 mAttributeTable->setItem( i,
static_cast<int>( ColumnIndex::Type ), item );
574 if ( foundFieldThatCanBeExportedAsDisplayedValue )
578 const QString widgetId( setup.
type() );
579 if ( flags == Qt::ItemIsEnabled &&
580 widgetId != QLatin1String(
"TextEdit" ) &&
583 item =
new QTableWidgetItem( tr(
"Use %1" ).arg( factory->
name() ) );
584 item->setFlags( ( selectAllFields ) ? ( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable ) : Qt::ItemIsUserCheckable );
585 const bool checkItem = ( selectAllFields && isFormatForFieldsAsDisplayedValues &&
586 ( widgetId == QLatin1String(
"ValueMap" ) ||
587 widgetId == QLatin1String(
"ValueRelation" ) ||
588 widgetId == QLatin1String(
"CheckBox" ) ||
589 widgetId == QLatin1String(
"RelationReference" ) ) );
590 checkReplaceRawFieldValues &= checkItem;
591 item->setCheckState( checkItem ?
592 Qt::Checked : Qt::Unchecked );
593 mAttributeTable->setItem( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ), item );
597 item =
new QTableWidgetItem();
598 item->setFlags( Qt::NoItemFlags );
599 mAttributeTable->setItem( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ), item );
605 whileBlocking( mReplaceRawFieldValues )->setChecked( checkReplaceRawFieldValues );
606 mReplaceRawFieldValues->setEnabled( selectAllFields );
607 mReplaceRawFieldValues->setVisible( foundFieldThatCanBeExportedAsDisplayedValue );
609 mAttributeTable->resizeColumnsToContents();
614 while ( mDatasourceOptionsGroupBox->layout()->count() )
616 QLayoutItem *item = mDatasourceOptionsGroupBox->layout()->takeAt( 0 );
617 delete item->widget();
621 while ( mLayerOptionsGroupBox->layout()->count() )
623 QLayoutItem *item = mLayerOptionsGroupBox->layout()->takeAt( 0 );
624 delete item->widget();
628 typedef QPair<QLabel *, QWidget *> LabelControlPair;
634 mDatasourceOptionsGroupBox->setVisible(
true );
635 QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.
driverOptions );
637 QFormLayout *datasourceLayout =
dynamic_cast<QFormLayout *
>( mDatasourceOptionsGroupBox->layout() );
639 const auto constControls = controls;
640 for ( LabelControlPair control : constControls )
642 datasourceLayout->addRow( control.first, control.second );
647 mDatasourceOptionsGroupBox->setVisible(
false );
652 mLayerOptionsGroupBox->setVisible(
true );
653 QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.
layerOptions );
655 QFormLayout *layerOptionsLayout =
dynamic_cast<QFormLayout *
>( mLayerOptionsGroupBox->layout() );
657 const auto constControls = controls;
658 for ( LabelControlPair control : constControls )
660 layerOptionsLayout->addRow( control.first, control.second );
665 mLayerOptionsGroupBox->setVisible(
false );
670 mEncodingComboBox->setEnabled(
true );
677 mEncodingComboBox->setCurrentIndex( idx );
678 mEncodingComboBox->setDisabled(
true );
682 mEncodingComboBox->setEnabled(
true );
689 mEncodingComboBox->setEnabled(
true );
692 GDALDriverH hDriver = GDALGetDriverByName(
format().toUtf8().constData() );
695 mAddToCanvas->setEnabled( GDALGetMetadataItem( hDriver, GDAL_DCAP_OPEN,
nullptr ) !=
nullptr );
699void QgsVectorLayerSaveAsDialog::mUseAliasesForExportedName_stateChanged(
int state )
701 const QSignalBlocker signalBlocker( mAttributeTable );
708 bool modifiedEntries =
false;
709 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
711 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportName ) )->text()
712 != mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportName ) )->data( Qt::UserRole ).toString() )
714 modifiedEntries =
true;
719 if ( modifiedEntries )
721 if ( QMessageBox::question(
this,
722 tr(
"Modified names" ),
723 tr(
"Some names were modified and will be overridden. Do you want to continue?" ) )
726 whileBlocking( mUseAliasesForExportedName )->setCheckState( Qt::PartiallyChecked );
731 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
733 mUseAliasesForExportedName->setTristate(
false );
734 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportName ) )->setText( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->text() );
741 bool modifiedEntries =
false;
742 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
744 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportName ) )->text()
745 != mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->text() )
746 modifiedEntries =
true;
749 if ( modifiedEntries )
751 if ( QMessageBox::question(
this,
752 tr(
"Modified names" ),
753 tr(
"Some names were modified and will be overridden. Do you want to continue?" ) )
756 whileBlocking( mUseAliasesForExportedName )->setCheckState( Qt::PartiallyChecked );
761 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
763 mUseAliasesForExportedName->setTristate(
false );
764 const QString alias = mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportName ) )->data( Qt::UserRole ).toString();
765 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportName ) )->setText( alias );
769 case Qt::PartiallyChecked:
775void QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged(
int )
777 if ( mAttributeTable->isColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) )
780 const QSignalBlocker signalBlockerAttributeTable( mAttributeTable );
781 const QSignalBlocker signalBlockerReplaceRawFieldValues( mReplaceRawFieldValues );
783 if ( mReplaceRawFieldValues->checkState() != Qt::PartiallyChecked )
785 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
787 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->checkState() == Qt::Checked &&
788 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) &&
789 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->flags() & Qt::ItemIsEnabled )
791 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->setCheckState( mReplaceRawFieldValues->checkState() );
795 mReplaceRawFieldValues->setTristate(
false );
798void QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged( QTableWidgetItem *item )
800 const QSignalBlocker signalBlockerAttributeTable( mAttributeTable );
801 const QSignalBlocker signalBlockerReplaceRawFieldValues( mReplaceRawFieldValues );
803 int row = item->row();
804 int column = item->column();
806 switch (
static_cast<ColumnIndex
>( column ) )
808 case ColumnIndex::Name:
810 if ( mAttributeTable->isColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) ||
811 ! mAttributeTable->item( row,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) ||
812 !( mAttributeTable->item( row,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->flags() & Qt::ItemIsUserCheckable ) )
815 if ( mAttributeTable->item( row, column )->checkState() == Qt::Unchecked )
817 mAttributeTable->item( row,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->setCheckState( Qt::Unchecked );
818 mAttributeTable->item( row,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->setFlags( Qt::ItemIsUserCheckable );
819 bool checkBoxEnabled =
false;
820 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
822 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) &&
823 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->flags() & Qt::ItemIsEnabled )
825 checkBoxEnabled =
true;
829 mReplaceRawFieldValues->setEnabled( checkBoxEnabled );
830 if ( !checkBoxEnabled )
831 mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
833 else if ( mAttributeTable->item( row, column )->checkState() == Qt::Checked )
835 mAttributeTable->item( row,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
836 mReplaceRawFieldValues->setEnabled(
true );
840 case ColumnIndex::ExportName:
843 if ( item->text().isEmpty() )
845 QMessageBox::warning(
this,
846 tr(
"Empty export name" ),
847 tr(
"Empty export name are not allowed." ) );
853 while ( names.count( item->text() ) > 1 )
854 item->setText( QString(
"%1_2" ).arg( item->text() ) );
856 mUseAliasesForExportedName->setCheckState( Qt::PartiallyChecked );
859 case ColumnIndex::Type:
862 case ColumnIndex::ExportAsDisplayedValue:
864 if ( mAttributeTable->item( row, column )->flags() & Qt::ItemIsUserCheckable )
866 bool allChecked =
true;
867 bool allUnchecked =
true;
868 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
870 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) &&
871 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->flags() & Qt::ItemIsEnabled )
873 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->checkState() == Qt::Unchecked )
876 allUnchecked =
false;
879 mReplaceRawFieldValues->setCheckState( ( !allChecked && !allUnchecked ) ? Qt::PartiallyChecked : ( allChecked ) ? Qt::Checked : Qt::Unchecked );
889 mExtentGroupBox->setOutputCrs( mSelectedCrs );
894 return mFilename->filePath();
899 return leLayername->text();
904 return mEncodingComboBox->currentText();
909 return mFormatComboBox->currentData().toString();
914 return mSelectedCrs.
srsid();
930 QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
934 switch ( it.value()->type )
939 QSpinBox *sb = mDatasourceOptionsGroupBox->findChild<QSpinBox *>( it.key() );
941 options << QStringLiteral(
"%1=%2" ).arg( it.key() ).arg( sb->value() );
948 QComboBox *cb = mDatasourceOptionsGroupBox->findChild<QComboBox *>( it.key() );
949 if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->
defaultValue )
950 options << QStringLiteral(
"%1=%2" ).arg( it.key(), cb->currentText() );
957 QLineEdit *le = mDatasourceOptionsGroupBox->findChild<QLineEdit *>( it.key() );
959 options << QStringLiteral(
"%1=%2" ).arg( it.key(), le->text() );
967 if ( !opt->
mValue.isEmpty() )
968 options << QStringLiteral(
"%1=%2" ).arg( it.key(), opt->
mValue );
975 QString plainText = mOgrDatasourceOptions->toPlainText().trimmed();
976 if ( !plainText.isEmpty() )
977 options += plainText.split(
'\n' );
990 QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
994 switch ( it.value()->type )
999 QSpinBox *sb = mLayerOptionsGroupBox->findChild<QSpinBox *>( it.key() );
1001 options << QStringLiteral(
"%1=%2" ).arg( it.key() ).arg( sb->value() );
1008 QComboBox *cb = mLayerOptionsGroupBox->findChild<QComboBox *>( it.key() );
1009 if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->
defaultValue )
1010 options << QStringLiteral(
"%1=%2" ).arg( it.key(), cb->currentText() );
1017 QLineEdit *le = mLayerOptionsGroupBox->findChild<QLineEdit *>( it.key() );
1019 options << QStringLiteral(
"%1=%2" ).arg( it.key(), le->text() );
1027 if ( !opt->
mValue.isEmpty() )
1028 options << QStringLiteral(
"%1=%2" ).arg( it.key(), opt->
mValue );
1035 QString plainText = mOgrLayerOptions->toPlainText().trimmed();
1036 if ( !plainText.isEmpty() )
1037 options += plainText.split(
'\n' );
1046 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1048 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->checkState() == Qt::Checked )
1050 attributes.append( i );
1061 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1063 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->checkState() == Qt::Checked &&
1064 ! mAttributeTable->isColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) &&
1065 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->checkState() == Qt::Checked )
1067 attributes.append( i );
1076 QStringList exportNames;
1077 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1078 exportNames.append( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportName ) )->text() );
1085 return mAddToCanvas->isChecked() && mAddToCanvas->isEnabled();
1090 mAddToCanvas->setChecked( enabled );
1095 return mSymbologyExportComboBox->currentData().toInt();
1100 return mScaleWidget->scale();
1105 mMapCanvas = canvas;
1106 mScaleWidget->setMapCanvas( canvas );
1107 mScaleWidget->setShowCurrentScaleButton(
true );
1113 return mExtentGroupBox->isChecked();
1118 return mExtentGroupBox->outputExtent();
1128 return mSelectedOnly->isChecked();
1133 return mCheckPersistMetadata->isChecked();
1138 int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
1139 if ( currentIndexData == -1 )
1150 int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
1151 return currentIndexData == -1;
1156 return mForceMultiCheckBox->isChecked();
1161 mForceMultiCheckBox->setChecked( checked );
1166 return mIncludeZCheckBox->isChecked();
1171 return mActionOnExistingFile;
1176 mIncludeZCheckBox->setChecked( checked );
1179void QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged(
const QString &text )
1181 bool scaleEnabled =
true;
1182 if ( text == tr(
"No symbology" ) )
1184 scaleEnabled =
false;
1186 mScaleWidget->setEnabled( scaleEnabled );
1187 mScaleLabel->setEnabled( scaleEnabled );
1190void QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged(
int index )
1192 int currentIndexData = mGeometryTypeComboBox->itemData( index ).toInt();
1196 mForceMultiCheckBox->setEnabled(
true );
1197 mIncludeZCheckBox->setEnabled(
true );
1201 mForceMultiCheckBox->setEnabled(
false );
1202 mForceMultiCheckBox->setChecked(
false );
1203 mIncludeZCheckBox->setEnabled(
false );
1204 mIncludeZCheckBox->setChecked(
false );
1208void QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked()
1210 const QSignalBlocker signalBlockerAttributeTable( mAttributeTable );
1211 const QSignalBlocker signalBlockerReplaceRawFieldValues( mReplaceRawFieldValues );
1213 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1215 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->flags() & Qt::ItemIsEnabled )
1217 if ( ! mAttributeTable->isColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) &&
1218 ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->flags() & Qt::ItemIsUserCheckable ) )
1220 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
1222 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->setCheckState( Qt::Checked );
1225 if ( ! mAttributeTable->isColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) )
1227 mReplaceRawFieldValues->setEnabled(
true );
1231void QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked()
1233 const QSignalBlocker signalBlockerAttributeTable( mAttributeTable );
1234 const QSignalBlocker signalBlockerReplaceRawFieldValues( mReplaceRawFieldValues );
1236 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1238 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->setCheckState( Qt::Unchecked );
1239 if ( ! mAttributeTable->isColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) &&
1240 ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->flags() & Qt::ItemIsUserCheckable ) )
1242 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->setFlags( Qt::ItemIsUserCheckable );
1243 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->setCheckState( Qt::Unchecked );
1246 if ( ! mAttributeTable->isColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) )
1248 mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
1249 mReplaceRawFieldValues->setEnabled(
false );
1253void QgsVectorLayerSaveAsDialog::showHelp()
1255 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
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.
QString displayName() const
Returns the name to use when displaying this field.
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).
@ ClearToDefault
Reset value to default value (see defaultValue() )
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.
static QString launderLayerName(const QString &name)
Launders a layer's name, converting it into a format which is general suitable for file names or data...
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.
QStringList attributesExportNames() const
Returns a list of export names for attributes.
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.
Type
The WKB type describes the number of dimensions a geometry has.
static QString translatedDisplayString(Type type)
Returns a translated display string type for a WKB type, e.g., the geometry name used in WKT geometry...
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
QList< int > QgsAttributeList
const QgsCoordinateReferenceSystem & crs
Details of available driver formats.