33#include <QRegularExpression>
42 : QDialog( parent, fl )
50 : QDialog( parent, fl )
57 mSelectedCrs = layer->
crs();
58 mLayerExtent = layer->
extent();
65 leLayername->setDefaultValue( mDefaultOutputLayerNameFromInputLayerName );
67 if ( leLayername->isEnabled() )
68 leLayername->setText( mDefaultOutputLayerNameFromInputLayerName );
73 mSymbologyExportLabel->hide();
74 mSymbologyExportComboBox->hide();
84 if ( !( mOptions &
Fields ) )
85 mAttributesSelection->hide();
88 mSelectedOnly->hide();
94 mGeometryGroupBox->hide();
96 if ( !( mOptions &
Extent ) )
97 mExtentGroupBox->hide();
101 mCheckPersistMetadata->setChecked(
false );
102 mCheckPersistMetadata->hide();
106 mButtonBox->button( QDialogButtonBox::Ok )->setDisabled(
true );
109void QgsVectorLayerSaveAsDialog::setup()
114 connect( mFormatComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged );
116 connect( mSymbologyExportComboBox, &QComboBox::currentTextChanged,
this, &QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged );
117 connect( mGeometryTypeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged );
118 connect( mSelectAllAttributes, &QPushButton::clicked,
this, &QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked );
119 connect( mDeselectAllAttributes, &QPushButton::clicked,
this, &QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked );
120 connect( mUseAliasesForExportedName, &QCheckBox::stateChanged,
this, &QgsVectorLayerSaveAsDialog::mUseAliasesForExportedName_stateChanged );
121 connect( mReplaceRawFieldValues, &QCheckBox::stateChanged,
this, &QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged );
122 connect( mAttributeTable, &QTableWidget::itemChanged,
this, &QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged );
125 mHelpButtonBox->setVisible(
false );
126 mButtonBox->addButton( QDialogButtonBox::Help );
127 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorLayerSaveAsDialog::showHelp );
129 connect( mHelpButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorLayerSaveAsDialog::showHelp );
131 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QgsVectorLayerSaveAsDialog::accept );
132 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsVectorLayerSaveAsDialog::reject );
135 mFormatComboBox->blockSignals(
true );
138 mFormatComboBox->addItem( driver.longName, driver.driverName );
142 QString
format = settings.
value( QStringLiteral(
"UI/lastVectorFormat" ),
"GPKG" ).toString();
143 mFormatComboBox->setCurrentIndex( mFormatComboBox->findData(
format ) );
144 mFormatComboBox->blockSignals(
false );
152 mGeometryTypeComboBox->addItem( tr(
"Automatic" ), -1 );
158 mGeometryTypeComboBox->setCurrentIndex( mGeometryTypeComboBox->findData( -1 ) );
162 QString enc = settings.
value( QStringLiteral(
"UI/encoding" ),
"System" ).toString();
163 int idx = mEncodingComboBox->findText( enc );
166 mEncodingComboBox->insertItem( 0, enc );
170 mCrsSelector->setCrs( mSelectedCrs );
171 mCrsSelector->setLayerCrs( mSelectedCrs );
172 mCrsSelector->setMessage( tr(
"Select the coordinate reference system for the vector file. "
173 "The data points will be transformed from the layer coordinate reference system." ) );
175 mEncodingComboBox->setCurrentIndex( idx );
176 mFormatComboBox_currentIndexChanged( mFormatComboBox->currentIndex() );
182 mSymbologyExportComboBox_currentIndexChanged( mSymbologyExportComboBox->currentText() );
185 mExtentGroupBox->setOutputCrs( mSelectedCrs );
186 mExtentGroupBox->setOriginalExtent( mLayerExtent, mSelectedCrs );
187 mExtentGroupBox->setOutputExtentFromOriginal();
188 mExtentGroupBox->setCheckable(
true );
189 mExtentGroupBox->setChecked(
false );
190 mExtentGroupBox->setCollapsed(
true );
193 mFilename->setDialogTitle( tr(
"Save Layer As" ) );
194 mFilename->setDefaultRoot( settings.
value( QStringLiteral(
"UI/lastVectorFileFilterDir" ), QDir::homePath() ).toString() );
195 mFilename->setConfirmOverwrite(
false );
199 QFileInfo tmplFileInfo( filePath );
200 settings.
setValue( QStringLiteral(
"UI/lastVectorFileFilterDir" ), tmplFileInfo.absolutePath() );
202 const QFileInfo fileInfo( filePath );
204 if ( mDefaultOutputLayerNameFromInputLayerName.isEmpty() )
205 leLayername->setDefaultValue( suggestedLayerName );
208 if ( leLayername->text().isEmpty() && !filePath.isEmpty() && leLayername->isEnabled() )
210 leLayername->setText( suggestedLayerName );
212 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( !filePath.isEmpty() );
220 mCrsSelector->setSourceEnsemble( ensemble.
name() );
227 mCrsSelector->setShowAccuracyWarnings(
true );
230QList<QPair<QLabel *, QWidget *> > QgsVectorLayerSaveAsDialog::createControls(
const QMap<QString, QgsVectorFileWriter::Option *> &options )
232 QList<QPair<QLabel *, QWidget *> > controls;
233 QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
235 for ( it = options.constBegin(); it != options.constEnd(); ++it )
238 QLabel *label =
new QLabel( it.key() );
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() );
298 label->setToolTip( QStringLiteral(
"<p>%1</p>" ).arg( option->
docString.toHtmlEscaped() ) );
299 control->setToolTip( QStringLiteral(
"<p>%1</p>" ).arg( option->
docString.toHtmlEscaped() ) );
301 controls << QPair<QLabel *, QWidget *>( label, control );
308void QgsVectorLayerSaveAsDialog::accept()
312 QgsVectorFileWriter::EditionCapabilities caps =
317 msgBox.setIcon( QMessageBox::Question );
318 msgBox.setWindowTitle( tr(
"Save Vector Layer As" ) );
319 QPushButton *overwriteFileButton = msgBox.addButton( tr(
"Overwrite File" ), QMessageBox::ActionRole );
320 QPushButton *overwriteLayerButton = msgBox.addButton( tr(
"Overwrite Layer" ), QMessageBox::ActionRole );
321 QPushButton *appendToLayerButton = msgBox.addButton( tr(
"Append to Layer" ), QMessageBox::ActionRole );
322 msgBox.setStandardButtons( QMessageBox::Cancel );
323 msgBox.setDefaultButton( QMessageBox::Cancel );
324 overwriteFileButton->hide();
325 overwriteLayerButton->hide();
326 appendToLayerButton->hide();
333 msgBox.setText( tr(
"The layer already exists. Do you want to overwrite the whole file or overwrite the layer?" ) );
334 overwriteFileButton->setVisible(
true );
335 overwriteLayerButton->setVisible(
true );
339 msgBox.setText( tr(
"The file already exists. Do you want to overwrite it?" ) );
340 overwriteFileButton->setVisible(
true );
345 msgBox.setText( tr(
"The layer already exists. Do you want to overwrite the whole file, overwrite the layer or append features to the layer?" ) );
346 appendToLayerButton->setVisible(
true );
347 overwriteFileButton->setVisible(
true );
348 overwriteLayerButton->setVisible(
true );
352 msgBox.setText( tr(
"The layer already exists. Do you want to overwrite the whole file or append features to the layer?" ) );
353 appendToLayerButton->setVisible(
true );
354 overwriteFileButton->setVisible(
true );
357 int ret = msgBox.exec();
358 if ( ret == QMessageBox::Cancel )
360 if ( msgBox.clickedButton() == overwriteFileButton )
362 else if ( msgBox.clickedButton() == overwriteLayerButton )
364 else if ( msgBox.clickedButton() == appendToLayerButton )
376 if ( QMessageBox::question(
this,
377 tr(
"Save Vector Layer As" ),
378 tr(
"The file already exists. Do you want to overwrite it?" ) ) == QMessageBox::NoButton )
391 if ( QMessageBox::question(
this,
392 tr(
"Save Vector Layer As" ),
393 tr(
"The existing layer has additional fields. Do you want to add the missing fields to the layer?" ) ) == QMessageBox::Yes )
402 QStringList layerList;
403 layerList.reserve( sublayers.size() );
406 layerList.append( sublayer.name() );
408 if ( layerList.length() > 1 )
410 layerList.sort( Qt::CaseInsensitive );
412 msgBox.setIcon( QMessageBox::Warning );
413 msgBox.setWindowTitle( tr(
"Overwrite File" ) );
414 msgBox.setText( tr(
"This file contains %1 layers that will be lost!\n" ).arg( QLocale().toString( layerList.length() ) ) );
415 msgBox.setDetailedText( tr(
"The following layers will be permanently lost:\n\n%1" ).arg( layerList.join(
"\n" ) ) );
416 msgBox.setStandardButtons( QMessageBox::Ok | QMessageBox::Cancel );
417 if ( msgBox.exec() == QMessageBox::Cancel )
423 settings.
setValue( QStringLiteral(
"UI/lastVectorFileFilterDir" ), QFileInfo(
filename() ).absolutePath() );
424 settings.
setValue( QStringLiteral(
"UI/lastVectorFormat" ),
format() );
429void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged(
int idx )
433 mFilename->setEnabled(
true );
438 if ( !mFilename->filePath().isEmpty() )
440 QRegularExpression rx(
"\\.(.*?)[\\s]" );
443 if ( !ext.isEmpty() )
445 QFileInfo fi( mFilename->filePath() );
446 mFilename->setFilePath( QStringLiteral(
"%1/%2.%3" ).arg( fi.path() ).arg( fi.baseName() ).arg( ext ) );
450 bool selectAllFields =
true;
455 bool isFormatForFieldsAsDisplayedValues =
false;
457 const QString sFormat(
format() );
458 if ( sFormat == QLatin1String(
"DXF" ) || sFormat == QLatin1String(
"DGN" ) )
460 mAttributesSelection->setVisible(
false );
461 selectAllFields =
false;
467 mAttributesSelection->setVisible(
true );
468 isFormatForFieldsAsDisplayedValues = ( sFormat == QLatin1String(
"CSV" ) ||
469 sFormat == QLatin1String(
"XLS" ) ||
470 sFormat == QLatin1String(
"XLSX" ) ||
471 sFormat == QLatin1String(
"ODS" ) );
478 mSymbologyExportLabel->setVisible(
true );
479 mSymbologyExportComboBox->setVisible(
true );
480 mScaleLabel->setVisible(
true );
481 mScaleWidget->setVisible(
true );
485 mSymbologyExportLabel->hide();
486 mSymbologyExportComboBox->hide();
488 mScaleWidget->hide();
491 leLayername->setEnabled( sFormat == QLatin1String(
"KML" ) ||
492 sFormat == QLatin1String(
"GPKG" ) ||
493 sFormat == QLatin1String(
"XLSX" ) ||
494 sFormat == QLatin1String(
"ODS" ) ||
495 sFormat == QLatin1String(
"FileGDB" ) ||
496 sFormat == QLatin1String(
"OpenFileGDB" ) ||
497 sFormat == QLatin1String(
"SQLite" ) ||
498 sFormat == QLatin1String(
"SpatiaLite" ) );
500 if ( sFormat == QLatin1String(
"XLSX" ) )
501 leLayername->setMaxLength( 31 );
502 else if ( leLayername->isEnabled() )
503 leLayername->setMaxLength( 32767 );
505 if ( !leLayername->isEnabled() )
506 leLayername->setText( QString() );
507 else if ( leLayername->text().isEmpty() )
509 QString layerName = mDefaultOutputLayerNameFromInputLayerName;
510 if ( layerName.isEmpty() && !mFilename->filePath().isEmpty() )
512 layerName = QFileInfo( mFilename->filePath() ).baseName();
513 leLayername->setDefaultValue( layerName );
515 if ( layerName.isEmpty() )
516 layerName = tr(
"new_layer" );
517 leLayername->setText( layerName );
522 mAttributeTable->setRowCount( mLayer->
fields().
count() );
524 QStringList horizontalHeaders = QStringList() << tr(
"Name" ) << tr(
"Export name" ) << tr(
"Type" ) << tr(
"Replace with displayed values" );
525 mAttributeTable->setColumnCount( horizontalHeaders.size() );
526 mAttributeTable->setHorizontalHeaderLabels( horizontalHeaders );
528 bool foundFieldThatCanBeExportedAsDisplayedValue =
false;
529 for (
int i = 0; i < mLayer->
fields().size(); ++i )
532 if ( setup.
type() != QLatin1String(
"TextEdit" ) &&
535 foundFieldThatCanBeExportedAsDisplayedValue =
true;
539 mAttributeTable->setColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ),
540 ! foundFieldThatCanBeExportedAsDisplayedValue );
542 bool checkReplaceRawFieldValues = selectAllFields && isFormatForFieldsAsDisplayedValues;
543 const QSignalBlocker signalBlockerAttributeTable( mAttributeTable );
545 for (
int i = 0; i < mLayer->
fields().size(); ++i )
548 Qt::ItemFlags flags = mLayer->
providerType() != QLatin1String(
"oracle" ) || !fld.
typeName().contains( QLatin1String(
"SDO_GEOMETRY" ) ) ? Qt::ItemIsEnabled : Qt::NoItemFlags;
549 QTableWidgetItem *item =
nullptr;
550 item =
new QTableWidgetItem( fld.
name() );
551 item->setFlags( flags | Qt::ItemIsUserCheckable );
552 item->setCheckState( ( selectAllFields ) ? Qt::Checked : Qt::Unchecked );
553 mAttributeTable->setItem( i,
static_cast<int>( ColumnIndex::Name ), item );
555 item =
new QTableWidgetItem( fld.
name() );
556 item->setFlags( flags | Qt::ItemIsEditable );
558 mAttributeTable->setItem( i,
static_cast<int>( ColumnIndex::ExportName ), item );
560 item =
new QTableWidgetItem( fld.
typeName() );
561 item->setFlags( flags );
562 mAttributeTable->setItem( i,
static_cast<int>( ColumnIndex::Type ), item );
564 if ( foundFieldThatCanBeExportedAsDisplayedValue )
568 const QString widgetId( setup.
type() );
569 if ( flags == Qt::ItemIsEnabled &&
570 widgetId != QLatin1String(
"TextEdit" ) &&
573 item =
new QTableWidgetItem( tr(
"Use %1" ).arg( factory->
name() ) );
574 item->setFlags( ( selectAllFields ) ? ( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable ) : Qt::ItemIsUserCheckable );
575 const bool checkItem = ( selectAllFields && isFormatForFieldsAsDisplayedValues &&
576 ( widgetId == QLatin1String(
"ValueMap" ) ||
577 widgetId == QLatin1String(
"ValueRelation" ) ||
578 widgetId == QLatin1String(
"CheckBox" ) ||
579 widgetId == QLatin1String(
"RelationReference" ) ) );
580 checkReplaceRawFieldValues &= checkItem;
581 item->setCheckState( checkItem ?
582 Qt::Checked : Qt::Unchecked );
583 mAttributeTable->setItem( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ), item );
587 item =
new QTableWidgetItem();
588 item->setFlags( Qt::NoItemFlags );
589 mAttributeTable->setItem( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ), item );
595 whileBlocking( mReplaceRawFieldValues )->setChecked( checkReplaceRawFieldValues );
596 mReplaceRawFieldValues->setEnabled( selectAllFields );
597 mReplaceRawFieldValues->setVisible( foundFieldThatCanBeExportedAsDisplayedValue );
599 mAttributeTable->resizeColumnsToContents();
604 while ( mDatasourceOptionsGroupBox->layout()->count() )
606 QLayoutItem *item = mDatasourceOptionsGroupBox->layout()->takeAt( 0 );
607 delete item->widget();
611 while ( mLayerOptionsGroupBox->layout()->count() )
613 QLayoutItem *item = mLayerOptionsGroupBox->layout()->takeAt( 0 );
614 delete item->widget();
618 typedef QPair<QLabel *, QWidget *> LabelControlPair;
624 mDatasourceOptionsGroupBox->setVisible(
true );
625 QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.
driverOptions );
627 QFormLayout *datasourceLayout =
dynamic_cast<QFormLayout *
>( mDatasourceOptionsGroupBox->layout() );
629 const auto constControls = controls;
630 for ( LabelControlPair control : constControls )
632 datasourceLayout->addRow( control.first, control.second );
637 mDatasourceOptionsGroupBox->setVisible(
false );
642 mLayerOptionsGroupBox->setVisible(
true );
643 QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.
layerOptions );
645 QFormLayout *layerOptionsLayout =
dynamic_cast<QFormLayout *
>( mLayerOptionsGroupBox->layout() );
647 const auto constControls = controls;
648 for ( LabelControlPair control : constControls )
650 layerOptionsLayout->addRow( control.first, control.second );
655 mLayerOptionsGroupBox->setVisible(
false );
660 mEncodingComboBox->setEnabled(
true );
667 mEncodingComboBox->setCurrentIndex( idx );
668 mEncodingComboBox->setDisabled(
true );
672 mEncodingComboBox->setEnabled(
true );
679 mEncodingComboBox->setEnabled(
true );
682 GDALDriverH hDriver = GDALGetDriverByName(
format().toUtf8().constData() );
685 mAddToCanvas->setEnabled( GDALGetMetadataItem( hDriver, GDAL_DCAP_OPEN,
nullptr ) !=
nullptr );
689void QgsVectorLayerSaveAsDialog::mUseAliasesForExportedName_stateChanged(
int state )
691 const QSignalBlocker signalBlocker( mAttributeTable );
698 bool modifiedEntries =
false;
699 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
701 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportName ) )->text()
702 != mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportName ) )->data( Qt::UserRole ).toString() )
704 modifiedEntries =
true;
709 if ( modifiedEntries )
711 if ( QMessageBox::question(
this,
712 tr(
"Modified names" ),
713 tr(
"Some names were modified and will be overridden. Do you want to continue?" ) )
716 whileBlocking( mUseAliasesForExportedName )->setCheckState( Qt::PartiallyChecked );
721 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
723 mUseAliasesForExportedName->setTristate(
false );
724 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportName ) )->setText( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->text() );
731 bool modifiedEntries =
false;
732 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
734 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportName ) )->text()
735 != mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->text() )
736 modifiedEntries =
true;
739 if ( modifiedEntries )
741 if ( QMessageBox::question(
this,
742 tr(
"Modified names" ),
743 tr(
"Some names were modified and will be overridden. Do you want to continue?" ) )
746 whileBlocking( mUseAliasesForExportedName )->setCheckState( Qt::PartiallyChecked );
751 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
753 mUseAliasesForExportedName->setTristate(
false );
754 const QString alias = mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportName ) )->data( Qt::UserRole ).toString();
755 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportName ) )->setText( alias );
759 case Qt::PartiallyChecked:
765void QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged(
int )
767 if ( mAttributeTable->isColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) )
770 const QSignalBlocker signalBlockerAttributeTable( mAttributeTable );
771 const QSignalBlocker signalBlockerReplaceRawFieldValues( mReplaceRawFieldValues );
773 if ( mReplaceRawFieldValues->checkState() != Qt::PartiallyChecked )
775 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
777 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->checkState() == Qt::Checked &&
778 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) &&
779 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->flags() & Qt::ItemIsEnabled )
781 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->setCheckState( mReplaceRawFieldValues->checkState() );
785 mReplaceRawFieldValues->setTristate(
false );
788void QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged( QTableWidgetItem *item )
790 const QSignalBlocker signalBlockerAttributeTable( mAttributeTable );
791 const QSignalBlocker signalBlockerReplaceRawFieldValues( mReplaceRawFieldValues );
793 int row = item->row();
794 int column = item->column();
796 switch (
static_cast<ColumnIndex
>( column ) )
798 case ColumnIndex::Name:
800 if ( mAttributeTable->isColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) ||
801 ! mAttributeTable->item( row,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) ||
802 !( mAttributeTable->item( row,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->flags() & Qt::ItemIsUserCheckable ) )
805 if ( mAttributeTable->item( row, column )->checkState() == Qt::Unchecked )
807 mAttributeTable->item( row,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->setCheckState( Qt::Unchecked );
808 mAttributeTable->item( row,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->setFlags( Qt::ItemIsUserCheckable );
809 bool checkBoxEnabled =
false;
810 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
812 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) &&
813 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->flags() & Qt::ItemIsEnabled )
815 checkBoxEnabled =
true;
819 mReplaceRawFieldValues->setEnabled( checkBoxEnabled );
820 if ( !checkBoxEnabled )
821 mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
823 else if ( mAttributeTable->item( row, column )->checkState() == Qt::Checked )
825 mAttributeTable->item( row,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
826 mReplaceRawFieldValues->setEnabled(
true );
830 case ColumnIndex::ExportName:
833 if ( item->text().isEmpty() )
835 QMessageBox::warning(
this,
836 tr(
"Empty export name" ),
837 tr(
"Empty export name are not allowed." ) );
843 while ( names.count( item->text() ) > 1 )
844 item->setText( QString(
"%1_2" ).arg( item->text() ) );
846 mUseAliasesForExportedName->setCheckState( Qt::PartiallyChecked );
849 case ColumnIndex::Type:
852 case ColumnIndex::ExportAsDisplayedValue:
854 if ( mAttributeTable->item( row, column )->flags() & Qt::ItemIsUserCheckable )
856 bool allChecked =
true;
857 bool allUnchecked =
true;
858 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
860 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) &&
861 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->flags() & Qt::ItemIsEnabled )
863 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->checkState() == Qt::Unchecked )
866 allUnchecked =
false;
869 mReplaceRawFieldValues->setCheckState( ( !allChecked && !allUnchecked ) ? Qt::PartiallyChecked : ( allChecked ) ? Qt::Checked : Qt::Unchecked );
879 mExtentGroupBox->setOutputCrs( mSelectedCrs );
884 return mFilename->filePath();
889 return leLayername->text();
894 return mEncodingComboBox->currentText();
899 return mFormatComboBox->currentData().toString();
904 return mSelectedCrs.
srsid();
920 QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
924 switch ( it.value()->type )
929 QSpinBox *sb = mDatasourceOptionsGroupBox->findChild<QSpinBox *>( it.key() );
931 options << QStringLiteral(
"%1=%2" ).arg( it.key() ).arg( sb->value() );
938 QComboBox *cb = mDatasourceOptionsGroupBox->findChild<QComboBox *>( it.key() );
939 if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->
defaultValue )
940 options << QStringLiteral(
"%1=%2" ).arg( it.key(), cb->currentText() );
947 QLineEdit *le = mDatasourceOptionsGroupBox->findChild<QLineEdit *>( it.key() );
949 options << QStringLiteral(
"%1=%2" ).arg( it.key(), le->text() );
957 options << QStringLiteral(
"%1=%2" ).arg( it.key(), opt->
mValue );
964 QString plainText = mOgrDatasourceOptions->toPlainText().trimmed();
965 if ( !plainText.isEmpty() )
966 options += plainText.split(
'\n' );
979 QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
983 switch ( it.value()->type )
988 QSpinBox *sb = mLayerOptionsGroupBox->findChild<QSpinBox *>( it.key() );
990 options << QStringLiteral(
"%1=%2" ).arg( it.key() ).arg( sb->value() );
997 QComboBox *cb = mLayerOptionsGroupBox->findChild<QComboBox *>( it.key() );
998 if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->
defaultValue )
999 options << QStringLiteral(
"%1=%2" ).arg( it.key(), cb->currentText() );
1006 QLineEdit *le = mLayerOptionsGroupBox->findChild<QLineEdit *>( it.key() );
1008 options << QStringLiteral(
"%1=%2" ).arg( it.key(), le->text() );
1016 options << QStringLiteral(
"%1=%2" ).arg( it.key(), opt->
mValue );
1023 QString plainText = mOgrLayerOptions->toPlainText().trimmed();
1024 if ( !plainText.isEmpty() )
1025 options += plainText.split(
'\n' );
1034 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1036 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->checkState() == Qt::Checked )
1038 attributes.append( i );
1049 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1051 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->checkState() == Qt::Checked &&
1052 ! mAttributeTable->isColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) &&
1053 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->checkState() == Qt::Checked )
1055 attributes.append( i );
1064 QStringList exportNames;
1065 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1066 exportNames.append( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportName ) )->text() );
1073 return mAddToCanvas->isChecked() && mAddToCanvas->isEnabled();
1078 mAddToCanvas->setChecked( enabled );
1083 return mSymbologyExportComboBox->currentData().toInt();
1088 return mScaleWidget->scale();
1093 mMapCanvas = canvas;
1094 mScaleWidget->setMapCanvas( canvas );
1095 mScaleWidget->setShowCurrentScaleButton(
true );
1101 return mExtentGroupBox->isChecked();
1106 return mExtentGroupBox->outputExtent();
1116 return mSelectedOnly->isChecked();
1121 return mCheckPersistMetadata->isChecked();
1126 int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
1127 if ( currentIndexData == -1 )
1138 int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
1139 return currentIndexData == -1;
1144 return mForceMultiCheckBox->isChecked();
1149 mForceMultiCheckBox->setChecked( checked );
1154 return mIncludeZCheckBox->isChecked();
1159 return mActionOnExistingFile;
1164 mIncludeZCheckBox->setChecked( checked );
1167void QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged(
const QString &text )
1169 bool scaleEnabled =
true;
1170 if ( text == tr(
"No symbology" ) )
1172 scaleEnabled =
false;
1174 mScaleWidget->setEnabled( scaleEnabled );
1175 mScaleLabel->setEnabled( scaleEnabled );
1178void QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged(
int )
1184 mForceMultiCheckBox->setEnabled(
true );
1185 mIncludeZCheckBox->setEnabled(
true );
1189 mForceMultiCheckBox->setEnabled(
false );
1190 mForceMultiCheckBox->setChecked(
false );
1191 mIncludeZCheckBox->setEnabled(
false );
1192 mIncludeZCheckBox->setChecked(
false );
1196void QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked()
1198 const QSignalBlocker signalBlockerAttributeTable( mAttributeTable );
1199 const QSignalBlocker signalBlockerReplaceRawFieldValues( mReplaceRawFieldValues );
1201 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1203 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->flags() & Qt::ItemIsEnabled )
1205 if ( ! mAttributeTable->isColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) &&
1206 ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->flags() & Qt::ItemIsUserCheckable ) )
1208 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
1210 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->setCheckState( Qt::Checked );
1213 if ( ! mAttributeTable->isColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) )
1215 mReplaceRawFieldValues->setEnabled(
true );
1219void QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked()
1221 const QSignalBlocker signalBlockerAttributeTable( mAttributeTable );
1222 const QSignalBlocker signalBlockerReplaceRawFieldValues( mReplaceRawFieldValues );
1224 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1226 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->setCheckState( Qt::Unchecked );
1227 if ( ! mAttributeTable->isColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) &&
1228 ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->flags() & Qt::ItemIsUserCheckable ) )
1230 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->setFlags( Qt::ItemIsUserCheckable );
1231 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->setCheckState( Qt::Unchecked );
1234 if ( ! mAttributeTable->isColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) )
1236 mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
1237 mReplaceRawFieldValues->setEnabled(
false );
1241void QgsVectorLayerSaveAsDialog::showHelp()
1243 QgsHelp::openHelp( QStringLiteral(
"managing_data_source/create_layers.html#creating-new-layers-from-an-existing-layer" ) );
WkbType
The WKB type describes the number of dimensions a geometry has.
@ GeometryCollection
GeometryCollection.
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.
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(Qgis::WkbType 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.
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.
Qgis::WkbType geometryType() const
Returns the selected flat geometry type for the export.
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(Qgis::WkbType type) SIP_HOLDGIL
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.