QGIS API Documentation  2.9.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  mSaveAsLineEdit->setText( fileName );
207  }
208 }
209 
210 void QgsRasterLayerSaveAsDialog::on_mSaveAsLineEdit_textChanged( const QString& text )
211 {
212  QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
213  if ( !okButton )
214  {
215  return;
216  }
217 
218  okButton->setEnabled( QFileInfo( text ).absoluteDir().exists() );
219 }
220 
221 
222 void QgsRasterLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( const QString & text )
223 {
224  //gdal-specific
225  if ( mDataProvider && mDataProvider->name() == "gdal" )
226  {
227  mCreateOptionsWidget->setFormat( text );
228  mCreateOptionsWidget->update();
229  }
230 }
231 
233 {
234  return mColumnsLineEdit->text().toInt();
235 }
236 
238 {
239  return mRowsLineEdit->text().toInt();
240 }
241 
243 {
244  return mXResolutionLineEdit->text().toDouble();
245 }
246 
248 {
249  return mYResolutionLineEdit->text().toDouble();
250 }
251 
253 {
254  return mMaximumSizeXLineEdit->text().toInt();
255 }
256 
258 {
259  return mMaximumSizeYLineEdit->text().toInt();
260 }
261 
263 {
264  return mTileModeCheckBox->isChecked();
265 }
266 
268 {
269  return mAddToCanvas->isChecked();
270 }
271 
273 {
274  return mSaveAsLineEdit->text();
275 }
276 
278 {
279  return mFormatComboBox->currentText();
280 }
281 
283 {
284  return mCreateOptionsGroupBox->isChecked() ? mCreateOptionsWidget->options() : QStringList();
285 }
286 
288 {
289  return mExtentGroupBox->outputExtent();
290 }
291 
293 {
294  mFormatLabel->hide();
295  mFormatComboBox->hide();
296 }
297 
299 {
300  mSaveAsLabel->hide();
301  mSaveAsLineEdit->hide();
302  mBrowseButton->hide();
303  QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
304  if ( okButton )
305  {
306  okButton->setEnabled( true );
307  }
308 }
309 
310 void QgsRasterLayerSaveAsDialog::toggleResolutionSize()
311 {
312  bool hasResolution = mDataProvider && mDataProvider->capabilities() & QgsRasterDataProvider::Size;
313 
314  bool on = mResolutionRadioButton->isChecked();
315  mXResolutionLineEdit->setEnabled( on );
316  mYResolutionLineEdit->setEnabled( on );
317  mOriginalResolutionPushButton->setEnabled( on && hasResolution );
318  mColumnsLineEdit->setEnabled( !on );
319  mRowsLineEdit->setEnabled( !on );
320  mOriginalSizePushButton->setEnabled( !on && hasResolution );
321 }
322 
323 void QgsRasterLayerSaveAsDialog::setOriginalResolution()
324 {
325  double xRes, yRes;
326 
327  if ( mDataProvider->capabilities() & QgsRasterDataProvider::Size )
328  {
329  xRes = mDataProvider->extent().width() / mDataProvider->xSize();
330  yRes = mDataProvider->extent().height() / mDataProvider->ySize();
331  }
332  else
333  {
334  // Init to something if no original resolution is available
335  xRes = yRes = mDataProvider->extent().width() / 100;
336  }
337  setResolution( xRes, yRes, mLayerCrs );
338  mResolutionState = OriginalResolution;
339  recalcSize();
340 }
341 
342 void QgsRasterLayerSaveAsDialog::setResolution( double xRes, double yRes, const QgsCoordinateReferenceSystem& srcCrs )
343 {
344  if ( srcCrs != outputCrs() )
345  {
346  // We reproject pixel rectangle from center of selected extent, of course, it gives
347  // bigger xRes,yRes than reprojected edges (envelope), it may also be that
348  // close to margins are higher resolutions (even very, too high)
349  // TODO: consider more precise resolution calculation
350 
351  QgsPoint center = outputRectangle().center();
352  QgsCoordinateTransform ct( srcCrs, outputCrs() );
353  QgsPoint srsCenter = ct.transform( center, QgsCoordinateTransform::ReverseTransform );
354 
355  QgsRectangle srcExtent( srsCenter.x() - xRes / 2, srsCenter.y() - yRes / 2, srsCenter.x() + xRes / 2, srsCenter.y() + yRes / 2 );
356 
357  QgsRectangle extent = ct.transform( srcExtent );
358  xRes = extent.width();
359  yRes = extent.height();
360  }
361  mXResolutionLineEdit->setText( QString::number( xRes ) );
362  mYResolutionLineEdit->setText( QString::number( yRes ) );
363 }
364 
365 void QgsRasterLayerSaveAsDialog::recalcSize()
366 {
367  QgsDebugMsg( "Entered" );
368  QgsRectangle extent = outputRectangle();
369  int xSize = xResolution() != 0 ? static_cast<int>( qRound( extent.width() / xResolution() ) ) : 0;
370  int ySize = yResolution() != 0 ? static_cast<int>( qRound( extent.height() / yResolution() ) ) : 0;
371  mColumnsLineEdit->setText( QString::number( xSize ) );
372  mRowsLineEdit->setText( QString::number( ySize ) );
373  updateResolutionStateMsg();
374 }
375 
376 void QgsRasterLayerSaveAsDialog::setOriginalSize()
377 {
378  mColumnsLineEdit->setText( QString::number( mDataProvider->xSize() ) );
379  mRowsLineEdit->setText( QString::number( mDataProvider->ySize() ) );
380  recalcResolution();
381 }
382 
383 void QgsRasterLayerSaveAsDialog::recalcResolution()
384 {
385  QgsDebugMsg( "Entered" );
386  QgsRectangle extent = outputRectangle();
387  double xRes = nColumns() != 0 ? extent.width() / nColumns() : 0;
388  double yRes = nRows() != 0 ? extent.height() / nRows() : 0;
389  mXResolutionLineEdit->setText( QString::number( xRes ) );
390  mYResolutionLineEdit->setText( QString::number( yRes ) );
391  updateResolutionStateMsg();
392 }
393 
394 void QgsRasterLayerSaveAsDialog::recalcResolutionSize()
395 {
396  QgsDebugMsg( "Entered" );
397  if ( mResolutionRadioButton->isChecked() )
398  {
399  recalcSize();
400  }
401  else
402  {
403  mResolutionState = UserResolution;
404  recalcResolution();
405  }
406 }
407 
408 void QgsRasterLayerSaveAsDialog::updateResolutionStateMsg()
409 {
410  QString msg;
411  switch ( mResolutionState )
412  {
413  case OriginalResolution:
414  msg = tr( "layer" );
415  break;
416  case UserResolution:
417  msg = tr( "user defined" );
418  break;
419  default:
420  break;
421  }
422  msg = tr( "Resolution (current: %1)" ).arg( msg );
423  mResolutionGroupBox->setTitle( msg );
424 }
425 
426 void QgsRasterLayerSaveAsDialog::extentChanged()
427 {
428  // Whenever extent changes with fixed size, original resolution is lost
429  if ( mSizeRadioButton->isChecked() )
430  {
431  mResolutionState = UserResolution;
432  }
433  recalcResolutionSize();
434 }
435 
436 void QgsRasterLayerSaveAsDialog::crsChanged()
437 {
438  if ( outputCrs() != mPreviousCrs )
439  {
440  mExtentGroupBox->setOutputCrs( outputCrs() );
441  QgsExtentGroupBox::ExtentState state = mExtentGroupBox->extentState();
442 
443  // Reset extent
444  // We could reproject previous but that would add additional space also if
445  // it is was not necessary or at leas it could decrease accuracy
446  if ( state == QgsExtentGroupBox::OriginalExtent )
447  {
448  mExtentGroupBox->setOutputExtentFromOriginal();
449  }
450  else if ( state == QgsExtentGroupBox::CurrentExtent )
451  {
452  mExtentGroupBox->setOutputExtentFromCurrent();
453  }
454  else
455  {
456  mExtentGroupBox->setOutputExtentFromUser( mExtentGroupBox->outputExtent(), mPreviousCrs );
457  }
458 
459  // Reset resolution
460  if ( mResolutionRadioButton->isChecked() )
461  {
462  if ( mResolutionState == OriginalResolution )
463  {
464  setOriginalResolution();
465  }
466  else
467  {
468  // reset from present resolution and present crs
469  setResolution( xResolution(), yResolution(), mPreviousCrs );
470  }
471  }
472  else
473  {
474  // Size does not change, we just recalc resolution from new extent
475  recalcResolution();
476  }
477  }
478  mPreviousCrs = outputCrs();
479 }
480 
482 {
483  return mCrsSelector->crs();
484 }
485 
487 {
488  if ( mRenderedModeRadioButton->isChecked() ) return RenderedImageMode;
489  return RawDataMode;
490 }
491 
492 void QgsRasterLayerSaveAsDialog::on_mRawModeRadioButton_toggled( bool checked )
493 {
494  mNoDataGroupBox->setEnabled( checked && mDataProvider->bandCount() == 1 );
495 }
496 
497 void QgsRasterLayerSaveAsDialog::on_mAddNoDataManuallyToolButton_clicked()
498 {
499  addNoDataRow( std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN() );
500 }
501 
502 void QgsRasterLayerSaveAsDialog::on_mLoadTransparentNoDataToolButton_clicked()
503 {
504  if ( !mRasterLayer->renderer() ) return;
505  const QgsRasterTransparency* rasterTransparency = mRasterLayer->renderer()->rasterTransparency();
506  if ( !rasterTransparency ) return;
507 
508  foreach ( QgsRasterTransparency::TransparentSingleValuePixel transparencyPixel, rasterTransparency->transparentSingleValuePixelList() )
509  {
510  if ( transparencyPixel.percentTransparent == 100 )
511  {
512  addNoDataRow( transparencyPixel.min, transparencyPixel.max );
513  if ( transparencyPixel.min != transparencyPixel.max )
514  {
515  setNoDataToEdited( mNoDataTableWidget->rowCount() - 1 );
516  }
517  }
518  }
519 }
520 
521 void QgsRasterLayerSaveAsDialog::on_mRemoveSelectedNoDataToolButton_clicked()
522 {
523  mNoDataTableWidget->removeRow( mNoDataTableWidget->currentRow() );
524 }
525 
526 void QgsRasterLayerSaveAsDialog::on_mRemoveAllNoDataToolButton_clicked()
527 {
528  while ( mNoDataTableWidget->rowCount() > 0 )
529  {
530  mNoDataTableWidget->removeRow( 0 );
531  }
532 }
533 
534 void QgsRasterLayerSaveAsDialog::addNoDataRow( double min, double max )
535 {
536  mNoDataTableWidget->insertRow( mNoDataTableWidget->rowCount() );
537  for ( int i = 0; i < 2; i++ )
538  {
539  double value = i == 0 ? min : max;
540  QLineEdit *lineEdit = new QLineEdit();
541  lineEdit->setFrame( false );
542  lineEdit->setContentsMargins( 1, 1, 1, 1 );
543  QString valueString;
544  switch ( mRasterLayer->dataProvider()->srcDataType( 1 ) )
545  {
546  case QGis::Float32:
547  case QGis::Float64:
548  lineEdit->setValidator( new QDoubleValidator( 0 ) );
549  if ( !qIsNaN( value ) )
550  {
551  valueString = QgsRasterBlock::printValue( value );
552  }
553  break;
554  default:
555  lineEdit->setValidator( new QIntValidator( 0 ) );
556  if ( !qIsNaN( value ) )
557  {
558  valueString = QString::number( static_cast<int>( value ) );
559  }
560  break;
561  }
562  lineEdit->setText( valueString );
563  mNoDataTableWidget->setCellWidget( mNoDataTableWidget->rowCount() - 1, i, lineEdit );
564 
565  adjustNoDataCellWidth( mNoDataTableWidget->rowCount() - 1, i );
566 
567  connect( lineEdit, SIGNAL( textEdited( const QString & ) ), this, SLOT( noDataCellTextEdited( const QString & ) ) );
568  }
569  mNoDataTableWidget->resizeColumnsToContents();
570  mNoDataTableWidget->resizeRowsToContents();
571 }
572 
573 void QgsRasterLayerSaveAsDialog::noDataCellTextEdited( const QString & text )
574 {
575  Q_UNUSED( text );
576 
577  QLineEdit *lineEdit = dynamic_cast<QLineEdit *>( sender() );
578  if ( !lineEdit ) return;
579  int row = -1;
580  int column = -1;
581  for ( int r = 0 ; r < mNoDataTableWidget->rowCount(); r++ )
582  {
583  for ( int c = 0 ; c < mNoDataTableWidget->columnCount(); c++ )
584  {
585  if ( mNoDataTableWidget->cellWidget( r, c ) == sender() )
586  {
587  row = r;
588  column = c;
589  break;
590  }
591  }
592  if ( row != -1 ) break;
593  }
594  QgsDebugMsg( QString( "row = %1 column =%2" ).arg( row ).arg( column ) );
595 
596  if ( column == 0 )
597  {
598  QLineEdit *toLineEdit = dynamic_cast<QLineEdit *>( mNoDataTableWidget->cellWidget( row, 1 ) );
599  if ( !toLineEdit ) return;
600  bool toChanged = mNoDataToEdited.value( row );
601  QgsDebugMsg( QString( "toChanged = %1" ).arg( toChanged ) );
602  if ( !toChanged )
603  {
604  toLineEdit->setText( lineEdit->text() );
605  }
606  }
607  else if ( column == 1 )
608  {
609  setNoDataToEdited( row );
610  }
611 }
612 
613 void QgsRasterLayerSaveAsDialog::on_mTileModeCheckBox_toggled( bool toggled )
614 {
615  if ( toggled )
616  {
617  // enable pyramids
618 
619  // Disabled (Radim), auto enabling of pyramids was making impression that
620  // we (programmers) know better what you (user) want to do,
621  // certainly auto expaning was bad experience
622 
623  //if ( ! mPyramidsGroupBox->isChecked() )
624  // mPyramidsGroupBox->setChecked( true );
625 
626  // Auto expanding mPyramidsGroupBox is bad - it auto crolls content of dialog
627  //if ( mPyramidsGroupBox->isCollapsed() )
628  // mPyramidsGroupBox->setCollapsed( false );
629  //mPyramidsOptionsWidget->checkAllLevels( true );
630 
631  // Show / hide tile options
632  mTilesGroupBox->show();
633  }
634  else
635  {
636  mTilesGroupBox->hide();
637  }
638 }
639 
640 void QgsRasterLayerSaveAsDialog::on_mPyramidsGroupBox_toggled( bool toggled )
641 {
642  Q_UNUSED( toggled );
643  populatePyramidsLevels();
644 }
645 
646 void QgsRasterLayerSaveAsDialog::populatePyramidsLevels()
647 {
648  QString text;
649 
650  if ( mPyramidsGroupBox->isChecked() )
651  {
652  QList<QgsRasterPyramid> myPyramidList;
653  // if use existing, get pyramids from actual layer
654  // but that's not available yet
655  if ( mPyramidsUseExistingCheckBox->isChecked() )
656  {
657  myPyramidList = mDataProvider->buildPyramidList();
658  }
659  else
660  {
661  if ( ! mPyramidsOptionsWidget->overviewList().isEmpty() )
662  myPyramidList = mDataProvider->buildPyramidList( mPyramidsOptionsWidget->overviewList() );
663  }
664  QList<QgsRasterPyramid>::iterator myRasterPyramidIterator;
665  for ( myRasterPyramidIterator = myPyramidList.begin();
666  myRasterPyramidIterator != myPyramidList.end();
667  ++myRasterPyramidIterator )
668  {
669  if ( ! mPyramidsUseExistingCheckBox->isChecked() || myRasterPyramidIterator->exists )
670  {
671  text += QString::number( myRasterPyramidIterator->xDim ) + QString( "x" ) +
672  QString::number( myRasterPyramidIterator->yDim ) + " ";
673  }
674  }
675  }
676 
677  mPyramidResolutionsLineEdit->setText( text.trimmed() );
678 }
679 
680 void QgsRasterLayerSaveAsDialog::setNoDataToEdited( int row )
681 {
682  if ( row >= mNoDataToEdited.size() )
683  {
684  mNoDataToEdited.resize( row + 1 );
685  }
686  mNoDataToEdited[row] = true;
687 }
688 
689 double QgsRasterLayerSaveAsDialog::noDataCellValue( int row, int column ) const
690 {
691  QLineEdit *lineEdit = dynamic_cast<QLineEdit *>( mNoDataTableWidget->cellWidget( row, column ) );
692  if ( !lineEdit || lineEdit->text().isEmpty() )
693  {
694  std::numeric_limits<double>::quiet_NaN();
695  }
696  return lineEdit->text().toDouble();
697 }
698 
699 void QgsRasterLayerSaveAsDialog::adjustNoDataCellWidth( int row, int column )
700 {
701  QLineEdit *lineEdit = dynamic_cast<QLineEdit *>( mNoDataTableWidget->cellWidget( row, column ) );
702  if ( !lineEdit ) return;
703 
704  int width = qMax( lineEdit->fontMetrics().width( lineEdit->text() ) + 10, 100 );
705  width = qMax( width, mNoDataTableWidget->columnWidth( column ) );
706 
707  lineEdit->setFixedWidth( width );
708 }
709 
711 {
712  QgsRasterRangeList noDataList;
713  if ( ! mNoDataGroupBox->isChecked() )
714  return noDataList;
715 
716  for ( int r = 0 ; r < mNoDataTableWidget->rowCount(); r++ )
717  {
718  QgsRasterRange noData( noDataCellValue( r, 0 ), noDataCellValue( r, 1 ) );
719  noDataList.append( noData );
720 
721  }
722  return noDataList;
723 }
724 
726 {
727  return mPyramidsGroupBox->isChecked() ? mPyramidsOptionsWidget->overviewList() : QList<int>();
728 }
729 
731 {
732  if ( ! mPyramidsGroupBox->isChecked() )
734  else if ( mPyramidsUseExistingCheckBox->isChecked() )
736  else
738 }
739 
740 bool QgsRasterLayerSaveAsDialog::validate() const
741 {
742  if ( mCreateOptionsGroupBox->isChecked() )
743  {
744  QString message = mCreateOptionsWidget->validateOptions( true, false );
745  if ( !message.isNull() )
746  return false;
747  }
748  if ( mPyramidsGroupBox->isChecked() )
749  {
750  QString message = mPyramidsOptionsWidget->createOptionsWidget()->validateOptions( true, false );
751  if ( !message.isNull() )
752  return false;
753  }
754  return true;
755 }
756 
virtual int bandCount() const =0
Get number of bands.
QList< QgsRasterTransparency::TransparentSingleValuePixel > transparentSingleValuePixelList() const
Accessor for transparentSingleValuePixelList.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
static QString printValue(double value)
Print double value with all necessary significant digits.
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
Raster values range container.
QgsCoordinateReferenceSystem outputCrs()
double x() const
Definition: qgspoint.h:126
virtual QString name() const =0
return a provider name
virtual int ySize() const
const QgsRasterTransparency * rasterTransparency() const
QgsRasterLayerSaveAsDialog(QgsRasterLayer *rasterLayer, QgsRasterDataProvider *sourceProvider, const QgsRectangle &currentExtent, const QgsCoordinateReferenceSystem &layerCrs, const QgsCoordinateReferenceSystem &currentCrs, QWidget *parent=0, Qt::WindowFlags f=0)
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
A class to represent a point.
Definition: qgspoint.h:63
int min(int a, int b)
Definition: util.h:93
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
virtual QgsRectangle extent() override=0
Get the extent of the data source.
QgsRasterRangeList noData() const
QList< QgsRasterRange > QgsRasterRangeList
virtual int xSize() const
Get raster size.
RasterBuildPyramids
Definition: qgsraster.h:71
Class for storing a coordinate reference system (CRS)
Class for doing transforms between two map coordinate systems.
double y() const
Definition: qgspoint.h:134
QgsRasterDataProvider * dataProvider()
Returns the data provider.
Defines the list of pixel values to be considered as transparent or semi transparent when rendering r...
double width() const
Width of the rectangle.
Definition: qgsrectangle.h:202
int max(int a, int b)
Definition: util.h:87
QgsPoint center() const
Center point of the rectangle.
Definition: qgsrectangle.h:212
double height() const
Height of the rectangle.
Definition: qgsrectangle.h:207
Base class for raster data providers.
#define tr(sourceText)