QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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"
22 #include "qgsogrdataitems.h"
24 #include "qgseditorwidgetfactory.h"
26 #include "qgssettings.h"
27 #include "qgsmapcanvas.h"
28 #include "qgsgui.h"
29 #include "qgsapplication.h"
30 #include <QMessageBox>
31 #include <QFileDialog>
32 #include <QTextCodec>
33 #include <QSpinBox>
34 #include "gdal.h"
35 
36 static const int COLUMN_IDX_NAME = 0;
37 static const int COLUMN_IDX_TYPE = 1;
38 static const int COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE = 2;
39 
40 QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( long srsid, QWidget *parent, Qt::WindowFlags fl )
41  : QDialog( parent, fl )
42  , mSelectedCrs( QgsCoordinateReferenceSystem::fromSrsId( srsid ) )
43  , mAttributeTableItemChangedSlotEnabled( true )
44  , mReplaceRawFieldValuesStateChangedSlotEnabled( true )
45  , mActionOnExistingFile( QgsVectorFileWriter::CreateOrOverwriteFile )
46 {
47  setup();
48 }
49 
50 QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( QgsVectorLayer *layer, int options, QWidget *parent, Qt::WindowFlags fl )
51  : QDialog( parent, fl )
52  , mLayer( layer )
53  , mAttributeTableItemChangedSlotEnabled( true )
54  , mReplaceRawFieldValuesStateChangedSlotEnabled( true )
55  , mActionOnExistingFile( QgsVectorFileWriter::CreateOrOverwriteFile )
56  , mOptions( static_cast< Options >( options ) )
57 {
58  if ( layer )
59  {
60  mSelectedCrs = layer->crs();
61  mLayerExtent = layer->extent();
62  }
63  setup();
64 
65  if ( !( mOptions & Symbology ) )
66  {
67  mSymbologyExportLabel->hide();
68  mSymbologyExportComboBox->hide();
69  mScaleLabel->hide();
70  mScaleWidget->hide();
71  }
72 
73  if ( !( mOptions & DestinationCrs ) )
74  {
75  mCrsLabel->hide();
76  mCrsSelector->hide();
77  }
78  if ( !( mOptions & Fields ) )
79  mAttributesSelection->hide();
80 
81  if ( !( mOptions & SelectedOnly ) )
82  mSelectedOnly->hide();
83 
84  if ( !( mOptions & AddToCanvas ) )
85  mAddToCanvas->hide();
86 
87  if ( !( mOptions & GeometryType ) )
88  mGeometryGroupBox->hide();
89 
90  if ( !( mOptions & Extent ) )
91  mExtentGroupBox->hide();
92 
93  mSelectedOnly->setEnabled( layer && layer->selectedFeatureCount() != 0 );
94  mButtonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
95 }
96 
97 void QgsVectorLayerSaveAsDialog::setup()
98 {
99  setupUi( this );
101 
102  connect( mFormatComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged );
103  connect( mCrsSelector, &QgsProjectionSelectionWidget::crsChanged, this, &QgsVectorLayerSaveAsDialog::mCrsSelector_crsChanged );
104  connect( mSymbologyExportComboBox, &QComboBox::currentTextChanged, this, &QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged );
105  connect( mGeometryTypeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged );
106  connect( mSelectAllAttributes, &QPushButton::clicked, this, &QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked );
107  connect( mDeselectAllAttributes, &QPushButton::clicked, this, &QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked );
108  connect( mReplaceRawFieldValues, &QCheckBox::stateChanged, this, &QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged );
109  connect( mAttributeTable, &QTableWidget::itemChanged, this, &QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged );
110 
111 #ifdef Q_OS_WIN
112  mHelpButtonBox->setVisible( false );
113  mButtonBox->addButton( QDialogButtonBox::Help );
114  connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsVectorLayerSaveAsDialog::showHelp );
115 #else
116  connect( mHelpButtonBox, &QDialogButtonBox::helpRequested, this, &QgsVectorLayerSaveAsDialog::showHelp );
117 #endif
118  connect( mButtonBox, &QDialogButtonBox::accepted, this, &QgsVectorLayerSaveAsDialog::accept );
119  connect( mButtonBox, &QDialogButtonBox::rejected, this, &QgsVectorLayerSaveAsDialog::reject );
120 
121  const QList< QgsVectorFileWriter::DriverDetails > drivers = QgsVectorFileWriter::ogrDriverList();
122  mFormatComboBox->blockSignals( true );
123  for ( const QgsVectorFileWriter::DriverDetails &driver : drivers )
124  {
125  mFormatComboBox->addItem( driver.longName, driver.driverName );
126  }
127 
128  QgsSettings settings;
129  QString format = settings.value( QStringLiteral( "UI/lastVectorFormat" ), "GPKG" ).toString();
130  mFormatComboBox->setCurrentIndex( mFormatComboBox->findData( format ) );
131  mFormatComboBox->blockSignals( false );
132 
133  //add geometry types to combobox
134  mGeometryTypeComboBox->addItem( tr( "Automatic" ), -1 );
135  mGeometryTypeComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconPointLayer.svg" ) ), QgsWkbTypes::displayString( QgsWkbTypes::Point ), QgsWkbTypes::Point );
136  mGeometryTypeComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconLineLayer.svg" ) ), QgsWkbTypes::displayString( QgsWkbTypes::LineString ), QgsWkbTypes::LineString );
137  mGeometryTypeComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconPolygonLayer.svg" ) ), QgsWkbTypes::displayString( QgsWkbTypes::Polygon ), QgsWkbTypes::Polygon );
139  mGeometryTypeComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconTableLayer.svg" ) ), tr( "No geometry" ), QgsWkbTypes::NoGeometry );
140  mGeometryTypeComboBox->setCurrentIndex( mGeometryTypeComboBox->findData( -1 ) );
141 
142  mEncodingComboBox->addItems( QgsVectorDataProvider::availableEncodings() );
143 
144  QString enc = settings.value( QStringLiteral( "UI/encoding" ), "System" ).toString();
145  int idx = mEncodingComboBox->findText( enc );
146  if ( idx < 0 )
147  {
148  mEncodingComboBox->insertItem( 0, enc );
149  idx = 0;
150  }
151 
152  mCrsSelector->setCrs( mSelectedCrs );
153  mCrsSelector->setLayerCrs( mSelectedCrs );
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( mSelectedCrs );
168  mExtentGroupBox->setOriginalExtent( mLayerExtent, mSelectedCrs );
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  QMessageBox msgBox;
278  msgBox.setIcon( QMessageBox::Question );
279  msgBox.setWindowTitle( tr( "Save Vector Layer As" ) );
280  QPushButton *overwriteFileButton = msgBox.addButton( tr( "Overwrite File" ), QMessageBox::ActionRole );
281  QPushButton *overwriteLayerButton = msgBox.addButton( tr( "Overwrite Layer" ), QMessageBox::ActionRole );
282  QPushButton *appendToLayerButton = msgBox.addButton( tr( "Append to Layer" ), QMessageBox::ActionRole );
283  msgBox.setStandardButtons( QMessageBox::Cancel );
284  msgBox.setDefaultButton( QMessageBox::Cancel );
285  overwriteFileButton->hide();
286  overwriteLayerButton->hide();
287  appendToLayerButton->hide();
288  if ( layerExists )
289  {
293  {
294  msgBox.setText( tr( "The layer already exists. Do you want to overwrite the whole file or overwrite the layer?" ) );
295  overwriteFileButton->setVisible( true );
296  overwriteLayerButton->setVisible( true );
297  }
298  else if ( !( caps & QgsVectorFileWriter::CanAppendToExistingLayer ) )
299  {
300  msgBox.setText( tr( "The file already exists. Do you want to overwrite it?" ) );
301  overwriteFileButton->setVisible( true );
302  }
303  else if ( ( caps & QgsVectorFileWriter::CanDeleteLayer ) &&
305  {
306  msgBox.setText( tr( "The layer already exists. Do you want to overwrite the whole file, overwrite the layer or append features to the layer?" ) );
307  appendToLayerButton->setVisible( true );
308  overwriteFileButton->setVisible( true );
309  overwriteLayerButton->setVisible( true );
310  }
311  else
312  {
313  msgBox.setText( tr( "The layer already exists. Do you want to overwrite the whole file or append features to the layer?" ) );
314  appendToLayerButton->setVisible( true );
315  overwriteFileButton->setVisible( true );
316  }
317 
318  int ret = msgBox.exec();
319  if ( ret == QMessageBox::Cancel )
320  return;
321  if ( msgBox.clickedButton() == overwriteFileButton )
322  mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteFile;
323  else if ( msgBox.clickedButton() == overwriteLayerButton )
324  mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteLayer;
325  else if ( msgBox.clickedButton() == appendToLayerButton )
326  mActionOnExistingFile = QgsVectorFileWriter::AppendToLayerNoNewFields;
327  }
328  else // !layerExists
329  {
330  if ( ( caps & QgsVectorFileWriter::CanAddNewLayer ) )
331  {
332  mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteLayer;
333  }
334  else
335  {
336  // should not reach here, layer does not exist and cannot add new layer
337  if ( QMessageBox::question( this,
338  tr( "Save Vector Layer As" ),
339  tr( "The file already exists. Do you want to overwrite it?" ) ) == QMessageBox::NoButton )
340  {
341  return;
342  }
343  mActionOnExistingFile = QgsVectorFileWriter::CreateOrOverwriteFile;
344  }
345  }
346  }
347 
348  if ( mActionOnExistingFile == QgsVectorFileWriter::AppendToLayerNoNewFields )
349  {
351  {
352  if ( QMessageBox::question( this,
353  tr( "Save Vector Layer As" ),
354  tr( "The existing layer has additional fields. Do you want to add the missing fields to the layer?" ) ) == QMessageBox::Yes )
355  {
356  mActionOnExistingFile = QgsVectorFileWriter::AppendToLayerAddFields;
357  }
358  }
359  }
360  else if ( mActionOnExistingFile == QgsVectorFileWriter::CreateOrOverwriteFile && QFile::exists( filename() ) )
361  {
362  try
363  {
364  const QList<QgsOgrDbLayerInfo *> subLayers = QgsOgrLayerItem::subLayers( filename(), format() );
365  QStringList layerList;
366  for ( const QgsOgrDbLayerInfo *layer : subLayers )
367  {
368  layerList.append( layer->name() );
369  }
370  qDeleteAll( subLayers );
371  if ( layerList.length() > 1 )
372  {
373  layerList.sort( Qt::CaseInsensitive );
374  QMessageBox msgBox;
375  msgBox.setIcon( QMessageBox::Warning );
376  msgBox.setWindowTitle( tr( "Overwrite File" ) );
377  msgBox.setText( tr( "This file contains %1 layers that will be lost!\n" ).arg( QString::number( layerList.length() ) ) );
378  msgBox.setDetailedText( tr( "The following layers will be permanently lost:\n\n%1" ).arg( layerList.join( "\n" ) ) );
379  msgBox.setStandardButtons( QMessageBox::Ok | QMessageBox::Cancel );
380  if ( msgBox.exec() == QMessageBox::Cancel )
381  return;
382  }
383  }
384  catch ( QgsOgrLayerNotValidException &ex )
385  {
386  QMessageBox::critical( this,
387  tr( "Save Vector Layer As" ),
388  tr( "Error opening destination file: %1" ).arg( ex.what() ) );
389  return;
390  }
391  }
392 
393  QgsSettings settings;
394  settings.setValue( QStringLiteral( "UI/lastVectorFileFilterDir" ), QFileInfo( filename() ).absolutePath() );
395  settings.setValue( QStringLiteral( "UI/lastVectorFormat" ), format() );
396  settings.setValue( QStringLiteral( "UI/encoding" ), encoding() );
397  QDialog::accept();
398 }
399 
400 void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int idx )
401 {
402  Q_UNUSED( idx )
403 
404  mFilename->setEnabled( true );
405  mFilename->setFilter( QgsVectorFileWriter::filterForDriver( format() ) );
406 
407  // if output filename already defined we need to replace old suffix
408  // to avoid double extensions like .gpkg.shp
409  if ( !mFilename->filePath().isEmpty() )
410  {
411  QRegularExpression rx( "\\.(.*?)[\\s]" );
412  QString ext;
413  ext = rx.match( QgsVectorFileWriter::filterForDriver( format() ) ).captured( 1 );
414  if ( !ext.isEmpty() )
415  {
416  QFileInfo fi( mFilename->filePath() );
417  mFilename->setFilePath( QStringLiteral( "%1/%2.%3" ).arg( fi.path() ).arg( fi.baseName() ).arg( ext ) );
418  }
419  }
420 
421  bool selectAllFields = true;
422 
423  // Is it a format for which fields that have attached widgets of types
424  // ValueMap, ValueRelation, etc. should be by default exported with their displayed
425  // values
426  bool isFormatForFieldsAsDisplayedValues = false;
427 
428  const QString sFormat( format() );
429  if ( sFormat == QLatin1String( "DXF" ) || sFormat == QLatin1String( "DGN" ) )
430  {
431  mAttributesSelection->setVisible( false );
432  selectAllFields = false;
433  }
434  else
435  {
436  if ( mOptions & Fields )
437  {
438  mAttributesSelection->setVisible( true );
439  isFormatForFieldsAsDisplayedValues = ( sFormat == QLatin1String( "CSV" ) ||
440  sFormat == QLatin1String( "XLS" ) ||
441  sFormat == QLatin1String( "XLSX" ) ||
442  sFormat == QLatin1String( "ODS" ) );
443  }
444  }
445 
446  // Show symbology options only for some formats
447  if ( QgsVectorFileWriter::supportsFeatureStyles( sFormat ) && ( mOptions & Symbology ) )
448  {
449  mSymbologyExportLabel->setVisible( true );
450  mSymbologyExportComboBox->setVisible( true );
451  mScaleLabel->setVisible( true );
452  mScaleWidget->setVisible( true );
453  }
454  else
455  {
456  mSymbologyExportLabel->hide();
457  mSymbologyExportComboBox->hide();
458  mScaleLabel->hide();
459  mScaleWidget->hide();
460  }
461 
462  leLayername->setEnabled( sFormat == QLatin1String( "KML" ) ||
463  sFormat == QLatin1String( "GPKG" ) ||
464  sFormat == QLatin1String( "XLSX" ) ||
465  sFormat == QLatin1String( "ODS" ) ||
466  sFormat == QLatin1String( "FileGDB" ) ||
467  sFormat == QLatin1String( "SQLite" ) ||
468  sFormat == QLatin1String( "SpatiaLite" ) );
469  if ( !leLayername->isEnabled() )
470  leLayername->setText( QString() );
471  else if ( leLayername->text().isEmpty() &&
472  !mFilename->filePath().isEmpty() )
473  {
474  QString layerName = QFileInfo( mFilename->filePath() ).baseName();
475  leLayername->setText( layerName );
476  }
477 
478  if ( mLayer )
479  {
480  mAttributeTable->setRowCount( mLayer->fields().count() );
481 
482  bool foundFieldThatCanBeExportedAsDisplayedValue = false;
483  for ( int i = 0; i < mLayer->fields().size(); ++i )
484  {
485  const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mLayer, mLayer->fields()[i].name() );
486  if ( setup.type() != QLatin1String( "TextEdit" ) &&
487  QgsGui::editorWidgetRegistry()->factory( setup.type() ) )
488  {
489  foundFieldThatCanBeExportedAsDisplayedValue = true;
490  break;
491  }
492  }
493  if ( foundFieldThatCanBeExportedAsDisplayedValue )
494  {
495  mAttributeTable->setColumnCount( 3 );
496  mAttributeTable->setHorizontalHeaderLabels( QStringList() << tr( "Name" ) << tr( "Type" ) << tr( "Replace with displayed values" ) );
497  }
498  else
499  {
500  mAttributeTable->setColumnCount( 2 );
501  mAttributeTable->setHorizontalHeaderLabels( QStringList() << tr( "Name" ) << tr( "Type" ) );
502  }
503 
504  mAttributeTableItemChangedSlotEnabled = false;
505 
506  bool checkReplaceRawFieldValues = selectAllFields && isFormatForFieldsAsDisplayedValues;
507  for ( int i = 0; i < mLayer->fields().size(); ++i )
508  {
509  QgsField fld = mLayer->fields().at( i );
510  Qt::ItemFlags flags = mLayer->providerType() != QLatin1String( "oracle" ) || !fld.typeName().contains( QLatin1String( "SDO_GEOMETRY" ) ) ? Qt::ItemIsEnabled : Qt::NoItemFlags;
511  QTableWidgetItem *item = nullptr;
512  item = new QTableWidgetItem( fld.name() );
513  item->setFlags( flags | Qt::ItemIsUserCheckable );
514  item->setCheckState( ( selectAllFields ) ? Qt::Checked : Qt::Unchecked );
515  mAttributeTable->setItem( i, COLUMN_IDX_NAME, item );
516 
517  item = new QTableWidgetItem( fld.typeName() );
518  item->setFlags( flags );
519  mAttributeTable->setItem( i, COLUMN_IDX_TYPE, item );
520 
521  if ( foundFieldThatCanBeExportedAsDisplayedValue )
522  {
523  const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mLayer, mLayer->fields()[i].name() );
524  QgsEditorWidgetFactory *factory = nullptr;
525  const QString widgetId( setup.type() );
526  if ( flags == Qt::ItemIsEnabled &&
527  widgetId != QLatin1String( "TextEdit" ) &&
528  ( factory = QgsGui::editorWidgetRegistry()->factory( widgetId ) ) )
529  {
530  item = new QTableWidgetItem( tr( "Use %1" ).arg( factory->name() ) );
531  item->setFlags( ( selectAllFields ) ? ( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable ) : Qt::ItemIsUserCheckable );
532  const bool checkItem = ( selectAllFields && isFormatForFieldsAsDisplayedValues &&
533  ( widgetId == QLatin1String( "ValueMap" ) ||
534  widgetId == QLatin1String( "ValueRelation" ) ||
535  widgetId == QLatin1String( "CheckBox" ) ||
536  widgetId == QLatin1String( "RelationReference" ) ) );
537  checkReplaceRawFieldValues &= checkItem;
538  item->setCheckState( checkItem ?
539  Qt::Checked : Qt::Unchecked );
540  mAttributeTable->setItem( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE, item );
541  }
542  else
543  {
544  item = new QTableWidgetItem();
545  item->setFlags( Qt::NoItemFlags );
546  mAttributeTable->setItem( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE, item );
547  }
548  }
549  }
550 
551  mAttributeTableItemChangedSlotEnabled = true;
552 
553  mReplaceRawFieldValuesStateChangedSlotEnabled = false;
554  mReplaceRawFieldValues->setChecked( checkReplaceRawFieldValues );
555  mReplaceRawFieldValuesStateChangedSlotEnabled = true;
556  mReplaceRawFieldValues->setEnabled( selectAllFields );
557  mReplaceRawFieldValues->setVisible( foundFieldThatCanBeExportedAsDisplayedValue );
558 
559  mAttributeTable->resizeColumnsToContents();
560  }
561 
562  QgsVectorFileWriter::MetaData driverMetaData;
563 
564  while ( mDatasourceOptionsGroupBox->layout()->count() )
565  {
566  QLayoutItem *item = mDatasourceOptionsGroupBox->layout()->takeAt( 0 );
567  delete item->widget();
568  delete item;
569  }
570 
571  while ( mLayerOptionsGroupBox->layout()->count() )
572  {
573  QLayoutItem *item = mLayerOptionsGroupBox->layout()->takeAt( 0 );
574  delete item->widget();
575  delete item;
576  }
577 
578  // workaround so the Q_FOREACH macro does not get confused by the ','
579  typedef QPair<QLabel *, QWidget *> LabelControlPair;
580 
581  if ( QgsVectorFileWriter::driverMetadata( format(), driverMetaData ) )
582  {
583  if ( !driverMetaData.driverOptions.empty() )
584  {
585  mDatasourceOptionsGroupBox->setVisible( true );
586  QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.driverOptions );
587 
588  QFormLayout *datasourceLayout = dynamic_cast<QFormLayout *>( mDatasourceOptionsGroupBox->layout() );
589 
590  const auto constControls = controls;
591  for ( LabelControlPair control : constControls )
592  {
593  datasourceLayout->addRow( control.first, control.second );
594  }
595  }
596  else
597  {
598  mDatasourceOptionsGroupBox->setVisible( false );
599  }
600 
601  if ( !driverMetaData.layerOptions.empty() )
602  {
603  mLayerOptionsGroupBox->setVisible( true );
604  QList<QPair<QLabel *, QWidget *> > controls = createControls( driverMetaData.layerOptions );
605 
606  QFormLayout *layerOptionsLayout = dynamic_cast<QFormLayout *>( mLayerOptionsGroupBox->layout() );
607 
608  const auto constControls = controls;
609  for ( LabelControlPair control : constControls )
610  {
611  layerOptionsLayout->addRow( control.first, control.second );
612  }
613  }
614  else
615  {
616  mLayerOptionsGroupBox->setVisible( false );
617  }
618 
619  if ( driverMetaData.compulsoryEncoding.isEmpty() )
620  {
621  mEncodingComboBox->setEnabled( true );
622  }
623  else
624  {
625  int idx = mEncodingComboBox->findText( driverMetaData.compulsoryEncoding );
626  if ( idx >= 0 )
627  {
628  mEncodingComboBox->setCurrentIndex( idx );
629  mEncodingComboBox->setDisabled( true );
630  }
631  else
632  {
633  mEncodingComboBox->setEnabled( true );
634  }
635  }
636 
637  }
638  else
639  {
640  mEncodingComboBox->setEnabled( true );
641  }
642 
643  GDALDriverH hDriver = GDALGetDriverByName( format().toUtf8().constData() );
644  if ( hDriver )
645  {
646  mAddToCanvas->setEnabled( GDALGetMetadataItem( hDriver, GDAL_DCAP_OPEN, nullptr ) != nullptr );
647  }
648 }
649 
650 void QgsVectorLayerSaveAsDialog::mReplaceRawFieldValues_stateChanged( int )
651 {
652  if ( !mReplaceRawFieldValuesStateChangedSlotEnabled )
653  return;
654  if ( mAttributeTable->columnCount() != 3 )
655  return;
656  mReplaceRawFieldValuesStateChangedSlotEnabled = false;
657  mAttributeTableItemChangedSlotEnabled = false;
658  if ( mReplaceRawFieldValues->checkState() != Qt::PartiallyChecked )
659  {
660  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
661  {
662  if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked &&
663  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
664  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
665  {
666  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( mReplaceRawFieldValues->checkState() );
667  }
668  }
669  }
670  mReplaceRawFieldValues->setTristate( false );
671  mAttributeTableItemChangedSlotEnabled = true;
672  mReplaceRawFieldValuesStateChangedSlotEnabled = true;
673 }
674 
675 void QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged( QTableWidgetItem *item )
676 {
677  if ( !mAttributeTableItemChangedSlotEnabled )
678  return;
679  mReplaceRawFieldValuesStateChangedSlotEnabled = false;
680  mAttributeTableItemChangedSlotEnabled = false;
681  int row = item->row();
682  int column = item->column();
683  if ( column == COLUMN_IDX_NAME &&
684  mAttributeTable->item( row, column )->checkState() == Qt::Unchecked &&
685  mAttributeTable->columnCount() == 3 &&
686  mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
687  ( mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
688  {
689  mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( Qt::Unchecked );
690  mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable );
691  bool checkBoxEnabled = false;
692  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
693  {
694  if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
695  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
696  {
697  checkBoxEnabled = true;
698  break;
699  }
700  }
701  mReplaceRawFieldValues->setEnabled( checkBoxEnabled );
702  if ( !checkBoxEnabled )
703  mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
704  }
705  else if ( column == COLUMN_IDX_NAME &&
706  mAttributeTable->item( row, column )->checkState() == Qt::Checked &&
707  mAttributeTable->columnCount() == 3 &&
708  mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
709  ( mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
710  {
711  mAttributeTable->item( row, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
712  mReplaceRawFieldValues->setEnabled( true );
713  }
714  else if ( column == COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE &&
715  ( mAttributeTable->item( row, column )->flags() & Qt::ItemIsUserCheckable ) )
716  {
717  bool allChecked = true;
718  bool allUnchecked = true;
719  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
720  {
721  if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE ) &&
722  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsEnabled )
723  {
724  if ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->checkState() == Qt::Unchecked )
725  allChecked = false;
726  else
727  allUnchecked = false;
728  }
729  }
730  mReplaceRawFieldValues->setCheckState( ( !allChecked && !allUnchecked ) ? Qt::PartiallyChecked : ( allChecked ) ? Qt::Checked : Qt::Unchecked );
731  }
732  mAttributeTableItemChangedSlotEnabled = true;
733  mReplaceRawFieldValuesStateChangedSlotEnabled = true;
734 }
735 
736 void QgsVectorLayerSaveAsDialog::mCrsSelector_crsChanged( const QgsCoordinateReferenceSystem &crs )
737 {
738  mSelectedCrs = crs;
739  mExtentGroupBox->setOutputCrs( mSelectedCrs );
740 }
741 
743 {
744  return mFilename->filePath();
745 }
746 
748 {
749  return leLayername->text();
750 }
751 
753 {
754  return mEncodingComboBox->currentText();
755 }
756 
758 {
759  return mFormatComboBox->currentData().toString();
760 }
761 
763 {
764  return mSelectedCrs.srsid();
765 }
766 
768 {
769  return mSelectedCrs;
770 }
771 
773 {
774  QStringList options;
775 
776  QgsVectorFileWriter::MetaData driverMetaData;
777 
778  if ( QgsVectorFileWriter::driverMetadata( format(), driverMetaData ) )
779  {
780  QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
781 
782  for ( it = driverMetaData.driverOptions.constBegin(); it != driverMetaData.driverOptions.constEnd(); ++it )
783  {
784  switch ( it.value()->type )
785  {
787  {
789  QSpinBox *sb = mDatasourceOptionsGroupBox->findChild<QSpinBox *>( it.key() );
790  if ( opt && sb && sb->value() != opt->defaultValue )
791  options << QStringLiteral( "%1=%2" ).arg( it.key() ).arg( sb->value() );
792  break;
793  }
794 
796  {
798  QComboBox *cb = mDatasourceOptionsGroupBox->findChild<QComboBox *>( it.key() );
799  if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->defaultValue )
800  options << QStringLiteral( "%1=%2" ).arg( it.key(), cb->currentText() );
801  break;
802  }
803 
805  {
807  QLineEdit *le = mDatasourceOptionsGroupBox->findChild<QLineEdit *>( it.key() );
808  if ( opt && le && le->text() != opt->defaultValue )
809  options << QStringLiteral( "%1=%2" ).arg( it.key(), le->text() );
810  break;
811  }
812 
814  {
816  dynamic_cast<QgsVectorFileWriter::HiddenOption *>( it.value() );
817  options << QStringLiteral( "%1=%2" ).arg( it.key(), opt->mValue );
818  break;
819  }
820  }
821  }
822  }
823 
824  QString plainText = mOgrDatasourceOptions->toPlainText().trimmed();
825  if ( !plainText.isEmpty() )
826  options += plainText.split( '\n' );
827 
828  return options;
829 }
830 
832 {
833  QStringList options;
834 
835  QgsVectorFileWriter::MetaData driverMetaData;
836 
837  if ( QgsVectorFileWriter::driverMetadata( format(), driverMetaData ) )
838  {
839  QMap<QString, QgsVectorFileWriter::Option *>::ConstIterator it;
840 
841  for ( it = driverMetaData.layerOptions.constBegin(); it != driverMetaData.layerOptions.constEnd(); ++it )
842  {
843  switch ( it.value()->type )
844  {
846  {
848  QSpinBox *sb = mLayerOptionsGroupBox->findChild<QSpinBox *>( it.key() );
849  if ( opt && sb && sb->value() != opt->defaultValue )
850  options << QStringLiteral( "%1=%2" ).arg( it.key() ).arg( sb->value() );
851  break;
852  }
853 
855  {
857  QComboBox *cb = mLayerOptionsGroupBox->findChild<QComboBox *>( it.key() );
858  if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->defaultValue )
859  options << QStringLiteral( "%1=%2" ).arg( it.key(), cb->currentText() );
860  break;
861  }
862 
864  {
866  QLineEdit *le = mLayerOptionsGroupBox->findChild<QLineEdit *>( it.key() );
867  if ( opt && le && le->text() != opt->defaultValue )
868  options << QStringLiteral( "%1=%2" ).arg( it.key(), le->text() );
869  break;
870  }
871 
873  {
875  dynamic_cast<QgsVectorFileWriter::HiddenOption *>( it.value() );
876  options << QStringLiteral( "%1=%2" ).arg( it.key(), opt->mValue );
877  break;
878  }
879  }
880  }
881  }
882 
883  QString plainText = mOgrLayerOptions->toPlainText().trimmed();
884  if ( !plainText.isEmpty() )
885  options += plainText.split( '\n' );
886 
887  return options;
888 }
889 
891 {
892  QgsAttributeList attributes;
893 
894  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
895  {
896  if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked )
897  {
898  attributes.append( i );
899  }
900  }
901 
902  return attributes;
903 }
904 
906 {
907  QgsAttributeList attributes;
908 
909  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
910  {
911  if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->checkState() == Qt::Checked &&
912  mAttributeTable->columnCount() == 3 &&
913  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->checkState() == Qt::Checked )
914  {
915  attributes.append( i );
916  }
917  }
918 
919  return attributes;
920 }
921 
923 {
924  return mAddToCanvas->isChecked() && mAddToCanvas->isEnabled();
925 }
926 
928 {
929  mAddToCanvas->setChecked( enabled );
930 }
931 
933 {
934  return mSymbologyExportComboBox->currentData().toInt();
935 }
936 
938 {
939  return mScaleWidget->scale();
940 }
941 
943 {
944  mMapCanvas = canvas;
945  mScaleWidget->setMapCanvas( canvas );
946  mScaleWidget->setShowCurrentScaleButton( true );
947  mExtentGroupBox->setCurrentExtent( canvas->mapSettings().visibleExtent(), canvas->mapSettings().destinationCrs() );
948 }
949 
951 {
952  return mExtentGroupBox->isChecked();
953 }
954 
956 {
957  return mExtentGroupBox->outputExtent();
958 }
959 
961 {
962  mSelectedOnly->setChecked( onlySelected );
963 }
964 
966 {
967  return mSelectedOnly->isChecked();
968 }
969 
971 {
972  int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
973  if ( currentIndexData == -1 )
974  {
975  //automatic
976  return QgsWkbTypes::Unknown;
977  }
978 
979  return static_cast< QgsWkbTypes::Type >( currentIndexData );
980 }
981 
983 {
984  int currentIndexData = mGeometryTypeComboBox->currentData().toInt();
985  return currentIndexData == -1;
986 }
987 
989 {
990  return mForceMultiCheckBox->isChecked();
991 }
992 
994 {
995  mForceMultiCheckBox->setChecked( checked );
996 }
997 
999 {
1000  return mIncludeZCheckBox->isChecked();
1001 }
1002 
1004 {
1005  return mActionOnExistingFile;
1006 }
1007 
1009 {
1010  mIncludeZCheckBox->setChecked( checked );
1011 }
1012 
1013 void QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged( const QString &text )
1014 {
1015  bool scaleEnabled = true;
1016  if ( text == tr( "No symbology" ) )
1017  {
1018  scaleEnabled = false;
1019  }
1020  mScaleWidget->setEnabled( scaleEnabled );
1021  mScaleLabel->setEnabled( scaleEnabled );
1022 }
1023 
1024 void QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged( int index )
1025 {
1026  int currentIndexData = mGeometryTypeComboBox->itemData( index ).toInt();
1027 
1028  if ( currentIndexData != -1 && currentIndexData != QgsWkbTypes::NoGeometry )
1029  {
1030  mForceMultiCheckBox->setEnabled( true );
1031  mIncludeZCheckBox->setEnabled( true );
1032  }
1033  else
1034  {
1035  mForceMultiCheckBox->setEnabled( false );
1036  mForceMultiCheckBox->setChecked( false );
1037  mIncludeZCheckBox->setEnabled( false );
1038  mIncludeZCheckBox->setChecked( false );
1039  }
1040 }
1041 
1042 void QgsVectorLayerSaveAsDialog::mSelectAllAttributes_clicked()
1043 {
1044  mAttributeTableItemChangedSlotEnabled = false;
1045  mReplaceRawFieldValuesStateChangedSlotEnabled = false;
1046  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
1047  {
1048  if ( mAttributeTable->item( i, COLUMN_IDX_NAME )->flags() & Qt::ItemIsEnabled )
1049  {
1050  if ( mAttributeTable->columnCount() == 3 &&
1051  ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
1052  {
1053  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
1054  }
1055  mAttributeTable->item( i, COLUMN_IDX_NAME )->setCheckState( Qt::Checked );
1056  }
1057  }
1058  if ( mAttributeTable->columnCount() == 3 )
1059  {
1060  mReplaceRawFieldValues->setEnabled( true );
1061  }
1062  mAttributeTableItemChangedSlotEnabled = true;
1063  mReplaceRawFieldValuesStateChangedSlotEnabled = true;
1064 }
1065 
1066 void QgsVectorLayerSaveAsDialog::mDeselectAllAttributes_clicked()
1067 {
1068  mAttributeTableItemChangedSlotEnabled = false;
1069  mReplaceRawFieldValuesStateChangedSlotEnabled = false;
1070  for ( int i = 0; i < mAttributeTable->rowCount(); i++ )
1071  {
1072  mAttributeTable->item( i, COLUMN_IDX_NAME )->setCheckState( Qt::Unchecked );
1073  if ( mAttributeTable->columnCount() == 3 &&
1074  ( mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->flags() & Qt::ItemIsUserCheckable ) )
1075  {
1076  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setFlags( Qt::ItemIsUserCheckable );
1077  mAttributeTable->item( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE )->setCheckState( Qt::Unchecked );
1078  }
1079  }
1080  if ( mAttributeTable->columnCount() == 3 )
1081  {
1082  mReplaceRawFieldValues->setCheckState( Qt::Unchecked );
1083  mReplaceRawFieldValues->setEnabled( false );
1084  }
1085  mAttributeTableItemChangedSlotEnabled = true;
1086  mReplaceRawFieldValuesStateChangedSlotEnabled = true;
1087 }
1088 
1089 void QgsVectorLayerSaveAsDialog::showHelp()
1090 {
1091  QgsHelp::openHelp( QStringLiteral( "managing_data_source/create_layers.html#save-layer-from-an-existing-file" ) );
1092 }
QgsVectorFileWriter::IntOption
Definition: qgsvectorfilewriter.h:107
QgsVectorFileWriter::DriverDetails
Details of available driver formats.
Definition: qgsvectorfilewriter.h:718
QgsVectorFileWriter::MetaData
Definition: qgsvectorfilewriter.h:143
QgsMapLayer::crs
QgsCoordinateReferenceSystem crs
Definition: qgsmaplayer.h:89
QgsFileWidget::fileChanged
void fileChanged(const QString &path)
Emitted whenever the current file or directory path is changed.
QgsVectorLayerSaveAsDialog::crs
Q_DECL_DEPRECATED long crs() const
Returns the internal CRS ID.
Definition: qgsvectorlayersaveasdialog.cpp:762
QgsVectorLayerSaveAsDialog::includeZ
bool includeZ() const
Returns true if include z dimension is checked.
Definition: qgsvectorlayersaveasdialog.cpp:998
QgsGui::editorWidgetRegistry
static QgsEditorWidgetRegistry * editorWidgetRegistry()
Returns the global editor widget registry, used for managing all known edit widget factories.
Definition: qgsgui.cpp:74
QgsVectorFileWriter::MetaData::driverOptions
QMap< QString, QgsVectorFileWriter::Option * > driverOptions
Definition: qgsvectorfilewriter.h:161
QgsVectorFileWriter::IntOption::defaultValue
int defaultValue
Definition: qgsvectorfilewriter.h:114
QgsVectorFileWriter::Set
@ Set
Definition: qgsvectorfilewriter.h:50
QgsEditorWidgetFactory::name
QString name()
Returns The human readable identifier name of this widget type.
Definition: qgseditorwidgetfactory.cpp:40
QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog
Q_DECL_DEPRECATED QgsVectorLayerSaveAsDialog(long srsid, QWidget *parent=nullptr, Qt::WindowFlags fl=Qt::WindowFlags())
Construct a new QgsVectorLayerSaveAsDialog.
Definition: qgsvectorlayersaveasdialog.cpp:40
QgsEditorWidgetFactory
Every attribute editor widget needs a factory, which inherits this class.
Definition: qgseditorwidgetfactory.h:43
QgsWkbTypes::displayString
static QString displayString(Type type) SIP_HOLDGIL
Returns a display string type for a WKB type, e.g., the geometry name used in WKT geometry representa...
Definition: qgswkbtypes.cpp:145
QgsApplication::getThemeIcon
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
Definition: qgsapplication.cpp:626
QgsWkbTypes::Point
@ Point
Definition: qgswkbtypes.h:72
QgsVectorFileWriter::CreateOrOverwriteFile
@ CreateOrOverwriteFile
Create or overwrite file.
Definition: qgsvectorfilewriter.h:266
QgsSettings::value
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Definition: qgssettings.cpp:174
QgsVectorFileWriter::Option::type
QgsVectorFileWriter::OptionType type
Definition: qgsvectorfilewriter.h:68
QgsVectorFileWriter
A convenience class for writing vector files to disk.
Definition: qgsvectorfilewriter.h:46
qgsmapcanvas.h
QgsEditorWidgetSetup
Holder for the widget type and its configuration for a field.
Definition: qgseditorwidgetsetup.h:29
QgsMapCanvas::mapSettings
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
Definition: qgsmapcanvas.cpp:391
QgsVectorLayerSaveAsDialog::filename
QString filename() const
Returns the target filename.
Definition: qgsvectorlayersaveasdialog.cpp:742
QgsVectorFileWriter::HiddenOption
Definition: qgsvectorfilewriter.h:132
qgsgui.h
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:51
QgsVectorLayerSaveAsDialog::GeometryType
@ GeometryType
Show geometry group.
Definition: qgsvectorlayersaveasdialog.h:52
QgsVectorFileWriter::CanDeleteLayer
@ CanDeleteLayer
Flag to indicate that an existing layer can be deleted.
Definition: qgsvectorfilewriter.h:250
QgsProjectionSelectionWidget::crsChanged
void crsChanged(const QgsCoordinateReferenceSystem &)
Emitted when the selected CRS is changed.
QgsWkbTypes::LineString
@ LineString
Definition: qgswkbtypes.h:73
QgsFields::count
int count() const
Returns number of items.
Definition: qgsfields.cpp:133
QgsMapCanvas
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:85
QgsVectorFileWriter::supportsFeatureStyles
static bool supportsFeatureStyles(const QString &driverName)
Returns true if the specified driverName supports feature styles.
Definition: qgsvectorfilewriter.cpp:170
QgsField::typeName
QString typeName() const
Gets the field type.
Definition: qgsfield.cpp:138
QgsVectorLayerSaveAsDialog::encoding
QString encoding() const
The encoding of the target file.
Definition: qgsvectorlayersaveasdialog.cpp:752
QgsSettings
This class is a composition of two QSettings instances:
Definition: qgssettings.h:62
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
QgsVectorFileWriter::NoSymbology
@ NoSymbology
Definition: qgsvectorfilewriter.h:183
QgsVectorFileWriter::CreateOrOverwriteLayer
@ CreateOrOverwriteLayer
Create or overwrite layer.
Definition: qgsvectorfilewriter.h:269
QgsVectorLayerSaveAsDialog::Symbology
@ Symbology
Show symbology options.
Definition: qgsvectorlayersaveasdialog.h:47
QgsVectorFileWriter::AppendToLayerAddFields
@ AppendToLayerAddFields
Append features to existing layer, and create new fields if needed.
Definition: qgsvectorfilewriter.h:275
QgsAttributeList
QList< int > QgsAttributeList
Definition: qgsfield.h:26
QgsField::name
QString name
Definition: qgsfield.h:59
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsVectorFileWriter::MetaData::compulsoryEncoding
QString compulsoryEncoding
Some formats require a compulsory encoding, typically UTF-8. If no compulsory encoding,...
Definition: qgsvectorfilewriter.h:164
QgsVectorLayerSaveAsDialog::Extent
@ Extent
Show extent group.
Definition: qgsvectorlayersaveasdialog.h:53
QgsVectorFileWriter::driverMetadata
static bool driverMetadata(const QString &driverName, MetaData &driverMetadata)
Definition: qgsvectorfilewriter.cpp:2225
QgsMapLayer::providerType
QString providerType() const
Returns the provider type (provider key) for this layer.
Definition: qgsmaplayer.cpp:1617
QgsVectorFileWriter::HiddenOption::mValue
QString mValue
Definition: qgsvectorfilewriter.h:139
QgsVectorLayerSaveAsDialog::filterExtent
QgsRectangle filterExtent() const
Determines the extent to be exported.
Definition: qgsvectorlayersaveasdialog.cpp:955
QgsFileWidget::SaveFile
@ SaveFile
Select a single new or pre-existing file.
Definition: qgsfilewidget.h:69
QgsVectorLayerSaveAsDialog::creationActionOnExistingFile
QgsVectorFileWriter::ActionOnExistingFile creationActionOnExistingFile() const
Returns creation action.
Definition: qgsvectorlayersaveasdialog.cpp:1003
qgsapplication.h
qgsprojectionselectiondialog.h
QgsVectorLayerSaveAsDialog::Options
Options
Bitmask of options to be shown.
Definition: qgsvectorlayersaveasdialog.h:46
QgsGui::enableAutoGeometryRestore
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:139
QgsVectorLayer::fields
QgsFields fields() const FINAL
Returns the list of fields of this layer.
Definition: qgsvectorlayer.cpp:3283
QgsVectorLayerSaveAsDialog::Fields
@ Fields
Show field customization group.
Definition: qgsvectorlayersaveasdialog.h:49
QgsEditorWidgetSetup::type
QString type() const
Definition: qgseditorwidgetsetup.h:46
QgsVectorLayerSaveAsDialog::automaticGeometryType
bool automaticGeometryType() const
Returns true if geometry type is set to automatic.
Definition: qgsvectorlayersaveasdialog.cpp:982
QgsVectorLayerSaveAsDialog::datasourceOptions
QStringList datasourceOptions() const
Returns a list of additional data source options which are passed to OGR.
Definition: qgsvectorlayersaveasdialog.cpp:772
QgsVectorFileWriter::String
@ String
Definition: qgsvectorfilewriter.h:51
QgsCoordinateReferenceSystem::srsid
long srsid() const
Returns the internal CRS ID, if available.
Definition: qgscoordinatereferencesystem.cpp:1311
QgsWkbTypes::Unknown
@ Unknown
Definition: qgswkbtypes.h:71
QgsVectorFileWriter::Hidden
@ Hidden
Definition: qgsvectorfilewriter.h:53
QgsVectorLayerSaveAsDialog::setMapCanvas
void setMapCanvas(QgsMapCanvas *canvas)
Sets a map canvas to associate with the dialog.
Definition: qgsvectorlayersaveasdialog.cpp:942
QgsVectorFileWriter::StringOption::defaultValue
QString defaultValue
Definition: qgsvectorfilewriter.h:100
QgsVectorLayerSaveAsDialog::setIncludeZ
void setIncludeZ(bool checked)
Sets whether the include z dimension checkbox should be checked.
Definition: qgsvectorlayersaveasdialog.cpp:1008
QgsVectorLayerSaveAsDialog::layerOptions
QStringList layerOptions() const
Returns a list of additional layer options which are passed to OGR.
Definition: qgsvectorlayersaveasdialog.cpp:831
QgsVectorLayerSaveAsDialog::symbologyExport
int symbologyExport() const
Returns type of symbology export.
Definition: qgsvectorlayersaveasdialog.cpp:932
QgsVectorFileWriter::editionCapabilities
static QgsVectorFileWriter::EditionCapabilities editionCapabilities(const QString &datasetName)
Returns edition capabilities for an existing dataset name.
Definition: qgsvectorfilewriter.cpp:3858
QgsVectorLayerSaveAsDialog::geometryType
QgsWkbTypes::Type geometryType() const
Returns the selected flat geometry type for the export.
Definition: qgsvectorlayersaveasdialog.cpp:970
QgsWkbTypes::GeometryCollection
@ GeometryCollection
Definition: qgswkbtypes.h:79
QgsVectorLayerSaveAsDialog::DestinationCrs
@ DestinationCrs
Show destination CRS (reprojection) option.
Definition: qgsvectorlayersaveasdialog.h:48
QgsVectorLayerSaveAsDialog::setForceMulti
void setForceMulti(bool checked)
Sets whether the force multi geometry checkbox should be checked.
Definition: qgsvectorlayersaveasdialog.cpp:993
qgsvectordataprovider.h
QgsEditorWidgetRegistry::findBest
QgsEditorWidgetSetup findBest(const QgsVectorLayer *vl, const QString &fieldName) const
Find the best editor widget and its configuration for a given field.
Definition: qgseditorwidgetregistry.cpp:76
QgsVectorFileWriter::SymbolLayerSymbology
@ SymbolLayerSymbology
Definition: qgsvectorfilewriter.h:185
QgsVectorFileWriter::targetLayerExists
static bool targetLayerExists(const QString &datasetName, const QString &layerName)
Returns whether the target layer already exists.
Definition: qgsvectorfilewriter.cpp:3897
QgsSettings::setValue
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
Definition: qgssettings.cpp:289
QgsVectorLayerSaveAsDialog::hasFilterExtent
bool hasFilterExtent() const
Determines if filtering the export by an extent is activated.
Definition: qgsvectorlayersaveasdialog.cpp:950
QgsVectorLayerSaveAsDialog::forceMulti
bool forceMulti() const
Returns true if force multi geometry type is checked.
Definition: qgsvectorlayersaveasdialog.cpp:988
qgsvectorlayersaveasdialog.h
QgsVectorLayerSaveAsDialog::attributesAsDisplayedValues
QgsAttributeList attributesAsDisplayedValues() const
Returns selected attributes that must be exported with their displayed values instead of their raw va...
Definition: qgsvectorlayersaveasdialog.cpp:905
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
QgsVectorLayerSaveAsDialog::setAddToCanvas
void setAddToCanvas(bool checked)
Sets whether the "add to canvas" checkbox should be checked.
Definition: qgsvectorlayersaveasdialog.cpp:927
QgsVectorLayer::extent
QgsRectangle extent() const FINAL
Returns the extent of the layer.
Definition: qgsvectorlayer.cpp:833
QgsVectorDataProvider::availableEncodings
static QStringList availableEncodings()
Returns a list of available encodings.
Definition: qgsvectordataprovider.cpp:649
QgsMapSettings::destinationCrs
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
Definition: qgsmapsettings.cpp:318
QgsVectorFileWriter::AppendToLayerNoNewFields
@ AppendToLayerNoNewFields
Append features to existing layer, but do not create new fields.
Definition: qgsvectorfilewriter.h:272
QgsVectorFileWriter::CanAddNewLayer
@ CanAddNewLayer
Flag to indicate that a new layer can be added to the dataset.
Definition: qgsvectorfilewriter.h:241
QgsVectorFileWriter::StringOption
Definition: qgsvectorfilewriter.h:93
QgsVectorLayerSaveAsDialog::format
QString format() const
The format in which the export should be written.
Definition: qgsvectorlayersaveasdialog.cpp:757
qgseditorwidgetregistry.h
QgsWkbTypes::NoGeometry
@ NoGeometry
Definition: qgswkbtypes.h:85
QgsVectorLayerSaveAsDialog::crsObject
QgsCoordinateReferenceSystem crsObject() const
Returns the CRS chosen for export.
Definition: qgsvectorlayersaveasdialog.cpp:767
QgsHelp::openHelp
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition: qgshelp.cpp:36
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
qgseditorwidgetfactory.h
QgsVectorFileWriter::SetOption::allowNone
bool allowNone
Definition: qgsvectorfilewriter.h:86
QgsVectorFileWriter::Int
@ Int
Definition: qgsvectorfilewriter.h:52
QgsWkbTypes::Polygon
@ Polygon
Definition: qgswkbtypes.h:74
QgsVectorLayerSaveAsDialog::selectedAttributes
QgsAttributeList selectedAttributes() const
Returns a list of attributes which are selected for saving.
Definition: qgsvectorlayersaveasdialog.cpp:890
qgssettings.h
QgsVectorFileWriter::areThereNewFieldsToCreate
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.
Definition: qgsvectorfilewriter.cpp:3913
QgsVectorFileWriter::MetaData::layerOptions
QMap< QString, QgsVectorFileWriter::Option * > layerOptions
Definition: qgsvectorfilewriter.h:162
QgsVectorLayerSaveAsDialog::layername
QString layername() const
Returns the target layer name.
Definition: qgsvectorlayersaveasdialog.cpp:747
QgsVectorFileWriter::SetOption::defaultValue
QString defaultValue
Definition: qgsvectorfilewriter.h:85
QgsVectorFileWriter::ogrDriverList
static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList(VectorFormatOptions options=SortRecommended)
Returns the driver list that can be used for dialogs.
Definition: qgsvectorfilewriter.cpp:3368
QgsVectorLayerSaveAsDialog::SelectedOnly
@ SelectedOnly
Show selected features only option.
Definition: qgsvectorlayersaveasdialog.h:51
QgsVectorLayerSaveAsDialog::addToCanvas
bool addToCanvas() const
Returns true if the "add to canvas" checkbox is checked.
Definition: qgsvectorlayersaveasdialog.cpp:922
QgsVectorFileWriter::CanAppendToExistingLayer
@ CanAppendToExistingLayer
Flag to indicate that new features can be added to an existing layer.
Definition: qgsvectorfilewriter.h:244
QgsVectorFileWriter::Option
Definition: qgsvectorfilewriter.h:60
QgsVectorLayerSaveAsDialog::scale
double scale() const
Returns the specified map scale.
Definition: qgsvectorlayersaveasdialog.cpp:937
QgsVectorFileWriter::ActionOnExistingFile
ActionOnExistingFile
Combination of CanAddNewLayer, CanAppendToExistingLayer, CanAddNewFieldsToExistingLayer or CanDeleteL...
Definition: qgsvectorfilewriter.h:264
QgsVectorLayerSaveAsDialog::setOnlySelected
void setOnlySelected(bool onlySelected)
Sets whether only selected features will be saved.
Definition: qgsvectorlayersaveasdialog.cpp:960
QgsVectorLayer::selectedFeatureCount
int selectedFeatureCount() const
Returns the number of features that are selected in this layer.
Definition: qgsvectorlayer.cpp:3436
QgsVectorFileWriter::SetOption::values
QSet< QString > values
Definition: qgsvectorfilewriter.h:84
qgslogger.h
QgsFields::at
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
Definition: qgsfields.cpp:163
QgsMapSettings::visibleExtent
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
Definition: qgsmapsettings.cpp:371
QgsVectorFileWriter::filterForDriver
static QString filterForDriver(const QString &driverName)
Creates a filter for an OGR driver key.
Definition: qgsvectorfilewriter.cpp:3511
QgsVectorLayerSaveAsDialog::onlySelected
bool onlySelected() const
Returns whether only selected features will be saved.
Definition: qgsvectorlayersaveasdialog.cpp:965
QgsVectorLayerSaveAsDialog::AddToCanvas
@ AddToCanvas
Show add to map option.
Definition: qgsvectorlayersaveasdialog.h:50
qgscoordinatereferencesystem.h
QgsVectorFileWriter::SetOption
Definition: qgsvectorfilewriter.h:75
QgsVectorFileWriter::Option::docString
QString docString
Definition: qgsvectorfilewriter.h:67
QgsField
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:50
QgsVectorFileWriter::FeatureSymbology
@ FeatureSymbology
Definition: qgsvectorfilewriter.h:184