QGIS API Documentation  2.11.0-Master
qgsrasterlayersaveasdialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrasterlayersaveasdialog.cpp
3  ---------------------
4  begin : May 2012
5  copyright : (C) 2012 by Marco Hugentobler
6  email : marco dot hugentobler at sourcepole dot ch
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #include "qgsapplication.h"
16 #include "qgslogger.h"
17 #include "qgscoordinatetransform.h"
18 #include "qgsrasterlayer.h"
20 #include "qgsrasterdataprovider.h"
23 
24 #include <QFileDialog>
25 #include <QMessageBox>
26 #include <QSettings>
27 
29  QgsRasterDataProvider* sourceProvider, const QgsRectangle& currentExtent,
30  const QgsCoordinateReferenceSystem& layerCrs, const QgsCoordinateReferenceSystem& currentCrs,
31  QWidget* parent, Qt::WindowFlags f ) :
32  QDialog( parent, f )
33  , mRasterLayer( rasterLayer ), mDataProvider( sourceProvider )
34  , mCurrentExtent( currentExtent ), mLayerCrs( layerCrs )
35  , mCurrentCrs( currentCrs )
36  , mResolutionState( OriginalResolution )
37 {
38  setupUi( this );
39  mAddNoDataManuallyToolButton->setIcon( QgsApplication::getThemeIcon( "/mActionNewAttribute.png" ) );
40  mLoadTransparentNoDataToolButton->setIcon( QgsApplication::getThemeIcon( "/mActionCopySelected.png" ) );
41  mRemoveSelectedNoDataToolButton->setIcon( QgsApplication::getThemeIcon( "/mActionDeleteAttribute.png" ) );
42  mRemoveAllNoDataToolButton->setIcon( QgsApplication::getThemeIcon( "/mActionRemove.png" ) );
43 
44  mNoDataTableWidget->setColumnCount( 2 );
45  mNoDataTableWidget->setHorizontalHeaderItem( 0, new QTableWidgetItem( tr( "From" ) ) );
46  mNoDataTableWidget->setHorizontalHeaderItem( 1, new QTableWidgetItem( tr( "To" ) ) );
47 
48  on_mRawModeRadioButton_toggled( true );
49 
50  setValidators();
51 
52  toggleResolutionSize();
53 
54  //only one hardcoded format at the moment
55  QStringList myFormats;
56  myFormats << "GTiff";
57  foreach ( QString myFormat, myFormats )
58  {
59  mFormatComboBox->addItem( myFormat );
60  }
61 
62  //fill reasonable default values depending on the provider
63  if ( mDataProvider )
64  {
65  if ( mDataProvider->capabilities() & QgsRasterDataProvider::Size )
66  {
67  setOriginalResolution();
68  int xSize = mDataProvider->xSize();
69  int ySize = mDataProvider->ySize();
70  mMaximumSizeXLineEdit->setText( QString::number( xSize ) );
71  mMaximumSizeYLineEdit->setText( QString::number( ySize ) );
72  }
73  else //wms, sometimes wcs
74  {
75  mTileModeCheckBox->setChecked( true );
76  mMaximumSizeXLineEdit->setText( QString::number( 2000 ) );
77  mMaximumSizeYLineEdit->setText( QString::number( 2000 ) );
78  }
79 
80  // setup creation option widget
81  mCreateOptionsWidget->setProvider( mDataProvider->name() );
82  if ( mDataProvider->name() == "gdal" )
83  {
84  mCreateOptionsWidget->setFormat( myFormats[0] );
85  }
86  mCreateOptionsWidget->setRasterLayer( mRasterLayer );
87  mCreateOptionsWidget->update();
88  }
89 
90  // Only do pyramids if dealing directly with GDAL.
91  if ( mDataProvider && mDataProvider->capabilities() & QgsRasterDataProvider::BuildPyramids )
92  {
93  // setup pyramids option widget
94  // mPyramidsOptionsWidget->createOptionsWidget()->setType( QgsRasterFormatSaveOptionsWidget::ProfileLineEdit );
95  mPyramidsOptionsWidget->createOptionsWidget()->setRasterLayer( mRasterLayer );
96 
97  // TODO enable "use existing", has no effect for now, because using Create() in gdal provider
98  // if ( ! mDataProvider->hasPyramids() )
99  // mPyramidsButtonGroup->button( QgsRaster::PyramidsCopyExisting )->setEnabled( false );
100  mPyramidsUseExistingCheckBox->setEnabled( false );
101  mPyramidsUseExistingCheckBox->setVisible( false );
102 
103  populatePyramidsLevels();
104  connect( mPyramidsOptionsWidget, SIGNAL( overviewListChanged() ),
105  this, SLOT( populatePyramidsLevels() ) );
106  }
107  else
108  {
109  mPyramidsGroupBox->setEnabled( false );
110  }
111 
112  // restore checked state for most groupboxes (default is to restore collapsed state)
113  // create options and pyramids will be preset, if user has selected defaults in the gdal options dlg
114  mCreateOptionsGroupBox->setSaveCheckedState( true );
115  //mTilesGroupBox->setSaveCheckedState( true );
116  // don't restore nodata, it needs user input
117  // pyramids are not necessarily built every time
118 
119  mTilesGroupBox->hide();
120 
121  mCrsSelector->setLayerCrs( mLayerCrs );
122  mCrsSelector->setCrs( mCurrentCrs );
123  connect( mCrsSelector, SIGNAL( crsChanged( QgsCoordinateReferenceSystem ) ),
124  this, SLOT( crsChanged() ) );
125 
126  QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
127  if ( okButton )
128  {
129  okButton->setEnabled( false );
130  }
131 
132  mExtentGroupBox->setOutputCrs( outputCrs() );
133  mExtentGroupBox->setOriginalExtent( mDataProvider->extent(), mLayerCrs );
134  mExtentGroupBox->setCurrentExtent( mCurrentExtent, mCurrentCrs );
135  mExtentGroupBox->setOutputExtentFromOriginal();
136  connect( mExtentGroupBox, SIGNAL( extentChanged( QgsRectangle ) ), this, SLOT( extentChanged() ) );
137 
138  recalcResolutionSize();
139 }
140 
141 void QgsRasterLayerSaveAsDialog::setValidators()
142 {
143  mXResolutionLineEdit->setValidator( new QDoubleValidator( this ) );
144  mYResolutionLineEdit->setValidator( new QDoubleValidator( this ) );
145  mColumnsLineEdit->setValidator( new QIntValidator( this ) );
146  mRowsLineEdit->setValidator( new QIntValidator( this ) );
147  mMaximumSizeXLineEdit->setValidator( new QIntValidator( this ) );
148  mMaximumSizeYLineEdit->setValidator( new QIntValidator( this ) );
149 }
150 
152 {
153 }
154 
155 void QgsRasterLayerSaveAsDialog::on_mBrowseButton_clicked()
156 {
157  QString fileName;
158 
159  QSettings settings;
160  QString dirName = mSaveAsLineEdit->text().isEmpty() ? settings.value( "/UI/lastRasterFileDir", "." ).toString() : mSaveAsLineEdit->text();
161 
162  if ( mTileModeCheckBox->isChecked() )
163  {
164  while ( true )
165  {
166  // TODO: would not it be better to select .vrt file instead of directory?
167  fileName = QFileDialog::getExistingDirectory( this, tr( "Select output directory" ), dirName );
168  //fileName = QFileDialog::getSaveFileName( this, tr( "Select output file" ), QString(), tr( "VRT" ) + " (*.vrt *.VRT)" );
169 
170  if ( fileName.isEmpty() ) break; // canceled
171 
172  // Check if directory is empty
173  QDir dir( fileName );
174  QString baseName = QFileInfo( fileName ).baseName();
175  QStringList filters;
176  filters << QString( "%1.*" ).arg( baseName );
177  QStringList files = dir.entryList( filters );
178  if ( !files.isEmpty() )
179  {
180  QMessageBox::StandardButton button = QMessageBox::warning( this, tr( "Warning" ),
181  tr( "The directory %1 contains files which will be overwritten: %2" ).arg( dir.absolutePath() ).arg( files.join( ", " ) ),
182  QMessageBox::Ok | QMessageBox::Cancel );
183 
184  if ( button == QMessageBox::Ok )
185  {
186  break;
187  }
188  else
189  {
190  fileName = "";
191  }
192  }
193  else
194  {
195  break;
196  }
197  }
198  }
199  else
200  {
201  fileName = QFileDialog::getSaveFileName( this, tr( "Select output file" ), dirName, tr( "GeoTIFF" ) + " (*.tif *.tiff *.TIF *.TIFF)" );
202  }
203 
204  if ( !fileName.isEmpty() )
205  {
206  // ensure the user never ommited the extension from the file name
207  if ( !fileName.toLower().endsWith( ".tif" ) && !fileName.toLower().endsWith( ".tiff" ) )
208  {
209  fileName += ".tif";
210  }
211  mSaveAsLineEdit->setText( fileName );
212  }
213 }
214 
215 void QgsRasterLayerSaveAsDialog::on_mSaveAsLineEdit_textChanged( const QString& text )
216 {
217  QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
218  if ( !okButton )
219  {
220  return;
221  }
222 
223  okButton->setEnabled( QFileInfo( text ).absoluteDir().exists() );
224 }
225 
226 
227 void QgsRasterLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( const QString & text )
228 {
229  //gdal-specific
230  if ( mDataProvider && mDataProvider->name() == "gdal" )
231  {
232  mCreateOptionsWidget->setFormat( text );
233  mCreateOptionsWidget->update();
234  }
235 }
236 
238 {
239  return mColumnsLineEdit->text().toInt();
240 }
241 
243 {
244  return mRowsLineEdit->text().toInt();
245 }
246 
248 {
249  return mXResolutionLineEdit->text().toDouble();
250 }
251 
253 {
254  return mYResolutionLineEdit->text().toDouble();
255 }
256 
258 {
259  return mMaximumSizeXLineEdit->text().toInt();
260 }
261 
263 {
264  return mMaximumSizeYLineEdit->text().toInt();
265 }
266 
268 {
269  return mTileModeCheckBox->isChecked();
270 }
271 
273 {
274  return mAddToCanvas->isChecked();
275 }
276 
278 {
279  return mSaveAsLineEdit->text();
280 }
281 
283 {
284  return mFormatComboBox->currentText();
285 }
286 
288 {
289  return mCreateOptionsGroupBox->isChecked() ? mCreateOptionsWidget->options() : QStringList();
290 }
291 
293 {
294  return mExtentGroupBox->outputExtent();
295 }
296 
298 {
299  mFormatLabel->hide();
300  mFormatComboBox->hide();
301 }
302 
304 {
305  mSaveAsLabel->hide();
306  mSaveAsLineEdit->hide();
307  mBrowseButton->hide();
308  QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
309  if ( okButton )
310  {
311  okButton->setEnabled( true );
312  }
313 }
314 
315 void QgsRasterLayerSaveAsDialog::toggleResolutionSize()
316 {
317  bool hasResolution = mDataProvider && mDataProvider->capabilities() & QgsRasterDataProvider::Size;
318 
319  bool on = mResolutionRadioButton->isChecked();
320  mXResolutionLineEdit->setEnabled( on );
321  mYResolutionLineEdit->setEnabled( on );
322  mOriginalResolutionPushButton->setEnabled( on && hasResolution );
323  mColumnsLineEdit->setEnabled( !on );
324  mRowsLineEdit->setEnabled( !on );
325  mOriginalSizePushButton->setEnabled( !on && hasResolution );
326 }
327 
328 void QgsRasterLayerSaveAsDialog::setOriginalResolution()
329 {
330  double xRes, yRes;
331 
332  if ( mDataProvider->capabilities() & QgsRasterDataProvider::Size )
333  {
334  xRes = mDataProvider->extent().width() / mDataProvider->xSize();
335  yRes = mDataProvider->extent().height() / mDataProvider->ySize();
336  }
337  else
338  {
339  // Init to something if no original resolution is available
340  xRes = yRes = mDataProvider->extent().width() / 100;
341  }
342  setResolution( xRes, yRes, mLayerCrs );
343  mResolutionState = OriginalResolution;
344  recalcSize();
345 }
346 
347 void QgsRasterLayerSaveAsDialog::setResolution( double xRes, double yRes, const QgsCoordinateReferenceSystem& srcCrs )
348 {
349  if ( srcCrs != outputCrs() )
350  {
351  // We reproject pixel rectangle from center of selected extent, of course, it gives
352  // bigger xRes,yRes than reprojected edges (envelope), it may also be that
353  // close to margins are higher resolutions (even very, too high)
354  // TODO: consider more precise resolution calculation
355 
356  QgsPoint center = outputRectangle().center();
357  QgsCoordinateTransform ct( srcCrs, outputCrs() );
358  QgsPoint srsCenter = ct.transform( center, QgsCoordinateTransform::ReverseTransform );
359 
360  QgsRectangle srcExtent( srsCenter.x() - xRes / 2, srsCenter.y() - yRes / 2, srsCenter.x() + xRes / 2, srsCenter.y() + yRes / 2 );
361 
362  QgsRectangle extent = ct.transform( srcExtent );
363  xRes = extent.width();
364  yRes = extent.height();
365  }
366  mXResolutionLineEdit->setText( QString::number( xRes ) );
367  mYResolutionLineEdit->setText( QString::number( yRes ) );
368 }
369 
370 void QgsRasterLayerSaveAsDialog::recalcSize()
371 {
372  QgsDebugMsg( "Entered" );
373  QgsRectangle extent = outputRectangle();
374  int xSize = xResolution() != 0 ? static_cast<int>( qRound( extent.width() / xResolution() ) ) : 0;
375  int ySize = yResolution() != 0 ? static_cast<int>( qRound( extent.height() / yResolution() ) ) : 0;
376  mColumnsLineEdit->setText( QString::number( xSize ) );
377  mRowsLineEdit->setText( QString::number( ySize ) );
378  updateResolutionStateMsg();
379 }
380 
381 void QgsRasterLayerSaveAsDialog::setOriginalSize()
382 {
383  mColumnsLineEdit->setText( QString::number( mDataProvider->xSize() ) );
384  mRowsLineEdit->setText( QString::number( mDataProvider->ySize() ) );
385  recalcResolution();
386 }
387 
388 void QgsRasterLayerSaveAsDialog::recalcResolution()
389 {
390  QgsDebugMsg( "Entered" );
391  QgsRectangle extent = outputRectangle();
392  double xRes = nColumns() != 0 ? extent.width() / nColumns() : 0;
393  double yRes = nRows() != 0 ? extent.height() / nRows() : 0;
394  mXResolutionLineEdit->setText( QString::number( xRes ) );
395  mYResolutionLineEdit->setText( QString::number( yRes ) );
396  updateResolutionStateMsg();
397 }
398 
399 void QgsRasterLayerSaveAsDialog::recalcResolutionSize()
400 {
401  QgsDebugMsg( "Entered" );
402  if ( mResolutionRadioButton->isChecked() )
403  {
404  recalcSize();
405  }
406  else
407  {
408  mResolutionState = UserResolution;
409  recalcResolution();
410  }
411 }
412 
413 void QgsRasterLayerSaveAsDialog::updateResolutionStateMsg()
414 {
415  QString msg;
416  switch ( mResolutionState )
417  {
418  case OriginalResolution:
419  msg = tr( "layer" );
420  break;
421  case UserResolution:
422  msg = tr( "user defined" );
423  break;
424  default:
425  break;
426  }
427  msg = tr( "Resolution (current: %1)" ).arg( msg );
428  mResolutionGroupBox->setTitle( msg );
429 }
430 
431 void QgsRasterLayerSaveAsDialog::extentChanged()
432 {
433  // Whenever extent changes with fixed size, original resolution is lost
434  if ( mSizeRadioButton->isChecked() )
435  {
436  mResolutionState = UserResolution;
437  }
438  recalcResolutionSize();
439 }
440 
441 void QgsRasterLayerSaveAsDialog::crsChanged()
442 {
443  if ( outputCrs() != mPreviousCrs )
444  {
445  mExtentGroupBox->setOutputCrs( outputCrs() );
446  QgsExtentGroupBox::ExtentState state = mExtentGroupBox->extentState();
447 
448  // Reset extent
449  // We could reproject previous but that would add additional space also if
450  // it is was not necessary or at leas it could decrease accuracy
451  if ( state == QgsExtentGroupBox::OriginalExtent )
452  {
453  mExtentGroupBox->setOutputExtentFromOriginal();
454  }
455  else if ( state == QgsExtentGroupBox::CurrentExtent )
456  {
457  mExtentGroupBox->setOutputExtentFromCurrent();
458  }
459  else
460  {
461  mExtentGroupBox->setOutputExtentFromUser( mExtentGroupBox->outputExtent(), mPreviousCrs );
462  }
463 
464  // Reset resolution
465  if ( mResolutionRadioButton->isChecked() )
466  {
467  if ( mResolutionState == OriginalResolution )
468  {
469  setOriginalResolution();
470  }
471  else
472  {
473  // reset from present resolution and present crs
474  setResolution( xResolution(), yResolution(), mPreviousCrs );
475  }
476  }
477  else
478  {
479  // Size does not change, we just recalc resolution from new extent
480  recalcResolution();
481  }
482  }
483  mPreviousCrs = outputCrs();
484 }
485 
487 {
488  return mCrsSelector->crs();
489 }
490 
492 {
493  if ( mRenderedModeRadioButton->isChecked() ) return RenderedImageMode;
494  return RawDataMode;
495 }
496 
497 void QgsRasterLayerSaveAsDialog::on_mRawModeRadioButton_toggled( bool checked )
498 {
499  mNoDataGroupBox->setEnabled( checked && mDataProvider->bandCount() == 1 );
500 }
501 
502 void QgsRasterLayerSaveAsDialog::on_mAddNoDataManuallyToolButton_clicked()
503 {
504  addNoDataRow( std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN() );
505 }
506 
507 void QgsRasterLayerSaveAsDialog::on_mLoadTransparentNoDataToolButton_clicked()
508 {
509  if ( !mRasterLayer->renderer() ) return;
510  const QgsRasterTransparency* rasterTransparency = mRasterLayer->renderer()->rasterTransparency();
511  if ( !rasterTransparency ) return;
512 
513  foreach ( QgsRasterTransparency::TransparentSingleValuePixel transparencyPixel, rasterTransparency->transparentSingleValuePixelList() )
514  {
515  if ( transparencyPixel.percentTransparent == 100 )
516  {
517  addNoDataRow( transparencyPixel.min, transparencyPixel.max );
518  if ( transparencyPixel.min != transparencyPixel.max )
519  {
520  setNoDataToEdited( mNoDataTableWidget->rowCount() - 1 );
521  }
522  }
523  }
524 }
525 
526 void QgsRasterLayerSaveAsDialog::on_mRemoveSelectedNoDataToolButton_clicked()
527 {
528  mNoDataTableWidget->removeRow( mNoDataTableWidget->currentRow() );
529 }
530 
531 void QgsRasterLayerSaveAsDialog::on_mRemoveAllNoDataToolButton_clicked()
532 {
533  while ( mNoDataTableWidget->rowCount() > 0 )
534  {
535  mNoDataTableWidget->removeRow( 0 );
536  }
537 }
538 
539 void QgsRasterLayerSaveAsDialog::addNoDataRow( double min, double max )
540 {
541  mNoDataTableWidget->insertRow( mNoDataTableWidget->rowCount() );
542  for ( int i = 0; i < 2; i++ )
543  {
544  double value = i == 0 ? min : max;
545  QLineEdit *lineEdit = new QLineEdit();
546  lineEdit->setFrame( false );
547  lineEdit->setContentsMargins( 1, 1, 1, 1 );
548  QString valueString;
549  switch ( mRasterLayer->dataProvider()->srcDataType( 1 ) )
550  {
551  case QGis::Float32:
552  case QGis::Float64:
553  lineEdit->setValidator( new QDoubleValidator( 0 ) );
554  if ( !qIsNaN( value ) )
555  {
556  valueString = QgsRasterBlock::printValue( value );
557  }
558  break;
559  default:
560  lineEdit->setValidator( new QIntValidator( 0 ) );
561  if ( !qIsNaN( value ) )
562  {
563  valueString = QString::number( static_cast<int>( value ) );
564  }
565  break;
566  }
567  lineEdit->setText( valueString );
568  mNoDataTableWidget->setCellWidget( mNoDataTableWidget->rowCount() - 1, i, lineEdit );
569 
570  adjustNoDataCellWidth( mNoDataTableWidget->rowCount() - 1, i );
571 
572  connect( lineEdit, SIGNAL( textEdited( const QString & ) ), this, SLOT( noDataCellTextEdited( const QString & ) ) );
573  }
574  mNoDataTableWidget->resizeColumnsToContents();
575  mNoDataTableWidget->resizeRowsToContents();
576 }
577 
578 void QgsRasterLayerSaveAsDialog::noDataCellTextEdited( const QString & text )
579 {
580  Q_UNUSED( text );
581 
582  QLineEdit *lineEdit = dynamic_cast<QLineEdit *>( sender() );
583  if ( !lineEdit ) return;
584  int row = -1;
585  int column = -1;
586  for ( int r = 0 ; r < mNoDataTableWidget->rowCount(); r++ )
587  {
588  for ( int c = 0 ; c < mNoDataTableWidget->columnCount(); c++ )
589  {
590  if ( mNoDataTableWidget->cellWidget( r, c ) == sender() )
591  {
592  row = r;
593  column = c;
594  break;
595  }
596  }
597  if ( row != -1 ) break;
598  }
599  QgsDebugMsg( QString( "row = %1 column =%2" ).arg( row ).arg( column ) );
600 
601  if ( column == 0 )
602  {
603  QLineEdit *toLineEdit = dynamic_cast<QLineEdit *>( mNoDataTableWidget->cellWidget( row, 1 ) );
604  if ( !toLineEdit ) return;
605  bool toChanged = mNoDataToEdited.value( row );
606  QgsDebugMsg( QString( "toChanged = %1" ).arg( toChanged ) );
607  if ( !toChanged )
608  {
609  toLineEdit->setText( lineEdit->text() );
610  }
611  }
612  else if ( column == 1 )
613  {
614  setNoDataToEdited( row );
615  }
616 }
617 
618 void QgsRasterLayerSaveAsDialog::on_mTileModeCheckBox_toggled( bool toggled )
619 {
620  if ( toggled )
621  {
622  // enable pyramids
623 
624  // Disabled (Radim), auto enabling of pyramids was making impression that
625  // we (programmers) know better what you (user) want to do,
626  // certainly auto expaning was bad experience
627 
628  //if ( ! mPyramidsGroupBox->isChecked() )
629  // mPyramidsGroupBox->setChecked( true );
630 
631  // Auto expanding mPyramidsGroupBox is bad - it auto crolls content of dialog
632  //if ( mPyramidsGroupBox->isCollapsed() )
633  // mPyramidsGroupBox->setCollapsed( false );
634  //mPyramidsOptionsWidget->checkAllLevels( true );
635 
636  // Show / hide tile options
637  mTilesGroupBox->show();
638  }
639  else
640  {
641  mTilesGroupBox->hide();
642  }
643 }
644 
645 void QgsRasterLayerSaveAsDialog::on_mPyramidsGroupBox_toggled( bool toggled )
646 {
647  Q_UNUSED( toggled );
648  populatePyramidsLevels();
649 }
650 
651 void QgsRasterLayerSaveAsDialog::populatePyramidsLevels()
652 {
653  QString text;
654 
655  if ( mPyramidsGroupBox->isChecked() )
656  {
657  QList<QgsRasterPyramid> myPyramidList;
658  // if use existing, get pyramids from actual layer
659  // but that's not available yet
660  if ( mPyramidsUseExistingCheckBox->isChecked() )
661  {
662  myPyramidList = mDataProvider->buildPyramidList();
663  }
664  else
665  {
666  if ( ! mPyramidsOptionsWidget->overviewList().isEmpty() )
667  myPyramidList = mDataProvider->buildPyramidList( mPyramidsOptionsWidget->overviewList() );
668  }
669  QList<QgsRasterPyramid>::iterator myRasterPyramidIterator;
670  for ( myRasterPyramidIterator = myPyramidList.begin();
671  myRasterPyramidIterator != myPyramidList.end();
672  ++myRasterPyramidIterator )
673  {
674  if ( ! mPyramidsUseExistingCheckBox->isChecked() || myRasterPyramidIterator->exists )
675  {
676  text += QString::number( myRasterPyramidIterator->xDim ) + QString( "x" ) +
677  QString::number( myRasterPyramidIterator->yDim ) + " ";
678  }
679  }
680  }
681 
682  mPyramidResolutionsLineEdit->setText( text.trimmed() );
683 }
684 
685 void QgsRasterLayerSaveAsDialog::setNoDataToEdited( int row )
686 {
687  if ( row >= mNoDataToEdited.size() )
688  {
689  mNoDataToEdited.resize( row + 1 );
690  }
691  mNoDataToEdited[row] = true;
692 }
693 
694 double QgsRasterLayerSaveAsDialog::noDataCellValue( int row, int column ) const
695 {
696  QLineEdit *lineEdit = dynamic_cast<QLineEdit *>( mNoDataTableWidget->cellWidget( row, column ) );
697  if ( !lineEdit || lineEdit->text().isEmpty() )
698  {
699  std::numeric_limits<double>::quiet_NaN();
700  }
701  return lineEdit->text().toDouble();
702 }
703 
704 void QgsRasterLayerSaveAsDialog::adjustNoDataCellWidth( int row, int column )
705 {
706  QLineEdit *lineEdit = dynamic_cast<QLineEdit *>( mNoDataTableWidget->cellWidget( row, column ) );
707  if ( !lineEdit ) return;
708 
709  int width = qMax( lineEdit->fontMetrics().width( lineEdit->text() ) + 10, 100 );
710  width = qMax( width, mNoDataTableWidget->columnWidth( column ) );
711 
712  lineEdit->setFixedWidth( width );
713 }
714 
716 {
717  QgsRasterRangeList noDataList;
718  if ( ! mNoDataGroupBox->isChecked() )
719  return noDataList;
720 
721  for ( int r = 0 ; r < mNoDataTableWidget->rowCount(); r++ )
722  {
723  QgsRasterRange noData( noDataCellValue( r, 0 ), noDataCellValue( r, 1 ) );
724  noDataList.append( noData );
725 
726  }
727  return noDataList;
728 }
729 
731 {
732  return mPyramidsGroupBox->isChecked() ? mPyramidsOptionsWidget->overviewList() : QList<int>();
733 }
734 
736 {
737  if ( ! mPyramidsGroupBox->isChecked() )
739  else if ( mPyramidsUseExistingCheckBox->isChecked() )
741  else
743 }
744 
745 bool QgsRasterLayerSaveAsDialog::validate() const
746 {
747  if ( mCreateOptionsGroupBox->isChecked() )
748  {
749  QString message = mCreateOptionsWidget->validateOptions( true, false );
750  if ( !message.isNull() )
751  return false;
752  }
753  if ( mPyramidsGroupBox->isChecked() )
754  {
755  QString message = mPyramidsOptionsWidget->createOptionsWidget()->validateOptions( true, false );
756  if ( !message.isNull() )
757  return false;
758  }
759  return true;
760 }
761 
virtual int bandCount() const =0
Get number of bands.
Sixty four bit floating point (double)
Definition: qgis.h:213
QList< QgsRasterTransparency::TransparentSingleValuePixel > transparentSingleValuePixelList() const
Accessor for transparentSingleValuePixelList.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
QString getExistingDirectory(QWidget *parent, const QString &caption, const QString &dir, QFlags< QFileDialog::Option > options)
void setupUi(QWidget *widget)
static QString printValue(double value)
Print double value with all necessary significant digits.
void setFixedWidth(int w)
void setText(const QString &)
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
QObject * sender() const
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
Raster values range container.
QgsCoordinateReferenceSystem outputCrs()
QString join(const QString &separator) const
QString tr(const char *sourceText, const char *disambiguation, int n)
double x() const
Get the x value of the point.
Definition: qgspoint.h:126
virtual QString name() const =0
Return a provider name.
virtual int ySize() const
bool isNull() const
T value(int i) const
const QgsRasterTransparency * rasterTransparency() const
int width() const
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
QgsRasterLayerSaveAsDialog(QgsRasterLayer *rasterLayer, QgsRasterDataProvider *sourceProvider, const QgsRectangle &currentExtent, const QgsCoordinateReferenceSystem &layerCrs, const QgsCoordinateReferenceSystem &currentCrs, QWidget *parent=0, Qt::WindowFlags f=0)
void setEnabled(bool)
QString number(int n, int base)
void append(const T &value)
Thirty two bit floating point (float)
Definition: qgis.h:212
void resize(int size)
QgsRasterRenderer * renderer() const
virtual QGis::DataType srcDataType(int bandNo) const override=0
Returns source data type for the band specified by number, source data type may be shorter than dataT...
virtual QList< QgsRasterPyramid > buildPyramidList(QList< int > overviewList=QList< int >())
Accessor for ths raster layers pyramid list.
QgsRaster::RasterBuildPyramids buildPyramidsFlag() const
bool isEmpty() const
bool isEmpty() const
QString trimmed() const
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
A class to represent a point.
Definition: qgspoint.h:63
iterator end()
QString toLower() const
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
int width(const QString &text, int len) const
virtual QgsRectangle extent() override=0
Get the extent of the data source.
QgsRasterRangeList noData() const
QVariant value(const QString &key, const QVariant &defaultValue) const
void setFrame(bool)
QFontMetrics fontMetrics() const
virtual int xSize() const
Get raster size.
RasterBuildPyramids
Definition: qgsraster.h:71
Class for storing a coordinate reference system (CRS)
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFlags< QFileDialog::Option > options)
Class for doing transforms between two map coordinate systems.
double y() const
Get the y value of the point.
Definition: qgspoint.h:134
StandardButton warning(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
typedef WindowFlags
QgsRasterDataProvider * dataProvider()
Returns the data provider.
Defines the list of pixel values to be considered as transparent or semi transparent when rendering r...
double ANALYSIS_EXPORT min(double x, double y)
Returns the minimum of two doubles or the first argument if both are equal.
double width() const
Width of the rectangle.
Definition: qgsrectangle.h:202
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
int size() const
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QString toString() const
void setValidator(const QValidator *v)
QgsPoint center() const
Center point of the rectangle.
Definition: qgsrectangle.h:212
QString baseName() const
iterator begin()
double height() const
Height of the rectangle.
Definition: qgsrectangle.h:207
void setContentsMargins(int left, int top, int right, int bottom)
Base class for raster data providers.