23 #include "qgsogrdataitems.h"
31 #include <QMessageBox>
32 #include <QFileDialog>
35 #include <QRegularExpression>
38 static const int COLUMN_IDX_NAME = 0;
39 static const int COLUMN_IDX_TYPE = 1;
40 static const int COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE = 2;
43 : QDialog( parent, fl )
45 , mAttributeTableItemChangedSlotEnabled( true )
46 , mReplaceRawFieldValuesStateChangedSlotEnabled( true )
53 : QDialog( parent, fl )
55 , mAttributeTableItemChangedSlotEnabled( true )
56 , mReplaceRawFieldValuesStateChangedSlotEnabled( true )
58 , mOptions( static_cast<
Options >( options ) )
62 mSelectedCrs = layer->
crs();
63 mLayerExtent = layer->
extent();
69 mSymbologyExportLabel->hide();
70 mSymbologyExportComboBox->hide();
80 if ( !( mOptions &
Fields ) )
81 mAttributesSelection->hide();
84 mSelectedOnly->hide();
90 mGeometryGroupBox->hide();
92 if ( !( mOptions &
Extent ) )
93 mExtentGroupBox->hide();
96 mButtonBox->button( QDialogButtonBox::Ok )->setDisabled(
true );
99 void QgsVectorLayerSaveAsDialog::setup()
104 connect( mFormatComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged );
106 connect( mSymbologyExportComboBox, &QComboBox::currentTextChanged,
this, &QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged );
107 connect( mGeometryTypeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged );
108 connect( mSelectAllAttributes, &QPushButton::clicked,
this, &QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked );
109 connect( mDeselectAllAttributes, &QPushButton::clicked,
this, &QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked );
110 connect( mReplaceRawFieldValues, &QCheckBox::stateChanged,
this, &QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged );
111 connect( mAttributeTable, &QTableWidget::itemChanged,
this, &QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged );
114 mHelpButtonBox->setVisible(
false );
115 mButtonBox->addButton( QDialogButtonBox::Help );
116 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorLayerSaveAsDialog::showHelp );
118 connect( mHelpButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorLayerSaveAsDialog::showHelp );
120 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QgsVectorLayerSaveAsDialog::accept );
121 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsVectorLayerSaveAsDialog::reject );
124 mFormatComboBox->blockSignals(
true );
127 mFormatComboBox->addItem( driver.longName, driver.driverName );
131 QString
format = settings.
value( QStringLiteral(
"UI/lastVectorFormat" ),
"GPKG" ).toString();
132 mFormatComboBox->setCurrentIndex( mFormatComboBox->findData(
format ) );
133 mFormatComboBox->blockSignals(
false );
141 mGeometryTypeComboBox->addItem( tr(
"Automatic" ), -1 );
147 mGeometryTypeComboBox->setCurrentIndex( mGeometryTypeComboBox->findData( -1 ) );
151 QString enc = settings.
value( QStringLiteral(
"UI/encoding" ),
"System" ).toString();
152 int idx = mEncodingComboBox->findText( enc );
155 mEncodingComboBox->insertItem( 0, enc );
159 mCrsSelector->setCrs( mSelectedCrs );
160 mCrsSelector->setLayerCrs( mSelectedCrs );
161 mCrsSelector->setMessage( tr(
"Select the coordinate reference system for the vector file. "
162 "The data points will be transformed from the layer coordinate reference system." ) );
164 mEncodingComboBox->setCurrentIndex( idx );
165 mFormatComboBox_currentIndexChanged( mFormatComboBox->currentIndex() );
171 mSymbologyExportComboBox_currentIndexChanged( mSymbologyExportComboBox->currentText() );
174 mExtentGroupBox->setOutputCrs( mSelectedCrs );
175 mExtentGroupBox->setOriginalExtent( mLayerExtent, mSelectedCrs );
176 mExtentGroupBox->setOutputExtentFromOriginal();
177 mExtentGroupBox->setCheckable(
true );
178 mExtentGroupBox->setChecked(
false );
179 mExtentGroupBox->setCollapsed(
true );
182 mFilename->setDialogTitle( tr(
"Save Layer As" ) );
183 mFilename->setDefaultRoot( settings.
value( QStringLiteral(
"UI/lastVectorFileFilterDir" ), QDir::homePath() ).toString() );
184 mFilename->setConfirmOverwrite(
false );
188 QFileInfo tmplFileInfo( filePath );
189 settings.
setValue( QStringLiteral(
"UI/lastVectorFileFilterDir" ), tmplFileInfo.absolutePath() );
190 if ( !filePath.isEmpty() && leLayername->isEnabled() )
192 QFileInfo fileInfo( filePath );
193 leLayername->setText( fileInfo.completeBaseName() );
195 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( !filePath.isEmpty() );
199 QList<QPair<QLabel *, QWidget *> > QgsVectorLayerSaveAsDialog::createControls(
const QMap<QString, QgsVectorFileWriter::Option *> &options )
201 QList<QPair<QLabel *, QWidget *> > controls;
202 QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
204 for ( it = options.constBegin(); it != options.constEnd(); ++it )
207 QLabel *label =
new QLabel( it.key() );
208 QWidget *control =
nullptr;
209 switch ( option->
type )
216 QSpinBox *sb =
new QSpinBox();
217 sb->setObjectName( it.key() );
229 QComboBox *cb =
new QComboBox();
230 cb->setObjectName( it.key() );
231 for (
const QString &val : qgis::as_const( opt->
values ) )
233 cb->addItem( val, val );
236 cb->addItem( tr(
"<Default>" ), QVariant( QVariant::String ) );
239 idx = cb->findData( QVariant( QVariant::String ) );
240 cb->setCurrentIndex( idx );
252 le->setObjectName( it.key() );
266 label->setToolTip( QStringLiteral(
"<p>%1</p>" ).arg( option->
docString ) );
267 control->setToolTip( QStringLiteral(
"<p>%1</p>" ).arg( option->
docString ) );
269 controls << QPair<QLabel *, QWidget *>( label, control );
276 void QgsVectorLayerSaveAsDialog::accept()
280 QgsVectorFileWriter::EditionCapabilities caps =
285 msgBox.setIcon( QMessageBox::Question );
286 msgBox.setWindowTitle( tr(
"Save Vector Layer As" ) );
287 QPushButton *overwriteFileButton = msgBox.addButton( tr(
"Overwrite File" ), QMessageBox::ActionRole );
288 QPushButton *overwriteLayerButton = msgBox.addButton( tr(
"Overwrite Layer" ), QMessageBox::ActionRole );
289 QPushButton *appendToLayerButton = msgBox.addButton( tr(
"Append to Layer" ), QMessageBox::ActionRole );
290 msgBox.setStandardButtons( QMessageBox::Cancel );
291 msgBox.setDefaultButton( QMessageBox::Cancel );
292 overwriteFileButton->hide();
293 overwriteLayerButton->hide();
294 appendToLayerButton->hide();
301 msgBox.setText( tr(
"The layer already exists. Do you want to overwrite the whole file or overwrite the layer?" ) );
302 overwriteFileButton->setVisible(
true );
303 overwriteLayerButton->setVisible(
true );
307 msgBox.setText( tr(
"The file already exists. Do you want to overwrite it?" ) );
308 overwriteFileButton->setVisible(
true );
313 msgBox.setText( tr(
"The layer already exists. Do you want to overwrite the whole file, overwrite the layer or append features to the layer?" ) );
314 appendToLayerButton->setVisible(
true );
315 overwriteFileButton->setVisible(
true );
316 overwriteLayerButton->setVisible(
true );
320 msgBox.setText( tr(
"The layer already exists. Do you want to overwrite the whole file or append features to the layer?" ) );
321 appendToLayerButton->setVisible(
true );
322 overwriteFileButton->setVisible(
true );
325 int ret = msgBox.exec();
326 if ( ret == QMessageBox::Cancel )
328 if ( msgBox.clickedButton() == overwriteFileButton )
330 else if ( msgBox.clickedButton() == overwriteLayerButton )
332 else if ( msgBox.clickedButton() == appendToLayerButton )
344 if ( QMessageBox::question(
this,
345 tr(
"Save Vector Layer As" ),
346 tr(
"The file already exists. Do you want to overwrite it?" ) ) == QMessageBox::NoButton )
359 if ( QMessageBox::question(
this,
360 tr(
"Save Vector Layer As" ),
361 tr(
"The existing layer has additional fields. Do you want to add the missing fields to the layer?" ) ) == QMessageBox::Yes )
371 const QList<QgsOgrDbLayerInfo *> subLayers = QgsOgrLayerItem::subLayers(
filename(),
format() );
372 QStringList layerList;
373 for (
const QgsOgrDbLayerInfo *layer : subLayers )
375 layerList.append( layer->name() );
377 qDeleteAll( subLayers );
378 if ( layerList.length() > 1 )
380 layerList.sort( Qt::CaseInsensitive );
382 msgBox.setIcon( QMessageBox::Warning );
383 msgBox.setWindowTitle( tr(
"Overwrite File" ) );
384 msgBox.setText( tr(
"This file contains %1 layers that will be lost!\n" ).arg( QString::number( layerList.length() ) ) );
385 msgBox.setDetailedText( tr(
"The following layers will be permanently lost:\n\n%1" ).arg( layerList.join(
"\n" ) ) );
386 msgBox.setStandardButtons( QMessageBox::Ok | QMessageBox::Cancel );
387 if ( msgBox.exec() == QMessageBox::Cancel )
391 catch ( QgsOgrLayerNotValidException &ex )
393 QMessageBox::critical(
this,
394 tr(
"Save Vector Layer As" ),
395 tr(
"Error opening destination file: %1" ).arg( ex.what() ) );
401 settings.
setValue( QStringLiteral(
"UI/lastVectorFileFilterDir" ), QFileInfo(
filename() ).absolutePath() );
402 settings.
setValue( QStringLiteral(
"UI/lastVectorFormat" ),
format() );
407 void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged(
int idx )
411 mFilename->setEnabled(
true );
416 if ( !mFilename->filePath().isEmpty() )
418 QRegularExpression rx(
"\\.(.*?)[\\s]" );
421 if ( !ext.isEmpty() )
423 QFileInfo fi( mFilename->filePath() );
424 mFilename->setFilePath( QStringLiteral(
"%1/%2.%3" ).arg( fi.path() ).arg( fi.baseName() ).arg( ext ) );
428 bool selectAllFields =
true;
433 bool isFormatForFieldsAsDisplayedValues =
false;
435 const QString sFormat(
format() );
436 if ( sFormat == QLatin1String(
"DXF" ) || sFormat == QLatin1String(
"DGN" ) )
438 mAttributesSelection->setVisible(
false );
439 selectAllFields =
false;
445 mAttributesSelection->setVisible(
true );
446 isFormatForFieldsAsDisplayedValues = ( sFormat == QLatin1String(
"CSV" ) ||
447 sFormat == QLatin1String(
"XLS" ) ||
448 sFormat == QLatin1String(
"XLSX" ) ||
449 sFormat == QLatin1String(
"ODS" ) );
456 mSymbologyExportLabel->setVisible(
true );
457 mSymbologyExportComboBox->setVisible(
true );
458 mScaleLabel->setVisible(
true );
459 mScaleWidget->setVisible(
true );
463 mSymbologyExportLabel->hide();
464 mSymbologyExportComboBox->hide();
466 mScaleWidget->hide();
469 leLayername->setEnabled( sFormat == QLatin1String(
"KML" ) ||
470 sFormat == QLatin1String(
"GPKG" ) ||
471 sFormat == QLatin1String(
"XLSX" ) ||
472 sFormat == QLatin1String(
"ODS" ) ||
473 sFormat == QLatin1String(
"FileGDB" ) ||
474 sFormat == QLatin1String(
"SQLite" ) ||
475 sFormat == QLatin1String(
"SpatiaLite" ) );
476 if ( !leLayername->isEnabled() )
477 leLayername->setText( QString() );
478 else if ( leLayername->text().isEmpty() &&
479 !mFilename->filePath().isEmpty() )
481 QString layerName = QFileInfo( mFilename->filePath() ).baseName();
482 leLayername->setText( layerName );
487 mAttributeTable->setRowCount( mLayer->
fields().
count() );
489 bool foundFieldThatCanBeExportedAsDisplayedValue =
false;
490 for (
int i = 0; i < mLayer->
fields().size(); ++i )
493 if ( setup.
type() != QLatin1String(
"TextEdit" ) &&
496 foundFieldThatCanBeExportedAsDisplayedValue =
true;
500 if ( foundFieldThatCanBeExportedAsDisplayedValue )
502 mAttributeTable->setColumnCount( 3 );
503 mAttributeTable->setHorizontalHeaderLabels( QStringList() << tr(
"Name" ) << tr(
"Type" ) << tr(
"Replace with displayed values" ) );
507 mAttributeTable->setColumnCount( 2 );
508 mAttributeTable->setHorizontalHeaderLabels( QStringList() << tr(
"Name" ) << tr(
"Type" ) );
511 mAttributeTableItemChangedSlotEnabled =
false;
513 bool checkReplaceRawFieldValues = selectAllFields && isFormatForFieldsAsDisplayedValues;
514 for (
int i = 0; i < mLayer->
fields().size(); ++i )
517 Qt::ItemFlags flags = mLayer->
providerType() != QLatin1String(
"oracle" ) || !fld.
typeName().contains( QLatin1String(
"SDO_GEOMETRY" ) ) ? Qt::ItemIsEnabled : Qt::NoItemFlags;
518 QTableWidgetItem *item =
nullptr;
519 item =
new QTableWidgetItem( fld.
name() );
520 item->setFlags( flags | Qt::ItemIsUserCheckable );
521 item->setCheckState( ( selectAllFields ) ? Qt::Checked : Qt::Unchecked );
522 mAttributeTable->setItem( i, COLUMN_IDX_NAME, item );
524 item =
new QTableWidgetItem( fld.
typeName() );
525 item->setFlags( flags );
526 mAttributeTable->setItem( i, COLUMN_IDX_TYPE, item );
528 if ( foundFieldThatCanBeExportedAsDisplayedValue )
532 const QString widgetId( setup.
type() );
533 if ( flags == Qt::ItemIsEnabled &&
534 widgetId != QLatin1String(
"TextEdit" ) &&
537 item =
new QTableWidgetItem( tr(
"Use %1" ).arg( factory->
name() ) );
538 item->setFlags( ( selectAllFields ) ? ( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable ) : Qt::ItemIsUserCheckable );
539 const bool checkItem = ( selectAllFields && isFormatForFieldsAsDisplayedValues &&
540 ( widgetId == QLatin1String(
"ValueMap" ) ||
541 widgetId == QLatin1String(
"ValueRelation" ) ||
542 widgetId == QLatin1String(
"CheckBox" ) ||
543 widgetId == QLatin1String(
"RelationReference" ) ) );
544 checkReplaceRawFieldValues &= checkItem;
545 item->setCheckState( checkItem ?
546 Qt::Checked : Qt::Unchecked );
547 mAttributeTable->setItem( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE, item );
551 item =
new QTableWidgetItem();
552 item->setFlags( Qt::NoItemFlags );
553 mAttributeTable->setItem( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE, item );
558 mAttributeTableItemChangedSlotEnabled =
true;
560 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
561 mReplaceRawFieldValues->setChecked( checkReplaceRawFieldValues );
562 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
563 mReplaceRawFieldValues->setEnabled( selectAllFields );
564 mReplaceRawFieldValues->setVisible( foundFieldThatCanBeExportedAsDisplayedValue );
566 mAttributeTable->resizeColumnsToContents();
571 while ( mDatasourceOptionsGroupBox->layout()->count() )
573 QLayoutItem *item = mDatasourceOptionsGroupBox->layout()->takeAt( 0 );
574 delete item->widget();
578 while ( mLayerOptionsGroupBox->layout()->count() )
580 QLayoutItem *item = mLayerOptionsGroupBox->layout()->takeAt( 0 );
581 delete item->widget();
586 typedef QPair<QLabel *, QWidget *> LabelControlPair;
592 mDatasourceOptionsGroupBox->setVisible(
true );
593 QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.
driverOptions );
595 QFormLayout *datasourceLayout =
dynamic_cast<QFormLayout *
>( mDatasourceOptionsGroupBox->layout() );
597 const auto constControls = controls;
598 for ( LabelControlPair control : constControls )
600 datasourceLayout->addRow( control.first, control.second );
605 mDatasourceOptionsGroupBox->setVisible(
false );
610 mLayerOptionsGroupBox->setVisible(
true );
611 QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.
layerOptions );
613 QFormLayout *layerOptionsLayout =
dynamic_cast<QFormLayout *
>( mLayerOptionsGroupBox->layout() );
615 const auto constControls = controls;
616 for ( LabelControlPair control : constControls )
618 layerOptionsLayout->addRow( control.first, control.second );
623 mLayerOptionsGroupBox->setVisible(
false );
628 mEncodingComboBox->setEnabled(
true );
635 mEncodingComboBox->setCurrentIndex( idx );
636 mEncodingComboBox->setDisabled(
true );
640 mEncodingComboBox->setEnabled(
true );
647 mEncodingComboBox->setEnabled(
true );
650 GDALDriverH hDriver = GDALGetDriverByName(
format().toUtf8().constData() );
653 mAddToCanvas->setEnabled( GDALGetMetadataItem( hDriver, GDAL_DCAP_OPEN,
nullptr ) !=
nullptr );
657 void QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged(
int )
659 if ( !mReplaceRawFieldValuesStateChangedSlotEnabled )
661 if ( mAttributeTable->columnCount() != 3 )
663 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
664 mAttributeTableItemChangedSlotEnabled =
false;
665 if ( mReplaceRawFieldValues->checkState() != Qt::PartiallyChecked )
667 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
669 if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked &&
670 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
671 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
673 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( mReplaceRawFieldValues->checkState() );
677 mReplaceRawFieldValues->setTristate(
false );
678 mAttributeTableItemChangedSlotEnabled =
true;
679 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
682 void QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged( QTableWidgetItem *item )
684 if ( !mAttributeTableItemChangedSlotEnabled )
686 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
687 mAttributeTableItemChangedSlotEnabled =
false;
688 int row = item->row();
689 int column = item->column();
690 if ( column == COLUMN_IDX_NAME &&
691 mAttributeTable->item( row, column )->checkState() == Qt::Unchecked &&
692 mAttributeTable->columnCount() == 3 &&
693 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
694 ( mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
696 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( Qt::Unchecked );
697 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable );
698 bool checkBoxEnabled =
false;
699 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
701 if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
702 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
704 checkBoxEnabled =
true;
708 mReplaceRawFieldValues->setEnabled( checkBoxEnabled );
709 if ( !checkBoxEnabled )
710 mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
712 else if ( column == COLUMN_IDX_NAME &&
713 mAttributeTable->item( row, column )->checkState() == Qt::Checked &&
714 mAttributeTable->columnCount() == 3 &&
715 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
716 ( mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
718 mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
719 mReplaceRawFieldValues->setEnabled(
true );
721 else if ( column == COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE &&
722 ( mAttributeTable->item( row, column )->flags() & Qt::ItemIsUserCheckable ) )
724 bool allChecked =
true;
725 bool allUnchecked =
true;
726 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
728 if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
729 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
731 if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->checkState() == Qt::Unchecked )
734 allUnchecked =
false;
737 mReplaceRawFieldValues->setCheckState( ( !allChecked && !allUnchecked ) ? Qt::PartiallyChecked : ( allChecked ) ? Qt::Checked : Qt::Unchecked );
739 mAttributeTableItemChangedSlotEnabled =
true;
740 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
746 mExtentGroupBox->setOutputCrs( mSelectedCrs );
751 return mFilename->filePath();
756 return leLayername->text();
761 return mEncodingComboBox->currentText();
766 return mFormatComboBox->currentData().toString();
771 return mSelectedCrs.
srsid();
787 QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
791 switch ( it.value()->type )
796 QSpinBox *sb = mDatasourceOptionsGroupBox->findChild<QSpinBox *>( it.key() );
798 options << QStringLiteral(
"%1=%2" ).arg( it.key() ).arg( sb->value() );
805 QComboBox *cb = mDatasourceOptionsGroupBox->findChild<QComboBox *>( it.key() );
806 if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->
defaultValue )
807 options << QStringLiteral(
"%1=%2" ).arg( it.key(), cb->currentText() );
814 QLineEdit *le = mDatasourceOptionsGroupBox->findChild<QLineEdit *>( it.key() );
816 options << QStringLiteral(
"%1=%2" ).arg( it.key(), le->text() );
824 options << QStringLiteral(
"%1=%2" ).arg( it.key(), opt->
mValue );
831 QString plainText = mOgrDatasourceOptions->toPlainText().trimmed();
832 if ( !plainText.isEmpty() )
833 options += plainText.split(
'\n' );
846 QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
850 switch ( it.value()->type )
855 QSpinBox *sb = mLayerOptionsGroupBox->findChild<QSpinBox *>( it.key() );
857 options << QStringLiteral(
"%1=%2" ).arg( it.key() ).arg( sb->value() );
864 QComboBox *cb = mLayerOptionsGroupBox->findChild<QComboBox *>( it.key() );
865 if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->
defaultValue )
866 options << QStringLiteral(
"%1=%2" ).arg( it.key(), cb->currentText() );
873 QLineEdit *le = mLayerOptionsGroupBox->findChild<QLineEdit *>( it.key() );
875 options << QStringLiteral(
"%1=%2" ).arg( it.key(), le->text() );
883 options << QStringLiteral(
"%1=%2" ).arg( it.key(), opt->
mValue );
890 QString plainText = mOgrLayerOptions->toPlainText().trimmed();
891 if ( !plainText.isEmpty() )
892 options += plainText.split(
'\n' );
901 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
903 if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked )
905 attributes.append( i );
916 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
918 if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked &&
919 mAttributeTable->columnCount() == 3 &&
920 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->checkState() == Qt::Checked )
922 attributes.append( i );
931 return mAddToCanvas->isChecked() && mAddToCanvas->isEnabled();
936 mAddToCanvas->setChecked( enabled );
941 return mSymbologyExportComboBox->currentData().toInt();
946 return mScaleWidget->scale();
952 mScaleWidget->setMapCanvas( canvas );
953 mScaleWidget->setShowCurrentScaleButton(
true );
959 return mExtentGroupBox->isChecked();
964 return mExtentGroupBox->outputExtent();
974 return mSelectedOnly->isChecked();
979 int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
980 if ( currentIndexData == -1 )
991 int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
992 return currentIndexData == -1;
997 return mForceMultiCheckBox->isChecked();
1002 mForceMultiCheckBox->setChecked( checked );
1007 return mIncludeZCheckBox->isChecked();
1012 return mActionOnExistingFile;
1017 mIncludeZCheckBox->setChecked( checked );
1020 void QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged(
const QString &text )
1022 bool scaleEnabled =
true;
1023 if ( text == tr(
"No symbology" ) )
1025 scaleEnabled =
false;
1027 mScaleWidget->setEnabled( scaleEnabled );
1028 mScaleLabel->setEnabled( scaleEnabled );
1031 void QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged(
int index )
1033 int currentIndexData = mGeometryTypeComboBox->itemData( index ).toInt();
1037 mForceMultiCheckBox->setEnabled(
true );
1038 mIncludeZCheckBox->setEnabled(
true );
1042 mForceMultiCheckBox->setEnabled(
false );
1043 mForceMultiCheckBox->setChecked(
false );
1044 mIncludeZCheckBox->setEnabled(
false );
1045 mIncludeZCheckBox->setChecked(
false );
1049 void QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked()
1051 mAttributeTableItemChangedSlotEnabled =
false;
1052 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
1053 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1055 if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->flags() & Qt::ItemIsEnabled )
1057 if ( mAttributeTable->columnCount() == 3 &&
1058 ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
1060 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
1062 mAttributeTable->item( i, COLUMN_IDX_NAME )->setCheckState( Qt::Checked );
1065 if ( mAttributeTable->columnCount() == 3 )
1067 mReplaceRawFieldValues->setEnabled(
true );
1069 mAttributeTableItemChangedSlotEnabled =
true;
1070 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
1073 void QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked()
1075 mAttributeTableItemChangedSlotEnabled =
false;
1076 mReplaceRawFieldValuesStateChangedSlotEnabled =
false;
1077 for (
int i = 0; i < mAttributeTable->rowCount(); i++ )
1079 mAttributeTable->item( i, COLUMN_IDX_NAME )->setCheckState( Qt::Unchecked );
1080 if ( mAttributeTable->columnCount() == 3 &&
1081 ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
1083 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable );
1084 mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( Qt::Unchecked );
1087 if ( mAttributeTable->columnCount() == 3 )
1089 mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
1090 mReplaceRawFieldValues->setEnabled(
false );
1092 mAttributeTableItemChangedSlotEnabled =
true;
1093 mReplaceRawFieldValuesStateChangedSlotEnabled =
true;
1096 void QgsVectorLayerSaveAsDialog::showHelp()
1098 QgsHelp::openHelp( QStringLiteral(
"managing_data_source/create_layers.html#save-layer-from-an-existing-file" ) );
This class represents a coordinate reference system (CRS).
long srsid() const
Returns the internal CRS ID, if available.
Encapsulate a field in an attribute table or data source.
QString typeName() const
Gets the field type.
int count() const
Returns number of items.
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
static QgsEditorWidgetRegistry * editorWidgetRegistry()
Returns the global editor widget registry, used for managing all known edit widget factories.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
static QIcon iconForWkbType(QgsWkbTypes::Type type)
Returns the icon for a vector layer whose geometry type is provided.
Map canvas is a class for displaying all GIS data types on a canvas.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
QString providerType() const
Returns the provider type (provider key) for this layer.
QgsCoordinateReferenceSystem crs
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
A rectangle specified with double values.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
static QStringList availableEncodings()
Returns a list of available encodings.
QgsVectorFileWriter::OptionType type
A convenience class for writing vector files to disk.
@ CanAppendToExistingLayer
Flag to indicate that new features can be added to an existing layer.
@ CanAddNewLayer
Flag to indicate that a new layer can be added to the dataset.
@ CanDeleteLayer
Flag to indicate that an existing layer can be deleted.
static QgsVectorFileWriter::EditionCapabilities editionCapabilities(const QString &datasetName)
Returns edition capabilities for an existing dataset name.
static bool supportsFeatureStyles(const QString &driverName)
Returns true if the specified driverName supports feature styles.
static bool targetLayerExists(const QString &datasetName, const QString &layerName)
Returns whether the target layer already exists.
static bool driverMetadata(const QString &driverName, MetaData &driverMetadata)
static QString filterForDriver(const QString &driverName)
Creates a filter for an OGR driver key.
static bool areThereNewFieldsToCreate(const QString &datasetName, const QString &layerName, QgsVectorLayer *layer, const QgsAttributeList &attributes)
Returns whether there are among the attributes specified some that do not exist yet in the layer.
static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList(VectorFormatOptions options=SortRecommended)
Returns the driver list that can be used for dialogs.
ActionOnExistingFile
Combination of CanAddNewLayer, CanAppendToExistingLayer, CanAddNewFieldsToExistingLayer or CanDeleteL...
@ CreateOrOverwriteLayer
Create or overwrite layer.
@ CreateOrOverwriteFile
Create or overwrite file.
@ AppendToLayerNoNewFields
Append features to existing layer, but do not create new fields.
@ AppendToLayerAddFields
Append features to existing layer, and create new fields if needed.
bool onlySelected() const
Returns whether only selected features will be saved.
bool forceMulti() const
Returns true if force multi geometry type is checked.
QString filename() const
Returns the target filename.
QgsAttributeList selectedAttributes() const
Returns a list of attributes which are selected for saving.
QgsRectangle filterExtent() const
Determines the extent to be exported.
Q_DECL_DEPRECATED long crs() const
Returns the internal CRS ID.
Options
Bitmask of options to be shown.
@ DestinationCrs
Show destination CRS (reprojection) option.
@ AddToCanvas
Show add to map option.
@ Extent
Show extent group.
@ Symbology
Show symbology options.
@ SelectedOnly
Show selected features only option.
@ Fields
Show field customization group.
@ GeometryType
Show geometry group.
QString format() const
The format in which the export should be written.
QStringList datasourceOptions() const
Returns a list of additional data source options which are passed to OGR.
QString encoding() const
The encoding of the target file.
void setIncludeZ(bool checked)
Sets whether the include z dimension checkbox should be checked.
void setOnlySelected(bool onlySelected)
Sets whether only selected features will be saved.
bool automaticGeometryType() const
Returns true if geometry type is set to automatic.
QString layername() const
Returns the target layer name.
QgsWkbTypes::Type geometryType() const
Returns the selected flat geometry type for the export.
Q_DECL_DEPRECATED QgsVectorLayerSaveAsDialog(long srsid, QWidget *parent=nullptr, Qt::WindowFlags fl=Qt::WindowFlags())
Construct a new QgsVectorLayerSaveAsDialog.
bool includeZ() const
Returns true if include z dimension is checked.
QgsCoordinateReferenceSystem crsObject() const
Returns the CRS chosen for export.
QStringList layerOptions() const
Returns a list of additional layer options which are passed to OGR.
void setForceMulti(bool checked)
Sets whether the force multi geometry checkbox should be checked.
bool addToCanvas() const
Returns true if the "add to canvas" checkbox is checked.
void setMapCanvas(QgsMapCanvas *canvas)
Sets a map canvas to associate with the dialog.
QgsVectorFileWriter::ActionOnExistingFile creationActionOnExistingFile() const
Returns creation action.
int symbologyExport() const
Returns type of symbology export.
QgsAttributeList attributesAsDisplayedValues() const
Returns selected attributes that must be exported with their displayed values instead of their raw va...
double scale() const
Returns the specified map scale.
bool hasFilterExtent() const
Determines if filtering the export by an extent is activated.
void setAddToCanvas(bool checked)
Sets whether the "add to canvas" checkbox should be checked.
Represents a vector layer which manages a vector based data sets.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
int selectedFeatureCount() const
Returns the number of features that are selected in this layer.
QgsRectangle extent() const FINAL
Returns the extent of the layer.
static QString translatedDisplayString(Type type) SIP_HOLDGIL
Returns a translated display string type for a WKB type, e.g., the geometry name used in WKT geometry...
Type
The WKB type describes the number of dimensions a geometry has.
QList< int > QgsAttributeList
const QgsCoordinateReferenceSystem & crs
Details of available driver formats.