29 #include <QMessageBox> 30 #include <QFileDialog> 34 static const int COLUMN_IDX_NAME = 0;
35 static const int COLUMN_IDX_TYPE = 1;
36 static const int COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE = 2;
39 : QDialog( parent, fl )
41 , mAttributeTableItemChangedSlotEnabled( true )
42 , mReplaceRawFieldValuesStateChangedSlotEnabled( true )
49 : QDialog( parent, fl )
51 , mAttributeTableItemChangedSlotEnabled( true )
52 , mReplaceRawFieldValuesStateChangedSlotEnabled( true )
54 , mOptions( static_cast<
Options >( options ) )
59 mLayerExtent = layer->
extent();
65 mSymbologyExportLabel->hide();
66 mSymbologyExportComboBox->hide();
76 if ( !( mOptions &
Fields ) )
77 mAttributesSelection->hide();
80 mSelectedOnly->hide();
86 mGeometryGroupBox->hide();
88 if ( !( mOptions &
Extent ) )
89 mExtentGroupBox->hide();
92 mButtonBox->button( QDialogButtonBox::Ok )->setDisabled(
true );
95 void QgsVectorLayerSaveAsDialog::setup()
100 connect( mFormatComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged );
102 connect( mSymbologyExportComboBox,
static_cast<void ( QComboBox::* )(
const QString & )
>( &QComboBox::currentIndexChanged ),
this, &QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged );
103 connect( mGeometryTypeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged );
104 connect( mSelectAllAttributes, &QPushButton::clicked,
this, &QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked );
105 connect( mDeselectAllAttributes, &QPushButton::clicked,
this, &QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked );
106 connect( mReplaceRawFieldValues, &QCheckBox::stateChanged,
this, &QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged );
107 connect( mAttributeTable, &QTableWidget::itemChanged,
this, &QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged );
110 mHelpButtonBox->setVisible(
false );
111 mButtonBox->addButton( QDialogButtonBox::Help );
112 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorLayerSaveAsDialog::showHelp );
114 connect( mHelpButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorLayerSaveAsDialog::showHelp );
116 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QgsVectorLayerSaveAsDialog::accept );
117 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsVectorLayerSaveAsDialog::reject );
120 mFormatComboBox->blockSignals(
true );
123 mFormatComboBox->addItem( driver.longName, driver.driverName );
127 QString
format = settings.
value( QStringLiteral(
"UI/lastVectorFormat" ),
"GPKG" ).toString();
128 mFormatComboBox->setCurrentIndex( mFormatComboBox->findData( format ) );
129 mFormatComboBox->blockSignals(
false );
132 mGeometryTypeComboBox->addItem( tr(
"Automatic" ), -1 );
138 mGeometryTypeComboBox->setCurrentIndex( mGeometryTypeComboBox->findData( -1 ) );
142 QString enc = settings.
value( QStringLiteral(
"UI/encoding" ),
"System" ).toString();
143 int idx = mEncodingComboBox->findText( enc );
146 mEncodingComboBox->insertItem( 0, enc );
151 mCrsSelector->setCrs( srs );
152 mCrsSelector->setLayerCrs( srs );
153 mCrsSelector->setMessage( tr(
"Select the coordinate reference system for the vector file. " 154 "The data points will be transformed from the layer coordinate reference system." ) );
156 mEncodingComboBox->setCurrentIndex( idx );
157 mFormatComboBox_currentIndexChanged( mFormatComboBox->currentIndex() );
163 mSymbologyExportComboBox_currentIndexChanged( mSymbologyExportComboBox->currentText() );
166 mExtentGroupBox->setOutputCrs( srs );
167 mExtentGroupBox->setOriginalExtent( mLayerExtent, srs );
168 mExtentGroupBox->setOutputExtentFromOriginal();
169 mExtentGroupBox->setCheckable(
true );
170 mExtentGroupBox->setChecked(
false );
171 mExtentGroupBox->setCollapsed(
true );
174 mFilename->setDialogTitle( tr(
"Save Layer As" ) );
175 mFilename->setDefaultRoot( settings.
value( QStringLiteral(
"UI/lastVectorFileFilterDir" ), QDir::homePath() ).toString() );
176 mFilename->setConfirmOverwrite(
false );
180 QFileInfo tmplFileInfo( filePath );
181 settings.
setValue( QStringLiteral(
"UI/lastVectorFileFilterDir" ), tmplFileInfo.absolutePath() );
182 if ( !filePath.isEmpty() && leLayername->isEnabled() )
184 QFileInfo fileInfo( filePath );
185 leLayername->setText( fileInfo.baseName() );
187 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( !filePath.isEmpty() );
191 QList<QPair<QLabel *, QWidget *> > QgsVectorLayerSaveAsDialog::createControls(
const QMap<QString, QgsVectorFileWriter::Option *> &options )
193 QList<QPair<QLabel *, QWidget *> > controls;
194 QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
196 for ( it = options.constBegin(); it != options.constEnd(); ++it )
199 QLabel *label =
new QLabel( it.key() );
200 QWidget *control =
nullptr;
201 switch ( option->
type )
208 QSpinBox *sb =
new QSpinBox();
209 sb->setObjectName( it.key() );
221 QComboBox *cb =
new QComboBox();
222 cb->setObjectName( it.key() );
223 for (
const QString &val : qgis::as_const( opt->
values ) )
225 cb->addItem( val, val );
228 cb->addItem( tr(
"<Default>" ), QVariant( QVariant::String ) );
231 idx = cb->findData( QVariant( QVariant::String ) );
232 cb->setCurrentIndex( idx );
244 le->setObjectName( it.key() );
258 label->setToolTip( QStringLiteral(
"<p>%1</p>" ).arg( option->
docString ) );
259 control->setToolTip( QStringLiteral(
"<p>%1</p>" ).arg( option->
docString ) );
261 controls << QPair<QLabel *, QWidget *>( label, control );
268 void QgsVectorLayerSaveAsDialog::accept()
272 QgsVectorFileWriter::EditionCapabilities caps =
283 msgBox.setIcon( QMessageBox::Question );
284 msgBox.setWindowTitle( tr(
"Save Vector Layer As" ) );
285 msgBox.setText( tr(
"The layer already exists. Do you want to overwrite the whole file or overwrite the layer?" ) );
286 QPushButton *overwriteFileButton = msgBox.addButton( tr(
"Overwrite File" ), QMessageBox::ActionRole );
287 QPushButton *overwriteLayerButton = msgBox.addButton( tr(
"Overwrite Layer" ), QMessageBox::ActionRole );
288 msgBox.setStandardButtons( QMessageBox::Cancel );
289 msgBox.setDefaultButton( QMessageBox::Cancel );
290 int ret = msgBox.exec();
291 if ( ret == QMessageBox::Cancel )
293 if ( msgBox.clickedButton() == overwriteFileButton )
295 else if ( msgBox.clickedButton() == overwriteLayerButton )
298 else if ( !( caps & QgsVectorFileWriter::CanAppendToExistingLayer ) )
300 if ( QMessageBox::question(
this,
301 tr(
"Save Vector Layer As" ),
302 tr(
"The file already exists. Do you want to overwrite it?" ) ) == QMessageBox::NoButton )
308 else if ( ( caps & QgsVectorFileWriter::CanDeleteLayer ) &&
312 msgBox.setIcon( QMessageBox::Question );
313 msgBox.setWindowTitle( tr(
"Save Vector Layer As" ) );
314 msgBox.setText( tr(
"The layer already exists. Do you want to overwrite the whole file, overwrite the layer or append features to the layer?" ) );
315 QPushButton *overwriteFileButton = msgBox.addButton( tr(
"Overwrite File" ), QMessageBox::ActionRole );
316 QPushButton *overwriteLayerButton = msgBox.addButton( tr(
"Overwrite Layer" ), QMessageBox::ActionRole );
317 QPushButton *appendToLayerButton = msgBox.addButton( tr(
"Append to Layer" ), QMessageBox::ActionRole );
318 msgBox.setStandardButtons( QMessageBox::Cancel );
319 msgBox.setDefaultButton( QMessageBox::Cancel );
320 int ret = msgBox.exec();
321 if ( ret == QMessageBox::Cancel )
323 if ( msgBox.clickedButton() == overwriteFileButton )
325 else if ( msgBox.clickedButton() == overwriteLayerButton )
327 else if ( msgBox.clickedButton() == appendToLayerButton )
333 msgBox.setIcon( QMessageBox::Question );
334 msgBox.setWindowTitle( tr(
"Save Vector Layer As" ) );
335 msgBox.setText( tr(
"The layer already exists. Do you want to overwrite the whole file or append features to the layer?" ) );
336 QPushButton *overwriteFileButton = msgBox.addButton( tr(
"Overwrite File" ), QMessageBox::ActionRole );
337 QPushButton *appendToLayerButton = msgBox.addButton( tr(
"Append to Layer" ), QMessageBox::ActionRole );
338 msgBox.setStandardButtons( QMessageBox::Cancel );
339 msgBox.setDefaultButton( QMessageBox::Cancel );
340 int ret = msgBox.exec();
341 if ( ret == QMessageBox::Cancel )
343 if ( msgBox.clickedButton() == overwriteFileButton )
345 else if ( msgBox.clickedButton() == appendToLayerButton )
356 if ( QMessageBox::question(
this,
357 tr(
"Save Vector Layer As" ),
358 tr(
"The existing layer has different fields. Do you want to add the missing fields to the layer?" ) ) == QMessageBox::Yes )
374 if ( QMessageBox::question(
this,
375 tr(
"Save Vector Layer As" ),
376 tr(
"The file already exists. Do you want to overwrite it?" ) ) == QMessageBox::NoButton )
386 settings.
setValue( QStringLiteral(
"UI/lastVectorFileFilterDir" ), QFileInfo(
filename() ).absolutePath() );
387 settings.
setValue( QStringLiteral(
"UI/lastVectorFormat" ),
format() );
392 void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged(
int idx )
396 mFilename->setEnabled(
true );
399 bool selectAllFields =
true;
400 bool fieldsAsDisplayedValues =
false;
402 const QString sFormat(
format() );
403 if ( sFormat == QLatin1String(
"DXF" ) || sFormat == QLatin1String(
"DGN" ) )
405 mAttributesSelection->setVisible(
false );
406 selectAllFields =
false;
411 mAttributesSelection->setVisible(
true );
412 fieldsAsDisplayedValues = ( sFormat == QLatin1String(
"CSV" ) || sFormat == QLatin1String(
"XLS" ) || sFormat == QLatin1String(
"XLSX" ) || sFormat == QLatin1String(
"ODS" ) );
418 mSymbologyExportLabel->setVisible(
true );
419 mSymbologyExportComboBox->setVisible(
true );
420 mScaleLabel->setVisible(
true );
421 mScaleWidget->setVisible(
true );
425 mSymbologyExportLabel->hide();
426 mSymbologyExportComboBox->hide();
428 mScaleWidget->hide();
431 leLayername->setEnabled( sFormat == QLatin1String(
"KML" ) ||
432 sFormat == QLatin1String(
"GPKG" ) ||
433 sFormat == QLatin1String(
"XLSX" ) ||
434 sFormat == QLatin1String(
"ODS" ) ||
435 sFormat == QLatin1String(
"FileGDB" ) ||
436 sFormat == QLatin1String(
"SQLite" ) ||
437 sFormat == QLatin1String(
"SpatiaLite" ) );
438 if ( !leLayername->isEnabled() )
439 leLayername->setText( QString() );
440 else if ( leLayername->text().isEmpty() &&
441 !mFilename->filePath().isEmpty() )
443 QString layerName = QFileInfo( mFilename->filePath() ).baseName();
444 leLayername->setText( layerName );
449 mAttributeTable->setRowCount( mLayer->
fields().
count() );
451 bool foundFieldThatCanBeExportedAsDisplayedValue =
false;
452 for (
int i = 0; i < mLayer->
fields().
size(); ++i )
455 if ( setup.
type() != QLatin1String(
"TextEdit" ) &&
458 foundFieldThatCanBeExportedAsDisplayedValue =
true;
462 if ( foundFieldThatCanBeExportedAsDisplayedValue )
464 mAttributeTable->setColumnCount( 3 );
465 mAttributeTable->setHorizontalHeaderLabels( QStringList() << tr(
"Name" ) << tr(
"Type" ) << tr(
"Replace with displayed values" ) );
469 mAttributeTable->setColumnCount( 2 );
470 mAttributeTable->setHorizontalHeaderLabels( QStringList() << tr(
"Name" ) << tr(
"Type" ) );
473 mAttributeTableItemChangedSlotEnabled =
false;
475 for (
int i = 0; i < mLayer->
fields().
size(); ++i )
478 Qt::ItemFlags flags = mLayer->
providerType() != QLatin1String(
"oracle" ) || !fld.
typeName().contains( QLatin1String(
"SDO_GEOMETRY" ) ) ? Qt::ItemIsEnabled : Qt::NoItemFlags;
479 QTableWidgetItem *item =
nullptr;
480 item =
new QTableWidgetItem( fld.
name() );
481 item->setFlags( flags | Qt::ItemIsUserCheckable );
482 item->setCheckState( ( selectAllFields ) ? Qt::Checked : Qt::Unchecked );
483 mAttributeTable->setItem( i, COLUMN_IDX_NAME, item );
485 item =
new QTableWidgetItem( fld.
typeName() );
486 item->setFlags( flags );
487 mAttributeTable->setItem( i, COLUMN_IDX_TYPE, item );
489 if ( foundFieldThatCanBeExportedAsDisplayedValue )
493 if ( flags == Qt::ItemIsEnabled &&
494 setup.
type() != QLatin1String(
"TextEdit" ) &&
497 item =
new QTableWidgetItem( tr(
"Use %1" ).arg( factory->
name() ) );
498 item->setFlags( ( selectAllFields ) ? ( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable ) : Qt::ItemIsUserCheckable );
499 item->setCheckState( ( selectAllFields && fieldsAsDisplayedValues ) ? Qt::Checked : Qt::Unchecked );
500 mAttributeTable->setItem( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE, item );
504 item =
new QTableWidgetItem();
505 item->setFlags( Qt::NoItemFlags );
506 mAttributeTable->setItem( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE, item );
511 mAttributeTableItemChangedSlotEnabled =
true;
513 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
514 mReplaceRawFieldValues->setChecked( selectAllFields && fieldsAsDisplayedValues );
515 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
516 mReplaceRawFieldValues->setEnabled( selectAllFields );
517 mReplaceRawFieldValues->setVisible( foundFieldThatCanBeExportedAsDisplayedValue );
519 mAttributeTable->resizeColumnsToContents();
524 while ( mDatasourceOptionsGroupBox->layout()->count() )
526 QLayoutItem *item = mDatasourceOptionsGroupBox->layout()->takeAt( 0 );
527 delete item->widget();
531 while ( mLayerOptionsGroupBox->layout()->count() )
533 QLayoutItem *item = mLayerOptionsGroupBox->layout()->takeAt( 0 );
534 delete item->widget();
539 typedef QPair<QLabel *, QWidget *> LabelControlPair;
545 mDatasourceOptionsGroupBox->setVisible(
true );
546 QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.
driverOptions );
548 QFormLayout *datasourceLayout =
dynamic_cast<QFormLayout *
>( mDatasourceOptionsGroupBox->layout() );
550 const auto constControls = controls;
551 for ( LabelControlPair control : constControls )
553 datasourceLayout->addRow( control.first, control.second );
558 mDatasourceOptionsGroupBox->setVisible(
false );
563 mLayerOptionsGroupBox->setVisible(
true );
564 QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.
layerOptions );
566 QFormLayout *layerOptionsLayout =
dynamic_cast<QFormLayout *
>( mLayerOptionsGroupBox->layout() );
568 const auto constControls = controls;
569 for ( LabelControlPair control : constControls )
571 layerOptionsLayout->addRow( control.first, control.second );
576 mLayerOptionsGroupBox->setVisible(
false );
581 mEncodingComboBox->setEnabled(
true );
588 mEncodingComboBox->setCurrentIndex( idx );
589 mEncodingComboBox->setDisabled(
true );
593 mEncodingComboBox->setEnabled(
true );
600 mEncodingComboBox->setEnabled(
true );
604 void QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged(
int )
606 if ( !mReplaceRawFieldValuesStateChangedSlotEnabled )
608 if ( mAttributeTable->columnCount() != 3 )
610 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
611 mAttributeTableItemChangedSlotEnabled =
false;
612 if ( mReplaceRawFieldValues->checkState() != Qt::PartiallyChecked )
614 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
616 if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked &&
617 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
618 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
620 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( mReplaceRawFieldValues->checkState() );
624 mReplaceRawFieldValues->setTristate(
false );
625 mAttributeTableItemChangedSlotEnabled =
true;
626 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
629 void QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged( QTableWidgetItem *item )
631 if ( !mAttributeTableItemChangedSlotEnabled )
633 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
634 mAttributeTableItemChangedSlotEnabled =
false;
635 int row = item->row();
636 int column = item->column();
637 if ( column == COLUMN_IDX_NAME &&
638 mAttributeTable->item( row, column )->checkState() == Qt::Unchecked &&
639 mAttributeTable->columnCount() == 3 &&
640 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
641 ( mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
643 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( Qt::Unchecked );
644 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable );
645 bool checkBoxEnabled =
false;
646 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
648 if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
649 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
651 checkBoxEnabled =
true;
655 mReplaceRawFieldValues->setEnabled( checkBoxEnabled );
656 if ( !checkBoxEnabled )
657 mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
659 else if ( column == COLUMN_IDX_NAME &&
660 mAttributeTable->item( row, column )->checkState() == Qt::Checked &&
661 mAttributeTable->columnCount() == 3 &&
662 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
663 ( mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
665 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
666 mReplaceRawFieldValues->setEnabled(
true );
668 else if ( column == COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE &&
669 ( mAttributeTable->item( row, column )->flags() & Qt::ItemIsUserCheckable ) )
671 bool allChecked =
true;
672 bool allUnchecked =
true;
673 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
675 if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
676 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
678 if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->checkState() == Qt::Unchecked )
681 allUnchecked =
false;
684 mReplaceRawFieldValues->setCheckState( ( !allChecked && !allUnchecked ) ? Qt::PartiallyChecked : ( allChecked ) ? Qt::Checked : Qt::Unchecked );
686 mAttributeTableItemChangedSlotEnabled =
true;
687 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
693 mExtentGroupBox->setOutputCrs( crs );
698 return mFilename->filePath();
703 return leLayername->text();
708 return mEncodingComboBox->currentText();
713 return mFormatComboBox->currentData().toString();
729 QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
733 switch ( it.value()->type )
738 QSpinBox *sb = mDatasourceOptionsGroupBox->findChild<QSpinBox *>( it.key() );
740 options << QStringLiteral(
"%1=%2" ).arg( it.key() ).arg( sb->value() );
747 QComboBox *cb = mDatasourceOptionsGroupBox->findChild<QComboBox *>( it.key() );
748 if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->
defaultValue )
749 options << QStringLiteral(
"%1=%2" ).arg( it.key(), cb->currentText() );
756 QLineEdit *le = mDatasourceOptionsGroupBox->findChild<QLineEdit *>( it.key() );
758 options << QStringLiteral(
"%1=%2" ).arg( it.key(), le->text() );
766 options << QStringLiteral(
"%1=%2" ).arg( it.key(), opt->
mValue );
773 QString plainText = mOgrDatasourceOptions->toPlainText().trimmed();
774 if ( !plainText.isEmpty() )
775 options += plainText.split(
'\n' );
788 QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
792 switch ( it.value()->type )
797 QSpinBox *sb = mLayerOptionsGroupBox->findChild<QSpinBox *>( it.key() );
799 options << QStringLiteral(
"%1=%2" ).arg( it.key() ).arg( sb->value() );
806 QComboBox *cb = mLayerOptionsGroupBox->findChild<QComboBox *>( it.key() );
807 if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->
defaultValue )
808 options << QStringLiteral(
"%1=%2" ).arg( it.key(), cb->currentText() );
815 QLineEdit *le = mLayerOptionsGroupBox->findChild<QLineEdit *>( it.key() );
817 options << QStringLiteral(
"%1=%2" ).arg( it.key(), le->text() );
825 options << QStringLiteral(
"%1=%2" ).arg( it.key(), opt->
mValue );
832 QString plainText = mOgrLayerOptions->toPlainText().trimmed();
833 if ( !plainText.isEmpty() )
834 options += plainText.split(
'\n' );
843 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
845 if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked )
847 attributes.append( i );
858 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
860 if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked &&
861 mAttributeTable->columnCount() == 3 &&
862 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->checkState() == Qt::Checked )
864 attributes.append( i );
873 return mAddToCanvas->isChecked();
878 mAddToCanvas->setChecked( enabled );
883 return mSymbologyExportComboBox->currentData().toInt();
888 return mScaleWidget->scale();
894 mScaleWidget->setMapCanvas( canvas );
895 mScaleWidget->setShowCurrentScaleButton(
true );
901 return mExtentGroupBox->isChecked();
906 return mExtentGroupBox->outputExtent();
911 mSelectedOnly->setChecked( onlySelected );
916 return mSelectedOnly->isChecked();
921 int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
922 if ( currentIndexData == -1 )
933 int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
934 return currentIndexData == -1;
939 return mForceMultiCheckBox->isChecked();
944 mForceMultiCheckBox->setChecked( checked );
949 return mIncludeZCheckBox->isChecked();
954 return mActionOnExistingFile;
959 mIncludeZCheckBox->setChecked( checked );
962 void QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged(
const QString &text )
964 bool scaleEnabled =
true;
965 if ( text == tr(
"No symbology" ) )
967 scaleEnabled =
false;
969 mScaleWidget->setEnabled( scaleEnabled );
970 mScaleLabel->setEnabled( scaleEnabled );
973 void QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged(
int index )
975 int currentIndexData = mGeometryTypeComboBox->itemData( index ).toInt();
979 mForceMultiCheckBox->setEnabled(
true );
980 mIncludeZCheckBox->setEnabled(
true );
984 mForceMultiCheckBox->setEnabled(
false );
985 mForceMultiCheckBox->setChecked(
false );
986 mIncludeZCheckBox->setEnabled(
false );
987 mIncludeZCheckBox->setChecked(
false );
991 void QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked()
993 mAttributeTableItemChangedSlotEnabled =
false;
994 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
995 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
997 if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->flags() & Qt::ItemIsEnabled )
999 if ( mAttributeTable->columnCount() == 3 &&
1000 ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
1002 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
1004 mAttributeTable->item( i, COLUMN_IDX_NAME )->setCheckState( Qt::Checked );
1007 if ( mAttributeTable->columnCount() == 3 )
1009 mReplaceRawFieldValues->setEnabled(
true );
1011 mAttributeTableItemChangedSlotEnabled =
true;
1012 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
1015 void QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked()
1017 mAttributeTableItemChangedSlotEnabled =
false;
1018 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
1019 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1021 mAttributeTable->item( i, COLUMN_IDX_NAME )->setCheckState( Qt::Unchecked );
1022 if ( mAttributeTable->columnCount() == 3 &&
1023 ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
1025 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable );
1026 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( Qt::Unchecked );
1029 if ( mAttributeTable->columnCount() == 3 )
1031 mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
1032 mReplaceRawFieldValues->setEnabled(
false );
1034 mAttributeTableItemChangedSlotEnabled =
true;
1035 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
1038 void QgsVectorLayerSaveAsDialog::showHelp()
1040 QgsHelp::openHelp( QStringLiteral(
"managing_data_source/create_layers.html#save-layer-from-an-existing-file" ) );
Append features to existing layer, but do not create new fields.
Flag to indicate that a new layer can be added to the dataset.
A rectangle specified with double values.
QgsVectorFileWriter::OptionType type
long crs() const
Returns the internal CRS ID.
Details of available driver formats.
QgsVectorLayerSaveAsDialog(long srsid, QWidget *parent=nullptr, Qt::WindowFlags fl=nullptr)
Construct a new QgsVectorLayerSaveAsDialog.
int size() const
Returns number of items.
Flag to indicate that new features can be added to an existing layer.
QString encoding() const
The encoding of the target file.
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.
int selectedFeatureCount() const
Returns the number of features that are selected in this layer.
QString providerType() const
Returns the provider type (provider key) for this layer.
Options
Bitmask of options to be shown.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
static bool supportsFeatureStyles(const QString &driverName)
Returns true if the specified driverName supports feature styles.
A convenience class for writing vector files to disk.
bool automaticGeometryType() const
Returns true if geometry type is set to automatic.
int count() const
Returns number of items.
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
Map canvas is a class for displaying all GIS data types on a canvas.
static QgsVectorFileWriter::EditionCapabilities editionCapabilities(const QString &datasetName)
Returns edition capabilities for an existing dataset name.
QgsRectangle filterExtent() const
Determines the extent to be exported.
void setIncludeZ(bool checked)
Sets whether the include z dimension checkbox should be checked.
QStringList layerOptions() const
Returns a list of additional layer options which are passed to OGR.
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
QgsVectorFileWriter::ActionOnExistingFile creationActionOnExistingFile() const
Returns creation action.
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
Show destination CRS (reprojection) option.
Create or overwrite file.
Type
The WKB type describes the number of dimensions a geometry has.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
QStringList datasourceOptions() const
Returns a list of additional data source options which are passed to OGR.
int symbologyExport() const
Returns type of symbology export.
QString typeName() const
Gets the field type.
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 QgsEditorWidgetRegistry * editorWidgetRegistry()
Returns the global editor widget registry, used for managing all known edit widget factories...
QgsAttributeList attributesAsDisplayedValues() const
Returns selected attributes that must be exported with their displayed values instead of their raw va...
Create or overwrite layer.
ActionOnExistingFile
Combination of CanAddNewLayer, CanAppendToExistingLayer, CanAddNewFieldsToExistingLayer or CanDeleteL...
Show field customization group.
Encapsulate a field in an attribute table or data source.
void setMapCanvas(QgsMapCanvas *canvas)
Sets a map canvas to associate with the dialog.
bool hasFilterExtent() const
Determines if filtering the export by an extent is activated.
QgsWkbTypes::Type geometryType() const
Returns the selected flat geometry type for the export.
QgsRectangle extent() const FINAL
Returns the extent of the layer.
QString layername() const
Returns the target layer name.
Append features to existing layer, and create new fields if needed.
void setForceMulti(bool checked)
Sets whether the force multi geometry checkbox should be checked.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
double scale() const
Returns the specified map scale.
QString format() const
The format in which the export should be written.
bool addToCanvas() const
Returns true if the "add to canvas" checkbox is checked.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
QgsAttributeList selectedAttributes() const
Returns a list of attributes which are selected for saving.
bool forceMulti() const
Returns true if force multi geometry type is checked.
static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList(VectorFormatOptions options=SortRecommended)
Returns the driver list that can be used for dialogs.
void setAddToCanvas(bool checked)
Sets whether the "add to canvas" checkbox should be checked.
Show selected features only option.
This class represents a coordinate reference system (CRS).
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.
bool onlySelected() const
Returns whether only selected features will be saved.
static QString displayString(Type type)
Returns a display string type for a WKB type, e.g., the geometry name used in WKT geometry representa...
Flag to indicate that an existing layer can be deleted.
QList< int > QgsAttributeList
static bool targetLayerExists(const QString &datasetName, const QString &layerName)
Returns whether the target layer already exists.
long srsid() const
Returns the internal CRS ID, if available.
Represents a vector layer which manages a vector based data sets.
bool includeZ() const
Returns true if include z dimension is checked.
static QString filterForDriver(const QString &driverName)
Creates a filter for an OGR driver key.
static QStringList availableEncodings()
Returns a list of available encodings.
QgsCoordinateReferenceSystem crs
static QgsCoordinateReferenceSystem fromSrsId(long srsId)
Creates a CRS from a specified QGIS SRS ID.
void setOnlySelected(bool onlySelected)
Sets whether only selected features will be saved.
QString filename() const
Returns the target filename.
static bool driverMetadata(const QString &driverName, MetaData &driverMetadata)