QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 #include "gdal.h"
34 
35 static const int COLUMN_IDX_NAME = 0;
36 static const int COLUMN_IDX_TYPE = 1;
37 static const int COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE = 2;
38 
39 QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( long srsid, QWidget *parent, Qt::WindowFlags fl )
40  : QDialog( parent, fl )
41  , mCRS( srsid )
42  , mAttributeTableItemChangedSlotEnabled( true )
43  , mReplaceRawFieldValuesStateChangedSlotEnabled( true )
44  , mActionOnExistingFile( QgsVectorFileWriter::CreateOrOverwriteFile )
45 {
46  setup();
47 }
48 
49 QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( QgsVectorLayer *layer, int options, QWidget *parent, Qt::WindowFlags fl )
50  : QDialog( parent, fl )
51  , mLayer( layer )
52  , mAttributeTableItemChangedSlotEnabled( true )
53  , mReplaceRawFieldValuesStateChangedSlotEnabled( true )
54  , mActionOnExistingFile( QgsVectorFileWriter::CreateOrOverwriteFile )
55  , mOptions( static_cast< Options >( options ) )
56 {
57  if ( layer )
58  {
59  mCRS = layer->crs().srsid();
60  mLayerExtent = layer->extent();
61  }
62  setup();
63 
64  if ( !( mOptions & Symbology ) )
65  {
66  mSymbologyExportLabel->hide();
67  mSymbologyExportComboBox->hide();
68  mScaleLabel->hide();
69  mScaleWidget->hide();
70  }
71 
72  if ( !( mOptions & DestinationCrs ) )
73  {
74  mCrsLabel->hide();
75  mCrsSelector->hide();
76  }
77  if ( !( mOptions & Fields ) )
78  mAttributesSelection->hide();
79 
80  if ( !( mOptions & SelectedOnly ) )
81  mSelectedOnly->hide();
82 
83  if ( !( mOptions & AddToCanvas ) )
84  mAddToCanvas->hide();
85 
86  if ( !( mOptions & GeometryType ) )
87  mGeometryGroupBox->hide();
88 
89  if ( !( mOptions & Extent ) )
90  mExtentGroupBox->hide();
91 
92  mSelectedOnly->setEnabled( layer && layer->selectedFeatureCount() != 0 );
93  mButtonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
94 }
95 
96 void QgsVectorLayerSaveAsDialog::setup()
97 {
98  setupUi( this );
100 
101  connect( mFormatComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged );
102  connect( mCrsSelector, &QgsProjectionSelectionWidget::crsChanged, this, &QgsVectorLayerSaveAsDialog::mCrsSelector_crsChanged );
103  connect( mSymbologyExportComboBox, &QComboBox::currentTextChanged, this, &QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged );
104  connect( mGeometryTypeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged );
105  connect( mSelectAllAttributes, &QPushButton::clicked, this, &QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked );
106  connect( mDeselectAllAttributes, &QPushButton::clicked, this, &QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked );
107  connect( mReplaceRawFieldValues, &QCheckBox::stateChanged, this, &QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged );
108  connect( mAttributeTable, &QTableWidget::itemChanged, this, &QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged );
109 
110 #ifdef Q_OS_WIN
111  mHelpButtonBox->setVisible( false );
112  mButtonBox->addButton( QDialogButtonBox::Help );
113  connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsVectorLayerSaveAsDialog::showHelp );
114 #else
115  connect( mHelpButtonBox, &QDialogButtonBox::helpRequested, this, &QgsVectorLayerSaveAsDialog::showHelp );
116 #endif
117  connect( mButtonBox, &QDialogButtonBox::accepted, this, &QgsVectorLayerSaveAsDialog::accept );
118  connect( mButtonBox, &QDialogButtonBox::rejected, this, &QgsVectorLayerSaveAsDialog::reject );
119 
120  const QList< QgsVectorFileWriter::DriverDetails > drivers = QgsVectorFileWriter::ogrDriverList();
121  mFormatComboBox->blockSignals( true );
122  for ( const QgsVectorFileWriter::DriverDetails &driver : drivers )
123  {
124  mFormatComboBox->addItem( driver.longName, driver.driverName );
125  }
126 
127  QgsSettings settings;
128  QString format = settings.value( QStringLiteral( "UI/lastVectorFormat" ), "GPKG" ).toString();
129  mFormatComboBox->setCurrentIndex( mFormatComboBox->findData( format ) );
130  mFormatComboBox->blockSignals( false );
131 
132  //add geometry types to combobox
133  mGeometryTypeComboBox->addItem( tr( "Automatic" ), -1 );
134  mGeometryTypeComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconPointLayer.svg" ) ), QgsWkbTypes::displayString( QgsWkbTypes::Point ), QgsWkbTypes::Point );
135  mGeometryTypeComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconLineLayer.svg" ) ), QgsWkbTypes::displayString( QgsWkbTypes::LineString ), QgsWkbTypes::LineString );
136  mGeometryTypeComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconPolygonLayer.svg" ) ), QgsWkbTypes::displayString( QgsWkbTypes::Polygon ), QgsWkbTypes::Polygon );
138  mGeometryTypeComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconTableLayer.svg" ) ), tr( "No geometry" ), QgsWkbTypes::NoGeometry );
139  mGeometryTypeComboBox->setCurrentIndex( mGeometryTypeComboBox->findData( -1 ) );
140 
141  mEncodingComboBox->addItems( QgsVectorDataProvider::availableEncodings() );
142 
143  QString enc = settings.value( QStringLiteral( "UI/encoding" ), "System" ).toString();
144  int idx = mEncodingComboBox->findText( enc );
145  if ( idx < 0 )
146  {
147  mEncodingComboBox->insertItem( 0, enc );
148  idx = 0;
149  }
150 
152  mCrsSelector->setCrs( srs );
153  mCrsSelector->setLayerCrs( srs );
154  mCrsSelector->setMessage( tr( "Select the coordinate reference system for the vector file. "
155  "The data points will be transformed from the layer coordinate reference system." ) );
156 
157  mEncodingComboBox->setCurrentIndex( idx );
158  mFormatComboBox_currentIndexChanged( mFormatComboBox->currentIndex() );
159 
160  //symbology export combo box
161  mSymbologyExportComboBox->addItem( tr( "No symbology" ), QgsVectorFileWriter::NoSymbology );
162  mSymbologyExportComboBox->addItem( tr( "Feature symbology" ), QgsVectorFileWriter::FeatureSymbology );
163  mSymbologyExportComboBox->addItem( tr( "Symbol layer symbology" ), QgsVectorFileWriter::SymbolLayerSymbology );
164  mSymbologyExportComboBox_currentIndexChanged( mSymbologyExportComboBox->currentText() );
165 
166  // extent group box
167  mExtentGroupBox->setOutputCrs( srs );
168  mExtentGroupBox->setOriginalExtent( mLayerExtent, srs );
169  mExtentGroupBox->setOutputExtentFromOriginal();
170  mExtentGroupBox->setCheckable( true );
171  mExtentGroupBox->setChecked( false );
172  mExtentGroupBox->setCollapsed( true );
173 
174  mFilename->setStorageMode( QgsFileWidget::SaveFile );
175  mFilename->setDialogTitle( tr( "Save Layer As" ) );
176  mFilename->setDefaultRoot( settings.value( QStringLiteral( "UI/lastVectorFileFilterDir" ), QDir::homePath() ).toString() );
177  mFilename->setConfirmOverwrite( false );
178  connect( mFilename, &QgsFileWidget::fileChanged, this, [ = ]( const QString & filePath )
179  {
180  QgsSettings settings;
181  QFileInfo tmplFileInfo( filePath );
182  settings.setValue( QStringLiteral( "UI/lastVectorFileFilterDir" ), tmplFileInfo.absolutePath() );
183  if ( !filePath.isEmpty() && leLayername->isEnabled() )
184  {
185  QFileInfo fileInfo( filePath );
186  leLayername->setText( fileInfo.baseName() );
187  }
188  mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( !filePath.isEmpty() );
189  } );
190 }
191 
192 QList<QPair<QLabel *, QWidget *> > QgsVectorLayerSaveAsDialog::createControls( const QMap<QString, QgsVectorFileWriter::Option *> &options )
193 {
194  QList<QPair<QLabel *, QWidget *> > controls;
195  QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
196 
197  for ( it = options.constBegin(); it != options.constEnd(); ++it )
198  {
199  QgsVectorFileWriter::Option *option = it.value();
200  QLabel *label = new QLabel( it.key() );
201  QWidget *control = nullptr;
202  switch ( option->type )
203  {
205  {
206  QgsVectorFileWriter::IntOption *opt = dynamic_cast<QgsVectorFileWriter::IntOption *>( option );
207  if ( opt )
208  {
209  QSpinBox *sb = new QSpinBox();
210  sb->setObjectName( it.key() );
211  sb->setValue( opt->defaultValue );
212  control = sb;
213  }
214  break;
215  }
216 
218  {
219  QgsVectorFileWriter::SetOption *opt = dynamic_cast<QgsVectorFileWriter::SetOption *>( option );
220  if ( opt )
221  {
222  QComboBox *cb = new QComboBox();
223  cb->setObjectName( it.key() );
224  for ( const QString &val : qgis::as_const( opt->values ) )
225  {
226  cb->addItem( val, val );
227  }
228  if ( opt->allowNone )
229  cb->addItem( tr( "<Default>" ), QVariant( QVariant::String ) );
230  int idx = cb->findText( opt->defaultValue );
231  if ( idx == -1 )
232  idx = cb->findData( QVariant( QVariant::String ) );
233  cb->setCurrentIndex( idx );
234  control = cb;
235  }
236  break;
237  }
238 
240  {
242  if ( opt )
243  {
244  QLineEdit *le = new QLineEdit( opt->defaultValue );
245  le->setObjectName( it.key() );
246  control = le;
247  }
248  break;
249  }
250 
252  control = nullptr;
253  break;
254  }
255 
256  if ( control )
257  {
258  // Pack the tooltip in some html element, so it gets linebreaks.
259  label->setToolTip( QStringLiteral( "<p>%1</p>" ).arg( option->docString ) );
260  control->setToolTip( QStringLiteral( "<p>%1</p>" ).arg( option->docString ) );
261 
262  controls << QPair<QLabel *, QWidget *>( label, control );
263  }
264  }
265 
266  return controls;
267 }
268 
269 void QgsVectorLayerSaveAsDialog::accept()
270 {
271  if ( QFile::exists( filename() ) )
272  {
273  QgsVectorFileWriter::EditionCapabilities caps =
275  bool layerExists = QgsVectorFileWriter::targetLayerExists( filename(),
276  layername() );
277  if ( layerExists )
278  {
282  {
283  QMessageBox msgBox;
284  msgBox.setIcon( QMessageBox::Question );
285  msgBox.setWindowTitle( tr( "Save Vector Layer As" ) );
286  msgBox.setText( tr( "The layer already exists. Do you want to overwrite the whole file or overwrite the layer?" ) );
287  QPushButton *overwriteFileButton = msgBox.addButton( tr( "Overwrite File" ), QMessageBox::ActionRole );
288  QPushButton *overwriteLayerButton = msgBox.addButton( tr( "Overwrite Layer" ), QMessageBox::ActionRole );
289  msgBox.setStandardButtons( QMessageBox::Cancel );
290  msgBox.setDefaultButton( QMessageBox::Cancel );
291  int ret = msgBox.exec();
292  if ( ret == QMessageBox::Cancel )
293  return;
294  if ( msgBox.clickedButton() == overwriteFileButton )
295  mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteFile;
296  else if ( msgBox.clickedButton() == overwriteLayerButton )
297  mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteLayer;
298  }
299  else if ( !( caps & QgsVectorFileWriter::CanAppendToExistingLayer ) )
300  {
301  if ( QMessageBox::question( this,
302  tr( "Save Vector Layer As" ),
303  tr( "The file already exists. Do you want to overwrite it?" ) ) == QMessageBox::NoButton )
304  {
305  return;
306  }
307  mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteFile;
308  }
309  else if ( ( caps & QgsVectorFileWriter::CanDeleteLayer ) &&
311  {
312  QMessageBox msgBox;
313  msgBox.setIcon( QMessageBox::Question );
314  msgBox.setWindowTitle( tr( "Save Vector Layer As" ) );
315  msgBox.setText( tr( "The layer already exists. Do you want to overwrite the whole file, overwrite the layer or append features to the layer?" ) );
316  QPushButton *overwriteFileButton = msgBox.addButton( tr( "Overwrite File" ), QMessageBox::ActionRole );
317  QPushButton *overwriteLayerButton = msgBox.addButton( tr( "Overwrite Layer" ), QMessageBox::ActionRole );
318  QPushButton *appendToLayerButton = msgBox.addButton( tr( "Append to Layer" ), QMessageBox::ActionRole );
319  msgBox.setStandardButtons( QMessageBox::Cancel );
320  msgBox.setDefaultButton( QMessageBox::Cancel );
321  int ret = msgBox.exec();
322  if ( ret == QMessageBox::Cancel )
323  return;
324  if ( msgBox.clickedButton() == overwriteFileButton )
325  mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteFile;
326  else if ( msgBox.clickedButton() == overwriteLayerButton )
327  mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteLayer;
328  else if ( msgBox.clickedButton() == appendToLayerButton )
329  mActionOnExistingFile = QgsVectorFileWriter::AppendToLayerNoNewFields;
330  }
331  else
332  {
333  QMessageBox msgBox;
334  msgBox.setIcon( QMessageBox::Question );
335  msgBox.setWindowTitle( tr( "Save Vector Layer As" ) );
336  msgBox.setText( tr( "The layer already exists. Do you want to overwrite the whole file or append features to the layer?" ) );
337  QPushButton *overwriteFileButton = msgBox.addButton( tr( "Overwrite File" ), QMessageBox::ActionRole );
338  QPushButton *appendToLayerButton = msgBox.addButton( tr( "Append to Layer" ), QMessageBox::ActionRole );
339  msgBox.setStandardButtons( QMessageBox::Cancel );
340  msgBox.setDefaultButton( QMessageBox::Cancel );
341  int ret = msgBox.exec();
342  if ( ret == QMessageBox::Cancel )
343  return;
344  if ( msgBox.clickedButton() == overwriteFileButton )
345  mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteFile;
346  else if ( msgBox.clickedButton() == appendToLayerButton )
347  mActionOnExistingFile = QgsVectorFileWriter::AppendToLayerNoNewFields;
348  }
349 
350  if ( mActionOnExistingFile == QgsVectorFileWriter::AppendToLayerNoNewFields )
351  {
353  layername(),
354  mLayer,
355  selectedAttributes() ) )
356  {
357  if ( QMessageBox::question( this,
358  tr( "Save Vector Layer As" ),
359  tr( "The existing layer has different fields. Do you want to add the missing fields to the layer?" ) ) == QMessageBox::Yes )
360  {
361  mActionOnExistingFile = QgsVectorFileWriter::AppendToLayerAddFields;
362  }
363  }
364  }
365 
366  }
367  else
368  {
369  if ( ( caps & QgsVectorFileWriter::CanAddNewLayer ) )
370  {
371  mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteLayer;
372  }
373  else
374  {
375  if ( QMessageBox::question( this,
376  tr( "Save Vector Layer As" ),
377  tr( "The file already exists. Do you want to overwrite it?" ) ) == QMessageBox::NoButton )
378  {
379  return;
380  }
381  mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteFile;
382  }
383  }
384  }
385 
386  QgsSettings settings;
387  settings.setValue( QStringLiteral( "UI/lastVectorFileFilterDir" ), QFileInfo( filename() ).absolutePath() );
388  settings.setValue( QStringLiteral( "UI/lastVectorFormat" ), format() );
389  settings.setValue( QStringLiteral( "UI/encoding" ), encoding() );
390  QDialog::accept();
391 }
392 
393 void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int idx )
394 {
395  Q_UNUSED( idx )
396 
397  mFilename->setEnabled( true );
398  mFilename->setFilter( QgsVectorFileWriter::filterForDriver( format() ) );
399 
400  // if output filename already defined we need to replace old suffix
401  // to avoid double extensions like .gpkg.shp
402  if ( !mFilename->filePath().isEmpty() )
403  {
404  QRegularExpression rx( "\\.(.*?)[\\s]" );
405  QString ext;
406  ext = rx.match( QgsVectorFileWriter::filterForDriver( format() ) ).captured( 1 );
407  if ( !ext.isEmpty() )
408  {
409  QFileInfo fi( mFilename->filePath() );
410  mFilename->setFilePath( QStringLiteral( "%1/%2.%3" ).arg( fi.path() ).arg( fi.baseName() ).arg( ext ) );
411  }
412  }
413 
414  bool selectAllFields = true;
415  bool fieldsAsDisplayedValues = false;
416 
417  const QString sFormat( format() );
418  if ( sFormat == QLatin1String( "DXF" ) || sFormat == QLatin1String( "DGN" ) )
419  {
420  mAttributesSelection->setVisible( false );
421  selectAllFields = false;
422  }
423  else
424  {
425  if ( mOptions & Fields )
426  mAttributesSelection->setVisible( true );
427  fieldsAsDisplayedValues = ( sFormat == QLatin1String( "CSV" ) || sFormat == QLatin1String( "XLS" ) || sFormat == QLatin1String( "XLSX" ) || sFormat == QLatin1String( "ODS" ) );
428  }
429 
430  // Show symbology options only for some formats
431  if ( QgsVectorFileWriter::supportsFeatureStyles( sFormat ) && ( mOptions & Symbology ) )
432  {
433  mSymbologyExportLabel->setVisible( true );
434  mSymbologyExportComboBox->setVisible( true );
435  mScaleLabel->setVisible( true );
436  mScaleWidget->setVisible( true );
437  }
438  else
439  {
440  mSymbologyExportLabel->hide();
441  mSymbologyExportComboBox->hide();
442  mScaleLabel->hide();
443  mScaleWidget->hide();
444  }
445 
446  leLayername->setEnabled( sFormat == QLatin1String( "KML" ) ||
447  sFormat == QLatin1String( "GPKG" ) ||
448  sFormat == QLatin1String( "XLSX" ) ||
449  sFormat == QLatin1String( "ODS" ) ||
450  sFormat == QLatin1String( "FileGDB" ) ||
451  sFormat == QLatin1String( "SQLite" ) ||
452  sFormat == QLatin1String( "SpatiaLite" ) );
453  if ( !leLayername->isEnabled() )
454  leLayername->setText( QString() );
455  else if ( leLayername->text().isEmpty() &&
456  !mFilename->filePath().isEmpty() )
457  {
458  QString layerName = QFileInfo( mFilename->filePath() ).baseName();
459  leLayername->setText( layerName );
460  }
461 
462  if ( mLayer )
463  {
464  mAttributeTable->setRowCount( mLayer->fields().count() );
465 
466  bool foundFieldThatCanBeExportedAsDisplayedValue = false;
467  for ( int i = 0; i < mLayer->fields().size(); ++i )
468  {
469  const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mLayer, mLayer->fields()[i].name() );
470  if ( setup.type() != QLatin1String( "TextEdit" ) &&
472  {
473  foundFieldThatCanBeExportedAsDisplayedValue = true;
474  break;
475  }
476  }
477  if ( foundFieldThatCanBeExportedAsDisplayedValue )
478  {
479  mAttributeTable->setColumnCount( 3 );
480  mAttributeTable->setHorizontalHeaderLabels( QStringList() << tr( "Name" ) << tr( "Type" ) << tr( "Replace with displayed values" ) );
481  }
482  else
483  {
484  mAttributeTable->setColumnCount( 2 );
485  mAttributeTable->setHorizontalHeaderLabels( QStringList() << tr( "Name" ) << tr( "Type" ) );
486  }
487 
488  mAttributeTableItemChangedSlotEnabled = false;
489 
490  for ( int i = 0; i < mLayer->fields().size(); ++i )
491  {
492  QgsField fld = mLayer->fields().at( i );
493  Qt::ItemFlags flags = mLayer->providerType() != QLatin1String( "oracle" ) || !fld.typeName().contains( QLatin1String( "SDO_GEOMETRY" ) ) ? Qt::ItemIsEnabled : Qt::NoItemFlags;
494  QTableWidgetItem *item = nullptr;
495  item = new QTableWidgetItem( fld.name() );
496  item->setFlags( flags | Qt::ItemIsUserCheckable );
497  item->setCheckState( ( selectAllFields ) ? Qt::Checked : Qt::Unchecked );
498  mAttributeTable->setItem( i, COLUMN_IDX_NAME, item );
499 
500  item = new QTableWidgetItem( fld.typeName() );
501  item->setFlags( flags );
502  mAttributeTable->setItem( i, COLUMN_IDX_TYPE, item );
503 
504  if ( foundFieldThatCanBeExportedAsDisplayedValue )
505  {
506  const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mLayer, mLayer->fields()[i].name() );
507  QgsEditorWidgetFactory *factory = nullptr;
508  if ( flags == Qt::ItemIsEnabled &&
509  setup.type() != QLatin1String( "TextEdit" ) &&
510  ( factory = QgsGui::editorWidgetRegistry()->factory( setup.type() ) ) )
511  {
512  item = new QTableWidgetItem( tr( "Use %1" ).arg( factory->name() ) );
513  item->setFlags( ( selectAllFields ) ? ( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable ) : Qt::ItemIsUserCheckable );
514  item->setCheckState( ( selectAllFields && fieldsAsDisplayedValues ) ? Qt::Checked : Qt::Unchecked );
515  mAttributeTable->setItem( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE, item );
516  }
517  else
518  {
519  item = new QTableWidgetItem();
520  item->setFlags( Qt::NoItemFlags );
521  mAttributeTable->setItem( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE, item );
522  }
523  }
524  }
525 
526  mAttributeTableItemChangedSlotEnabled = true;
527 
528  mReplaceRawFieldValuesStateChangedSlotEnabled = false;
529  mReplaceRawFieldValues->setChecked( selectAllFields && fieldsAsDisplayedValues );
530  mReplaceRawFieldValuesStateChangedSlotEnabled = true;
531  mReplaceRawFieldValues->setEnabled( selectAllFields );
532  mReplaceRawFieldValues->setVisible( foundFieldThatCanBeExportedAsDisplayedValue );
533 
534  mAttributeTable->resizeColumnsToContents();
535  }
536 
537  QgsVectorFileWriter::MetaData driverMetaData;
538 
539  while ( mDatasourceOptionsGroupBox->layout()->count() )
540  {
541  QLayoutItem *item = mDatasourceOptionsGroupBox->layout()->takeAt( 0 );
542  delete item->widget();
543  delete item;
544  }
545 
546  while ( mLayerOptionsGroupBox->layout()->count() )
547  {
548  QLayoutItem *item = mLayerOptionsGroupBox->layout()->takeAt( 0 );
549  delete item->widget();
550  delete item;
551  }
552 
553  // workaround so the Q_FOREACH macro does not get confused by the ','
554  typedef QPair<QLabel *, QWidget *> LabelControlPair;
555 
556  if ( QgsVectorFileWriter::driverMetadata( format(), driverMetaData ) )
557  {
558  if ( !driverMetaData.driverOptions.empty() )
559  {
560  mDatasourceOptionsGroupBox->setVisible( true );
561  QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.driverOptions );
562 
563  QFormLayout *datasourceLayout = dynamic_cast<QFormLayout *>( mDatasourceOptionsGroupBox->layout() );
564 
565  const auto constControls = controls;
566  for ( LabelControlPair control : constControls )
567  {
568  datasourceLayout->addRow( control.first, control.second );
569  }
570  }
571  else
572  {
573  mDatasourceOptionsGroupBox->setVisible( false );
574  }
575 
576  if ( !driverMetaData.layerOptions.empty() )
577  {
578  mLayerOptionsGroupBox->setVisible( true );
579  QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.layerOptions );
580 
581  QFormLayout *layerOptionsLayout = dynamic_cast<QFormLayout *>( mLayerOptionsGroupBox->layout() );
582 
583  const auto constControls = controls;
584  for ( LabelControlPair control : constControls )
585  {
586  layerOptionsLayout->addRow( control.first, control.second );
587  }
588  }
589  else
590  {
591  mLayerOptionsGroupBox->setVisible( false );
592  }
593 
594  if ( driverMetaData.compulsoryEncoding.isEmpty() )
595  {
596  mEncodingComboBox->setEnabled( true );
597  }
598  else
599  {
600  int idx = mEncodingComboBox->findText( driverMetaData.compulsoryEncoding );
601  if ( idx >= 0 )
602  {
603  mEncodingComboBox->setCurrentIndex( idx );
604  mEncodingComboBox->setDisabled( true );
605  }
606  else
607  {
608  mEncodingComboBox->setEnabled( true );
609  }
610  }
611 
612  }
613  else
614  {
615  mEncodingComboBox->setEnabled( true );
616  }
617 
618  GDALDriverH hDriver = GDALGetDriverByName( format().toUtf8().constData() );
619  if ( hDriver )
620  {
621  mAddToCanvas->setEnabled( GDALGetMetadataItem( hDriver, GDAL_DCAP_OPEN, nullptr ) != nullptr );
622  }
623 }
624 
625 void QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged( int )
626 {
627  if ( !mReplaceRawFieldValuesStateChangedSlotEnabled )
628  return;
629  if ( mAttributeTable->columnCount() != 3 )
630  return;
631  mReplaceRawFieldValuesStateChangedSlotEnabled = false;
632  mAttributeTableItemChangedSlotEnabled = false;
633  if ( mReplaceRawFieldValues->checkState() != Qt::PartiallyChecked )
634  {
635  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
636  {
637  if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked &&
638  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
639  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
640  {
641  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( mReplaceRawFieldValues->checkState() );
642  }
643  }
644  }
645  mReplaceRawFieldValues->setTristate( false );
646  mAttributeTableItemChangedSlotEnabled = true;
647  mReplaceRawFieldValuesStateChangedSlotEnabled = true;
648 }
649 
650 void QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged( QTableWidgetItem *item )
651 {
652  if ( !mAttributeTableItemChangedSlotEnabled )
653  return;
654  mReplaceRawFieldValuesStateChangedSlotEnabled = false;
655  mAttributeTableItemChangedSlotEnabled = false;
656  int row = item->row();
657  int column = item->column();
658  if ( column == COLUMN_IDX_NAME &&
659  mAttributeTable->item( row, column )->checkState() == Qt::Unchecked &&
660  mAttributeTable->columnCount() == 3 &&
661  mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
662  ( mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
663  {
664  mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( Qt::Unchecked );
665  mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable );
666  bool checkBoxEnabled = false;
667  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
668  {
669  if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
670  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
671  {
672  checkBoxEnabled = true;
673  break;
674  }
675  }
676  mReplaceRawFieldValues->setEnabled( checkBoxEnabled );
677  if ( !checkBoxEnabled )
678  mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
679  }
680  else if ( column == COLUMN_IDX_NAME &&
681  mAttributeTable->item( row, column )->checkState() == Qt::Checked &&
682  mAttributeTable->columnCount() == 3 &&
683  mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
684  ( mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
685  {
686  mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
687  mReplaceRawFieldValues->setEnabled( true );
688  }
689  else if ( column == COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE &&
690  ( mAttributeTable->item( row, column )->flags() & Qt::ItemIsUserCheckable ) )
691  {
692  bool allChecked = true;
693  bool allUnchecked = true;
694  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
695  {
696  if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
697  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
698  {
699  if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->checkState() == Qt::Unchecked )
700  allChecked = false;
701  else
702  allUnchecked = false;
703  }
704  }
705  mReplaceRawFieldValues->setCheckState( ( !allChecked && !allUnchecked ) ? Qt::PartiallyChecked : ( allChecked ) ? Qt::Checked : Qt::Unchecked );
706  }
707  mAttributeTableItemChangedSlotEnabled = true;
708  mReplaceRawFieldValuesStateChangedSlotEnabled = true;
709 }
710 
711 void QgsVectorLayerSaveAsDialog::mCrsSelector_crsChanged( const QgsCoordinateReferenceSystem &crs )
712 {
713  mCRS = crs.srsid();
714  mExtentGroupBox->setOutputCrs( crs );
715 }
716 
718 {
719  return mFilename->filePath();
720 }
721 
723 {
724  return leLayername->text();
725 }
726 
728 {
729  return mEncodingComboBox->currentText();
730 }
731 
733 {
734  return mFormatComboBox->currentData().toString();
735 }
736 
738 {
739  return mCRS;
740 }
741 
743 {
744  QStringList options;
745 
746  QgsVectorFileWriter::MetaData driverMetaData;
747 
748  if ( QgsVectorFileWriter::driverMetadata( format(), driverMetaData ) )
749  {
750  QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
751 
752  for ( it = driverMetaData.driverOptions.constBegin(); it != driverMetaData.driverOptions.constEnd(); ++it )
753  {
754  switch ( it.value()->type )
755  {
757  {
759  QSpinBox *sb = mDatasourceOptionsGroupBox->findChild<QSpinBox *>( it.key() );
760  if ( opt && sb && sb->value() != opt->defaultValue )
761  options << QStringLiteral( "%1=%2" ).arg( it.key() ).arg( sb->value() );
762  break;
763  }
764 
766  {
768  QComboBox *cb = mDatasourceOptionsGroupBox->findChild<QComboBox *>( it.key() );
769  if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->defaultValue )
770  options << QStringLiteral( "%1=%2" ).arg( it.key(), cb->currentText() );
771  break;
772  }
773 
775  {
777  QLineEdit *le = mDatasourceOptionsGroupBox->findChild<QLineEdit *>( it.key() );
778  if ( opt && le && le->text() != opt->defaultValue )
779  options << QStringLiteral( "%1=%2" ).arg( it.key(), le->text() );
780  break;
781  }
782 
784  {
786  dynamic_cast<QgsVectorFileWriter::HiddenOption *>( it.value() );
787  options << QStringLiteral( "%1=%2" ).arg( it.key(), opt->mValue );
788  break;
789  }
790  }
791  }
792  }
793 
794  QString plainText = mOgrDatasourceOptions->toPlainText().trimmed();
795  if ( !plainText.isEmpty() )
796  options += plainText.split( '\n' );
797 
798  return options;
799 }
800 
802 {
803  QStringList options;
804 
805  QgsVectorFileWriter::MetaData driverMetaData;
806 
807  if ( QgsVectorFileWriter::driverMetadata( format(), driverMetaData ) )
808  {
809  QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
810 
811  for ( it = driverMetaData.layerOptions.constBegin(); it != driverMetaData.layerOptions.constEnd(); ++it )
812  {
813  switch ( it.value()->type )
814  {
816  {
818  QSpinBox *sb = mLayerOptionsGroupBox->findChild<QSpinBox *>( it.key() );
819  if ( opt && sb && sb->value() != opt->defaultValue )
820  options << QStringLiteral( "%1=%2" ).arg( it.key() ).arg( sb->value() );
821  break;
822  }
823 
825  {
827  QComboBox *cb = mLayerOptionsGroupBox->findChild<QComboBox *>( it.key() );
828  if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->defaultValue )
829  options << QStringLiteral( "%1=%2" ).arg( it.key(), cb->currentText() );
830  break;
831  }
832 
834  {
836  QLineEdit *le = mLayerOptionsGroupBox->findChild<QLineEdit *>( it.key() );
837  if ( opt && le && le->text() != opt->defaultValue )
838  options << QStringLiteral( "%1=%2" ).arg( it.key(), le->text() );
839  break;
840  }
841 
843  {
845  dynamic_cast<QgsVectorFileWriter::HiddenOption *>( it.value() );
846  options << QStringLiteral( "%1=%2" ).arg( it.key(), opt->mValue );
847  break;
848  }
849  }
850  }
851  }
852 
853  QString plainText = mOgrLayerOptions->toPlainText().trimmed();
854  if ( !plainText.isEmpty() )
855  options += plainText.split( '\n' );
856 
857  return options;
858 }
859 
861 {
862  QgsAttributeList attributes;
863 
864  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
865  {
866  if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked )
867  {
868  attributes.append( i );
869  }
870  }
871 
872  return attributes;
873 }
874 
876 {
877  QgsAttributeList attributes;
878 
879  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
880  {
881  if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked &&
882  mAttributeTable->columnCount() == 3 &&
883  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->checkState() == Qt::Checked )
884  {
885  attributes.append( i );
886  }
887  }
888 
889  return attributes;
890 }
891 
893 {
894  return mAddToCanvas->isChecked() && mAddToCanvas->isEnabled();
895 }
896 
898 {
899  mAddToCanvas->setChecked( enabled );
900 }
901 
903 {
904  return mSymbologyExportComboBox->currentData().toInt();
905 }
906 
908 {
909  return mScaleWidget->scale();
910 }
911 
913 {
914  mMapCanvas = canvas;
915  mScaleWidget->setMapCanvas( canvas );
916  mScaleWidget->setShowCurrentScaleButton( true );
917  mExtentGroupBox->setCurrentExtent( canvas->mapSettings().visibleExtent(), canvas->mapSettings().destinationCrs() );
918 }
919 
921 {
922  return mExtentGroupBox->isChecked();
923 }
924 
926 {
927  return mExtentGroupBox->outputExtent();
928 }
929 
931 {
932  mSelectedOnly->setChecked( onlySelected );
933 }
934 
936 {
937  return mSelectedOnly->isChecked();
938 }
939 
941 {
942  int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
943  if ( currentIndexData == -1 )
944  {
945  //automatic
946  return QgsWkbTypes::Unknown;
947  }
948 
949  return static_cast< QgsWkbTypes::Type >( currentIndexData );
950 }
951 
953 {
954  int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
955  return currentIndexData == -1;
956 }
957 
959 {
960  return mForceMultiCheckBox->isChecked();
961 }
962 
964 {
965  mForceMultiCheckBox->setChecked( checked );
966 }
967 
969 {
970  return mIncludeZCheckBox->isChecked();
971 }
972 
974 {
975  return mActionOnExistingFile;
976 }
977 
979 {
980  mIncludeZCheckBox->setChecked( checked );
981 }
982 
983 void QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged( const QString &text )
984 {
985  bool scaleEnabled = true;
986  if ( text == tr( "No symbology" ) )
987  {
988  scaleEnabled = false;
989  }
990  mScaleWidget->setEnabled( scaleEnabled );
991  mScaleLabel->setEnabled( scaleEnabled );
992 }
993 
994 void QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged( int index )
995 {
996  int currentIndexData = mGeometryTypeComboBox->itemData( index ).toInt();
997 
998  if ( currentIndexData != -1 && currentIndexData != QgsWkbTypes::NoGeometry )
999  {
1000  mForceMultiCheckBox->setEnabled( true );
1001  mIncludeZCheckBox->setEnabled( true );
1002  }
1003  else
1004  {
1005  mForceMultiCheckBox->setEnabled( false );
1006  mForceMultiCheckBox->setChecked( false );
1007  mIncludeZCheckBox->setEnabled( false );
1008  mIncludeZCheckBox->setChecked( false );
1009  }
1010 }
1011 
1012 void QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked()
1013 {
1014  mAttributeTableItemChangedSlotEnabled = false;
1015  mReplaceRawFieldValuesStateChangedSlotEnabled = false;
1016  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
1017  {
1018  if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->flags() & Qt::ItemIsEnabled )
1019  {
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 | Qt::ItemIsEnabled );
1024  }
1025  mAttributeTable->item( i, COLUMN_IDX_NAME )->setCheckState( Qt::Checked );
1026  }
1027  }
1028  if ( mAttributeTable->columnCount() == 3 )
1029  {
1030  mReplaceRawFieldValues->setEnabled( true );
1031  }
1032  mAttributeTableItemChangedSlotEnabled = true;
1033  mReplaceRawFieldValuesStateChangedSlotEnabled = true;
1034 }
1035 
1036 void QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked()
1037 {
1038  mAttributeTableItemChangedSlotEnabled = false;
1039  mReplaceRawFieldValuesStateChangedSlotEnabled = false;
1040  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
1041  {
1042  mAttributeTable->item( i, COLUMN_IDX_NAME )->setCheckState( Qt::Unchecked );
1043  if ( mAttributeTable->columnCount() == 3 &&
1044  ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
1045  {
1046  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable );
1047  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( Qt::Unchecked );
1048  }
1049  }
1050  if ( mAttributeTable->columnCount() == 3 )
1051  {
1052  mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
1053  mReplaceRawFieldValues->setEnabled( false );
1054  }
1055  mAttributeTableItemChangedSlotEnabled = true;
1056  mReplaceRawFieldValuesStateChangedSlotEnabled = true;
1057 }
1058 
1059 void QgsVectorLayerSaveAsDialog::showHelp()
1060 {
1061  QgsHelp::openHelp( QStringLiteral( "managing_data_source/create_layers.html#save-layer-from-an-existing-file" ) );
1062 }
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
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:75
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:72
void fileChanged(const QString &path)
Emitted whenever the current file or directory path is changed.
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:127
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:86
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)