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