29 #include <QMessageBox> 30 #include <QFileDialog> 35 static const int COLUMN_IDX_NAME = 0;
36 static const int COLUMN_IDX_TYPE = 1;
37 static const int COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE = 2;
40 : QDialog( parent, fl )
42 , mAttributeTableItemChangedSlotEnabled( true )
43 , mReplaceRawFieldValuesStateChangedSlotEnabled( true )
50 : QDialog( parent, fl )
52 , mAttributeTableItemChangedSlotEnabled( true )
53 , mReplaceRawFieldValuesStateChangedSlotEnabled( true )
55 , mOptions( static_cast<
Options >( options ) )
60 mLayerExtent = layer->
extent();
66 mSymbologyExportLabel->hide();
67 mSymbologyExportComboBox->hide();
77 if ( !( mOptions &
Fields ) )
78 mAttributesSelection->hide();
81 mSelectedOnly->hide();
87 mGeometryGroupBox->hide();
89 if ( !( mOptions &
Extent ) )
90 mExtentGroupBox->hide();
93 mButtonBox->button( QDialogButtonBox::Ok )->setDisabled(
true );
96 void QgsVectorLayerSaveAsDialog::setup()
101 connect( mFormatComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged );
103 connect( mSymbologyExportComboBox, &QComboBox::currentTextChanged,
this, &QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged );
104 connect( mGeometryTypeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged );
105 connect( mSelectAllAttributes, &QPushButton::clicked,
this, &QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked );
106 connect( mDeselectAllAttributes, &QPushButton::clicked,
this, &QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked );
107 connect( mReplaceRawFieldValues, &QCheckBox::stateChanged,
this, &QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged );
108 connect( mAttributeTable, &QTableWidget::itemChanged,
this, &QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged );
111 mHelpButtonBox->setVisible(
false );
112 mButtonBox->addButton( QDialogButtonBox::Help );
113 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorLayerSaveAsDialog::showHelp );
115 connect( mHelpButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorLayerSaveAsDialog::showHelp );
117 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QgsVectorLayerSaveAsDialog::accept );
118 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsVectorLayerSaveAsDialog::reject );
121 mFormatComboBox->blockSignals(
true );
124 mFormatComboBox->addItem( driver.longName, driver.driverName );
128 QString
format = settings.
value( QStringLiteral(
"UI/lastVectorFormat" ),
"GPKG" ).toString();
129 mFormatComboBox->setCurrentIndex( mFormatComboBox->findData( format ) );
130 mFormatComboBox->blockSignals(
false );
133 mGeometryTypeComboBox->addItem( tr(
"Automatic" ), -1 );
139 mGeometryTypeComboBox->setCurrentIndex( mGeometryTypeComboBox->findData( -1 ) );
143 QString enc = settings.
value( QStringLiteral(
"UI/encoding" ),
"System" ).toString();
144 int idx = mEncodingComboBox->findText( enc );
147 mEncodingComboBox->insertItem( 0, enc );
152 mCrsSelector->setCrs( srs );
153 mCrsSelector->setLayerCrs( srs );
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( srs );
168 mExtentGroupBox->setOriginalExtent( mLayerExtent, srs );
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 =
284 msgBox.setIcon( QMessageBox::Question );
285 msgBox.setWindowTitle( tr(
"Save Vector Layer As" ) );
286 msgBox.setText( tr(
"The layer already exists. Do you want to overwrite the whole file or overwrite the layer?" ) );
287 QPushButton *overwriteFileButton = msgBox.addButton( tr(
"Overwrite File" ), QMessageBox::ActionRole );
288 QPushButton *overwriteLayerButton = msgBox.addButton( tr(
"Overwrite Layer" ), QMessageBox::ActionRole );
289 msgBox.setStandardButtons( QMessageBox::Cancel );
290 msgBox.setDefaultButton( QMessageBox::Cancel );
291 int ret = msgBox.exec();
292 if ( ret == QMessageBox::Cancel )
294 if ( msgBox.clickedButton() == overwriteFileButton )
296 else if ( msgBox.clickedButton() == overwriteLayerButton )
299 else if ( !( caps & QgsVectorFileWriter::CanAppendToExistingLayer ) )
301 if ( QMessageBox::question(
this,
302 tr(
"Save Vector Layer As" ),
303 tr(
"The file already exists. Do you want to overwrite it?" ) ) == QMessageBox::NoButton )
309 else if ( ( caps & QgsVectorFileWriter::CanDeleteLayer ) &&
313 msgBox.setIcon( QMessageBox::Question );
314 msgBox.setWindowTitle( tr(
"Save Vector Layer As" ) );
315 msgBox.setText( tr(
"The layer already exists. Do you want to overwrite the whole file, overwrite the layer or append features to the layer?" ) );
316 QPushButton *overwriteFileButton = msgBox.addButton( tr(
"Overwrite File" ), QMessageBox::ActionRole );
317 QPushButton *overwriteLayerButton = msgBox.addButton( tr(
"Overwrite Layer" ), QMessageBox::ActionRole );
318 QPushButton *appendToLayerButton = msgBox.addButton( tr(
"Append to Layer" ), QMessageBox::ActionRole );
319 msgBox.setStandardButtons( QMessageBox::Cancel );
320 msgBox.setDefaultButton( QMessageBox::Cancel );
321 int ret = msgBox.exec();
322 if ( ret == QMessageBox::Cancel )
324 if ( msgBox.clickedButton() == overwriteFileButton )
326 else if ( msgBox.clickedButton() == overwriteLayerButton )
328 else if ( msgBox.clickedButton() == appendToLayerButton )
334 msgBox.setIcon( QMessageBox::Question );
335 msgBox.setWindowTitle( tr(
"Save Vector Layer As" ) );
336 msgBox.setText( tr(
"The layer already exists. Do you want to overwrite the whole file or append features to the layer?" ) );
337 QPushButton *overwriteFileButton = msgBox.addButton( tr(
"Overwrite File" ), QMessageBox::ActionRole );
338 QPushButton *appendToLayerButton = msgBox.addButton( tr(
"Append to Layer" ), QMessageBox::ActionRole );
339 msgBox.setStandardButtons( QMessageBox::Cancel );
340 msgBox.setDefaultButton( QMessageBox::Cancel );
341 int ret = msgBox.exec();
342 if ( ret == QMessageBox::Cancel )
344 if ( msgBox.clickedButton() == overwriteFileButton )
346 else if ( msgBox.clickedButton() == appendToLayerButton )
357 if ( QMessageBox::question(
this,
358 tr(
"Save Vector Layer As" ),
359 tr(
"The existing layer has different fields. Do you want to add the missing fields to the layer?" ) ) == QMessageBox::Yes )
375 if ( QMessageBox::question(
this,
376 tr(
"Save Vector Layer As" ),
377 tr(
"The file already exists. Do you want to overwrite it?" ) ) == QMessageBox::NoButton )
387 settings.
setValue( QStringLiteral(
"UI/lastVectorFileFilterDir" ), QFileInfo(
filename() ).absolutePath() );
388 settings.
setValue( QStringLiteral(
"UI/lastVectorFormat" ),
format() );
393 void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged(
int idx )
397 mFilename->setEnabled(
true );
402 if ( !mFilename->filePath().isEmpty() )
404 QRegularExpression rx(
"\\.(.*?)[\\s]" );
407 if ( !ext.isEmpty() )
409 QFileInfo fi( mFilename->filePath() );
410 mFilename->setFilePath( QStringLiteral(
"%1/%2.%3" ).arg( fi.path() ).arg( fi.baseName() ).arg( ext ) );
414 bool selectAllFields =
true;
415 bool fieldsAsDisplayedValues =
false;
417 const QString sFormat(
format() );
418 if ( sFormat == QLatin1String(
"DXF" ) || sFormat == QLatin1String(
"DGN" ) )
420 mAttributesSelection->setVisible(
false );
421 selectAllFields =
false;
426 mAttributesSelection->setVisible(
true );
427 fieldsAsDisplayedValues = ( sFormat == QLatin1String(
"CSV" ) || sFormat == QLatin1String(
"XLS" ) || sFormat == QLatin1String(
"XLSX" ) || sFormat == QLatin1String(
"ODS" ) );
433 mSymbologyExportLabel->setVisible(
true );
434 mSymbologyExportComboBox->setVisible(
true );
435 mScaleLabel->setVisible(
true );
436 mScaleWidget->setVisible(
true );
440 mSymbologyExportLabel->hide();
441 mSymbologyExportComboBox->hide();
443 mScaleWidget->hide();
446 leLayername->setEnabled( sFormat == QLatin1String(
"KML" ) ||
447 sFormat == QLatin1String(
"GPKG" ) ||
448 sFormat == QLatin1String(
"XLSX" ) ||
449 sFormat == QLatin1String(
"ODS" ) ||
450 sFormat == QLatin1String(
"FileGDB" ) ||
451 sFormat == QLatin1String(
"SQLite" ) ||
452 sFormat == QLatin1String(
"SpatiaLite" ) );
453 if ( !leLayername->isEnabled() )
454 leLayername->setText( QString() );
455 else if ( leLayername->text().isEmpty() &&
456 !mFilename->filePath().isEmpty() )
458 QString layerName = QFileInfo( mFilename->filePath() ).baseName();
459 leLayername->setText( layerName );
464 mAttributeTable->setRowCount( mLayer->
fields().
count() );
466 bool foundFieldThatCanBeExportedAsDisplayedValue =
false;
467 for (
int i = 0; i < mLayer->
fields().
size(); ++i )
470 if ( setup.
type() != QLatin1String(
"TextEdit" ) &&
473 foundFieldThatCanBeExportedAsDisplayedValue =
true;
477 if ( foundFieldThatCanBeExportedAsDisplayedValue )
479 mAttributeTable->setColumnCount( 3 );
480 mAttributeTable->setHorizontalHeaderLabels( QStringList() << tr(
"Name" ) << tr(
"Type" ) << tr(
"Replace with displayed values" ) );
484 mAttributeTable->setColumnCount( 2 );
485 mAttributeTable->setHorizontalHeaderLabels( QStringList() << tr(
"Name" ) << tr(
"Type" ) );
488 mAttributeTableItemChangedSlotEnabled =
false;
490 for (
int i = 0; i < mLayer->
fields().
size(); ++i )
493 Qt::ItemFlags flags = mLayer->
providerType() != QLatin1String(
"oracle" ) || !fld.
typeName().contains( QLatin1String(
"SDO_GEOMETRY" ) ) ? Qt::ItemIsEnabled : Qt::NoItemFlags;
494 QTableWidgetItem *item =
nullptr;
495 item =
new QTableWidgetItem( fld.
name() );
496 item->setFlags( flags | Qt::ItemIsUserCheckable );
497 item->setCheckState( ( selectAllFields ) ? Qt::Checked : Qt::Unchecked );
498 mAttributeTable->setItem( i, COLUMN_IDX_NAME, item );
500 item =
new QTableWidgetItem( fld.
typeName() );
501 item->setFlags( flags );
502 mAttributeTable->setItem( i, COLUMN_IDX_TYPE, item );
504 if ( foundFieldThatCanBeExportedAsDisplayedValue )
508 if ( flags == Qt::ItemIsEnabled &&
509 setup.
type() != QLatin1String(
"TextEdit" ) &&
512 item =
new QTableWidgetItem( tr(
"Use %1" ).arg( factory->
name() ) );
513 item->setFlags( ( selectAllFields ) ? ( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable ) : Qt::ItemIsUserCheckable );
514 item->setCheckState( ( selectAllFields && fieldsAsDisplayedValues ) ? Qt::Checked : Qt::Unchecked );
515 mAttributeTable->setItem( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE, item );
519 item =
new QTableWidgetItem();
520 item->setFlags( Qt::NoItemFlags );
521 mAttributeTable->setItem( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE, item );
526 mAttributeTableItemChangedSlotEnabled =
true;
528 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
529 mReplaceRawFieldValues->setChecked( selectAllFields && fieldsAsDisplayedValues );
530 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
531 mReplaceRawFieldValues->setEnabled( selectAllFields );
532 mReplaceRawFieldValues->setVisible( foundFieldThatCanBeExportedAsDisplayedValue );
534 mAttributeTable->resizeColumnsToContents();
539 while ( mDatasourceOptionsGroupBox->layout()->count() )
541 QLayoutItem *item = mDatasourceOptionsGroupBox->layout()->takeAt( 0 );
542 delete item->widget();
546 while ( mLayerOptionsGroupBox->layout()->count() )
548 QLayoutItem *item = mLayerOptionsGroupBox->layout()->takeAt( 0 );
549 delete item->widget();
554 typedef QPair<QLabel *, QWidget *> LabelControlPair;
560 mDatasourceOptionsGroupBox->setVisible(
true );
561 QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.
driverOptions );
563 QFormLayout *datasourceLayout =
dynamic_cast<QFormLayout *
>( mDatasourceOptionsGroupBox->layout() );
565 const auto constControls = controls;
566 for ( LabelControlPair control : constControls )
568 datasourceLayout->addRow( control.first, control.second );
573 mDatasourceOptionsGroupBox->setVisible(
false );
578 mLayerOptionsGroupBox->setVisible(
true );
579 QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.
layerOptions );
581 QFormLayout *layerOptionsLayout =
dynamic_cast<QFormLayout *
>( mLayerOptionsGroupBox->layout() );
583 const auto constControls = controls;
584 for ( LabelControlPair control : constControls )
586 layerOptionsLayout->addRow( control.first, control.second );
591 mLayerOptionsGroupBox->setVisible(
false );
596 mEncodingComboBox->setEnabled(
true );
603 mEncodingComboBox->setCurrentIndex( idx );
604 mEncodingComboBox->setDisabled(
true );
608 mEncodingComboBox->setEnabled(
true );
615 mEncodingComboBox->setEnabled(
true );
618 GDALDriverH hDriver = GDALGetDriverByName(
format().toUtf8().constData() );
621 mAddToCanvas->setEnabled( GDALGetMetadataItem( hDriver, GDAL_DCAP_OPEN,
nullptr ) !=
nullptr );
625 void QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged(
int )
627 if ( !mReplaceRawFieldValuesStateChangedSlotEnabled )
629 if ( mAttributeTable->columnCount() != 3 )
631 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
632 mAttributeTableItemChangedSlotEnabled =
false;
633 if ( mReplaceRawFieldValues->checkState() != Qt::PartiallyChecked )
635 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
637 if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked &&
638 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
639 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
641 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( mReplaceRawFieldValues->checkState() );
645 mReplaceRawFieldValues->setTristate(
false );
646 mAttributeTableItemChangedSlotEnabled =
true;
647 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
650 void QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged( QTableWidgetItem *item )
652 if ( !mAttributeTableItemChangedSlotEnabled )
654 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
655 mAttributeTableItemChangedSlotEnabled =
false;
656 int row = item->row();
657 int column = item->column();
658 if ( column == COLUMN_IDX_NAME &&
659 mAttributeTable->item( row, column )->checkState() == Qt::Unchecked &&
660 mAttributeTable->columnCount() == 3 &&
661 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
662 ( mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
664 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( Qt::Unchecked );
665 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable );
666 bool checkBoxEnabled =
false;
667 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
669 if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
670 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
672 checkBoxEnabled =
true;
676 mReplaceRawFieldValues->setEnabled( checkBoxEnabled );
677 if ( !checkBoxEnabled )
678 mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
680 else if ( column == COLUMN_IDX_NAME &&
681 mAttributeTable->item( row, column )->checkState() == Qt::Checked &&
682 mAttributeTable->columnCount() == 3 &&
683 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
684 ( mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
686 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
687 mReplaceRawFieldValues->setEnabled(
true );
689 else if ( column == COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE &&
690 ( mAttributeTable->item( row, column )->flags() & Qt::ItemIsUserCheckable ) )
692 bool allChecked =
true;
693 bool allUnchecked =
true;
694 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
696 if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
697 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
699 if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->checkState() == Qt::Unchecked )
702 allUnchecked =
false;
705 mReplaceRawFieldValues->setCheckState( ( !allChecked && !allUnchecked ) ? Qt::PartiallyChecked : ( allChecked ) ? Qt::Checked : Qt::Unchecked );
707 mAttributeTableItemChangedSlotEnabled =
true;
708 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
714 mExtentGroupBox->setOutputCrs( crs );
719 return mFilename->filePath();
724 return leLayername->text();
729 return mEncodingComboBox->currentText();
734 return mFormatComboBox->currentData().toString();
750 QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
754 switch ( it.value()->type )
759 QSpinBox *sb = mDatasourceOptionsGroupBox->findChild<QSpinBox *>( it.key() );
761 options << QStringLiteral(
"%1=%2" ).arg( it.key() ).arg( sb->value() );
768 QComboBox *cb = mDatasourceOptionsGroupBox->findChild<QComboBox *>( it.key() );
769 if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->
defaultValue )
770 options << QStringLiteral(
"%1=%2" ).arg( it.key(), cb->currentText() );
777 QLineEdit *le = mDatasourceOptionsGroupBox->findChild<QLineEdit *>( it.key() );
779 options << QStringLiteral(
"%1=%2" ).arg( it.key(), le->text() );
787 options << QStringLiteral(
"%1=%2" ).arg( it.key(), opt->
mValue );
794 QString plainText = mOgrDatasourceOptions->toPlainText().trimmed();
795 if ( !plainText.isEmpty() )
796 options += plainText.split(
'\n' );
809 QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
813 switch ( it.value()->type )
818 QSpinBox *sb = mLayerOptionsGroupBox->findChild<QSpinBox *>( it.key() );
820 options << QStringLiteral(
"%1=%2" ).arg( it.key() ).arg( sb->value() );
827 QComboBox *cb = mLayerOptionsGroupBox->findChild<QComboBox *>( it.key() );
828 if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->
defaultValue )
829 options << QStringLiteral(
"%1=%2" ).arg( it.key(), cb->currentText() );
836 QLineEdit *le = mLayerOptionsGroupBox->findChild<QLineEdit *>( it.key() );
838 options << QStringLiteral(
"%1=%2" ).arg( it.key(), le->text() );
846 options << QStringLiteral(
"%1=%2" ).arg( it.key(), opt->
mValue );
853 QString plainText = mOgrLayerOptions->toPlainText().trimmed();
854 if ( !plainText.isEmpty() )
855 options += plainText.split(
'\n' );
864 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
866 if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked )
868 attributes.append( i );
879 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
881 if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked &&
882 mAttributeTable->columnCount() == 3 &&
883 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->checkState() == Qt::Checked )
885 attributes.append( i );
894 return mAddToCanvas->isChecked() && mAddToCanvas->isEnabled();
899 mAddToCanvas->setChecked( enabled );
904 return mSymbologyExportComboBox->currentData().toInt();
909 return mScaleWidget->scale();
915 mScaleWidget->setMapCanvas( canvas );
916 mScaleWidget->setShowCurrentScaleButton(
true );
922 return mExtentGroupBox->isChecked();
927 return mExtentGroupBox->outputExtent();
932 mSelectedOnly->setChecked( onlySelected );
937 return mSelectedOnly->isChecked();
942 int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
943 if ( currentIndexData == -1 )
954 int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
955 return currentIndexData == -1;
960 return mForceMultiCheckBox->isChecked();
965 mForceMultiCheckBox->setChecked( checked );
970 return mIncludeZCheckBox->isChecked();
975 return mActionOnExistingFile;
980 mIncludeZCheckBox->setChecked( checked );
983 void QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged(
const QString &text )
985 bool scaleEnabled =
true;
986 if ( text == tr(
"No symbology" ) )
988 scaleEnabled =
false;
990 mScaleWidget->setEnabled( scaleEnabled );
991 mScaleLabel->setEnabled( scaleEnabled );
994 void QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged(
int index )
996 int currentIndexData = mGeometryTypeComboBox->itemData( index ).toInt();
1000 mForceMultiCheckBox->setEnabled(
true );
1001 mIncludeZCheckBox->setEnabled(
true );
1005 mForceMultiCheckBox->setEnabled(
false );
1006 mForceMultiCheckBox->setChecked(
false );
1007 mIncludeZCheckBox->setEnabled(
false );
1008 mIncludeZCheckBox->setChecked(
false );
1012 void QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked()
1014 mAttributeTableItemChangedSlotEnabled =
false;
1015 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
1016 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1018 if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->flags() & Qt::ItemIsEnabled )
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 | Qt::ItemIsEnabled );
1025 mAttributeTable->item( i, COLUMN_IDX_NAME )->setCheckState( Qt::Checked );
1028 if ( mAttributeTable->columnCount() == 3 )
1030 mReplaceRawFieldValues->setEnabled(
true );
1032 mAttributeTableItemChangedSlotEnabled =
true;
1033 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
1036 void QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked()
1038 mAttributeTableItemChangedSlotEnabled =
false;
1039 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
1040 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1042 mAttributeTable->item( i, COLUMN_IDX_NAME )->setCheckState( Qt::Unchecked );
1043 if ( mAttributeTable->columnCount() == 3 &&
1044 ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
1046 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable );
1047 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( Qt::Unchecked );
1050 if ( mAttributeTable->columnCount() == 3 )
1052 mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
1053 mReplaceRawFieldValues->setEnabled(
false );
1055 mAttributeTableItemChangedSlotEnabled =
true;
1056 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
1059 void QgsVectorLayerSaveAsDialog::showHelp()
1061 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)