QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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  for ( const QString &val : qgis::as_const( 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  const auto constControls = controls;
551  for ( LabelControlPair control : constControls )
552  {
553  datasourceLayout->addRow( control.first, control.second );
554  }
555  }
556  else
557  {
558  mDatasourceOptionsGroupBox->setVisible( false );
559  }
560 
561  if ( !driverMetaData.layerOptions.empty() )
562  {
563  mLayerOptionsGroupBox->setVisible( true );
564  QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.layerOptions );
565 
566  QFormLayout *layerOptionsLayout = dynamic_cast<QFormLayout *>( mLayerOptionsGroupBox->layout() );
567 
568  const auto constControls = controls;
569  for ( LabelControlPair control : constControls )
570  {
571  layerOptionsLayout->addRow( control.first, control.second );
572  }
573  }
574  else
575  {
576  mLayerOptionsGroupBox->setVisible( false );
577  }
578 
579  if ( driverMetaData.compulsoryEncoding.isEmpty() )
580  {
581  mEncodingComboBox->setEnabled( true );
582  }
583  else
584  {
585  int idx = mEncodingComboBox->findText( driverMetaData.compulsoryEncoding );
586  if ( idx >= 0 )
587  {
588  mEncodingComboBox->setCurrentIndex( idx );
589  mEncodingComboBox->setDisabled( true );
590  }
591  else
592  {
593  mEncodingComboBox->setEnabled( true );
594  }
595  }
596 
597  }
598  else
599  {
600  mEncodingComboBox->setEnabled( true );
601  }
602 }
603 
604 void QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged( int )
605 {
606  if ( !mReplaceRawFieldValuesStateChangedSlotEnabled )
607  return;
608  if ( mAttributeTable->columnCount() != 3 )
609  return;
610  mReplaceRawFieldValuesStateChangedSlotEnabled = false;
611  mAttributeTableItemChangedSlotEnabled = false;
612  if ( mReplaceRawFieldValues->checkState() != Qt::PartiallyChecked )
613  {
614  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
615  {
616  if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked &&
617  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
618  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
619  {
620  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( mReplaceRawFieldValues->checkState() );
621  }
622  }
623  }
624  mReplaceRawFieldValues->setTristate( false );
625  mAttributeTableItemChangedSlotEnabled = true;
626  mReplaceRawFieldValuesStateChangedSlotEnabled = true;
627 }
628 
629 void QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged( QTableWidgetItem *item )
630 {
631  if ( !mAttributeTableItemChangedSlotEnabled )
632  return;
633  mReplaceRawFieldValuesStateChangedSlotEnabled = false;
634  mAttributeTableItemChangedSlotEnabled = false;
635  int row = item->row();
636  int column = item->column();
637  if ( column == COLUMN_IDX_NAME &&
638  mAttributeTable->item( row, column )->checkState() == Qt::Unchecked &&
639  mAttributeTable->columnCount() == 3 &&
640  mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
641  ( mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
642  {
643  mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( Qt::Unchecked );
644  mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable );
645  bool checkBoxEnabled = false;
646  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
647  {
648  if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
649  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
650  {
651  checkBoxEnabled = true;
652  break;
653  }
654  }
655  mReplaceRawFieldValues->setEnabled( checkBoxEnabled );
656  if ( !checkBoxEnabled )
657  mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
658  }
659  else if ( column == COLUMN_IDX_NAME &&
660  mAttributeTable->item( row, column )->checkState() == Qt::Checked &&
661  mAttributeTable->columnCount() == 3 &&
662  mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
663  ( mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
664  {
665  mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
666  mReplaceRawFieldValues->setEnabled( true );
667  }
668  else if ( column == COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE &&
669  ( mAttributeTable->item( row, column )->flags() & Qt::ItemIsUserCheckable ) )
670  {
671  bool allChecked = true;
672  bool allUnchecked = true;
673  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
674  {
675  if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
676  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
677  {
678  if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->checkState() == Qt::Unchecked )
679  allChecked = false;
680  else
681  allUnchecked = false;
682  }
683  }
684  mReplaceRawFieldValues->setCheckState( ( !allChecked && !allUnchecked ) ? Qt::PartiallyChecked : ( allChecked ) ? Qt::Checked : Qt::Unchecked );
685  }
686  mAttributeTableItemChangedSlotEnabled = true;
687  mReplaceRawFieldValuesStateChangedSlotEnabled = true;
688 }
689 
690 void QgsVectorLayerSaveAsDialog::mCrsSelector_crsChanged( const QgsCoordinateReferenceSystem &crs )
691 {
692  mCRS = crs.srsid();
693  mExtentGroupBox->setOutputCrs( crs );
694 }
695 
697 {
698  return mFilename->filePath();
699 }
700 
702 {
703  return leLayername->text();
704 }
705 
707 {
708  return mEncodingComboBox->currentText();
709 }
710 
712 {
713  return mFormatComboBox->currentData().toString();
714 }
715 
717 {
718  return mCRS;
719 }
720 
722 {
723  QStringList options;
724 
725  QgsVectorFileWriter::MetaData driverMetaData;
726 
727  if ( QgsVectorFileWriter::driverMetadata( format(), driverMetaData ) )
728  {
729  QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
730 
731  for ( it = driverMetaData.driverOptions.constBegin(); it != driverMetaData.driverOptions.constEnd(); ++it )
732  {
733  switch ( it.value()->type )
734  {
736  {
738  QSpinBox *sb = mDatasourceOptionsGroupBox->findChild<QSpinBox *>( it.key() );
739  if ( opt && sb && sb->value() != opt->defaultValue )
740  options << QStringLiteral( "%1=%2" ).arg( it.key() ).arg( sb->value() );
741  break;
742  }
743 
745  {
747  QComboBox *cb = mDatasourceOptionsGroupBox->findChild<QComboBox *>( it.key() );
748  if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->defaultValue )
749  options << QStringLiteral( "%1=%2" ).arg( it.key(), cb->currentText() );
750  break;
751  }
752 
754  {
756  QLineEdit *le = mDatasourceOptionsGroupBox->findChild<QLineEdit *>( it.key() );
757  if ( opt && le && le->text() != opt->defaultValue )
758  options << QStringLiteral( "%1=%2" ).arg( it.key(), le->text() );
759  break;
760  }
761 
763  {
765  dynamic_cast<QgsVectorFileWriter::HiddenOption *>( it.value() );
766  options << QStringLiteral( "%1=%2" ).arg( it.key(), opt->mValue );
767  break;
768  }
769  }
770  }
771  }
772 
773  QString plainText = mOgrDatasourceOptions->toPlainText().trimmed();
774  if ( !plainText.isEmpty() )
775  options += plainText.split( '\n' );
776 
777  return options;
778 }
779 
781 {
782  QStringList options;
783 
784  QgsVectorFileWriter::MetaData driverMetaData;
785 
786  if ( QgsVectorFileWriter::driverMetadata( format(), driverMetaData ) )
787  {
788  QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
789 
790  for ( it = driverMetaData.layerOptions.constBegin(); it != driverMetaData.layerOptions.constEnd(); ++it )
791  {
792  switch ( it.value()->type )
793  {
795  {
797  QSpinBox *sb = mLayerOptionsGroupBox->findChild<QSpinBox *>( it.key() );
798  if ( opt && sb && sb->value() != opt->defaultValue )
799  options << QStringLiteral( "%1=%2" ).arg( it.key() ).arg( sb->value() );
800  break;
801  }
802 
804  {
806  QComboBox *cb = mLayerOptionsGroupBox->findChild<QComboBox *>( it.key() );
807  if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->defaultValue )
808  options << QStringLiteral( "%1=%2" ).arg( it.key(), cb->currentText() );
809  break;
810  }
811 
813  {
815  QLineEdit *le = mLayerOptionsGroupBox->findChild<QLineEdit *>( it.key() );
816  if ( opt && le && le->text() != opt->defaultValue )
817  options << QStringLiteral( "%1=%2" ).arg( it.key(), le->text() );
818  break;
819  }
820 
822  {
824  dynamic_cast<QgsVectorFileWriter::HiddenOption *>( it.value() );
825  options << QStringLiteral( "%1=%2" ).arg( it.key(), opt->mValue );
826  break;
827  }
828  }
829  }
830  }
831 
832  QString plainText = mOgrLayerOptions->toPlainText().trimmed();
833  if ( !plainText.isEmpty() )
834  options += plainText.split( '\n' );
835 
836  return options;
837 }
838 
840 {
841  QgsAttributeList attributes;
842 
843  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
844  {
845  if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked )
846  {
847  attributes.append( i );
848  }
849  }
850 
851  return attributes;
852 }
853 
855 {
856  QgsAttributeList attributes;
857 
858  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
859  {
860  if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked &&
861  mAttributeTable->columnCount() == 3 &&
862  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->checkState() == Qt::Checked )
863  {
864  attributes.append( i );
865  }
866  }
867 
868  return attributes;
869 }
870 
872 {
873  return mAddToCanvas->isChecked();
874 }
875 
877 {
878  mAddToCanvas->setChecked( enabled );
879 }
880 
882 {
883  return mSymbologyExportComboBox->currentData().toInt();
884 }
885 
887 {
888  return mScaleWidget->scale();
889 }
890 
892 {
893  mMapCanvas = canvas;
894  mScaleWidget->setMapCanvas( canvas );
895  mScaleWidget->setShowCurrentScaleButton( true );
896  mExtentGroupBox->setCurrentExtent( canvas->mapSettings().visibleExtent(), canvas->mapSettings().destinationCrs() );
897 }
898 
900 {
901  return mExtentGroupBox->isChecked();
902 }
903 
905 {
906  return mExtentGroupBox->outputExtent();
907 }
908 
910 {
911  mSelectedOnly->setChecked( onlySelected );
912 }
913 
915 {
916  return mSelectedOnly->isChecked();
917 }
918 
920 {
921  int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
922  if ( currentIndexData == -1 )
923  {
924  //automatic
925  return QgsWkbTypes::Unknown;
926  }
927 
928  return static_cast< QgsWkbTypes::Type >( currentIndexData );
929 }
930 
932 {
933  int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
934  return currentIndexData == -1;
935 }
936 
938 {
939  return mForceMultiCheckBox->isChecked();
940 }
941 
943 {
944  mForceMultiCheckBox->setChecked( checked );
945 }
946 
948 {
949  return mIncludeZCheckBox->isChecked();
950 }
951 
953 {
954  return mActionOnExistingFile;
955 }
956 
958 {
959  mIncludeZCheckBox->setChecked( checked );
960 }
961 
962 void QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged( const QString &text )
963 {
964  bool scaleEnabled = true;
965  if ( text == tr( "No symbology" ) )
966  {
967  scaleEnabled = false;
968  }
969  mScaleWidget->setEnabled( scaleEnabled );
970  mScaleLabel->setEnabled( scaleEnabled );
971 }
972 
973 void QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged( int index )
974 {
975  int currentIndexData = mGeometryTypeComboBox->itemData( index ).toInt();
976 
977  if ( currentIndexData != -1 && currentIndexData != QgsWkbTypes::NoGeometry )
978  {
979  mForceMultiCheckBox->setEnabled( true );
980  mIncludeZCheckBox->setEnabled( true );
981  }
982  else
983  {
984  mForceMultiCheckBox->setEnabled( false );
985  mForceMultiCheckBox->setChecked( false );
986  mIncludeZCheckBox->setEnabled( false );
987  mIncludeZCheckBox->setChecked( false );
988  }
989 }
990 
991 void QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked()
992 {
993  mAttributeTableItemChangedSlotEnabled = false;
994  mReplaceRawFieldValuesStateChangedSlotEnabled = false;
995  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
996  {
997  if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->flags() & Qt::ItemIsEnabled )
998  {
999  if ( mAttributeTable->columnCount() == 3 &&
1000  ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
1001  {
1002  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
1003  }
1004  mAttributeTable->item( i, COLUMN_IDX_NAME )->setCheckState( Qt::Checked );
1005  }
1006  }
1007  if ( mAttributeTable->columnCount() == 3 )
1008  {
1009  mReplaceRawFieldValues->setEnabled( true );
1010  }
1011  mAttributeTableItemChangedSlotEnabled = true;
1012  mReplaceRawFieldValuesStateChangedSlotEnabled = true;
1013 }
1014 
1015 void QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked()
1016 {
1017  mAttributeTableItemChangedSlotEnabled = false;
1018  mReplaceRawFieldValuesStateChangedSlotEnabled = false;
1019  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
1020  {
1021  mAttributeTable->item( i, COLUMN_IDX_NAME )->setCheckState( Qt::Unchecked );
1022  if ( mAttributeTable->columnCount() == 3 &&
1023  ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
1024  {
1025  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable );
1026  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( Qt::Unchecked );
1027  }
1028  }
1029  if ( mAttributeTable->columnCount() == 3 )
1030  {
1031  mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
1032  mReplaceRawFieldValues->setEnabled( false );
1033  }
1034  mAttributeTableItemChangedSlotEnabled = true;
1035  mReplaceRawFieldValuesStateChangedSlotEnabled = true;
1036 }
1037 
1038 void QgsVectorLayerSaveAsDialog::showHelp()
1039 {
1040  QgsHelp::openHelp( QStringLiteral( "managing_data_source/create_layers.html#save-layer-from-an-existing-file" ) );
1041 }
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 a single new or pre-existing file.
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:85
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)