QGIS API Documentation  3.6.0-Noosa (5873452)
qgsvectorlayersaveasdialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorlayersaveasdialog.h
3  Dialog to select destination, type and crs for ogr layers
4  -------------------
5  begin : Mon Mar 22 2010
6  copyright : (C) 2010 by Juergen E. Fischer
7  email : jef at norbit dot de
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 #include "qgslogger.h"
21 #include "qgsvectordataprovider.h"
23 #include "qgseditorwidgetfactory.h"
25 #include "qgssettings.h"
26 #include "qgsmapcanvas.h"
27 #include "qgsgui.h"
28 #include "qgsapplication.h"
29 #include <QMessageBox>
30 #include <QFileDialog>
31 #include <QTextCodec>
32 #include <QSpinBox>
33 
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;
37 
38 QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( long srsid, QWidget *parent, Qt::WindowFlags fl )
39  : QDialog( parent, fl )
40  , mCRS( srsid )
41  , mAttributeTableItemChangedSlotEnabled( true )
42  , mReplaceRawFieldValuesStateChangedSlotEnabled( true )
43  , mActionOnExistingFile( QgsVectorFileWriter::CreateOrOverwriteFile )
44 {
45  setup();
46 }
47 
48 QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( QgsVectorLayer *layer, int options, QWidget *parent, Qt::WindowFlags fl )
49  : QDialog( parent, fl )
50  , mLayer( layer )
51  , mAttributeTableItemChangedSlotEnabled( true )
52  , mReplaceRawFieldValuesStateChangedSlotEnabled( true )
53  , mActionOnExistingFile( QgsVectorFileWriter::CreateOrOverwriteFile )
54  , mOptions( static_cast< Options >( options ) )
55 {
56  if ( layer )
57  {
58  mCRS = layer->crs().srsid();
59  mLayerExtent = layer->extent();
60  }
61  setup();
62 
63  if ( !( mOptions & Symbology ) )
64  {
65  mSymbologyExportLabel->hide();
66  mSymbologyExportComboBox->hide();
67  mScaleLabel->hide();
68  mScaleWidget->hide();
69  }
70 
71  if ( !( mOptions & DestinationCrs ) )
72  {
73  mCrsLabel->hide();
74  mCrsSelector->hide();
75  }
76  if ( !( mOptions & Fields ) )
77  mAttributesSelection->hide();
78 
79  if ( !( mOptions & SelectedOnly ) )
80  mSelectedOnly->hide();
81 
82  if ( !( mOptions & AddToCanvas ) )
83  mAddToCanvas->hide();
84 
85  if ( !( mOptions & GeometryType ) )
86  mGeometryGroupBox->hide();
87 
88  if ( !( mOptions & Extent ) )
89  mExtentGroupBox->hide();
90 
91  mSelectedOnly->setEnabled( layer && layer->selectedFeatureCount() != 0 );
92  mButtonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
93 }
94 
95 void QgsVectorLayerSaveAsDialog::setup()
96 {
97  setupUi( this );
99 
100  connect( mFormatComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged );
101  connect( mCrsSelector, &QgsProjectionSelectionWidget::crsChanged, this, &QgsVectorLayerSaveAsDialog::mCrsSelector_crsChanged );
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 );
108 
109 #ifdef Q_OS_WIN
110  mHelpButtonBox->setVisible( false );
111  mButtonBox->addButton( QDialogButtonBox::Help );
112  connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsVectorLayerSaveAsDialog::showHelp );
113 #else
114  connect( mHelpButtonBox, &QDialogButtonBox::helpRequested, this, &QgsVectorLayerSaveAsDialog::showHelp );
115 #endif
116  connect( mButtonBox, &QDialogButtonBox::accepted, this, &QgsVectorLayerSaveAsDialog::accept );
117  connect( mButtonBox, &QDialogButtonBox::rejected, this, &QgsVectorLayerSaveAsDialog::reject );
118 
119  const QList< QgsVectorFileWriter::DriverDetails > drivers = QgsVectorFileWriter::ogrDriverList();
120  mFormatComboBox->blockSignals( true );
121  for ( const QgsVectorFileWriter::DriverDetails &driver : drivers )
122  {
123  mFormatComboBox->addItem( driver.longName, driver.driverName );
124  }
125 
126  QgsSettings settings;
127  QString format = settings.value( QStringLiteral( "UI/lastVectorFormat" ), "GPKG" ).toString();
128  mFormatComboBox->setCurrentIndex( mFormatComboBox->findData( format ) );
129  mFormatComboBox->blockSignals( false );
130 
131  //add geometry types to combobox
132  mGeometryTypeComboBox->addItem( tr( "Automatic" ), -1 );
133  mGeometryTypeComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconPointLayer.svg" ) ), QgsWkbTypes::displayString( QgsWkbTypes::Point ), QgsWkbTypes::Point );
134  mGeometryTypeComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconLineLayer.svg" ) ), QgsWkbTypes::displayString( QgsWkbTypes::LineString ), QgsWkbTypes::LineString );
135  mGeometryTypeComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconPolygonLayer.svg" ) ), QgsWkbTypes::displayString( QgsWkbTypes::Polygon ), QgsWkbTypes::Polygon );
137  mGeometryTypeComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconTableLayer.svg" ) ), tr( "No geometry" ), QgsWkbTypes::NoGeometry );
138  mGeometryTypeComboBox->setCurrentIndex( mGeometryTypeComboBox->findData( -1 ) );
139 
140  mEncodingComboBox->addItems( QgsVectorDataProvider::availableEncodings() );
141 
142  QString enc = settings.value( QStringLiteral( "UI/encoding" ), "System" ).toString();
143  int idx = mEncodingComboBox->findText( enc );
144  if ( idx < 0 )
145  {
146  mEncodingComboBox->insertItem( 0, enc );
147  idx = 0;
148  }
149 
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." ) );
155 
156  mEncodingComboBox->setCurrentIndex( idx );
157  mFormatComboBox_currentIndexChanged( mFormatComboBox->currentIndex() );
158 
159  //symbology export combo box
160  mSymbologyExportComboBox->addItem( tr( "No symbology" ), QgsVectorFileWriter::NoSymbology );
161  mSymbologyExportComboBox->addItem( tr( "Feature symbology" ), QgsVectorFileWriter::FeatureSymbology );
162  mSymbologyExportComboBox->addItem( tr( "Symbol layer symbology" ), QgsVectorFileWriter::SymbolLayerSymbology );
163  mSymbologyExportComboBox_currentIndexChanged( mSymbologyExportComboBox->currentText() );
164 
165  // extent group box
166  mExtentGroupBox->setOutputCrs( srs );
167  mExtentGroupBox->setOriginalExtent( mLayerExtent, srs );
168  mExtentGroupBox->setOutputExtentFromOriginal();
169  mExtentGroupBox->setCheckable( true );
170  mExtentGroupBox->setChecked( false );
171  mExtentGroupBox->setCollapsed( true );
172 
173  mFilename->setStorageMode( QgsFileWidget::SaveFile );
174  mFilename->setDialogTitle( tr( "Save Layer As" ) );
175  mFilename->setDefaultRoot( settings.value( QStringLiteral( "UI/lastVectorFileFilterDir" ), QDir::homePath() ).toString() );
176  mFilename->setConfirmOverwrite( false );
177  connect( mFilename, &QgsFileWidget::fileChanged, this, [ = ]( const QString & filePath )
178  {
179  QgsSettings settings;
180  QFileInfo tmplFileInfo( filePath );
181  settings.setValue( QStringLiteral( "UI/lastVectorFileFilterDir" ), tmplFileInfo.absolutePath() );
182  if ( !filePath.isEmpty() && leLayername->isEnabled() )
183  {
184  QFileInfo fileInfo( filePath );
185  leLayername->setText( fileInfo.baseName() );
186  }
187  mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( !filePath.isEmpty() );
188  } );
189 }
190 
191 QList<QPair<QLabel *, QWidget *> > QgsVectorLayerSaveAsDialog::createControls( const QMap<QString, QgsVectorFileWriter::Option *> &options )
192 {
193  QList<QPair<QLabel *, QWidget *> > controls;
194  QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
195 
196  for ( it = options.constBegin(); it != options.constEnd(); ++it )
197  {
198  QgsVectorFileWriter::Option *option = it.value();
199  QLabel *label = new QLabel( it.key() );
200  QWidget *control = nullptr;
201  switch ( option->type )
202  {
204  {
205  QgsVectorFileWriter::IntOption *opt = dynamic_cast<QgsVectorFileWriter::IntOption *>( option );
206  if ( opt )
207  {
208  QSpinBox *sb = new QSpinBox();
209  sb->setObjectName( it.key() );
210  sb->setValue( opt->defaultValue );
211  control = sb;
212  }
213  break;
214  }
215 
217  {
218  QgsVectorFileWriter::SetOption *opt = dynamic_cast<QgsVectorFileWriter::SetOption *>( option );
219  if ( opt )
220  {
221  QComboBox *cb = new QComboBox();
222  cb->setObjectName( it.key() );
223  Q_FOREACH ( const QString &val, opt->values )
224  {
225  cb->addItem( val, val );
226  }
227  if ( opt->allowNone )
228  cb->addItem( tr( "<Default>" ), QVariant( QVariant::String ) );
229  int idx = cb->findText( opt->defaultValue );
230  if ( idx == -1 )
231  idx = cb->findData( QVariant( QVariant::String ) );
232  cb->setCurrentIndex( idx );
233  control = cb;
234  }
235  break;
236  }
237 
239  {
241  if ( opt )
242  {
243  QLineEdit *le = new QLineEdit( opt->defaultValue );
244  le->setObjectName( it.key() );
245  control = le;
246  }
247  break;
248  }
249 
251  control = nullptr;
252  break;
253  }
254 
255  if ( control )
256  {
257  // Pack the tooltip in some html element, so it gets linebreaks.
258  label->setToolTip( QStringLiteral( "<p>%1</p>" ).arg( option->docString ) );
259  control->setToolTip( QStringLiteral( "<p>%1</p>" ).arg( option->docString ) );
260 
261  controls << QPair<QLabel *, QWidget *>( label, control );
262  }
263  }
264 
265  return controls;
266 }
267 
268 void QgsVectorLayerSaveAsDialog::accept()
269 {
270  if ( QFile::exists( filename() ) )
271  {
272  QgsVectorFileWriter::EditionCapabilities caps =
274  bool layerExists = QgsVectorFileWriter::targetLayerExists( filename(),
275  layername() );
276  if ( layerExists )
277  {
281  {
282  QMessageBox msgBox;
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 )
292  return;
293  if ( msgBox.clickedButton() == overwriteFileButton )
294  mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteFile;
295  else if ( msgBox.clickedButton() == overwriteLayerButton )
296  mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteLayer;
297  }
298  else if ( !( caps & QgsVectorFileWriter::CanAppendToExistingLayer ) )
299  {
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 )
303  {
304  return;
305  }
306  mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteFile;
307  }
308  else if ( ( caps & QgsVectorFileWriter::CanDeleteLayer ) &&
310  {
311  QMessageBox msgBox;
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 )
322  return;
323  if ( msgBox.clickedButton() == overwriteFileButton )
324  mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteFile;
325  else if ( msgBox.clickedButton() == overwriteLayerButton )
326  mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteLayer;
327  else if ( msgBox.clickedButton() == appendToLayerButton )
328  mActionOnExistingFile = QgsVectorFileWriter::AppendToLayerNoNewFields;
329  }
330  else
331  {
332  QMessageBox msgBox;
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 )
342  return;
343  if ( msgBox.clickedButton() == overwriteFileButton )
344  mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteFile;
345  else if ( msgBox.clickedButton() == appendToLayerButton )
346  mActionOnExistingFile = QgsVectorFileWriter::AppendToLayerNoNewFields;
347  }
348 
349  if ( mActionOnExistingFile == QgsVectorFileWriter::AppendToLayerNoNewFields )
350  {
352  layername(),
353  mLayer,
354  selectedAttributes() ) )
355  {
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 )
359  {
360  mActionOnExistingFile = QgsVectorFileWriter::AppendToLayerAddFields;
361  }
362  }
363  }
364 
365  }
366  else
367  {
368  if ( ( caps & QgsVectorFileWriter::CanAddNewLayer ) )
369  {
370  mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteLayer;
371  }
372  else
373  {
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 )
377  {
378  return;
379  }
380  mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteFile;
381  }
382  }
383  }
384 
385  QgsSettings settings;
386  settings.setValue( QStringLiteral( "UI/lastVectorFileFilterDir" ), QFileInfo( filename() ).absolutePath() );
387  settings.setValue( QStringLiteral( "UI/lastVectorFormat" ), format() );
388  settings.setValue( QStringLiteral( "UI/encoding" ), encoding() );
389  QDialog::accept();
390 }
391 
392 void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int idx )
393 {
394  Q_UNUSED( idx );
395 
396  mFilename->setEnabled( true );
397  mFilename->setFilter( QgsVectorFileWriter::filterForDriver( format() ) );
398 
399  bool selectAllFields = true;
400  bool fieldsAsDisplayedValues = false;
401 
402  const QString sFormat( format() );
403  if ( sFormat == QLatin1String( "DXF" ) || sFormat == QLatin1String( "DGN" ) )
404  {
405  mAttributesSelection->setVisible( false );
406  selectAllFields = false;
407  }
408  else
409  {
410  if ( mOptions & Fields )
411  mAttributesSelection->setVisible( true );
412  fieldsAsDisplayedValues = ( sFormat == QLatin1String( "CSV" ) || sFormat == QLatin1String( "XLS" ) || sFormat == QLatin1String( "XLSX" ) || sFormat == QLatin1String( "ODS" ) );
413  }
414 
415  // Show symbology options only for some formats
416  if ( QgsVectorFileWriter::supportsFeatureStyles( sFormat ) && ( mOptions & Symbology ) )
417  {
418  mSymbologyExportLabel->setVisible( true );
419  mSymbologyExportComboBox->setVisible( true );
420  mScaleLabel->setVisible( true );
421  mScaleWidget->setVisible( true );
422  }
423  else
424  {
425  mSymbologyExportLabel->hide();
426  mSymbologyExportComboBox->hide();
427  mScaleLabel->hide();
428  mScaleWidget->hide();
429  }
430 
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() )
442  {
443  QString layerName = QFileInfo( mFilename->filePath() ).baseName();
444  leLayername->setText( layerName );
445  }
446 
447  if ( mLayer )
448  {
449  mAttributeTable->setRowCount( mLayer->fields().count() );
450 
451  bool foundFieldThatCanBeExportedAsDisplayedValue = false;
452  for ( int i = 0; i < mLayer->fields().size(); ++i )
453  {
454  const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mLayer, mLayer->fields()[i].name() );
455  if ( setup.type() != QLatin1String( "TextEdit" ) &&
457  {
458  foundFieldThatCanBeExportedAsDisplayedValue = true;
459  break;
460  }
461  }
462  if ( foundFieldThatCanBeExportedAsDisplayedValue )
463  {
464  mAttributeTable->setColumnCount( 3 );
465  mAttributeTable->setHorizontalHeaderLabels( QStringList() << tr( "Name" ) << tr( "Type" ) << tr( "Replace with displayed values" ) );
466  }
467  else
468  {
469  mAttributeTable->setColumnCount( 2 );
470  mAttributeTable->setHorizontalHeaderLabels( QStringList() << tr( "Name" ) << tr( "Type" ) );
471  }
472 
473  mAttributeTableItemChangedSlotEnabled = false;
474 
475  for ( int i = 0; i < mLayer->fields().size(); ++i )
476  {
477  QgsField fld = mLayer->fields().at( 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 );
484 
485  item = new QTableWidgetItem( fld.typeName() );
486  item->setFlags( flags );
487  mAttributeTable->setItem( i, COLUMN_IDX_TYPE, item );
488 
489  if ( foundFieldThatCanBeExportedAsDisplayedValue )
490  {
491  const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mLayer, mLayer->fields()[i].name() );
492  QgsEditorWidgetFactory *factory = nullptr;
493  if ( flags == Qt::ItemIsEnabled &&
494  setup.type() != QLatin1String( "TextEdit" ) &&
495  ( factory = QgsGui::editorWidgetRegistry()->factory( setup.type() ) ) )
496  {
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 );
501  }
502  else
503  {
504  item = new QTableWidgetItem();
505  item->setFlags( Qt::NoItemFlags );
506  mAttributeTable->setItem( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE, item );
507  }
508  }
509  }
510 
511  mAttributeTableItemChangedSlotEnabled = true;
512 
513  mReplaceRawFieldValuesStateChangedSlotEnabled = false;
514  mReplaceRawFieldValues->setChecked( selectAllFields && fieldsAsDisplayedValues );
515  mReplaceRawFieldValuesStateChangedSlotEnabled = true;
516  mReplaceRawFieldValues->setEnabled( selectAllFields );
517  mReplaceRawFieldValues->setVisible( foundFieldThatCanBeExportedAsDisplayedValue );
518 
519  mAttributeTable->resizeColumnsToContents();
520  }
521 
522  QgsVectorFileWriter::MetaData driverMetaData;
523 
524  while ( mDatasourceOptionsGroupBox->layout()->count() )
525  {
526  QLayoutItem *item = mDatasourceOptionsGroupBox->layout()->takeAt( 0 );
527  delete item->widget();
528  delete item;
529  }
530 
531  while ( mLayerOptionsGroupBox->layout()->count() )
532  {
533  QLayoutItem *item = mLayerOptionsGroupBox->layout()->takeAt( 0 );
534  delete item->widget();
535  delete item;
536  }
537 
538  // workaround so the Q_FOREACH macro does not get confused by the ','
539  typedef QPair<QLabel *, QWidget *> LabelControlPair;
540 
541  if ( QgsVectorFileWriter::driverMetadata( format(), driverMetaData ) )
542  {
543  if ( !driverMetaData.driverOptions.empty() )
544  {
545  mDatasourceOptionsGroupBox->setVisible( true );
546  QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.driverOptions );
547 
548  QFormLayout *datasourceLayout = dynamic_cast<QFormLayout *>( mDatasourceOptionsGroupBox->layout() );
549 
550  Q_FOREACH ( LabelControlPair control, controls )
551  {
552  datasourceLayout->addRow( control.first, control.second );
553  }
554  }
555  else
556  {
557  mDatasourceOptionsGroupBox->setVisible( false );
558  }
559 
560  if ( !driverMetaData.layerOptions.empty() )
561  {
562  mLayerOptionsGroupBox->setVisible( true );
563  QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.layerOptions );
564 
565  QFormLayout *layerOptionsLayout = dynamic_cast<QFormLayout *>( mLayerOptionsGroupBox->layout() );
566 
567  Q_FOREACH ( LabelControlPair control, controls )
568  {
569  layerOptionsLayout->addRow( control.first, control.second );
570  }
571  }
572  else
573  {
574  mLayerOptionsGroupBox->setVisible( false );
575  }
576 
577  if ( driverMetaData.compulsoryEncoding.isEmpty() )
578  {
579  mEncodingComboBox->setEnabled( true );
580  }
581  else
582  {
583  int idx = mEncodingComboBox->findText( driverMetaData.compulsoryEncoding );
584  if ( idx >= 0 )
585  {
586  mEncodingComboBox->setCurrentIndex( idx );
587  mEncodingComboBox->setDisabled( true );
588  }
589  else
590  {
591  mEncodingComboBox->setEnabled( true );
592  }
593  }
594 
595  }
596  else
597  {
598  mEncodingComboBox->setEnabled( true );
599  }
600 }
601 
602 void QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged( int )
603 {
604  if ( !mReplaceRawFieldValuesStateChangedSlotEnabled )
605  return;
606  if ( mAttributeTable->columnCount() != 3 )
607  return;
608  mReplaceRawFieldValuesStateChangedSlotEnabled = false;
609  mAttributeTableItemChangedSlotEnabled = false;
610  if ( mReplaceRawFieldValues->checkState() != Qt::PartiallyChecked )
611  {
612  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
613  {
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 )
617  {
618  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( mReplaceRawFieldValues->checkState() );
619  }
620  }
621  }
622  mReplaceRawFieldValues->setTristate( false );
623  mAttributeTableItemChangedSlotEnabled = true;
624  mReplaceRawFieldValuesStateChangedSlotEnabled = true;
625 }
626 
627 void QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged( QTableWidgetItem *item )
628 {
629  if ( !mAttributeTableItemChangedSlotEnabled )
630  return;
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 ) )
640  {
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++ )
645  {
646  if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
647  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
648  {
649  checkBoxEnabled = true;
650  break;
651  }
652  }
653  mReplaceRawFieldValues->setEnabled( checkBoxEnabled );
654  if ( !checkBoxEnabled )
655  mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
656  }
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 ) )
662  {
663  mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
664  mReplaceRawFieldValues->setEnabled( true );
665  }
666  else if ( column == COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE &&
667  ( mAttributeTable->item( row, column )->flags() & Qt::ItemIsUserCheckable ) )
668  {
669  bool allChecked = true;
670  bool allUnchecked = true;
671  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
672  {
673  if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
674  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
675  {
676  if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->checkState() == Qt::Unchecked )
677  allChecked = false;
678  else
679  allUnchecked = false;
680  }
681  }
682  mReplaceRawFieldValues->setCheckState( ( !allChecked && !allUnchecked ) ? Qt::PartiallyChecked : ( allChecked ) ? Qt::Checked : Qt::Unchecked );
683  }
684  mAttributeTableItemChangedSlotEnabled = true;
685  mReplaceRawFieldValuesStateChangedSlotEnabled = true;
686 }
687 
688 void QgsVectorLayerSaveAsDialog::mCrsSelector_crsChanged( const QgsCoordinateReferenceSystem &crs )
689 {
690  mCRS = crs.srsid();
691  mExtentGroupBox->setOutputCrs( crs );
692 }
693 
695 {
696  return mFilename->filePath();
697 }
698 
700 {
701  return leLayername->text();
702 }
703 
705 {
706  return mEncodingComboBox->currentText();
707 }
708 
710 {
711  return mFormatComboBox->currentData().toString();
712 }
713 
715 {
716  return mCRS;
717 }
718 
720 {
721  QStringList options;
722 
723  QgsVectorFileWriter::MetaData driverMetaData;
724 
725  if ( QgsVectorFileWriter::driverMetadata( format(), driverMetaData ) )
726  {
727  QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
728 
729  for ( it = driverMetaData.driverOptions.constBegin(); it != driverMetaData.driverOptions.constEnd(); ++it )
730  {
731  switch ( it.value()->type )
732  {
734  {
736  QSpinBox *sb = mDatasourceOptionsGroupBox->findChild<QSpinBox *>( it.key() );
737  if ( opt && sb && sb->value() != opt->defaultValue )
738  options << QStringLiteral( "%1=%2" ).arg( it.key() ).arg( sb->value() );
739  break;
740  }
741 
743  {
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() );
748  break;
749  }
750 
752  {
754  QLineEdit *le = mDatasourceOptionsGroupBox->findChild<QLineEdit *>( it.key() );
755  if ( opt && le && le->text() != opt->defaultValue )
756  options << QStringLiteral( "%1=%2" ).arg( it.key(), le->text() );
757  break;
758  }
759 
761  {
763  dynamic_cast<QgsVectorFileWriter::HiddenOption *>( it.value() );
764  options << QStringLiteral( "%1=%2" ).arg( it.key(), opt->mValue );
765  break;
766  }
767  }
768  }
769  }
770 
771  QString plainText = mOgrDatasourceOptions->toPlainText().trimmed();
772  if ( !plainText.isEmpty() )
773  options += plainText.split( '\n' );
774 
775  return options;
776 }
777 
779 {
780  QStringList options;
781 
782  QgsVectorFileWriter::MetaData driverMetaData;
783 
784  if ( QgsVectorFileWriter::driverMetadata( format(), driverMetaData ) )
785  {
786  QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
787 
788  for ( it = driverMetaData.layerOptions.constBegin(); it != driverMetaData.layerOptions.constEnd(); ++it )
789  {
790  switch ( it.value()->type )
791  {
793  {
795  QSpinBox *sb = mLayerOptionsGroupBox->findChild<QSpinBox *>( it.key() );
796  if ( opt && sb && sb->value() != opt->defaultValue )
797  options << QStringLiteral( "%1=%2" ).arg( it.key() ).arg( sb->value() );
798  break;
799  }
800 
802  {
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() );
807  break;
808  }
809 
811  {
813  QLineEdit *le = mLayerOptionsGroupBox->findChild<QLineEdit *>( it.key() );
814  if ( opt && le && le->text() != opt->defaultValue )
815  options << QStringLiteral( "%1=%2" ).arg( it.key(), le->text() );
816  break;
817  }
818 
820  {
822  dynamic_cast<QgsVectorFileWriter::HiddenOption *>( it.value() );
823  options << QStringLiteral( "%1=%2" ).arg( it.key(), opt->mValue );
824  break;
825  }
826  }
827  }
828  }
829 
830  QString plainText = mOgrLayerOptions->toPlainText().trimmed();
831  if ( !plainText.isEmpty() )
832  options += plainText.split( '\n' );
833 
834  return options;
835 }
836 
838 {
839  QgsAttributeList attributes;
840 
841  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
842  {
843  if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked )
844  {
845  attributes.append( i );
846  }
847  }
848 
849  return attributes;
850 }
851 
853 {
854  QgsAttributeList attributes;
855 
856  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
857  {
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 )
861  {
862  attributes.append( i );
863  }
864  }
865 
866  return attributes;
867 }
868 
870 {
871  return mAddToCanvas->isChecked();
872 }
873 
875 {
876  mAddToCanvas->setChecked( enabled );
877 }
878 
880 {
881  return mSymbologyExportComboBox->currentData().toInt();
882 }
883 
885 {
886  return mScaleWidget->scale();
887 }
888 
890 {
891  mMapCanvas = canvas;
892  mScaleWidget->setMapCanvas( canvas );
893  mScaleWidget->setShowCurrentScaleButton( true );
894  mExtentGroupBox->setCurrentExtent( canvas->mapSettings().visibleExtent(), canvas->mapSettings().destinationCrs() );
895 }
896 
898 {
899  return mExtentGroupBox->isChecked();
900 }
901 
903 {
904  return mExtentGroupBox->outputExtent();
905 }
906 
908 {
909  mSelectedOnly->setChecked( onlySelected );
910 }
911 
913 {
914  return mSelectedOnly->isChecked();
915 }
916 
918 {
919  int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
920  if ( currentIndexData == -1 )
921  {
922  //automatic
923  return QgsWkbTypes::Unknown;
924  }
925 
926  return static_cast< QgsWkbTypes::Type >( currentIndexData );
927 }
928 
930 {
931  int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
932  return currentIndexData == -1;
933 }
934 
936 {
937  return mForceMultiCheckBox->isChecked();
938 }
939 
941 {
942  mForceMultiCheckBox->setChecked( checked );
943 }
944 
946 {
947  return mIncludeZCheckBox->isChecked();
948 }
949 
951 {
952  return mActionOnExistingFile;
953 }
954 
956 {
957  mIncludeZCheckBox->setChecked( checked );
958 }
959 
960 void QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged( const QString &text )
961 {
962  bool scaleEnabled = true;
963  if ( text == tr( "No symbology" ) )
964  {
965  scaleEnabled = false;
966  }
967  mScaleWidget->setEnabled( scaleEnabled );
968  mScaleLabel->setEnabled( scaleEnabled );
969 }
970 
971 void QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged( int index )
972 {
973  int currentIndexData = mGeometryTypeComboBox->itemData( index ).toInt();
974 
975  if ( currentIndexData != -1 && currentIndexData != QgsWkbTypes::NoGeometry )
976  {
977  mForceMultiCheckBox->setEnabled( true );
978  mIncludeZCheckBox->setEnabled( true );
979  }
980  else
981  {
982  mForceMultiCheckBox->setEnabled( false );
983  mForceMultiCheckBox->setChecked( false );
984  mIncludeZCheckBox->setEnabled( false );
985  mIncludeZCheckBox->setChecked( false );
986  }
987 }
988 
989 void QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked()
990 {
991  mAttributeTableItemChangedSlotEnabled = false;
992  mReplaceRawFieldValuesStateChangedSlotEnabled = false;
993  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
994  {
995  if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->flags() & Qt::ItemIsEnabled )
996  {
997  if ( mAttributeTable->columnCount() == 3 &&
998  ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
999  {
1000  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
1001  }
1002  mAttributeTable->item( i, COLUMN_IDX_NAME )->setCheckState( Qt::Checked );
1003  }
1004  }
1005  if ( mAttributeTable->columnCount() == 3 )
1006  {
1007  mReplaceRawFieldValues->setEnabled( true );
1008  }
1009  mAttributeTableItemChangedSlotEnabled = true;
1010  mReplaceRawFieldValuesStateChangedSlotEnabled = true;
1011 }
1012 
1013 void QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked()
1014 {
1015  mAttributeTableItemChangedSlotEnabled = false;
1016  mReplaceRawFieldValuesStateChangedSlotEnabled = false;
1017  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
1018  {
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 ) )
1022  {
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 );
1025  }
1026  }
1027  if ( mAttributeTable->columnCount() == 3 )
1028  {
1029  mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
1030  mReplaceRawFieldValues->setEnabled( false );
1031  }
1032  mAttributeTableItemChangedSlotEnabled = true;
1033  mReplaceRawFieldValuesStateChangedSlotEnabled = true;
1034 }
1035 
1036 void QgsVectorLayerSaveAsDialog::showHelp()
1037 {
1038  QgsHelp::openHelp( QStringLiteral( "managing_data_source/create_layers.html#save-layer-from-an-existing-file" ) );
1039 }
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.
Definition: qgsrectangle.h:41
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.
Definition: qgsfields.cpp:138
void fileChanged(const QString &)
emitted as soon as the current file or directory is changed
QString name
Definition: qgsfield.h:58
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:
Definition: qgssettings.h:58
QgsEditorWidgetFactory * factory(const QString &widgetId)
Gets a factory for the given widget type id.
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.
Definition: qgsfields.cpp:133
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.
Definition: qgsmapcanvas.h:73
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)
Definition: qgsfields.cpp:163
Show destination CRS (reprojection) option.
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
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.
Definition: qgsfield.cpp:105
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...
Definition: qgsgui.cpp:59
Every attribute editor widget needs a factory, which inherits this class.
QgsAttributeList attributesAsDisplayedValues() const
Returns selected attributes that must be exported with their displayed values instead of their raw va...
QMap< QString, QgsVectorFileWriter::Option * > layerOptions
ActionOnExistingFile
Combination of CanAddNewLayer, CanAppendToExistingLayer, CanAddNewFieldsToExistingLayer or CanDeleteL...
Show field customization group.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:48
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.
QString compulsoryEncoding
Some formats require a compulsory encoding, typically UTF-8. If no compulsory encoding, empty string.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
double scale() const
Returns the specified map scale.
QString name()
Returns The human readable identifier name of this widget type.
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.
QgsEditorWidgetSetup findBest(const QgsVectorLayer *vl, const QString &fieldName) const
Find the best editor widget and its configuration for a given field.
void crsChanged(const QgsCoordinateReferenceSystem &)
Emitted when the selected CRS is changed.
QgsAttributeList selectedAttributes() const
Returns a list of attributes which are selected for saving.
Holder for the widget type and its configuration for a field.
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).
Select multiple files.
Definition: qgsfilewidget.h:68
QMap< QString, QgsVectorFileWriter::Option * > driverOptions
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...
Definition: qgsgui.cpp:104
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition: qgshelp.cpp:36
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
Definition: qgsfield.h:27
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
Definition: qgsmaplayer.h:71
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)