|
QGIS API Documentation
master-6227475
|
00001 /*************************************************************************** 00002 qgsrasterformatsaveoptionswidget.cpp 00003 ------------------- 00004 begin : July 2012 00005 copyright : (C) 2012 by Etienne Tourigny 00006 email : etourigny dot dev at gmail dot com 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #include "qgsrasterformatsaveoptionswidget.h" 00019 #include "qgslogger.h" 00020 #include "qgsdialog.h" 00021 #include "qgsrasterlayer.h" 00022 #include "qgsproviderregistry.h" 00023 00024 #include <QSettings> 00025 #include <QInputDialog> 00026 #include <QMessageBox> 00027 #include <QTextEdit> 00028 #include <QMouseEvent> 00029 #include <QMenu> 00030 00031 00032 QMap< QString, QStringList > QgsRasterFormatSaveOptionsWidget::mBuiltinProfiles; 00033 00034 QgsRasterFormatSaveOptionsWidget::QgsRasterFormatSaveOptionsWidget( QWidget* parent, QString format, 00035 QgsRasterFormatSaveOptionsWidget::Type type, QString provider ) 00036 : QWidget( parent ), mFormat( format ), mProvider( provider ), mRasterLayer( 0 ), 00037 mRasterFileName( QString() ), mPyramids( false ), 00038 mPyramidsFormat( QgsRaster::PyramidsGTiff ) 00039 00040 { 00041 setupUi( this ); 00042 00043 setType( type ); 00044 00045 if ( mBuiltinProfiles.isEmpty() ) 00046 { 00047 // key=profileKey values=format,profileName,options 00048 mBuiltinProfiles[ "z_adefault" ] = ( QStringList() << "" << tr( "Default" ) << "" ); 00049 00050 // these GTiff profiles are based on Tim's benchmarks at 00051 // http://linfiniti.com/2011/05/gdal-efficiency-of-various-compression-algorithms/ 00052 // big: no compression | medium: reasonable size/speed tradeoff | small: smallest size 00053 mBuiltinProfiles[ "z_gtiff_1big" ] = 00054 ( QStringList() << "GTiff" << tr( "No compression" ) 00055 << "COMPRESS=NONE BIGTIFF=IF_NEEDED" ); 00056 mBuiltinProfiles[ "z_gtiff_2medium" ] = 00057 ( QStringList() << "GTiff" << tr( "Low compression" ) 00058 << "COMPRESS=PACKBITS" ); 00059 mBuiltinProfiles[ "z_gtiff_3small" ] = 00060 ( QStringList() << "GTiff" << tr( "High compression" ) 00061 << "COMPRESS=DEFLATE PREDICTOR=2 ZLEVEL=9" ); 00062 mBuiltinProfiles[ "z_gtiff_4jpeg" ] = 00063 ( QStringList() << "GTiff" << tr( "JPEG compression" ) 00064 << "COMPRESS=JPEG JPEG_QUALITY=75" ); 00065 00066 // overview compression schemes for GTiff format, see 00067 // http://www.gdal.org/gdaladdo.html and http://www.gdal.org/frmt_gtiff.html 00068 // TODO - should we offer GDAL_TIFF_OVR_BLOCKSIZE option here or in QgsRasterPyramidsOptionsWidget ? 00069 mBuiltinProfiles[ "z__pyramids_gtiff_1big" ] = 00070 ( QStringList() << "_pyramids" << tr( "No compression" ) 00071 << "COMPRESS_OVERVIEW=NONE BIGTIFF_OVERVIEW=IF_NEEDED" ); 00072 mBuiltinProfiles[ "z__pyramids_gtiff_2medium" ] = 00073 ( QStringList() << "_pyramids" << tr( "Low compression" ) 00074 << "COMPRESS_OVERVIEW=PACKBITS" ); 00075 mBuiltinProfiles[ "z__pyramids_gtiff_3small" ] = 00076 ( QStringList() << "_pyramids" << tr( "High compression" ) 00077 << "COMPRESS_OVERVIEW=DEFLATE PREDICTOR_OVERVIEW=2 ZLEVEL=9" ); // how to set zlevel? 00078 mBuiltinProfiles[ "z__pyramids_gtiff_4jpeg" ] = 00079 ( QStringList() << "_pyramids" << tr( "JPEG compression" ) 00080 << "JPEG_QUALITY_OVERVIEW=75 COMPRESS_OVERVIEW=JPEG PHOTOMETRIC_OVERVIEW=YCBCR INTERLEAVE_OVERVIEW=PIXEL" ); 00081 } 00082 00083 connect( mProfileComboBox, SIGNAL( currentIndexChanged( const QString & ) ), 00084 this, SLOT( updateOptions() ) ); 00085 connect( mOptionsTable, SIGNAL( cellChanged( int, int ) ), this, SLOT( optionsTableChanged() ) ); 00086 connect( mOptionsHelpButton, SIGNAL( clicked() ), this, SLOT( helpOptions() ) ); 00087 connect( mOptionsValidateButton, SIGNAL( clicked() ), this, SLOT( validateOptions() ) ); 00088 00089 // create eventFilter to map right click to swapOptionsUI() 00090 // mOptionsLabel->installEventFilter( this ); 00091 mOptionsLineEdit->installEventFilter( this ); 00092 mOptionsStackedWidget->installEventFilter( this ); 00093 00094 updateControls(); 00095 updateProfiles(); 00096 00097 QgsDebugMsg( "done" ); 00098 } 00099 00100 QgsRasterFormatSaveOptionsWidget::~QgsRasterFormatSaveOptionsWidget() 00101 { 00102 } 00103 00104 void QgsRasterFormatSaveOptionsWidget::setFormat( QString format ) 00105 { 00106 mFormat = format; 00107 updateControls(); 00108 updateProfiles(); 00109 } 00110 00111 void QgsRasterFormatSaveOptionsWidget::setProvider( QString provider ) 00112 { 00113 mProvider = provider; 00114 updateControls(); 00115 } 00116 00117 // show/hide widgets - we need this function if widget is used in creator 00118 void QgsRasterFormatSaveOptionsWidget::setType( QgsRasterFormatSaveOptionsWidget::Type type ) 00119 { 00120 QList< QWidget* > widgets = this->findChildren<QWidget *>(); 00121 if (( type == Table ) || ( type == LineEdit ) ) 00122 { 00123 // hide all controls, except stacked widget 00124 foreach ( QWidget* widget, widgets ) 00125 widget->setVisible( false ); 00126 mOptionsStackedWidget->setVisible( true ); 00127 foreach ( QWidget* widget, mOptionsStackedWidget->findChildren<QWidget *>() ) 00128 widget->setVisible( true ); 00129 00130 // show relevant page 00131 if ( type == Table ) 00132 swapOptionsUI( 0 ); 00133 else if ( type == LineEdit ) 00134 swapOptionsUI( 1 ); 00135 } 00136 else 00137 { 00138 // show all widgets, except profile buttons (unless Full) 00139 foreach ( QWidget* widget, widgets ) 00140 widget->setVisible( true ); 00141 if ( type != Full ) 00142 mProfileButtons->setVisible( false ); 00143 00144 // show elevant page 00145 if ( type == ProfileLineEdit ) 00146 swapOptionsUI( 1 ); 00147 } 00148 } 00149 00150 void QgsRasterFormatSaveOptionsWidget::updateProfiles() 00151 { 00152 // build profiles list = user + builtin(last) 00153 QString format = mPyramids ? "_pyramids" : mFormat; 00154 QStringList profileKeys = profiles(); 00155 QMapIterator<QString, QStringList> it( mBuiltinProfiles ); 00156 while ( it.hasNext() ) 00157 { 00158 it.next(); 00159 QString profileKey = it.key(); 00160 if ( ! profileKeys.contains( profileKey ) && it.value().count() > 0 ) 00161 { 00162 // insert key if is for all formats or this format (GTiff) 00163 if ( it.value()[0] == "" || it.value()[0] == format ) 00164 { 00165 profileKeys.insert( 0, profileKey ); 00166 } 00167 } 00168 } 00169 qSort( profileKeys ); 00170 00171 // populate mOptionsMap and mProfileComboBox 00172 mOptionsMap.clear(); 00173 mProfileComboBox->blockSignals( true ); 00174 mProfileComboBox->clear(); 00175 foreach ( QString profileKey, profileKeys ) 00176 { 00177 QString profileName, profileOptions; 00178 profileOptions = createOptions( profileKey ); 00179 if ( mBuiltinProfiles.contains( profileKey ) ) 00180 { 00181 profileName = mBuiltinProfiles[ profileKey ][ 1 ]; 00182 if ( profileOptions.isEmpty() ) 00183 profileOptions = mBuiltinProfiles[ profileKey ][ 2 ]; 00184 } 00185 else 00186 { 00187 profileName = profileKey; 00188 } 00189 mOptionsMap[ profileKey ] = profileOptions; 00190 mProfileComboBox->addItem( profileName, profileKey ); 00191 } 00192 00193 // update UI 00194 mProfileComboBox->blockSignals( false ); 00195 // mProfileComboBox->setCurrentIndex( 0 ); 00196 QSettings mySettings; 00197 mProfileComboBox->setCurrentIndex( mProfileComboBox->findData( mySettings.value( 00198 mProvider + "/driverOptions/" + format.toLower() + "/defaultProfile", 00199 "z_adefault" ) ) ); 00200 updateOptions(); 00201 } 00202 00203 void QgsRasterFormatSaveOptionsWidget::updateOptions() 00204 { 00205 QString myOptions = mOptionsMap.value( currentProfileKey() ); 00206 QStringList myOptionsList = myOptions.trimmed().split( " ", QString::SkipEmptyParts ); 00207 00208 if ( mOptionsStackedWidget->currentIndex() == 0 ) 00209 { 00210 mOptionsTable->setRowCount( 0 ); 00211 for ( int i = 0; i < myOptionsList.count(); i++ ) 00212 { 00213 QStringList key_value = myOptionsList[i].split( "=" ); 00214 if ( key_value.count() == 2 ) 00215 { 00216 mOptionsTable->insertRow( i ); 00217 mOptionsTable->setItem( i, 0, new QTableWidgetItem( key_value[0] ) ); 00218 mOptionsTable->setItem( i, 1, new QTableWidgetItem( key_value[1] ) ); 00219 } 00220 } 00221 } 00222 else 00223 { 00224 mOptionsLineEdit->setText( myOptions ); 00225 mOptionsLineEdit->setCursorPosition( 0 ); 00226 } 00227 00228 emit optionsChanged(); 00229 } 00230 00231 void QgsRasterFormatSaveOptionsWidget::apply() 00232 { 00233 setCreateOptions(); 00234 } 00235 00236 // typedefs for gdal provider function pointers 00237 typedef QString validateCreationOptionsFormat_t( const QStringList& createOptions, QString format ); 00238 typedef QString helpCreationOptionsFormat_t( QString format ); 00239 00240 void QgsRasterFormatSaveOptionsWidget::helpOptions() 00241 { 00242 QString message; 00243 00244 if ( mProvider == "gdal" && mFormat != "" && ! mPyramids ) 00245 { 00246 // get helpCreationOptionsFormat() function ptr for provider 00247 QLibrary *library = QgsProviderRegistry::instance()->providerLibrary( mProvider ); 00248 if ( library ) 00249 { 00250 helpCreationOptionsFormat_t * helpCreationOptionsFormat = 00251 ( helpCreationOptionsFormat_t * ) cast_to_fptr( library->resolve( "helpCreationOptionsFormat" ) ); 00252 if ( helpCreationOptionsFormat ) 00253 { 00254 message = helpCreationOptionsFormat( mFormat ); 00255 } 00256 else 00257 { 00258 message = library->fileName() + " does not have helpCreationOptionsFormat"; 00259 } 00260 } 00261 else 00262 message = QString( "cannot load provider library %1" ).arg( mProvider ); 00263 00264 00265 if ( message.isEmpty() ) 00266 message = tr( "Cannot get create options for driver %1" ).arg( mFormat ); 00267 } 00268 else if ( mProvider == "gdal" && mPyramids ) 00269 { 00270 message = tr( "For details on pyramids options please see the following pages" ); 00271 message += "\n\nhttp://www.gdal.org/gdaladdo.html\n\nhttp://www.gdal.org/frmt_gtiff.html"; 00272 } 00273 else 00274 message = tr( "No help available" ); 00275 00276 // show simple non-modal dialog - should we make the basic xml prettier? 00277 QgsDialog *dlg = new QgsDialog( this ); 00278 QTextEdit *textEdit = new QTextEdit( dlg ); 00279 textEdit->setReadOnly( true ); 00280 // message = tr( "Create Options:\n\n%1" ).arg( message ); 00281 textEdit->setText( message ); 00282 dlg->layout()->addWidget( textEdit ); 00283 dlg->resize( 600, 400 ); 00284 #ifdef Q_WS_MAC 00285 dlg->exec(); //modal 00286 #else 00287 dlg->show(); //non modal 00288 #endif 00289 } 00290 00291 QString QgsRasterFormatSaveOptionsWidget::validateOptions( bool gui, bool reportOK ) 00292 { 00293 QStringList createOptions = options(); 00294 QString message; 00295 00296 QgsDebugMsg( QString( "layer: [%1] file: [%2] format: [%3]" ).arg( mRasterLayer ? mRasterLayer->id() : "none" ).arg( mRasterFileName ).arg( mFormat ) ); 00297 // if no rasterLayer is defined, but we have a raster fileName, then create a temp. rasterLayer to validate options 00298 // ideally we should keep it for future access, but this is trickier 00299 QgsRasterLayer* rasterLayer = mRasterLayer; 00300 bool tmpLayer = false; 00301 if ( !( mRasterLayer && rasterLayer->dataProvider() ) && ! mRasterFileName.isNull() ) 00302 { 00303 // temporarily override /Projections/defaultBehaviour to avoid dialog prompt 00304 // this is taken from qgsbrowserdockwidget.cpp 00305 // TODO - integrate this into qgis core 00306 QSettings settings; 00307 QString defaultProjectionOption = settings.value( "/Projections/defaultBehaviour", "prompt" ).toString(); 00308 if ( settings.value( "/Projections/defaultBehaviour", "prompt" ).toString() == "prompt" ) 00309 { 00310 settings.setValue( "/Projections/defaultBehaviour", "useProject" ); 00311 } 00312 tmpLayer = true; 00313 rasterLayer = new QgsRasterLayer( mRasterFileName, QFileInfo( mRasterFileName ).baseName(), "gdal" ); 00314 // restore /Projections/defaultBehaviour 00315 if ( defaultProjectionOption == "prompt" ) 00316 { 00317 settings.setValue( "/Projections/defaultBehaviour", defaultProjectionOption ); 00318 } 00319 } 00320 00321 if ( mProvider == "gdal" && mPyramids ) 00322 { 00323 if ( rasterLayer && rasterLayer->dataProvider() ) 00324 { 00325 QgsDebugMsg( "calling validate pyramids on layer's data provider" ); 00326 message = rasterLayer->dataProvider()->validatePyramidsConfigOptions( mPyramidsFormat, createOptions, mFormat ); 00327 } 00328 else 00329 { 00330 message = tr( "cannot validate pyramid options" ); 00331 } 00332 } 00333 else if ( !createOptions.isEmpty() && mProvider == "gdal" && mFormat != "" ) 00334 { 00335 if ( rasterLayer && rasterLayer->dataProvider() ) 00336 { 00337 QgsDebugMsg( "calling validate on layer's data provider" ); 00338 message = rasterLayer->dataProvider()->validateCreationOptions( createOptions, mFormat ); 00339 } 00340 else 00341 { 00342 // get validateCreationOptionsFormat() function ptr for provider 00343 QLibrary *library = QgsProviderRegistry::instance()->providerLibrary( mProvider ); 00344 if ( library ) 00345 { 00346 validateCreationOptionsFormat_t * validateCreationOptionsFormat = 00347 ( validateCreationOptionsFormat_t * ) cast_to_fptr( library->resolve( "validateCreationOptionsFormat" ) ); 00348 if ( validateCreationOptionsFormat ) 00349 { 00350 message = validateCreationOptionsFormat( createOptions, mFormat ); 00351 } 00352 else 00353 { 00354 message = library->fileName() + " does not have validateCreationOptionsFormat"; 00355 } 00356 } 00357 else 00358 message = QString( "cannot load provider library %1" ).arg( mProvider ); 00359 } 00360 } 00361 else if ( ! createOptions.isEmpty() ) 00362 { 00363 QMessageBox::information( this, "", tr( "Cannot validate creation options" ), QMessageBox::Close ); 00364 if ( tmpLayer ) 00365 delete rasterLayer; 00366 return QString(); 00367 } 00368 00369 if ( gui ) 00370 { 00371 if ( message.isNull() ) 00372 { 00373 if ( reportOK ) 00374 QMessageBox::information( this, "", tr( "Valid" ), QMessageBox::Close ); 00375 } 00376 else 00377 { 00378 QMessageBox::warning( this, "", 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" ) ).arg( message ), QMessageBox::Close ); 00379 } 00380 } 00381 00382 if ( tmpLayer ) 00383 delete rasterLayer; 00384 00385 return message; 00386 } 00387 00388 void QgsRasterFormatSaveOptionsWidget::optionsTableChanged() 00389 { 00390 QTableWidgetItem *key, *value; 00391 QString options; 00392 for ( int i = 0 ; i < mOptionsTable->rowCount(); i++ ) 00393 { 00394 key = mOptionsTable->item( i, 0 ); 00395 if ( ! key || key->text().isEmpty() ) 00396 continue; 00397 value = mOptionsTable->item( i, 1 ); 00398 if ( ! value || value->text().isEmpty() ) 00399 continue; 00400 options += key->text() + "=" + value->text() + " "; 00401 } 00402 options = options.trimmed(); 00403 mOptionsMap[ currentProfileKey()] = options; 00404 mOptionsLineEdit->setText( options ); 00405 mOptionsLineEdit->setCursorPosition( 0 ); 00406 } 00407 00408 void QgsRasterFormatSaveOptionsWidget::on_mOptionsLineEdit_editingFinished() 00409 { 00410 mOptionsMap[ currentProfileKey()] = mOptionsLineEdit->text().trimmed(); 00411 } 00412 00413 void QgsRasterFormatSaveOptionsWidget::on_mProfileNewButton_clicked() 00414 { 00415 QString profileName = QInputDialog::getText( this, "", tr( "Profile name:" ) ); 00416 if ( ! profileName.isEmpty() ) 00417 { 00418 profileName = profileName.trimmed(); 00419 mOptionsMap[ profileName ] = ""; 00420 mProfileComboBox->addItem( profileName, profileName ); 00421 mProfileComboBox->setCurrentIndex( mProfileComboBox->count() - 1 ); 00422 } 00423 } 00424 00425 void QgsRasterFormatSaveOptionsWidget::on_mProfileDeleteButton_clicked() 00426 { 00427 int index = mProfileComboBox->currentIndex(); 00428 QString profileKey = currentProfileKey(); 00429 if ( index != -1 && ! mBuiltinProfiles.contains( profileKey ) ) 00430 { 00431 mOptionsMap.remove( profileKey ); 00432 mProfileComboBox->removeItem( index ); 00433 } 00434 } 00435 00436 void QgsRasterFormatSaveOptionsWidget::on_mProfileResetButton_clicked() 00437 { 00438 QString profileKey = currentProfileKey(); 00439 if ( mBuiltinProfiles.contains( profileKey ) ) 00440 { 00441 mOptionsMap[ profileKey ] = mBuiltinProfiles[ profileKey ][ 2 ]; 00442 } 00443 else 00444 { 00445 mOptionsMap[ profileKey ] = ""; 00446 } 00447 mOptionsLineEdit->setText( mOptionsMap.value( currentProfileKey() ) ); 00448 mOptionsLineEdit->setCursorPosition( 0 ); 00449 updateOptions(); 00450 } 00451 00452 void QgsRasterFormatSaveOptionsWidget::optionsTableEnableDeleteButton() 00453 { 00454 mOptionsDeleteButton->setEnabled( mOptionsTable->currentRow() >= 0 ); 00455 } 00456 00457 void QgsRasterFormatSaveOptionsWidget::on_mOptionsAddButton_clicked() 00458 { 00459 mOptionsTable->insertRow( mOptionsTable->rowCount() ); 00460 // select the added row 00461 int newRow = mOptionsTable->rowCount() - 1; 00462 QTableWidgetItem* item = new QTableWidgetItem(); 00463 mOptionsTable->setItem( newRow, 0, item ); 00464 mOptionsTable->setCurrentItem( item ); 00465 } 00466 00467 void QgsRasterFormatSaveOptionsWidget::on_mOptionsDeleteButton_clicked() 00468 { 00469 if ( mOptionsTable->currentRow() >= 0 ) 00470 { 00471 mOptionsTable->removeRow( mOptionsTable->currentRow() ); 00472 // select the previous row or the next one if there is no previous row 00473 QTableWidgetItem* item = mOptionsTable->item( mOptionsTable->currentRow(), 0 ); 00474 mOptionsTable->setCurrentItem( item ); 00475 optionsTableChanged(); 00476 } 00477 } 00478 00479 00480 QString QgsRasterFormatSaveOptionsWidget::settingsKey( QString profileName ) const 00481 { 00482 if ( profileName != "" ) 00483 profileName = "/profile_" + profileName; 00484 else 00485 profileName = "/profile_default" + profileName; 00486 return mProvider + "/driverOptions/" + mFormat.toLower() + profileName + "/create"; 00487 } 00488 00489 QString QgsRasterFormatSaveOptionsWidget::currentProfileKey() const 00490 { 00491 return mProfileComboBox->itemData( mProfileComboBox->currentIndex() ).toString(); 00492 } 00493 00494 QStringList QgsRasterFormatSaveOptionsWidget::options() const 00495 { 00496 return mOptionsMap.value( currentProfileKey() ).trimmed().split( " ", QString::SkipEmptyParts ); 00497 } 00498 00499 QString QgsRasterFormatSaveOptionsWidget::createOptions( QString profileName ) const 00500 { 00501 QSettings mySettings; 00502 return mySettings.value( settingsKey( profileName ), "" ).toString(); 00503 } 00504 00505 void QgsRasterFormatSaveOptionsWidget::deleteCreateOptions( QString profileName ) 00506 { 00507 QSettings mySettings; 00508 mySettings.remove( settingsKey( profileName ) ); 00509 } 00510 00511 void QgsRasterFormatSaveOptionsWidget::setCreateOptions() 00512 { 00513 QSettings mySettings; 00514 QString myProfiles; 00515 QMap< QString, QString >::iterator i = mOptionsMap.begin(); 00516 while ( i != mOptionsMap.end() ) 00517 { 00518 setCreateOptions( i.key(), i.value() ); 00519 myProfiles += i.key() + QString( " " ); 00520 ++i; 00521 } 00522 mySettings.setValue( mProvider + "/driverOptions/" + mFormat.toLower() + "/profiles", 00523 myProfiles.trimmed() ); 00524 mySettings.setValue( mProvider + "/driverOptions/" + mFormat.toLower() + "/defaultProfile", 00525 currentProfileKey().trimmed() ); 00526 } 00527 00528 void QgsRasterFormatSaveOptionsWidget::setCreateOptions( QString profileName, QString options ) 00529 { 00530 QSettings mySettings; 00531 mySettings.setValue( settingsKey( profileName ), options.trimmed() ); 00532 } 00533 00534 void QgsRasterFormatSaveOptionsWidget::setCreateOptions( QString profileName, QStringList list ) 00535 { 00536 setCreateOptions( profileName, list.join( " " ) ); 00537 } 00538 00539 QStringList QgsRasterFormatSaveOptionsWidget::profiles() const 00540 { 00541 QSettings mySettings; 00542 return mySettings.value( mProvider + "/driverOptions/" + mFormat.toLower() + "/profiles", "" ).toString().trimmed().split( " ", QString::SkipEmptyParts ); 00543 } 00544 00545 void QgsRasterFormatSaveOptionsWidget::swapOptionsUI( int newIndex ) 00546 { 00547 // set new page 00548 int oldIndex; 00549 if ( newIndex == -1 ) 00550 { 00551 oldIndex = mOptionsStackedWidget->currentIndex(); 00552 newIndex = ( oldIndex + 1 ) % 2; 00553 } 00554 else 00555 { 00556 oldIndex = ( newIndex + 1 ) % 2; 00557 } 00558 00559 // resize pages to minimum - this works well with gdaltools merge ui, but not raster save as... 00560 mOptionsStackedWidget->setCurrentIndex( newIndex ); 00561 mOptionsStackedWidget->widget( newIndex )->setSizePolicy( 00562 QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) ); 00563 mOptionsStackedWidget->widget( oldIndex )->setSizePolicy( 00564 QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored ) ); 00565 layout()->activate(); 00566 00567 updateOptions(); 00568 } 00569 00570 void QgsRasterFormatSaveOptionsWidget::updateControls() 00571 { 00572 bool valid = mProvider == "gdal" && mFormat != ""; 00573 mOptionsValidateButton->setEnabled( valid ); 00574 mOptionsHelpButton->setEnabled( valid ); 00575 } 00576 00577 // map options label left mouse click to optionsToggle() 00578 bool QgsRasterFormatSaveOptionsWidget::eventFilter( QObject *obj, QEvent *event ) 00579 { 00580 if ( event->type() == QEvent::MouseButtonPress ) 00581 { 00582 QMouseEvent *mouseEvent = static_cast<QMouseEvent *>( event ); 00583 if ( mouseEvent && ( mouseEvent->button() == Qt::RightButton ) ) 00584 { 00585 QMenu* menu = 0; 00586 QString text; 00587 if ( mOptionsStackedWidget->currentIndex() == 0 ) 00588 text = tr( "Use simple interface" ); 00589 else 00590 text = tr( "Use table interface" ); 00591 if ( obj->objectName() == "mOptionsLineEdit" ) 00592 { 00593 menu = mOptionsLineEdit->createStandardContextMenu(); 00594 menu->addSeparator(); 00595 } 00596 else 00597 menu = new QMenu( this ); 00598 QAction* action = new QAction( text, menu ); 00599 menu->addAction( action ); 00600 connect( action, SIGNAL( triggered() ), this, SLOT( swapOptionsUI() ) ); 00601 menu->exec( mouseEvent->globalPos() ); 00602 delete menu; 00603 return true; 00604 } 00605 } 00606 // standard event processing 00607 return QObject::eventFilter( obj, event ); 00608 } 00609 00610 void QgsRasterFormatSaveOptionsWidget::showEvent( QShowEvent * event ) 00611 { 00612 Q_UNUSED( event ); 00613 mOptionsTable->horizontalHeader()->resizeSection( 0, mOptionsTable->width() - 115 ); 00614 QgsDebugMsg( "done" ); 00615 } 00616