QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsrasterformatsaveoptionswidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrasterformatsaveoptionswidget.cpp
3  -------------------
4  begin : July 2012
5  copyright : (C) 2012 by Etienne Tourigny
6  email : etourigny dot dev at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
19 #include "qgslogger.h"
20 #include "qgsdialog.h"
21 #include "qgsrasterlayer.h"
22 #include "qgsproviderregistry.h"
23 #include "qgsrasterdataprovider.h"
24 #include "qgssettings.h"
25 #include "qgsgdalutils.h"
26 
27 #include <QInputDialog>
28 #include <QMessageBox>
29 #include <QTextEdit>
30 #include <QMouseEvent>
31 #include <QMenu>
32 
33 
34 QMap< QString, QStringList > QgsRasterFormatSaveOptionsWidget::sBuiltinProfiles;
35 
36 static const QString PYRAMID_JPEG_YCBCR_COMPRESSION( QStringLiteral( "JPEG_QUALITY_OVERVIEW=75 COMPRESS_OVERVIEW=JPEG PHOTOMETRIC_OVERVIEW=YCBCR INTERLEAVE_OVERVIEW=PIXEL" ) );
37 static const QString PYRAMID_JPEG_COMPRESSION( QStringLiteral( "JPEG_QUALITY_OVERVIEW=75 COMPRESS_OVERVIEW=JPEG INTERLEAVE_OVERVIEW=PIXEL" ) );
38 
40  QgsRasterFormatSaveOptionsWidget::Type type, const QString &provider )
41  : QWidget( parent )
42  , mFormat( format )
43  , mProvider( provider )
44 {
45  setupUi( this );
46  connect( mProfileNewButton, &QPushButton::clicked, this, &QgsRasterFormatSaveOptionsWidget::mProfileNewButton_clicked );
47  connect( mProfileDeleteButton, &QPushButton::clicked, this, &QgsRasterFormatSaveOptionsWidget::mProfileDeleteButton_clicked );
48  connect( mProfileResetButton, &QPushButton::clicked, this, &QgsRasterFormatSaveOptionsWidget::mProfileResetButton_clicked );
49  connect( mOptionsAddButton, &QPushButton::clicked, this, &QgsRasterFormatSaveOptionsWidget::mOptionsAddButton_clicked );
50  connect( mOptionsDeleteButton, &QPushButton::clicked, this, &QgsRasterFormatSaveOptionsWidget::mOptionsDeleteButton_clicked );
51  connect( mOptionsLineEdit, &QLineEdit::editingFinished, this, &QgsRasterFormatSaveOptionsWidget::mOptionsLineEdit_editingFinished );
52 
53  setType( type );
54 
55  if ( sBuiltinProfiles.isEmpty() )
56  {
57  // key=profileKey values=format,profileName,options
58  sBuiltinProfiles[ QStringLiteral( "z_adefault" )] = ( QStringList() << QString() << tr( "Default" ) << QString() );
59 
60  // these GTiff profiles are based on Tim's benchmarks at
61  // http://linfiniti.com/2011/05/gdal-efficiency-of-various-compression-algorithms/
62  // big: no compression | medium: reasonable size/speed tradeoff | small: smallest size
63  sBuiltinProfiles[ QStringLiteral( "z_gtiff_1big" )] =
64  ( QStringList() << QStringLiteral( "GTiff" ) << tr( "No Compression" )
65  << QStringLiteral( "COMPRESS=NONE BIGTIFF=IF_NEEDED" ) );
66  sBuiltinProfiles[ QStringLiteral( "z_gtiff_2medium" )] =
67  ( QStringList() << QStringLiteral( "GTiff" ) << tr( "Low Compression" )
68  << QStringLiteral( "COMPRESS=PACKBITS" ) );
69  sBuiltinProfiles[ QStringLiteral( "z_gtiff_3small" )] =
70  ( QStringList() << QStringLiteral( "GTiff" ) << tr( "High Compression" )
71  << QStringLiteral( "COMPRESS=DEFLATE PREDICTOR=2 ZLEVEL=9" ) );
72  sBuiltinProfiles[ QStringLiteral( "z_gtiff_4jpeg" )] =
73  ( QStringList() << QStringLiteral( "GTiff" ) << tr( "JPEG Compression" )
74  << QStringLiteral( "COMPRESS=JPEG JPEG_QUALITY=75" ) );
75 
76  // overview compression schemes for GTiff format, see
77  // http://www.gdal.org/gdaladdo.html and http://www.gdal.org/frmt_gtiff.html
78  // TODO - should we offer GDAL_TIFF_OVR_BLOCKSIZE option here or in QgsRasterPyramidsOptionsWidget ?
79  sBuiltinProfiles[ QStringLiteral( "z__pyramids_gtiff_1big" )] =
80  ( QStringList() << QStringLiteral( "_pyramids" ) << tr( "No Compression" )
81  << QStringLiteral( "COMPRESS_OVERVIEW=NONE BIGTIFF_OVERVIEW=IF_NEEDED" ) );
82  sBuiltinProfiles[ QStringLiteral( "z__pyramids_gtiff_2medium" )] =
83  ( QStringList() << QStringLiteral( "_pyramids" ) << tr( "Low Compression" )
84  << QStringLiteral( "COMPRESS_OVERVIEW=PACKBITS" ) );
85  sBuiltinProfiles[ QStringLiteral( "z__pyramids_gtiff_3small" )] =
86  ( QStringList() << QStringLiteral( "_pyramids" ) << tr( "High Compression" )
87  << QStringLiteral( "COMPRESS_OVERVIEW=DEFLATE PREDICTOR_OVERVIEW=2 ZLEVEL=9" ) ); // how to set zlevel?
88  sBuiltinProfiles[ QStringLiteral( "z__pyramids_gtiff_4jpeg" )] =
89  ( QStringList() << QStringLiteral( "_pyramids" ) << tr( "JPEG Compression" )
90  << PYRAMID_JPEG_YCBCR_COMPRESSION );
91  }
92 
93  connect( mProfileComboBox, &QComboBox::currentTextChanged,
94  this, &QgsRasterFormatSaveOptionsWidget::updateOptions );
95  connect( mOptionsTable, &QTableWidget::cellChanged, this, &QgsRasterFormatSaveOptionsWidget::optionsTableChanged );
96  connect( mOptionsHelpButton, &QAbstractButton::clicked, this, &QgsRasterFormatSaveOptionsWidget::helpOptions );
97  connect( mOptionsValidateButton, &QAbstractButton::clicked, this, [ = ] { validateOptions(); } );
98 
99  // create eventFilter to map right click to swapOptionsUI()
100  // mOptionsLabel->installEventFilter( this );
101  mOptionsLineEdit->installEventFilter( this );
102  mOptionsStackedWidget->installEventFilter( this );
103 
104  updateControls();
105  updateProfiles();
106 
107  QgsDebugMsg( QStringLiteral( "done" ) );
108 }
109 
110 void QgsRasterFormatSaveOptionsWidget::setFormat( const QString &format )
111 {
112  mFormat = format;
113  updateControls();
114  updateProfiles();
115 }
116 
117 void QgsRasterFormatSaveOptionsWidget::setProvider( const QString &provider )
118 {
119  mProvider = provider;
120  updateControls();
121 }
122 
123 // show/hide widgets - we need this function if widget is used in creator
125 {
126  QList< QWidget * > widgets = this->findChildren<QWidget *>();
127  if ( ( type == Table ) || ( type == LineEdit ) )
128  {
129  // hide all controls, except stacked widget
130  const auto constWidgets = widgets;
131  for ( QWidget *widget : constWidgets )
132  widget->setVisible( false );
133  mOptionsStackedWidget->setVisible( true );
134  const auto children { mOptionsStackedWidget->findChildren<QWidget *>() };
135  for ( QWidget *widget : children )
136  widget->setVisible( true );
137 
138  // show relevant page
139  if ( type == Table )
140  swapOptionsUI( 0 );
141  else if ( type == LineEdit )
142  swapOptionsUI( 1 );
143  }
144  else
145  {
146  // show all widgets, except profile buttons (unless Full)
147  const auto constWidgets = widgets;
148  for ( QWidget *widget : constWidgets )
149  widget->setVisible( true );
150  if ( type != Full )
151  mProfileButtons->setVisible( false );
152 
153  // show elevant page
154  if ( type == ProfileLineEdit )
155  swapOptionsUI( 1 );
156  }
157 }
158 
159 QString QgsRasterFormatSaveOptionsWidget::pseudoFormat() const
160 {
161  return mPyramids ? QStringLiteral( "_pyramids" ) : mFormat;
162 }
163 
165 {
166  // build profiles list = user + builtin(last)
167  QString format = pseudoFormat();
168  QStringList profileKeys = profiles();
169  QMapIterator<QString, QStringList> it( sBuiltinProfiles );
170  while ( it.hasNext() )
171  {
172  it.next();
173  QString profileKey = it.key();
174  if ( ! profileKeys.contains( profileKey ) && !it.value().isEmpty() )
175  {
176  // insert key if is for all formats or this format (GTiff)
177  if ( it.value()[0].isEmpty() || it.value()[0] == format )
178  {
179  profileKeys.insert( 0, profileKey );
180  }
181  }
182  }
183  std::sort( profileKeys.begin(), profileKeys.end() );
184 
185  // populate mOptionsMap and mProfileComboBox
186  mOptionsMap.clear();
187  mProfileComboBox->blockSignals( true );
188  mProfileComboBox->clear();
189  const auto constProfileKeys = profileKeys;
190  for ( const QString &profileKey : constProfileKeys )
191  {
192  QString profileName, profileOptions;
193  profileOptions = createOptions( profileKey );
194  if ( sBuiltinProfiles.contains( profileKey ) )
195  {
196  profileName = sBuiltinProfiles[ profileKey ][ 1 ];
197  if ( profileOptions.isEmpty() )
198  profileOptions = sBuiltinProfiles[ profileKey ][ 2 ];
199  }
200  else
201  {
202  profileName = profileKey;
203  }
204  mOptionsMap[ profileKey ] = profileOptions;
205  mProfileComboBox->addItem( profileName, profileKey );
206  }
207 
208  // update UI
209  mProfileComboBox->blockSignals( false );
210  // mProfileComboBox->setCurrentIndex( 0 );
211  QgsSettings mySettings;
212  mProfileComboBox->setCurrentIndex( mProfileComboBox->findData( mySettings.value(
213  mProvider + "/driverOptions/" + format.toLower() + "/defaultProfile",
214  "z_adefault" ) ) );
215  updateOptions();
216 }
217 
218 void QgsRasterFormatSaveOptionsWidget::updateOptions()
219 {
220  QString myOptions = mOptionsMap.value( currentProfileKey() );
221  QStringList myOptionsList = myOptions.trimmed().split( ' ', QString::SkipEmptyParts );
222 
223  // If the default JPEG compression profile was selected, remove PHOTOMETRIC_OVERVIEW=YCBCR
224  // if the raster is not RGB. Otherwise this is bound to fail afterwards.
225  if ( mRasterLayer && mRasterLayer->bandCount() != 3 &&
226  myOptions == PYRAMID_JPEG_YCBCR_COMPRESSION )
227  {
228  myOptions = PYRAMID_JPEG_COMPRESSION;
229  }
230 
231  if ( mOptionsStackedWidget->currentIndex() == 0 )
232  {
233  mOptionsTable->setRowCount( 0 );
234  for ( int i = 0; i < myOptionsList.count(); i++ )
235  {
236  QStringList key_value = myOptionsList[i].split( '=' );
237  if ( key_value.count() == 2 )
238  {
239  mOptionsTable->insertRow( i );
240  mOptionsTable->setItem( i, 0, new QTableWidgetItem( key_value[0] ) );
241  mOptionsTable->setItem( i, 1, new QTableWidgetItem( key_value[1] ) );
242  }
243  }
244  }
245  else
246  {
247  mOptionsLineEdit->setText( myOptions );
248  mOptionsLineEdit->setCursorPosition( 0 );
249  }
250 
251  emit optionsChanged();
252 }
253 
255 {
256  setCreateOptions();
257 }
258 
260 {
261  QString message;
262 
263  if ( mProvider == QLatin1String( "gdal" ) && !mFormat.isEmpty() && ! mPyramids )
264  {
265  message = QgsGdalUtils::helpCreationOptionsFormat( mFormat );
266  if ( message.isEmpty() )
267  message = tr( "Cannot get create options for driver %1" ).arg( mFormat );
268  }
269  else if ( mProvider == QLatin1String( "gdal" ) && mPyramids )
270  {
271  message = tr( "For details on pyramids options please see the following pages" );
272  message += QLatin1String( "\n\nhttps://gdal.org/programs/gdaladdo.html\n\nhttps://gdal.org/drivers/raster/gtiff.html" );
273  }
274  else
275  message = tr( "No help available" );
276 
277  // show simple non-modal dialog - should we make the basic xml prettier?
278  QgsDialog *dlg = new QgsDialog( this );
279  dlg->setWindowTitle( tr( "Create Options for %1" ).arg( mFormat ) );
280  QTextEdit *textEdit = new QTextEdit( dlg );
281  textEdit->setReadOnly( true );
282  // message = tr( "Create Options:\n\n%1" ).arg( message );
283  textEdit->setText( message );
284  dlg->layout()->addWidget( textEdit );
285  dlg->resize( 600, 400 );
286 #ifdef Q_OS_MAC
287  dlg->exec(); //modal
288 #else
289  dlg->show(); //non modal
290 #endif
291 }
292 
293 QString QgsRasterFormatSaveOptionsWidget::validateOptions( bool gui, bool reportOK )
294 {
295  QStringList createOptions = options();
296  QString message;
297 
298  QgsDebugMsg( QStringLiteral( "layer: [%1] file: [%2] format: [%3]" ).arg( mRasterLayer ? mRasterLayer->id() : "none", mRasterFileName, mFormat ) );
299  // if no rasterLayer is defined, but we have a raster fileName, then create a temp. rasterLayer to validate options
300  // ideally we should keep it for future access, but this is trickier
301  QgsRasterLayer *rasterLayer = mRasterLayer;
302  bool tmpLayer = false;
303  if ( !( mRasterLayer && rasterLayer->dataProvider() ) && ! mRasterFileName.isNull() )
304  {
305  tmpLayer = true;
307  options.skipCrsValidation = true;
308  rasterLayer = new QgsRasterLayer( mRasterFileName, QFileInfo( mRasterFileName ).baseName(), QStringLiteral( "gdal" ), options );
309  }
310 
311  if ( mProvider == QLatin1String( "gdal" ) && mPyramids )
312  {
313  if ( rasterLayer && rasterLayer->dataProvider() )
314  {
315  QgsDebugMsg( QStringLiteral( "calling validate pyramids on layer's data provider" ) );
316  message = rasterLayer->dataProvider()->validatePyramidsConfigOptions( mPyramidsFormat, createOptions, mFormat );
317  }
318  else
319  {
320  message = tr( "cannot validate pyramid options" );
321  }
322  }
323  else if ( !createOptions.isEmpty() && mProvider == QLatin1String( "gdal" ) && !mFormat.isEmpty() )
324  {
325  if ( rasterLayer && rasterLayer->dataProvider() )
326  {
327  QgsDebugMsg( QStringLiteral( "calling validate on layer's data provider" ) );
328  message = rasterLayer->dataProvider()->validateCreationOptions( createOptions, mFormat );
329  }
330  else
331  {
332  // get validateCreationOptionsFormat() function ptr for provider
333  message = QgsGdalUtils::validateCreationOptionsFormat( createOptions, mFormat );
334 
335  }
336  }
337  else if ( ! createOptions.isEmpty() )
338  {
339  QMessageBox::information( this, QString(), tr( "Cannot validate creation options." ), QMessageBox::Close );
340  if ( tmpLayer )
341  delete rasterLayer;
342  return QString();
343  }
344 
345  if ( gui )
346  {
347  if ( message.isNull() )
348  {
349  if ( reportOK )
350  QMessageBox::information( this, QString(), tr( "Valid" ), QMessageBox::Close );
351  }
352  else
353  {
354  QMessageBox::warning( this, QString(), tr( "Invalid %1:\n\n%2\n\nClick on help button to get valid creation options for this format." ).arg( mPyramids ? tr( "pyramid creation option" ) : tr( "creation option" ), message ), QMessageBox::Close );
355  }
356  }
357 
358  if ( tmpLayer )
359  delete rasterLayer;
360 
361  return message;
362 }
363 
364 void QgsRasterFormatSaveOptionsWidget::optionsTableChanged()
365 {
366  QTableWidgetItem *key, *value;
367  QString options;
368  for ( int i = 0; i < mOptionsTable->rowCount(); i++ )
369  {
370  key = mOptionsTable->item( i, 0 );
371  if ( ! key || key->text().isEmpty() )
372  continue;
373  value = mOptionsTable->item( i, 1 );
374  if ( ! value || value->text().isEmpty() )
375  continue;
376  options += key->text() + '=' + value->text() + ' ';
377  }
378  options = options.trimmed();
379  mOptionsMap[ currentProfileKey()] = options;
380  mOptionsLineEdit->setText( options );
381  mOptionsLineEdit->setCursorPosition( 0 );
382 }
383 
384 void QgsRasterFormatSaveOptionsWidget::mOptionsLineEdit_editingFinished()
385 {
386  mOptionsMap[ currentProfileKey()] = mOptionsLineEdit->text().trimmed();
387 }
388 
389 void QgsRasterFormatSaveOptionsWidget::mProfileNewButton_clicked()
390 {
391  QString profileName = QInputDialog::getText( this, QString(), tr( "Profile name:" ) );
392  if ( ! profileName.isEmpty() )
393  {
394  profileName = profileName.trimmed();
395  mOptionsMap[ profileName ] = QString();
396  mProfileComboBox->addItem( profileName, profileName );
397  mProfileComboBox->setCurrentIndex( mProfileComboBox->count() - 1 );
398  }
399 }
400 
401 void QgsRasterFormatSaveOptionsWidget::mProfileDeleteButton_clicked()
402 {
403  int index = mProfileComboBox->currentIndex();
404  QString profileKey = currentProfileKey();
405  if ( index != -1 && ! sBuiltinProfiles.contains( profileKey ) )
406  {
407  mOptionsMap.remove( profileKey );
408  mProfileComboBox->removeItem( index );
409  }
410 }
411 
412 void QgsRasterFormatSaveOptionsWidget::mProfileResetButton_clicked()
413 {
414  QString profileKey = currentProfileKey();
415  if ( sBuiltinProfiles.contains( profileKey ) )
416  {
417  mOptionsMap[ profileKey ] = sBuiltinProfiles[ profileKey ][ 2 ];
418  }
419  else
420  {
421  mOptionsMap[ profileKey ] = QString();
422  }
423  mOptionsLineEdit->setText( mOptionsMap.value( currentProfileKey() ) );
424  mOptionsLineEdit->setCursorPosition( 0 );
425  updateOptions();
426 }
427 
428 void QgsRasterFormatSaveOptionsWidget::optionsTableEnableDeleteButton()
429 {
430  mOptionsDeleteButton->setEnabled( mOptionsTable->currentRow() >= 0 );
431 }
432 
433 void QgsRasterFormatSaveOptionsWidget::mOptionsAddButton_clicked()
434 {
435  mOptionsTable->insertRow( mOptionsTable->rowCount() );
436  // select the added row
437  int newRow = mOptionsTable->rowCount() - 1;
438  QTableWidgetItem *item = new QTableWidgetItem();
439  mOptionsTable->setItem( newRow, 0, item );
440  mOptionsTable->setCurrentItem( item );
441 }
442 
443 void QgsRasterFormatSaveOptionsWidget::mOptionsDeleteButton_clicked()
444 {
445  if ( mOptionsTable->currentRow() >= 0 )
446  {
447  mOptionsTable->removeRow( mOptionsTable->currentRow() );
448  // select the previous row or the next one if there is no previous row
449  QTableWidgetItem *item = mOptionsTable->item( mOptionsTable->currentRow(), 0 );
450  mOptionsTable->setCurrentItem( item );
451  optionsTableChanged();
452  }
453 }
454 
455 QString QgsRasterFormatSaveOptionsWidget::settingsKey( QString profileName ) const
456 {
457  if ( !profileName.isEmpty() )
458  profileName = "/profile_" + profileName;
459  else
460  profileName = "/profile_default" + profileName;
461  return mProvider + "/driverOptions/" + pseudoFormat().toLower() + profileName + "/create";
462 }
463 
464 QString QgsRasterFormatSaveOptionsWidget::currentProfileKey() const
465 {
466  return mProfileComboBox->currentData().toString();
467 }
468 
470 {
471  return mOptionsMap.value( currentProfileKey() ).trimmed().split( ' ', QString::SkipEmptyParts );
472 }
473 
474 QString QgsRasterFormatSaveOptionsWidget::createOptions( const QString &profileName ) const
475 {
476  QgsSettings mySettings;
477  return mySettings.value( settingsKey( profileName ), "" ).toString();
478 }
479 
480 void QgsRasterFormatSaveOptionsWidget::deleteCreateOptions( const QString &profileName )
481 {
482  QgsSettings mySettings;
483  mySettings.remove( settingsKey( profileName ) );
484 }
485 
486 void QgsRasterFormatSaveOptionsWidget::setCreateOptions()
487 {
488  QgsSettings mySettings;
489  QStringList myProfiles;
490  QMap< QString, QString >::const_iterator i = mOptionsMap.constBegin();
491  while ( i != mOptionsMap.constEnd() )
492  {
493  setCreateOptions( i.key(), i.value() );
494  myProfiles << i.key();
495  ++i;
496  }
497  mySettings.setValue( mProvider + "/driverOptions/" + pseudoFormat().toLower() + "/profiles",
498  myProfiles );
499  mySettings.setValue( mProvider + "/driverOptions/" + pseudoFormat().toLower() + "/defaultProfile",
500  currentProfileKey().trimmed() );
501 }
502 
503 void QgsRasterFormatSaveOptionsWidget::setCreateOptions( const QString &profileName, const QString &options )
504 {
505  QgsSettings mySettings;
506  mySettings.setValue( settingsKey( profileName ), options.trimmed() );
507 }
508 
509 void QgsRasterFormatSaveOptionsWidget::setCreateOptions( const QString &profileName, const QStringList &list )
510 {
511  setCreateOptions( profileName, list.join( QLatin1Char( ' ' ) ) );
512 }
513 
514 QStringList QgsRasterFormatSaveOptionsWidget::profiles() const
515 {
516  QgsSettings mySettings;
517  return mySettings.value( mProvider + "/driverOptions/" + pseudoFormat().toLower() + "/profiles", "" ).toStringList();
518 }
519 
520 void QgsRasterFormatSaveOptionsWidget::swapOptionsUI( int newIndex )
521 {
522  // set new page
523  int oldIndex;
524  if ( newIndex == -1 )
525  {
526  oldIndex = mOptionsStackedWidget->currentIndex();
527  newIndex = ( oldIndex + 1 ) % 2;
528  }
529  else
530  {
531  oldIndex = ( newIndex + 1 ) % 2;
532  }
533 
534  // resize pages to minimum - this works well with gdaltools merge ui, but not raster save as...
535  mOptionsStackedWidget->setCurrentIndex( newIndex );
536  mOptionsStackedWidget->widget( newIndex )->setSizePolicy(
537  QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) );
538  mOptionsStackedWidget->widget( oldIndex )->setSizePolicy(
539  QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored ) );
540  layout()->activate();
541 
542  updateOptions();
543 }
544 
545 void QgsRasterFormatSaveOptionsWidget::updateControls()
546 {
547  bool valid = mProvider == QLatin1String( "gdal" ) && !mFormat.isEmpty();
548  mOptionsValidateButton->setEnabled( valid );
549  mOptionsHelpButton->setEnabled( valid );
550 }
551 
552 // map options label left mouse click to optionsToggle()
553 bool QgsRasterFormatSaveOptionsWidget::eventFilter( QObject *obj, QEvent *event )
554 {
555  if ( event->type() == QEvent::MouseButtonPress )
556  {
557  QMouseEvent *mouseEvent = static_cast<QMouseEvent *>( event );
558  if ( mouseEvent && ( mouseEvent->button() == Qt::RightButton ) )
559  {
560  QMenu *menu = nullptr;
561  QString text;
562  if ( mOptionsStackedWidget->currentIndex() == 0 )
563  text = tr( "Use simple interface" );
564  else
565  text = tr( "Use table interface" );
566  if ( obj->objectName() == QLatin1String( "mOptionsLineEdit" ) )
567  {
568  menu = mOptionsLineEdit->createStandardContextMenu();
569  menu->addSeparator();
570  }
571  else
572  menu = new QMenu( this );
573  QAction *action = new QAction( text, menu );
574  menu->addAction( action );
575  connect( action, &QAction::triggered, this, &QgsRasterFormatSaveOptionsWidget::swapOptionsUI );
576  menu->exec( mouseEvent->globalPos() );
577  delete menu;
578  return true;
579  }
580  }
581  // standard event processing
582  return QObject::eventFilter( obj, event );
583 }
584 
586 {
587  Q_UNUSED( event )
588  mOptionsTable->horizontalHeader()->resizeSection( 0, mOptionsTable->width() - 115 );
589  QgsDebugMsg( QStringLiteral( "done" ) );
590 }
591 
592 void QgsRasterFormatSaveOptionsWidget::setOptions( const QString &options )
593 {
594  mOptionsTable->blockSignals( true );
595  mOptionsTable->clearContents();
596 
597  QStringList values;
598  QStringList optionsList = options.trimmed().split( ' ', QString::SkipEmptyParts );
599  const auto constOptionsList = optionsList;
600  for ( const QString &opt : constOptionsList )
601  {
602  int rowCount = mOptionsTable->rowCount();
603  mOptionsTable->insertRow( rowCount );
604 
605  values = opt.split( '=' );
606  if ( values.count() == 2 )
607  {
608  QTableWidgetItem *nameItem = new QTableWidgetItem( values.at( 0 ) );
609  mOptionsTable->setItem( rowCount, 0, nameItem );
610  QTableWidgetItem *valueItem = new QTableWidgetItem( values.at( 1 ) );
611  mOptionsTable->setItem( rowCount, 0, valueItem );
612  }
613  }
614 
615  mOptionsMap[ currentProfileKey()] = options.trimmed();
616  mOptionsLineEdit->setText( options.trimmed() );
617  mOptionsLineEdit->setCursorPosition( 0 );
618 
619  mOptionsTable->blockSignals( false );
620 }
QgsRasterLayer::bandCount
int bandCount() const
Returns the number of bands in this layer.
Definition: qgsrasterlayer.cpp:217
QgsSettings::remove
void remove(const QString &key, QgsSettings::Section section=QgsSettings::NoSection)
Removes the setting key and any sub-settings of key in a section.
Definition: qgssettings.cpp:205
qgsrasterlayer.h
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
QgsRasterDataProvider::validateCreationOptions
virtual QString validateCreationOptions(const QStringList &createOptions, const QString &format)
Validates creation options for a specific dataset and destination format.
Definition: qgsrasterdataprovider.h:515
qgsgdalutils.h
QgsSettings
This class is a composition of two QSettings instances:
Definition: qgssettings.h:62
QgsDialog::layout
QVBoxLayout * layout()
Returns the central layout. Widgets added to it must have this dialog as parent.
Definition: qgsdialog.h:46
QgsRasterFormatSaveOptionsWidget::setProvider
void setProvider(const QString &provider)
Set provider key, , it is used to determine list of available options.
Definition: qgsrasterformatsaveoptionswidget.cpp:117
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsRasterFormatSaveOptionsWidget::Type
Type
Definition: qgsrasterformatsaveoptionswidget.h:38
QgsRasterFormatSaveOptionsWidget::helpOptions
void helpOptions()
Opens window with options description for given provider and output format.
Definition: qgsrasterformatsaveoptionswidget.cpp:259
QgsRasterFormatSaveOptionsWidget::optionsChanged
void optionsChanged()
QgsRasterFormatSaveOptionsWidget::setOptions
void setOptions(const QString &options)
Populate widget with user-defined options.
Definition: qgsrasterformatsaveoptionswidget.cpp:592
QgsRasterFormatSaveOptionsWidget::updateProfiles
void updateProfiles()
Reloads profiles list from QGIS settings.
Definition: qgsrasterformatsaveoptionswidget.cpp:164
QgsDialog
A generic dialog with layout and button box.
Definition: qgsdialog.h:34
QgsGdalUtils::validateCreationOptionsFormat
static QString validateCreationOptionsFormat(const QStringList &createOptions, const QString &format)
Validates creation options for a given format, regardless of layer.
Definition: qgsgdalutils.cpp:269
QgsRasterDataProvider::validatePyramidsConfigOptions
virtual QString validatePyramidsConfigOptions(QgsRaster::RasterPyramidsFormat pyramidsFormat, const QStringList &configOptions, const QString &fileFormat)
Validates pyramid creation options for a specific dataset and destination format.
Definition: qgsrasterdataprovider.h:522
qgsproviderregistry.h
qgsrasterformatsaveoptionswidget.h
QgsRasterFormatSaveOptionsWidget::validateOptions
QString validateOptions(bool gui=true, bool reportOk=true)
Validates options correctness.
Definition: qgsrasterformatsaveoptionswidget.cpp:293
QgsRasterFormatSaveOptionsWidget::LineEdit
@ LineEdit
Definition: qgsrasterformatsaveoptionswidget.h:42
QgsRasterLayer::dataProvider
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
Definition: qgsrasterlayer.cpp:234
QgsRasterFormatSaveOptionsWidget::QgsRasterFormatSaveOptionsWidget
QgsRasterFormatSaveOptionsWidget(QWidget *parent SIP_TRANSFERTHIS=nullptr, const QString &format="GTiff", QgsRasterFormatSaveOptionsWidget::Type type=Default, const QString &provider="gdal")
Definition: qgsrasterformatsaveoptionswidget.cpp:39
QgsMapLayer::id
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
Definition: qgsmaplayer.cpp:148
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
QgsRasterFormatSaveOptionsWidget::Full
@ Full
Definition: qgsrasterformatsaveoptionswidget.h:40
QgsRasterLayer
Represents a raster layer.
Definition: qgsrasterlayer.h:71
QgsRasterFormatSaveOptionsWidget::apply
void apply()
Definition: qgsrasterformatsaveoptionswidget.cpp:254
QgsRasterLayer::LayerOptions
Setting options for loading raster layers.
Definition: qgsrasterlayer.h:104
QgsRasterFormatSaveOptionsWidget::showEvent
void showEvent(QShowEvent *event) override
Definition: qgsrasterformatsaveoptionswidget.cpp:585
qgssettings.h
qgsdialog.h
QgsRasterFormatSaveOptionsWidget::setType
void setType(QgsRasterFormatSaveOptionsWidget::Type type=Default)
Set widget look and feel.
Definition: qgsrasterformatsaveoptionswidget.cpp:124
QgsRasterFormatSaveOptionsWidget::setFormat
void setFormat(const QString &format)
Set output raster format, it is used to determine list of available options.
Definition: qgsrasterformatsaveoptionswidget.cpp:110
qgslogger.h
QgsGdalUtils::helpCreationOptionsFormat
static QString helpCreationOptionsFormat(const QString &format)
Gets creation options metadata for a given format.
Definition: qgsgdalutils.cpp:229
QgsRasterFormatSaveOptionsWidget::Table
@ Table
Definition: qgsrasterformatsaveoptionswidget.h:41
QgsRasterFormatSaveOptionsWidget::ProfileLineEdit
@ ProfileLineEdit
Definition: qgsrasterformatsaveoptionswidget.h:43
QgsRasterFormatSaveOptionsWidget::options
QStringList options() const
Returns list of selected options.
Definition: qgsrasterformatsaveoptionswidget.cpp:469
qgsrasterdataprovider.h