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