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 Q_FOREACH (
const QString &val, 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 Q_FOREACH ( LabelControlPair control, controls )
552 datasourceLayout->addRow( control.first, control.second );
557 mDatasourceOptionsGroupBox->setVisible(
false );
562 mLayerOptionsGroupBox->setVisible(
true );
563 QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.
layerOptions );
565 QFormLayout *layerOptionsLayout =
dynamic_cast<QFormLayout *
>( mLayerOptionsGroupBox->layout() );
567 Q_FOREACH ( LabelControlPair control, controls )
569 layerOptionsLayout->addRow( control.first, control.second );
574 mLayerOptionsGroupBox->setVisible(
false );
579 mEncodingComboBox->setEnabled(
true );
586 mEncodingComboBox->setCurrentIndex( idx );
587 mEncodingComboBox->setDisabled(
true );
591 mEncodingComboBox->setEnabled(
true );
598 mEncodingComboBox->setEnabled(
true );
602 void QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged(
int )
604 if ( !mReplaceRawFieldValuesStateChangedSlotEnabled )
606 if ( mAttributeTable->columnCount() != 3 )
608 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
609 mAttributeTableItemChangedSlotEnabled =
false;
610 if ( mReplaceRawFieldValues->checkState() != Qt::PartiallyChecked )
612 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
614 if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked &&
615 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
616 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
618 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( mReplaceRawFieldValues->checkState() );
622 mReplaceRawFieldValues->setTristate(
false );
623 mAttributeTableItemChangedSlotEnabled =
true;
624 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
627 void QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged( QTableWidgetItem *item )
629 if ( !mAttributeTableItemChangedSlotEnabled )
631 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
632 mAttributeTableItemChangedSlotEnabled =
false;
633 int row = item->row();
634 int column = item->column();
635 if ( column == COLUMN_IDX_NAME &&
636 mAttributeTable->item( row, column )->checkState() == Qt::Unchecked &&
637 mAttributeTable->columnCount() == 3 &&
638 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
639 ( mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
641 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( Qt::Unchecked );
642 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable );
643 bool checkBoxEnabled =
false;
644 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
646 if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
647 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
649 checkBoxEnabled =
true;
653 mReplaceRawFieldValues->setEnabled( checkBoxEnabled );
654 if ( !checkBoxEnabled )
655 mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
657 else if ( column == COLUMN_IDX_NAME &&
658 mAttributeTable->item( row, column )->checkState() == Qt::Checked &&
659 mAttributeTable->columnCount() == 3 &&
660 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
661 ( mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
663 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
664 mReplaceRawFieldValues->setEnabled(
true );
666 else if ( column == COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE &&
667 ( mAttributeTable->item( row, column )->flags() & Qt::ItemIsUserCheckable ) )
669 bool allChecked =
true;
670 bool allUnchecked =
true;
671 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
673 if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
674 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
676 if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->checkState() == Qt::Unchecked )
679 allUnchecked =
false;
682 mReplaceRawFieldValues->setCheckState( ( !allChecked && !allUnchecked ) ? Qt::PartiallyChecked : ( allChecked ) ? Qt::Checked : Qt::Unchecked );
684 mAttributeTableItemChangedSlotEnabled =
true;
685 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
691 mExtentGroupBox->setOutputCrs( crs );
696 return mFilename->filePath();
701 return leLayername->text();
706 return mEncodingComboBox->currentText();
711 return mFormatComboBox->currentData().toString();
727 QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
731 switch ( it.value()->type )
736 QSpinBox *sb = mDatasourceOptionsGroupBox->findChild<QSpinBox *>( it.key() );
738 options << QStringLiteral(
"%1=%2" ).arg( it.key() ).arg( sb->value() );
745 QComboBox *cb = mDatasourceOptionsGroupBox->findChild<QComboBox *>( it.key() );
746 if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->
defaultValue )
747 options << QStringLiteral(
"%1=%2" ).arg( it.key(), cb->currentText() );
754 QLineEdit *le = mDatasourceOptionsGroupBox->findChild<QLineEdit *>( it.key() );
756 options << QStringLiteral(
"%1=%2" ).arg( it.key(), le->text() );
764 options << QStringLiteral(
"%1=%2" ).arg( it.key(), opt->
mValue );
771 QString plainText = mOgrDatasourceOptions->toPlainText().trimmed();
772 if ( !plainText.isEmpty() )
773 options += plainText.split(
'\n' );
786 QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
790 switch ( it.value()->type )
795 QSpinBox *sb = mLayerOptionsGroupBox->findChild<QSpinBox *>( it.key() );
797 options << QStringLiteral(
"%1=%2" ).arg( it.key() ).arg( sb->value() );
804 QComboBox *cb = mLayerOptionsGroupBox->findChild<QComboBox *>( it.key() );
805 if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->
defaultValue )
806 options << QStringLiteral(
"%1=%2" ).arg( it.key(), cb->currentText() );
813 QLineEdit *le = mLayerOptionsGroupBox->findChild<QLineEdit *>( it.key() );
815 options << QStringLiteral(
"%1=%2" ).arg( it.key(), le->text() );
823 options << QStringLiteral(
"%1=%2" ).arg( it.key(), opt->
mValue );
830 QString plainText = mOgrLayerOptions->toPlainText().trimmed();
831 if ( !plainText.isEmpty() )
832 options += plainText.split(
'\n' );
841 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
843 if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked )
845 attributes.append( i );
856 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
858 if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked &&
859 mAttributeTable->columnCount() == 3 &&
860 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->checkState() == Qt::Checked )
862 attributes.append( i );
871 return mAddToCanvas->isChecked();
876 mAddToCanvas->setChecked( enabled );
881 return mSymbologyExportComboBox->currentData().toInt();
886 return mScaleWidget->scale();
892 mScaleWidget->setMapCanvas( canvas );
893 mScaleWidget->setShowCurrentScaleButton(
true );
899 return mExtentGroupBox->isChecked();
904 return mExtentGroupBox->outputExtent();
909 mSelectedOnly->setChecked( onlySelected );
914 return mSelectedOnly->isChecked();
919 int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
920 if ( currentIndexData == -1 )
931 int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
932 return currentIndexData == -1;
937 return mForceMultiCheckBox->isChecked();
942 mForceMultiCheckBox->setChecked( checked );
947 return mIncludeZCheckBox->isChecked();
952 return mActionOnExistingFile;
957 mIncludeZCheckBox->setChecked( checked );
960 void QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged(
const QString &text )
962 bool scaleEnabled =
true;
963 if ( text == tr(
"No symbology" ) )
965 scaleEnabled =
false;
967 mScaleWidget->setEnabled( scaleEnabled );
968 mScaleLabel->setEnabled( scaleEnabled );
971 void QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged(
int index )
973 int currentIndexData = mGeometryTypeComboBox->itemData( index ).toInt();
977 mForceMultiCheckBox->setEnabled(
true );
978 mIncludeZCheckBox->setEnabled(
true );
982 mForceMultiCheckBox->setEnabled(
false );
983 mForceMultiCheckBox->setChecked(
false );
984 mIncludeZCheckBox->setEnabled(
false );
985 mIncludeZCheckBox->setChecked(
false );
989 void QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked()
991 mAttributeTableItemChangedSlotEnabled =
false;
992 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
993 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
995 if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->flags() & Qt::ItemIsEnabled )
997 if ( mAttributeTable->columnCount() == 3 &&
998 ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
1000 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
1002 mAttributeTable->item( i, COLUMN_IDX_NAME )->setCheckState( Qt::Checked );
1005 if ( mAttributeTable->columnCount() == 3 )
1007 mReplaceRawFieldValues->setEnabled(
true );
1009 mAttributeTableItemChangedSlotEnabled =
true;
1010 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
1013 void QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked()
1015 mAttributeTableItemChangedSlotEnabled =
false;
1016 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
1017 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1019 mAttributeTable->item( i, COLUMN_IDX_NAME )->setCheckState( Qt::Unchecked );
1020 if ( mAttributeTable->columnCount() == 3 &&
1021 ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
1023 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable );
1024 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( Qt::Unchecked );
1027 if ( mAttributeTable->columnCount() == 3 )
1029 mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
1030 mReplaceRawFieldValues->setEnabled(
false );
1032 mAttributeTableItemChangedSlotEnabled =
true;
1033 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
1036 void QgsVectorLayerSaveAsDialog::showHelp()
1038 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)