22 #include "qgsogrdataitems.h"
30 #include <QMessageBox>
31 #include <QFileDialog>
36 static const int COLUMN_IDX_NAME = 0;
37 static const int COLUMN_IDX_TYPE = 1;
38 static const int COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE = 2;
41 : QDialog( parent, fl )
43 , mAttributeTableItemChangedSlotEnabled( true )
44 , mReplaceRawFieldValuesStateChangedSlotEnabled( true )
51 : QDialog( parent, fl )
53 , mAttributeTableItemChangedSlotEnabled( true )
54 , mReplaceRawFieldValuesStateChangedSlotEnabled( true )
56 , mOptions( static_cast<
Options >( options ) )
60 mSelectedCrs = layer->
crs();
61 mLayerExtent = layer->
extent();
67 mSymbologyExportLabel->hide();
68 mSymbologyExportComboBox->hide();
78 if ( !( mOptions &
Fields ) )
79 mAttributesSelection->hide();
82 mSelectedOnly->hide();
88 mGeometryGroupBox->hide();
90 if ( !( mOptions &
Extent ) )
91 mExtentGroupBox->hide();
94 mButtonBox->button( QDialogButtonBox::Ok )->setDisabled(
true );
97 void QgsVectorLayerSaveAsDialog::setup()
102 connect( mFormatComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged );
104 connect( mSymbologyExportComboBox, &QComboBox::currentTextChanged,
this, &QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged );
105 connect( mGeometryTypeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged );
106 connect( mSelectAllAttributes, &QPushButton::clicked,
this, &QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked );
107 connect( mDeselectAllAttributes, &QPushButton::clicked,
this, &QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked );
108 connect( mReplaceRawFieldValues, &QCheckBox::stateChanged,
this, &QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged );
109 connect( mAttributeTable, &QTableWidget::itemChanged,
this, &QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged );
112 mHelpButtonBox->setVisible(
false );
113 mButtonBox->addButton( QDialogButtonBox::Help );
114 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorLayerSaveAsDialog::showHelp );
116 connect( mHelpButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorLayerSaveAsDialog::showHelp );
118 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QgsVectorLayerSaveAsDialog::accept );
119 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsVectorLayerSaveAsDialog::reject );
122 mFormatComboBox->blockSignals(
true );
125 mFormatComboBox->addItem( driver.longName, driver.driverName );
129 QString
format = settings.
value( QStringLiteral(
"UI/lastVectorFormat" ),
"GPKG" ).toString();
130 mFormatComboBox->setCurrentIndex( mFormatComboBox->findData(
format ) );
131 mFormatComboBox->blockSignals(
false );
134 mGeometryTypeComboBox->addItem( tr(
"Automatic" ), -1 );
140 mGeometryTypeComboBox->setCurrentIndex( mGeometryTypeComboBox->findData( -1 ) );
144 QString enc = settings.
value( QStringLiteral(
"UI/encoding" ),
"System" ).toString();
145 int idx = mEncodingComboBox->findText( enc );
148 mEncodingComboBox->insertItem( 0, enc );
152 mCrsSelector->setCrs( mSelectedCrs );
153 mCrsSelector->setLayerCrs( mSelectedCrs );
154 mCrsSelector->setMessage( tr(
"Select the coordinate reference system for the vector file. "
155 "The data points will be transformed from the layer coordinate reference system." ) );
157 mEncodingComboBox->setCurrentIndex( idx );
158 mFormatComboBox_currentIndexChanged( mFormatComboBox->currentIndex() );
164 mSymbologyExportComboBox_currentIndexChanged( mSymbologyExportComboBox->currentText() );
167 mExtentGroupBox->setOutputCrs( mSelectedCrs );
168 mExtentGroupBox->setOriginalExtent( mLayerExtent, mSelectedCrs );
169 mExtentGroupBox->setOutputExtentFromOriginal();
170 mExtentGroupBox->setCheckable(
true );
171 mExtentGroupBox->setChecked(
false );
172 mExtentGroupBox->setCollapsed(
true );
175 mFilename->setDialogTitle( tr(
"Save Layer As" ) );
176 mFilename->setDefaultRoot( settings.
value( QStringLiteral(
"UI/lastVectorFileFilterDir" ), QDir::homePath() ).toString() );
177 mFilename->setConfirmOverwrite(
false );
181 QFileInfo tmplFileInfo( filePath );
182 settings.
setValue( QStringLiteral(
"UI/lastVectorFileFilterDir" ), tmplFileInfo.absolutePath() );
183 if ( !filePath.isEmpty() && leLayername->isEnabled() )
185 QFileInfo fileInfo( filePath );
186 leLayername->setText( fileInfo.baseName() );
188 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( !filePath.isEmpty() );
192 QList<QPair<QLabel *, QWidget *> > QgsVectorLayerSaveAsDialog::createControls(
const QMap<QString, QgsVectorFileWriter::Option *> &options )
194 QList<QPair<QLabel *, QWidget *> > controls;
195 QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
197 for ( it = options.constBegin(); it != options.constEnd(); ++it )
200 QLabel *label =
new QLabel( it.key() );
201 QWidget *control =
nullptr;
202 switch ( option->
type )
209 QSpinBox *sb =
new QSpinBox();
210 sb->setObjectName( it.key() );
222 QComboBox *cb =
new QComboBox();
223 cb->setObjectName( it.key() );
224 for (
const QString &val : qgis::as_const( opt->
values ) )
226 cb->addItem( val, val );
229 cb->addItem( tr(
"<Default>" ), QVariant( QVariant::String ) );
232 idx = cb->findData( QVariant( QVariant::String ) );
233 cb->setCurrentIndex( idx );
245 le->setObjectName( it.key() );
259 label->setToolTip( QStringLiteral(
"<p>%1</p>" ).arg( option->
docString ) );
260 control->setToolTip( QStringLiteral(
"<p>%1</p>" ).arg( option->
docString ) );
262 controls << QPair<QLabel *, QWidget *>( label, control );
269 void QgsVectorLayerSaveAsDialog::accept()
273 QgsVectorFileWriter::EditionCapabilities caps =
278 msgBox.setIcon( QMessageBox::Question );
279 msgBox.setWindowTitle( tr(
"Save Vector Layer As" ) );
280 QPushButton *overwriteFileButton = msgBox.addButton( tr(
"Overwrite File" ), QMessageBox::ActionRole );
281 QPushButton *overwriteLayerButton = msgBox.addButton( tr(
"Overwrite Layer" ), QMessageBox::ActionRole );
282 QPushButton *appendToLayerButton = msgBox.addButton( tr(
"Append to Layer" ), QMessageBox::ActionRole );
283 msgBox.setStandardButtons( QMessageBox::Cancel );
284 msgBox.setDefaultButton( QMessageBox::Cancel );
285 overwriteFileButton->hide();
286 overwriteLayerButton->hide();
287 appendToLayerButton->hide();
294 msgBox.setText( tr(
"The layer already exists. Do you want to overwrite the whole file or overwrite the layer?" ) );
295 overwriteFileButton->setVisible(
true );
296 overwriteLayerButton->setVisible(
true );
300 msgBox.setText( tr(
"The file already exists. Do you want to overwrite it?" ) );
301 overwriteFileButton->setVisible(
true );
306 msgBox.setText( tr(
"The layer already exists. Do you want to overwrite the whole file, overwrite the layer or append features to the layer?" ) );
307 appendToLayerButton->setVisible(
true );
308 overwriteFileButton->setVisible(
true );
309 overwriteLayerButton->setVisible(
true );
313 msgBox.setText( tr(
"The layer already exists. Do you want to overwrite the whole file or append features to the layer?" ) );
314 appendToLayerButton->setVisible(
true );
315 overwriteFileButton->setVisible(
true );
318 int ret = msgBox.exec();
319 if ( ret == QMessageBox::Cancel )
321 if ( msgBox.clickedButton() == overwriteFileButton )
323 else if ( msgBox.clickedButton() == overwriteLayerButton )
325 else if ( msgBox.clickedButton() == appendToLayerButton )
337 if ( QMessageBox::question(
this,
338 tr(
"Save Vector Layer As" ),
339 tr(
"The file already exists. Do you want to overwrite it?" ) ) == QMessageBox::NoButton )
352 if ( QMessageBox::question(
this,
353 tr(
"Save Vector Layer As" ),
354 tr(
"The existing layer has additional fields. Do you want to add the missing fields to the layer?" ) ) == QMessageBox::Yes )
364 const QList<QgsOgrDbLayerInfo *> subLayers = QgsOgrLayerItem::subLayers(
filename(),
format() );
365 QStringList layerList;
366 for (
const QgsOgrDbLayerInfo *layer : subLayers )
368 layerList.append( layer->name() );
370 qDeleteAll( subLayers );
371 if ( layerList.length() > 1 )
373 layerList.sort( Qt::CaseInsensitive );
375 msgBox.setIcon( QMessageBox::Warning );
376 msgBox.setWindowTitle( tr(
"Overwrite File" ) );
377 msgBox.setText( tr(
"This file contains %1 layers that will be lost!\n" ).arg( QString::number( layerList.length() ) ) );
378 msgBox.setDetailedText( tr(
"The following layers will be permanently lost:\n\n%1" ).arg( layerList.join(
"\n" ) ) );
379 msgBox.setStandardButtons( QMessageBox::Ok | QMessageBox::Cancel );
380 if ( msgBox.exec() == QMessageBox::Cancel )
384 catch ( QgsOgrLayerNotValidException &ex )
386 QMessageBox::critical(
this,
387 tr(
"Save Vector Layer As" ),
388 tr(
"Error opening destination file: %1" ).arg( ex.what() ) );
394 settings.
setValue( QStringLiteral(
"UI/lastVectorFileFilterDir" ), QFileInfo(
filename() ).absolutePath() );
395 settings.
setValue( QStringLiteral(
"UI/lastVectorFormat" ),
format() );
400 void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged(
int idx )
404 mFilename->setEnabled(
true );
409 if ( !mFilename->filePath().isEmpty() )
411 QRegularExpression rx(
"\\.(.*?)[\\s]" );
414 if ( !ext.isEmpty() )
416 QFileInfo fi( mFilename->filePath() );
417 mFilename->setFilePath( QStringLiteral(
"%1/%2.%3" ).arg( fi.path() ).arg( fi.baseName() ).arg( ext ) );
421 bool selectAllFields =
true;
426 bool isFormatForFieldsAsDisplayedValues =
false;
428 const QString sFormat(
format() );
429 if ( sFormat == QLatin1String(
"DXF" ) || sFormat == QLatin1String(
"DGN" ) )
431 mAttributesSelection->setVisible(
false );
432 selectAllFields =
false;
438 mAttributesSelection->setVisible(
true );
439 isFormatForFieldsAsDisplayedValues = ( sFormat == QLatin1String(
"CSV" ) ||
440 sFormat == QLatin1String(
"XLS" ) ||
441 sFormat == QLatin1String(
"XLSX" ) ||
442 sFormat == QLatin1String(
"ODS" ) );
449 mSymbologyExportLabel->setVisible(
true );
450 mSymbologyExportComboBox->setVisible(
true );
451 mScaleLabel->setVisible(
true );
452 mScaleWidget->setVisible(
true );
456 mSymbologyExportLabel->hide();
457 mSymbologyExportComboBox->hide();
459 mScaleWidget->hide();
462 leLayername->setEnabled( sFormat == QLatin1String(
"KML" ) ||
463 sFormat == QLatin1String(
"GPKG" ) ||
464 sFormat == QLatin1String(
"XLSX" ) ||
465 sFormat == QLatin1String(
"ODS" ) ||
466 sFormat == QLatin1String(
"FileGDB" ) ||
467 sFormat == QLatin1String(
"SQLite" ) ||
468 sFormat == QLatin1String(
"SpatiaLite" ) );
469 if ( !leLayername->isEnabled() )
470 leLayername->setText( QString() );
471 else if ( leLayername->text().isEmpty() &&
472 !mFilename->filePath().isEmpty() )
474 QString layerName = QFileInfo( mFilename->filePath() ).baseName();
475 leLayername->setText( layerName );
480 mAttributeTable->setRowCount( mLayer->
fields().
count() );
482 bool foundFieldThatCanBeExportedAsDisplayedValue =
false;
483 for (
int i = 0; i < mLayer->
fields().size(); ++i )
486 if ( setup.
type() != QLatin1String(
"TextEdit" ) &&
489 foundFieldThatCanBeExportedAsDisplayedValue =
true;
493 if ( foundFieldThatCanBeExportedAsDisplayedValue )
495 mAttributeTable->setColumnCount( 3 );
496 mAttributeTable->setHorizontalHeaderLabels( QStringList() << tr(
"Name" ) << tr(
"Type" ) << tr(
"Replace with displayed values" ) );
500 mAttributeTable->setColumnCount( 2 );
501 mAttributeTable->setHorizontalHeaderLabels( QStringList() << tr(
"Name" ) << tr(
"Type" ) );
504 mAttributeTableItemChangedSlotEnabled =
false;
506 bool checkReplaceRawFieldValues = selectAllFields && isFormatForFieldsAsDisplayedValues;
507 for (
int i = 0; i < mLayer->
fields().size(); ++i )
510 Qt::ItemFlags flags = mLayer->
providerType() != QLatin1String(
"oracle" ) || !fld.
typeName().contains( QLatin1String(
"SDO_GEOMETRY" ) ) ? Qt::ItemIsEnabled : Qt::NoItemFlags;
511 QTableWidgetItem *item =
nullptr;
512 item =
new QTableWidgetItem( fld.
name() );
513 item->setFlags( flags | Qt::ItemIsUserCheckable );
514 item->setCheckState( ( selectAllFields ) ? Qt::Checked : Qt::Unchecked );
515 mAttributeTable->setItem( i, COLUMN_IDX_NAME, item );
517 item =
new QTableWidgetItem( fld.
typeName() );
518 item->setFlags( flags );
519 mAttributeTable->setItem( i, COLUMN_IDX_TYPE, item );
521 if ( foundFieldThatCanBeExportedAsDisplayedValue )
525 const QString widgetId( setup.
type() );
526 if ( flags == Qt::ItemIsEnabled &&
527 widgetId != QLatin1String(
"TextEdit" ) &&
530 item =
new QTableWidgetItem( tr(
"Use %1" ).arg( factory->
name() ) );
531 item->setFlags( ( selectAllFields ) ? ( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable ) : Qt::ItemIsUserCheckable );
532 const bool checkItem = ( selectAllFields && isFormatForFieldsAsDisplayedValues &&
533 ( widgetId == QLatin1String(
"ValueMap" ) ||
534 widgetId == QLatin1String(
"ValueRelation" ) ||
535 widgetId == QLatin1String(
"CheckBox" ) ||
536 widgetId == QLatin1String(
"RelationReference" ) ) );
537 checkReplaceRawFieldValues &= checkItem;
538 item->setCheckState( checkItem ?
539 Qt::Checked : Qt::Unchecked );
540 mAttributeTable->setItem( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE, item );
544 item =
new QTableWidgetItem();
545 item->setFlags( Qt::NoItemFlags );
546 mAttributeTable->setItem( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE, item );
551 mAttributeTableItemChangedSlotEnabled =
true;
553 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
554 mReplaceRawFieldValues->setChecked( checkReplaceRawFieldValues );
555 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
556 mReplaceRawFieldValues->setEnabled( selectAllFields );
557 mReplaceRawFieldValues->setVisible( foundFieldThatCanBeExportedAsDisplayedValue );
559 mAttributeTable->resizeColumnsToContents();
564 while ( mDatasourceOptionsGroupBox->layout()->count() )
566 QLayoutItem *item = mDatasourceOptionsGroupBox->layout()->takeAt( 0 );
567 delete item->widget();
571 while ( mLayerOptionsGroupBox->layout()->count() )
573 QLayoutItem *item = mLayerOptionsGroupBox->layout()->takeAt( 0 );
574 delete item->widget();
579 typedef QPair<QLabel *, QWidget *> LabelControlPair;
585 mDatasourceOptionsGroupBox->setVisible(
true );
586 QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.
driverOptions );
588 QFormLayout *datasourceLayout =
dynamic_cast<QFormLayout *
>( mDatasourceOptionsGroupBox->layout() );
590 const auto constControls = controls;
591 for ( LabelControlPair control : constControls )
593 datasourceLayout->addRow( control.first, control.second );
598 mDatasourceOptionsGroupBox->setVisible(
false );
603 mLayerOptionsGroupBox->setVisible(
true );
604 QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.
layerOptions );
606 QFormLayout *layerOptionsLayout =
dynamic_cast<QFormLayout *
>( mLayerOptionsGroupBox->layout() );
608 const auto constControls = controls;
609 for ( LabelControlPair control : constControls )
611 layerOptionsLayout->addRow( control.first, control.second );
616 mLayerOptionsGroupBox->setVisible(
false );
621 mEncodingComboBox->setEnabled(
true );
628 mEncodingComboBox->setCurrentIndex( idx );
629 mEncodingComboBox->setDisabled(
true );
633 mEncodingComboBox->setEnabled(
true );
640 mEncodingComboBox->setEnabled(
true );
643 GDALDriverH hDriver = GDALGetDriverByName(
format().toUtf8().constData() );
646 mAddToCanvas->setEnabled( GDALGetMetadataItem( hDriver, GDAL_DCAP_OPEN,
nullptr ) !=
nullptr );
650 void QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged(
int )
652 if ( !mReplaceRawFieldValuesStateChangedSlotEnabled )
654 if ( mAttributeTable->columnCount() != 3 )
656 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
657 mAttributeTableItemChangedSlotEnabled =
false;
658 if ( mReplaceRawFieldValues->checkState() != Qt::PartiallyChecked )
660 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
662 if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked &&
663 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
664 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
666 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( mReplaceRawFieldValues->checkState() );
670 mReplaceRawFieldValues->setTristate(
false );
671 mAttributeTableItemChangedSlotEnabled =
true;
672 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
675 void QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged( QTableWidgetItem *item )
677 if ( !mAttributeTableItemChangedSlotEnabled )
679 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
680 mAttributeTableItemChangedSlotEnabled =
false;
681 int row = item->row();
682 int column = item->column();
683 if ( column == COLUMN_IDX_NAME &&
684 mAttributeTable->item( row, column )->checkState() == Qt::Unchecked &&
685 mAttributeTable->columnCount() == 3 &&
686 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
687 ( mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
689 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( Qt::Unchecked );
690 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable );
691 bool checkBoxEnabled =
false;
692 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
694 if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
695 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
697 checkBoxEnabled =
true;
701 mReplaceRawFieldValues->setEnabled( checkBoxEnabled );
702 if ( !checkBoxEnabled )
703 mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
705 else if ( column == COLUMN_IDX_NAME &&
706 mAttributeTable->item( row, column )->checkState() == Qt::Checked &&
707 mAttributeTable->columnCount() == 3 &&
708 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
709 ( mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
711 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
712 mReplaceRawFieldValues->setEnabled(
true );
714 else if ( column == COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE &&
715 ( mAttributeTable->item( row, column )->flags() & Qt::ItemIsUserCheckable ) )
717 bool allChecked =
true;
718 bool allUnchecked =
true;
719 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
721 if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
722 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
724 if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->checkState() == Qt::Unchecked )
727 allUnchecked =
false;
730 mReplaceRawFieldValues->setCheckState( ( !allChecked && !allUnchecked ) ? Qt::PartiallyChecked : ( allChecked ) ? Qt::Checked : Qt::Unchecked );
732 mAttributeTableItemChangedSlotEnabled =
true;
733 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
739 mExtentGroupBox->setOutputCrs( mSelectedCrs );
744 return mFilename->filePath();
749 return leLayername->text();
754 return mEncodingComboBox->currentText();
759 return mFormatComboBox->currentData().toString();
764 return mSelectedCrs.
srsid();
780 QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
784 switch ( it.value()->type )
789 QSpinBox *sb = mDatasourceOptionsGroupBox->findChild<QSpinBox *>( it.key() );
791 options << QStringLiteral(
"%1=%2" ).arg( it.key() ).arg( sb->value() );
798 QComboBox *cb = mDatasourceOptionsGroupBox->findChild<QComboBox *>( it.key() );
799 if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->
defaultValue )
800 options << QStringLiteral(
"%1=%2" ).arg( it.key(), cb->currentText() );
807 QLineEdit *le = mDatasourceOptionsGroupBox->findChild<QLineEdit *>( it.key() );
809 options << QStringLiteral(
"%1=%2" ).arg( it.key(), le->text() );
817 options << QStringLiteral(
"%1=%2" ).arg( it.key(), opt->
mValue );
824 QString plainText = mOgrDatasourceOptions->toPlainText().trimmed();
825 if ( !plainText.isEmpty() )
826 options += plainText.split(
'\n' );
839 QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
843 switch ( it.value()->type )
848 QSpinBox *sb = mLayerOptionsGroupBox->findChild<QSpinBox *>( it.key() );
850 options << QStringLiteral(
"%1=%2" ).arg( it.key() ).arg( sb->value() );
857 QComboBox *cb = mLayerOptionsGroupBox->findChild<QComboBox *>( it.key() );
858 if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->
defaultValue )
859 options << QStringLiteral(
"%1=%2" ).arg( it.key(), cb->currentText() );
866 QLineEdit *le = mLayerOptionsGroupBox->findChild<QLineEdit *>( it.key() );
868 options << QStringLiteral(
"%1=%2" ).arg( it.key(), le->text() );
876 options << QStringLiteral(
"%1=%2" ).arg( it.key(), opt->
mValue );
883 QString plainText = mOgrLayerOptions->toPlainText().trimmed();
884 if ( !plainText.isEmpty() )
885 options += plainText.split(
'\n' );
894 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
896 if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked )
898 attributes.append( i );
909 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
911 if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked &&
912 mAttributeTable->columnCount() == 3 &&
913 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->checkState() == Qt::Checked )
915 attributes.append( i );
924 return mAddToCanvas->isChecked() && mAddToCanvas->isEnabled();
929 mAddToCanvas->setChecked( enabled );
934 return mSymbologyExportComboBox->currentData().toInt();
939 return mScaleWidget->scale();
945 mScaleWidget->setMapCanvas( canvas );
946 mScaleWidget->setShowCurrentScaleButton(
true );
952 return mExtentGroupBox->isChecked();
957 return mExtentGroupBox->outputExtent();
967 return mSelectedOnly->isChecked();
972 int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
973 if ( currentIndexData == -1 )
984 int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
985 return currentIndexData == -1;
990 return mForceMultiCheckBox->isChecked();
995 mForceMultiCheckBox->setChecked( checked );
1000 return mIncludeZCheckBox->isChecked();
1005 return mActionOnExistingFile;
1010 mIncludeZCheckBox->setChecked( checked );
1013 void QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged(
const QString &text )
1015 bool scaleEnabled =
true;
1016 if ( text == tr(
"No symbology" ) )
1018 scaleEnabled =
false;
1020 mScaleWidget->setEnabled( scaleEnabled );
1021 mScaleLabel->setEnabled( scaleEnabled );
1024 void QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged(
int index )
1026 int currentIndexData = mGeometryTypeComboBox->itemData( index ).toInt();
1030 mForceMultiCheckBox->setEnabled(
true );
1031 mIncludeZCheckBox->setEnabled(
true );
1035 mForceMultiCheckBox->setEnabled(
false );
1036 mForceMultiCheckBox->setChecked(
false );
1037 mIncludeZCheckBox->setEnabled(
false );
1038 mIncludeZCheckBox->setChecked(
false );
1042 void QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked()
1044 mAttributeTableItemChangedSlotEnabled =
false;
1045 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
1046 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1048 if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->flags() & Qt::ItemIsEnabled )
1050 if ( mAttributeTable->columnCount() == 3 &&
1051 ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
1053 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
1055 mAttributeTable->item( i, COLUMN_IDX_NAME )->setCheckState( Qt::Checked );
1058 if ( mAttributeTable->columnCount() == 3 )
1060 mReplaceRawFieldValues->setEnabled(
true );
1062 mAttributeTableItemChangedSlotEnabled =
true;
1063 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
1066 void QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked()
1068 mAttributeTableItemChangedSlotEnabled =
false;
1069 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
1070 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1072 mAttributeTable->item( i, COLUMN_IDX_NAME )->setCheckState( Qt::Unchecked );
1073 if ( mAttributeTable->columnCount() == 3 &&
1074 ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
1076 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable );
1077 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( Qt::Unchecked );
1080 if ( mAttributeTable->columnCount() == 3 )
1082 mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
1083 mReplaceRawFieldValues->setEnabled(
false );
1085 mAttributeTableItemChangedSlotEnabled =
true;
1086 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
1089 void QgsVectorLayerSaveAsDialog::showHelp()
1091 QgsHelp::openHelp( QStringLiteral(
"managing_data_source/create_layers.html#save-layer-from-an-existing-file" ) );