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 QLabel *label =
new QLabel( it.key() );
240 QWidget *control =
nullptr;
241 switch ( option->
type )
248 QSpinBox *sb =
new QSpinBox();
249 sb->setObjectName( it.key() );
250 sb->setMaximum( std::numeric_limits<int>::max() );
262 QComboBox *cb =
new QComboBox();
263 cb->setObjectName( it.key() );
264 for (
const QString &val : std::as_const( opt->values ) )
266 cb->addItem( val, val );
269 cb->addItem( tr(
"<Default>" ), QVariant( QVariant::String ) );
272 idx = cb->findData( QVariant( QVariant::String ) );
273 cb->setCurrentIndex( idx );
285 le->setObjectName( it.key() );
299 label->setToolTip( QStringLiteral(
"<p>%1</p>" ).arg( option->
docString.toHtmlEscaped() ) );
300 control->setToolTip( QStringLiteral(
"<p>%1</p>" ).arg( option->
docString.toHtmlEscaped() ) );
302 controls << QPair<QLabel *, QWidget *>( label, control );
309void QgsVectorLayerSaveAsDialog::accept()
313 QgsVectorFileWriter::EditionCapabilities caps =
318 msgBox.setIcon( QMessageBox::Question );
319 msgBox.setWindowTitle( tr(
"Save Vector Layer As" ) );
320 QPushButton *overwriteFileButton = msgBox.addButton( tr(
"Overwrite File" ), QMessageBox::ActionRole );
321 QPushButton *overwriteLayerButton = msgBox.addButton( tr(
"Overwrite Layer" ), QMessageBox::ActionRole );
322 QPushButton *appendToLayerButton = msgBox.addButton( tr(
"Append to Layer" ), QMessageBox::ActionRole );
323 msgBox.setStandardButtons( QMessageBox::Cancel );
324 msgBox.setDefaultButton( QMessageBox::Cancel );
325 overwriteFileButton->hide();
326 overwriteLayerButton->hide();
327 appendToLayerButton->hide();
334 msgBox.setText( tr(
"The layer already exists. Do you want to overwrite the whole file or overwrite the layer?" ) );
335 overwriteFileButton->setVisible(
true );
336 overwriteLayerButton->setVisible(
true );
340 msgBox.setText( tr(
"The file already exists. Do you want to overwrite it?" ) );
341 overwriteFileButton->setVisible(
true );
346 msgBox.setText( tr(
"The layer already exists. Do you want to overwrite the whole file, overwrite the layer or append features to the layer?" ) );
347 appendToLayerButton->setVisible(
true );
348 overwriteFileButton->setVisible(
true );
349 overwriteLayerButton->setVisible(
true );
353 msgBox.setText( tr(
"The layer already exists. Do you want to overwrite the whole file or append features to the layer?" ) );
354 appendToLayerButton->setVisible(
true );
355 overwriteFileButton->setVisible(
true );
358 int ret = msgBox.exec();
359 if ( ret == QMessageBox::Cancel )
361 if ( msgBox.clickedButton() == overwriteFileButton )
363 else if ( msgBox.clickedButton() == overwriteLayerButton )
365 else if ( msgBox.clickedButton() == appendToLayerButton )
377 if ( QMessageBox::question(
this,
378 tr(
"Save Vector Layer As" ),
379 tr(
"The file already exists. Do you want to overwrite it?" ) ) == QMessageBox::NoButton )
392 if ( QMessageBox::question(
this,
393 tr(
"Save Vector Layer As" ),
394 tr(
"The existing layer has additional fields. Do you want to add the missing fields to the layer?" ) ) == QMessageBox::Yes )
403 QStringList layerList;
404 layerList.reserve( sublayers.size() );
407 layerList.append( sublayer.name() );
409 if ( layerList.length() > 1 )
411 layerList.sort( Qt::CaseInsensitive );
413 msgBox.setIcon( QMessageBox::Warning );
414 msgBox.setWindowTitle( tr(
"Overwrite File" ) );
415 msgBox.setText( tr(
"This file contains %1 layers that will be lost!\n" ).arg( QLocale().toString( layerList.length() ) ) );
416 msgBox.setDetailedText( tr(
"The following layers will be permanently lost:\n\n%1" ).arg( layerList.join(
"\n" ) ) );
417 msgBox.setStandardButtons( QMessageBox::Ok | QMessageBox::Cancel );
418 if ( msgBox.exec() == QMessageBox::Cancel )
424 settings.
setValue( QStringLiteral(
"UI/lastVectorFileFilterDir" ), QFileInfo(
filename() ).absolutePath() );
425 settings.
setValue( QStringLiteral(
"UI/lastVectorFormat" ),
format() );
430void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged(
int idx )
434 mFilename->setEnabled(
true );
439 if ( !mFilename->filePath().isEmpty() )
441 QRegularExpression rx(
"\\.(.*?)[\\s]" );
444 if ( !ext.isEmpty() )
446 QFileInfo fi( mFilename->filePath() );
447 mFilename->setFilePath( QStringLiteral(
"%1/%2.%3" ).arg( fi.path() ).arg( fi.baseName() ).arg( ext ) );
451 bool selectAllFields =
true;
456 bool isFormatForFieldsAsDisplayedValues =
false;
458 const QString sFormat(
format() );
459 if ( sFormat == QLatin1String(
"DXF" ) || sFormat == QLatin1String(
"DGN" ) )
461 mAttributesSelection->setVisible(
false );
462 selectAllFields =
false;
468 mAttributesSelection->setVisible(
true );
469 isFormatForFieldsAsDisplayedValues = ( sFormat == QLatin1String(
"CSV" ) ||
470 sFormat == QLatin1String(
"XLS" ) ||
471 sFormat == QLatin1String(
"XLSX" ) ||
472 sFormat == QLatin1String(
"ODS" ) );
479 mSymbologyExportLabel->setVisible(
true );
480 mSymbologyExportComboBox->setVisible(
true );
481 mScaleLabel->setVisible(
true );
482 mScaleWidget->setVisible(
true );
486 mSymbologyExportLabel->hide();
487 mSymbologyExportComboBox->hide();
489 mScaleWidget->hide();
492 leLayername->setEnabled( sFormat == QLatin1String(
"KML" ) ||
493 sFormat == QLatin1String(
"GPKG" ) ||
494 sFormat == QLatin1String(
"XLSX" ) ||
495 sFormat == QLatin1String(
"ODS" ) ||
496 sFormat == QLatin1String(
"FileGDB" ) ||
497 sFormat == QLatin1String(
"OpenFileGDB" ) ||
498 sFormat == QLatin1String(
"SQLite" ) ||
499 sFormat == QLatin1String(
"SpatiaLite" ) );
501 if ( sFormat == QLatin1String(
"XLSX" ) )
502 leLayername->setMaxLength( 31 );
503 else if ( leLayername->isEnabled() )
504 leLayername->setMaxLength( 32767 );
506 if ( !leLayername->isEnabled() )
507 leLayername->setText( QString() );
508 else if ( leLayername->text().isEmpty() )
510 QString layerName = mDefaultOutputLayerNameFromInputLayerName;
511 if ( layerName.isEmpty() && !mFilename->filePath().isEmpty() )
513 layerName = QFileInfo( mFilename->filePath() ).baseName();
514 leLayername->setDefaultValue( layerName );
516 if ( layerName.isEmpty() )
517 layerName = tr(
"new_layer" );
518 leLayername->setText( layerName );
523 mAttributeTable->setRowCount( mLayer->
fields().
count() );
525 QStringList horizontalHeaders = QStringList() << tr(
"Name" ) << tr(
"Export name" ) << tr(
"Type" ) << tr(
"Replace with displayed values" );
526 mAttributeTable->setColumnCount( horizontalHeaders.size() );
527 mAttributeTable->setHorizontalHeaderLabels( horizontalHeaders );
529 bool foundFieldThatCanBeExportedAsDisplayedValue =
false;
530 for (
int i = 0; i < mLayer->
fields().size(); ++i )
533 if ( setup.
type() != QLatin1String(
"TextEdit" ) &&
536 foundFieldThatCanBeExportedAsDisplayedValue =
true;
540 mAttributeTable->setColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ),
541 ! foundFieldThatCanBeExportedAsDisplayedValue );
543 bool checkReplaceRawFieldValues = selectAllFields && isFormatForFieldsAsDisplayedValues;
544 const QSignalBlocker signalBlockerAttributeTable( mAttributeTable );
546 for (
int i = 0; i < mLayer->
fields().size(); ++i )
549 Qt::ItemFlags flags = mLayer->
providerType() != QLatin1String(
"oracle" ) || !fld.
typeName().contains( QLatin1String(
"SDO_GEOMETRY" ) ) ? Qt::ItemIsEnabled : Qt::NoItemFlags;
550 QTableWidgetItem *item =
nullptr;
551 item =
new QTableWidgetItem( fld.
name() );
552 item->setFlags( flags | Qt::ItemIsUserCheckable );
553 item->setCheckState( ( selectAllFields ) ? Qt::Checked : Qt::Unchecked );
554 mAttributeTable->setItem( i,
static_cast<int>( ColumnIndex::Name ), item );
556 item =
new QTableWidgetItem( fld.
name() );
557 item->setFlags( flags | Qt::ItemIsEditable );
559 mAttributeTable->setItem( i,
static_cast<int>( ColumnIndex::ExportName ), item );
561 item =
new QTableWidgetItem( fld.
typeName() );
562 item->setFlags( flags );
563 mAttributeTable->setItem( i,
static_cast<int>( ColumnIndex::Type ), item );
565 if ( foundFieldThatCanBeExportedAsDisplayedValue )
569 const QString widgetId( setup.
type() );
570 if ( flags == Qt::ItemIsEnabled &&
571 widgetId != QLatin1String(
"TextEdit" ) &&
574 item =
new QTableWidgetItem( tr(
"Use %1" ).arg( factory->
name() ) );
575 item->setFlags( ( selectAllFields ) ? ( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable ) : Qt::ItemIsUserCheckable );
576 const bool checkItem = ( selectAllFields && isFormatForFieldsAsDisplayedValues &&
577 ( widgetId == QLatin1String(
"ValueMap" ) ||
578 widgetId == QLatin1String(
"ValueRelation" ) ||
579 widgetId == QLatin1String(
"CheckBox" ) ||
580 widgetId == QLatin1String(
"RelationReference" ) ) );
581 checkReplaceRawFieldValues &= checkItem;
582 item->setCheckState( checkItem ?
583 Qt::Checked : Qt::Unchecked );
584 mAttributeTable->setItem( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ), item );
588 item =
new QTableWidgetItem();
589 item->setFlags( Qt::NoItemFlags );
590 mAttributeTable->setItem( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ), item );
596 whileBlocking( mReplaceRawFieldValues )->setChecked( checkReplaceRawFieldValues );
597 mReplaceRawFieldValues->setEnabled( selectAllFields );
598 mReplaceRawFieldValues->setVisible( foundFieldThatCanBeExportedAsDisplayedValue );
600 mAttributeTable->resizeColumnsToContents();
605 while ( mDatasourceOptionsGroupBox->layout()->count() )
607 QLayoutItem *item = mDatasourceOptionsGroupBox->layout()->takeAt( 0 );
608 delete item->widget();
612 while ( mLayerOptionsGroupBox->layout()->count() )
614 QLayoutItem *item = mLayerOptionsGroupBox->layout()->takeAt( 0 );
615 delete item->widget();
619 typedef QPair<QLabel *, QWidget *> LabelControlPair;
625 mDatasourceOptionsGroupBox->setVisible(
true );
626 QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.
driverOptions );
628 QFormLayout *datasourceLayout =
dynamic_cast<QFormLayout *
>( mDatasourceOptionsGroupBox->layout() );
630 const auto constControls = controls;
631 for ( LabelControlPair control : constControls )
633 datasourceLayout->addRow( control.first, control.second );
638 mDatasourceOptionsGroupBox->setVisible(
false );
643 mLayerOptionsGroupBox->setVisible(
true );
644 QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.
layerOptions );
646 QFormLayout *layerOptionsLayout =
dynamic_cast<QFormLayout *
>( mLayerOptionsGroupBox->layout() );
648 const auto constControls = controls;
649 for ( LabelControlPair control : constControls )
651 layerOptionsLayout->addRow( control.first, control.second );
656 mLayerOptionsGroupBox->setVisible(
false );
661 mEncodingComboBox->setEnabled(
true );
668 mEncodingComboBox->setCurrentIndex( idx );
669 mEncodingComboBox->setDisabled(
true );
673 mEncodingComboBox->setEnabled(
true );
680 mEncodingComboBox->setEnabled(
true );
683 GDALDriverH hDriver = GDALGetDriverByName(
format().toUtf8().constData() );
686 mAddToCanvas->setEnabled( GDALGetMetadataItem( hDriver, GDAL_DCAP_OPEN,
nullptr ) !=
nullptr );
690void QgsVectorLayerSaveAsDialog::mUseAliasesForExportedName_stateChanged(
int state )
692 const QSignalBlocker signalBlocker( mAttributeTable );
699 bool modifiedEntries =
false;
700 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
702 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportName ) )->text()
703 != mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportName ) )->data( Qt::UserRole ).toString() )
705 modifiedEntries =
true;
710 if ( modifiedEntries )
712 if ( QMessageBox::question(
this,
713 tr(
"Modified names" ),
714 tr(
"Some names were modified and will be overridden. Do you want to continue?" ) )
717 whileBlocking( mUseAliasesForExportedName )->setCheckState( Qt::PartiallyChecked );
722 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
724 mUseAliasesForExportedName->setTristate(
false );
725 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportName ) )->setText( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->text() );
732 bool modifiedEntries =
false;
733 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
735 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportName ) )->text()
736 != mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->text() )
737 modifiedEntries =
true;
740 if ( modifiedEntries )
742 if ( QMessageBox::question(
this,
743 tr(
"Modified names" ),
744 tr(
"Some names were modified and will be overridden. Do you want to continue?" ) )
747 whileBlocking( mUseAliasesForExportedName )->setCheckState( Qt::PartiallyChecked );
752 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
754 mUseAliasesForExportedName->setTristate(
false );
755 const QString alias = mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportName ) )->data( Qt::UserRole ).toString();
756 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportName ) )->setText( alias );
760 case Qt::PartiallyChecked:
766void QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged(
int )
768 if ( mAttributeTable->isColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) )
771 const QSignalBlocker signalBlockerAttributeTable( mAttributeTable );
772 const QSignalBlocker signalBlockerReplaceRawFieldValues( mReplaceRawFieldValues );
774 if ( mReplaceRawFieldValues->checkState() != Qt::PartiallyChecked )
776 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
778 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->checkState() == Qt::Checked &&
779 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) &&
780 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->flags() & Qt::ItemIsEnabled )
782 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->setCheckState( mReplaceRawFieldValues->checkState() );
786 mReplaceRawFieldValues->setTristate(
false );
789void QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged( QTableWidgetItem *item )
791 const QSignalBlocker signalBlockerAttributeTable( mAttributeTable );
792 const QSignalBlocker signalBlockerReplaceRawFieldValues( mReplaceRawFieldValues );
794 int row = item->row();
795 int column = item->column();
797 switch (
static_cast<ColumnIndex
>( column ) )
799 case ColumnIndex::Name:
801 if ( mAttributeTable->isColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) ||
802 ! mAttributeTable->item( row,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) ||
803 !( mAttributeTable->item( row,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->flags() & Qt::ItemIsUserCheckable ) )
806 if ( mAttributeTable->item( row, column )->checkState() == Qt::Unchecked )
808 mAttributeTable->item( row,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->setCheckState( Qt::Unchecked );
809 mAttributeTable->item( row,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->setFlags( Qt::ItemIsUserCheckable );
810 bool checkBoxEnabled =
false;
811 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
813 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) &&
814 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->flags() & Qt::ItemIsEnabled )
816 checkBoxEnabled =
true;
820 mReplaceRawFieldValues->setEnabled( checkBoxEnabled );
821 if ( !checkBoxEnabled )
822 mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
824 else if ( mAttributeTable->item( row, column )->checkState() == Qt::Checked )
826 mAttributeTable->item( row,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
827 mReplaceRawFieldValues->setEnabled(
true );
831 case ColumnIndex::ExportName:
834 if ( item->text().isEmpty() )
836 QMessageBox::warning(
this,
837 tr(
"Empty export name" ),
838 tr(
"Empty export name are not allowed." ) );
844 while ( names.count( item->text() ) > 1 )
845 item->setText( QString(
"%1_2" ).arg( item->text() ) );
847 mUseAliasesForExportedName->setCheckState( Qt::PartiallyChecked );
850 case ColumnIndex::Type:
853 case ColumnIndex::ExportAsDisplayedValue:
855 if ( mAttributeTable->item( row, column )->flags() & Qt::ItemIsUserCheckable )
857 bool allChecked =
true;
858 bool allUnchecked =
true;
859 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
861 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) &&
862 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->flags() & Qt::ItemIsEnabled )
864 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->checkState() == Qt::Unchecked )
867 allUnchecked =
false;
870 mReplaceRawFieldValues->setCheckState( ( !allChecked && !allUnchecked ) ? Qt::PartiallyChecked : ( allChecked ) ? Qt::Checked : Qt::Unchecked );
880 mExtentGroupBox->setOutputCrs( mSelectedCrs );
885 return mFilename->filePath();
890 return leLayername->text();
895 return mEncodingComboBox->currentText();
900 return mFormatComboBox->currentData().toString();
905 return mSelectedCrs.
srsid();
921 QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
925 switch ( it.value()->type )
930 QSpinBox *sb = mDatasourceOptionsGroupBox->findChild<QSpinBox *>( it.key() );
932 options << QStringLiteral(
"%1=%2" ).arg( it.key() ).arg( sb->value() );
939 QComboBox *cb = mDatasourceOptionsGroupBox->findChild<QComboBox *>( it.key() );
940 if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->
defaultValue )
941 options << QStringLiteral(
"%1=%2" ).arg( it.key(), cb->currentText() );
948 QLineEdit *le = mDatasourceOptionsGroupBox->findChild<QLineEdit *>( it.key() );
950 options << QStringLiteral(
"%1=%2" ).arg( it.key(), le->text() );
958 options << QStringLiteral(
"%1=%2" ).arg( it.key(), opt->
mValue );
965 QString plainText = mOgrDatasourceOptions->toPlainText().trimmed();
966 if ( !plainText.isEmpty() )
967 options += plainText.split(
'\n' );
980 QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
984 switch ( it.value()->type )
989 QSpinBox *sb = mLayerOptionsGroupBox->findChild<QSpinBox *>( it.key() );
991 options << QStringLiteral(
"%1=%2" ).arg( it.key() ).arg( sb->value() );
998 QComboBox *cb = mLayerOptionsGroupBox->findChild<QComboBox *>( it.key() );
999 if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->
defaultValue )
1000 options << QStringLiteral(
"%1=%2" ).arg( it.key(), cb->currentText() );
1007 QLineEdit *le = mLayerOptionsGroupBox->findChild<QLineEdit *>( it.key() );
1009 options << QStringLiteral(
"%1=%2" ).arg( it.key(), le->text() );
1017 options << QStringLiteral(
"%1=%2" ).arg( it.key(), opt->
mValue );
1024 QString plainText = mOgrLayerOptions->toPlainText().trimmed();
1025 if ( !plainText.isEmpty() )
1026 options += plainText.split(
'\n' );
1035 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1037 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->checkState() == Qt::Checked )
1039 attributes.append( i );
1050 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1052 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->checkState() == Qt::Checked &&
1053 ! mAttributeTable->isColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) &&
1054 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->checkState() == Qt::Checked )
1056 attributes.append( i );
1065 QStringList exportNames;
1066 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1067 exportNames.append( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportName ) )->text() );
1074 return mAddToCanvas->isChecked() && mAddToCanvas->isEnabled();
1079 mAddToCanvas->setChecked( enabled );
1084 return mSymbologyExportComboBox->currentData().toInt();
1089 return mScaleWidget->scale();
1094 mMapCanvas = canvas;
1095 mScaleWidget->setMapCanvas( canvas );
1096 mScaleWidget->setShowCurrentScaleButton(
true );
1102 return mExtentGroupBox->isChecked();
1107 return mExtentGroupBox->outputExtent();
1117 return mSelectedOnly->isChecked();
1122 return mCheckPersistMetadata->isChecked();
1127 int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
1128 if ( currentIndexData == -1 )
1139 int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
1140 return currentIndexData == -1;
1145 return mForceMultiCheckBox->isChecked();
1150 mForceMultiCheckBox->setChecked( checked );
1155 return mIncludeZCheckBox->isChecked();
1160 return mActionOnExistingFile;
1165 mIncludeZCheckBox->setChecked( checked );
1168void QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged(
const QString &text )
1170 bool scaleEnabled =
true;
1171 if ( text == tr(
"No symbology" ) )
1173 scaleEnabled =
false;
1175 mScaleWidget->setEnabled( scaleEnabled );
1176 mScaleLabel->setEnabled( scaleEnabled );
1179void QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged(
int index )
1181 int currentIndexData = mGeometryTypeComboBox->itemData( index ).toInt();
1185 mForceMultiCheckBox->setEnabled(
true );
1186 mIncludeZCheckBox->setEnabled(
true );
1190 mForceMultiCheckBox->setEnabled(
false );
1191 mForceMultiCheckBox->setChecked(
false );
1192 mIncludeZCheckBox->setEnabled(
false );
1193 mIncludeZCheckBox->setChecked(
false );
1197void QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked()
1199 const QSignalBlocker signalBlockerAttributeTable( mAttributeTable );
1200 const QSignalBlocker signalBlockerReplaceRawFieldValues( mReplaceRawFieldValues );
1202 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1204 if ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->flags() & Qt::ItemIsEnabled )
1206 if ( ! mAttributeTable->isColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) &&
1207 ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->flags() & Qt::ItemIsUserCheckable ) )
1209 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
1211 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->setCheckState( Qt::Checked );
1214 if ( ! mAttributeTable->isColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) )
1216 mReplaceRawFieldValues->setEnabled(
true );
1220void QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked()
1222 const QSignalBlocker signalBlockerAttributeTable( mAttributeTable );
1223 const QSignalBlocker signalBlockerReplaceRawFieldValues( mReplaceRawFieldValues );
1225 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1227 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::Name ) )->setCheckState( Qt::Unchecked );
1228 if ( ! mAttributeTable->isColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) &&
1229 ( mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->flags() & Qt::ItemIsUserCheckable ) )
1231 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->setFlags( Qt::ItemIsUserCheckable );
1232 mAttributeTable->item( i,
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) )->setCheckState( Qt::Unchecked );
1235 if ( ! mAttributeTable->isColumnHidden(
static_cast<int>( ColumnIndex::ExportAsDisplayedValue ) ) )
1237 mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
1238 mReplaceRawFieldValues->setEnabled(
false );
1242void QgsVectorLayerSaveAsDialog::showHelp()
1244 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.