QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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->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  if ( mTileModeCheckBox->isChecked() )
159  {
160  while ( true )
161  {
162  // TODO: would not it be better to select .vrt file instead of directory?
163  fileName = QFileDialog::getExistingDirectory( this, tr( "Select output directory" ) );
164  //fileName = QFileDialog::getSaveFileName( this, tr( "Select output file" ), QString(), tr( "VRT" ) + " (*.vrt *.VRT)" );
165 
166  if ( fileName.isEmpty() ) break; // canceled
167 
168  // Check if directory is empty
169  QDir dir( fileName );
170  QString baseName = QFileInfo( fileName ).baseName();
171  QStringList filters;
172  filters << QString( "%1.*" ).arg( baseName );
173  QStringList files = dir.entryList( filters );
174  if ( !files.isEmpty() )
175  {
176  QMessageBox::StandardButton button = QMessageBox::warning( this, tr( "Warning" ),
177  tr( "The directory %1 contains files which will be overwritten: %2" ).arg( dir.absolutePath() ).arg( files.join( ", " ) ),
178  QMessageBox::Ok | QMessageBox::Cancel );
179 
180  if ( button == QMessageBox::Ok )
181  {
182  break;
183  }
184  else
185  {
186  fileName = "";
187  }
188  }
189  else
190  {
191  break;
192  }
193  }
194  }
195  else
196  {
197  fileName = QFileDialog::getSaveFileName( this, tr( "Select output file" ), QString(), tr( "GeoTIFF" ) + " (*.tif *.tiff *.TIF *.TIFF)" );
198  }
199 
200  if ( !fileName.isEmpty() )
201  {
202  mSaveAsLineEdit->setText( fileName );
203  }
204 }
205 
206 void QgsRasterLayerSaveAsDialog::on_mSaveAsLineEdit_textChanged( const QString& text )
207 {
208  QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
209  if ( !okButton )
210  {
211  return;
212  }
213 
214  okButton->setEnabled( QFileInfo( text ).absoluteDir().exists() );
215 }
216 
217 
218 void QgsRasterLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( const QString & text )
219 {
220  //gdal-specific
221  if ( mDataProvider && mDataProvider->name() == "gdal" )
222  {
223  mCreateOptionsWidget->setFormat( text );
224  mCreateOptionsWidget->update();
225  }
226 }
227 
229 {
230  return mColumnsLineEdit->text().toInt();
231 }
232 
234 {
235  return mRowsLineEdit->text().toInt();
236 }
237 
239 {
240  return mXResolutionLineEdit->text().toDouble();
241 }
242 
244 {
245  return mYResolutionLineEdit->text().toDouble();
246 }
247 
249 {
250  return mMaximumSizeXLineEdit->text().toInt();
251 }
252 
254 {
255  return mMaximumSizeYLineEdit->text().toInt();
256 }
257 
259 {
260  return mTileModeCheckBox->isChecked();
261 }
262 
264 {
265  return mSaveAsLineEdit->text();
266 }
267 
269 {
270  return mFormatComboBox->currentText();
271 }
272 
274 {
275  return mCreateOptionsGroupBox->isChecked() ? mCreateOptionsWidget->options() : QStringList();
276 }
277 
279 {
280  return mExtentGroupBox->outputExtent();
281 }
282 
284 {
285  mFormatLabel->hide();
286  mFormatComboBox->hide();
287 }
288 
290 {
291  mSaveAsLabel->hide();
292  mSaveAsLineEdit->hide();
293  mBrowseButton->hide();
294  QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
295  if ( okButton )
296  {
297  okButton->setEnabled( true );
298  }
299 }
300 
301 void QgsRasterLayerSaveAsDialog::toggleResolutionSize()
302 {
303  bool hasResolution = mDataProvider && mDataProvider->capabilities() & QgsRasterDataProvider::Size;
304 
305  bool on = mResolutionRadioButton->isChecked();
306  mXResolutionLineEdit->setEnabled( on );
307  mYResolutionLineEdit->setEnabled( on );
308  mOriginalResolutionPushButton->setEnabled( on && hasResolution );
309  mColumnsLineEdit->setEnabled( !on );
310  mRowsLineEdit->setEnabled( !on );
311  mOriginalSizePushButton->setEnabled( !on && hasResolution );
312 }
313 
314 void QgsRasterLayerSaveAsDialog::setOriginalResolution()
315 {
316  double xRes, yRes;
317 
318  if ( mDataProvider->capabilities() & QgsRasterDataProvider::Size )
319  {
320  xRes = mDataProvider->extent().width() / mDataProvider->xSize();
321  yRes = mDataProvider->extent().height() / mDataProvider->ySize();
322  }
323  else
324  {
325  // Init to something if no original resolution is available
326  xRes = yRes = mDataProvider->extent().width() / 100;
327  }
328  setResolution( xRes, yRes, mLayerCrs );
329  mResolutionState = OriginalResolution;
330  recalcSize();
331 }
332 
333 void QgsRasterLayerSaveAsDialog::setResolution( double xRes, double yRes, const QgsCoordinateReferenceSystem& srcCrs )
334 {
335  if ( srcCrs != outputCrs() )
336  {
337  // We reproject pixel rectangle from center of selected extent, of course, it gives
338  // bigger xRes,yRes than reprojected edges (envelope), it may also be that
339  // close to margins are higher resolutions (even very, too high)
340  // TODO: consider more precise resolution calculation
341 
342  QgsPoint center = outputRectangle().center();
343  QgsCoordinateTransform ct( srcCrs, outputCrs() );
344  QgsPoint srsCenter = ct.transform( center, QgsCoordinateTransform::ReverseTransform );
345 
346  QgsRectangle srcExtent( srsCenter.x() - xRes / 2, srsCenter.y() - yRes / 2, srsCenter.x() + xRes / 2, srsCenter.y() + yRes / 2 );
347 
348  QgsRectangle extent = ct.transform( srcExtent );
349  xRes = extent.width();
350  yRes = extent.height();
351  }
352  mXResolutionLineEdit->setText( QString::number( xRes ) );
353  mYResolutionLineEdit->setText( QString::number( yRes ) );
354 }
355 
356 void QgsRasterLayerSaveAsDialog::recalcSize()
357 {
358  QgsDebugMsg( "Entered" );
359  QgsRectangle extent = outputRectangle();
360  int xSize = xResolution() != 0 ? static_cast<int>( qRound( extent.width() / xResolution() ) ) : 0;
361  int ySize = yResolution() != 0 ? static_cast<int>( qRound( extent.height() / yResolution() ) ) : 0;
362  mColumnsLineEdit->setText( QString::number( xSize ) );
363  mRowsLineEdit->setText( QString::number( ySize ) );
364  updateResolutionStateMsg();
365 }
366 
367 void QgsRasterLayerSaveAsDialog::setOriginalSize()
368 {
369  mColumnsLineEdit->setText( QString::number( mDataProvider->xSize() ) );
370  mRowsLineEdit->setText( QString::number( mDataProvider->ySize() ) );
371  recalcResolution();
372 }
373 
374 void QgsRasterLayerSaveAsDialog::recalcResolution()
375 {
376  QgsDebugMsg( "Entered" );
377  QgsRectangle extent = outputRectangle();
378  double xRes = nColumns() != 0 ? extent.width() / nColumns() : 0;
379  double yRes = nRows() != 0 ? extent.height() / nRows() : 0;
380  mXResolutionLineEdit->setText( QString::number( xRes ) );
381  mYResolutionLineEdit->setText( QString::number( yRes ) );
382  updateResolutionStateMsg();
383 }
384 
385 void QgsRasterLayerSaveAsDialog::recalcResolutionSize()
386 {
387  QgsDebugMsg( "Entered" );
388  if ( mResolutionRadioButton->isChecked() )
389  {
390  recalcSize();
391  }
392  else
393  {
394  mResolutionState = UserResolution;
395  recalcResolution();
396  }
397 }
398 
399 void QgsRasterLayerSaveAsDialog::updateResolutionStateMsg()
400 {
401  QString msg;
402  switch ( mResolutionState )
403  {
404  case OriginalResolution:
405  msg = tr( "layer" );
406  break;
407  case UserResolution:
408  msg = tr( "user defined" );
409  break;
410  default:
411  break;
412  }
413  msg = tr( "Resolution (current: %1)" ).arg( msg );
414  mResolutionGroupBox->setTitle( msg );
415 }
416 
417 void QgsRasterLayerSaveAsDialog::extentChanged()
418 {
419  // Whenever extent changes with fixed size, original resolution is lost
420  if ( mSizeRadioButton->isChecked() )
421  {
422  mResolutionState = UserResolution;
423  }
424  recalcResolutionSize();
425 }
426 
427 void QgsRasterLayerSaveAsDialog::crsChanged()
428 {
429  if ( outputCrs() != mPreviousCrs )
430  {
431  mExtentGroupBox->setOutputCrs( outputCrs() );
432  QgsExtentGroupBox::ExtentState state = mExtentGroupBox->extentState();
433 
434  // Reset extent
435  // We could reproject previous but that would add additional space also if
436  // it is was not necessary or at leas it could decrease accuracy
437  if ( state == QgsExtentGroupBox::OriginalExtent )
438  {
439  mExtentGroupBox->setOutputExtentFromOriginal();
440  }
441  else if ( state == QgsExtentGroupBox::CurrentExtent )
442  {
443  mExtentGroupBox->setOutputExtentFromCurrent();
444  }
445  else
446  {
447  mExtentGroupBox->setOutputExtentFromUser( mExtentGroupBox->outputExtent(), mPreviousCrs );
448  }
449 
450  // Reset resolution
451  if ( mResolutionRadioButton->isChecked() )
452  {
453  if ( mResolutionState == OriginalResolution )
454  {
455  setOriginalResolution();
456  }
457  else
458  {
459  // reset from present resolution and present crs
460  setResolution( xResolution(), yResolution(), mPreviousCrs );
461  }
462  }
463  else
464  {
465  // Size does not change, we just recalc resolution from new extent
466  recalcResolution();
467  }
468  }
469  mPreviousCrs = outputCrs();
470 }
471 
473 {
474  return mCrsSelector->crs();
475 }
476 
478 {
479  if ( mRenderedModeRadioButton->isChecked() ) return RenderedImageMode;
480  return RawDataMode;
481 }
482 
483 void QgsRasterLayerSaveAsDialog::on_mRawModeRadioButton_toggled( bool checked )
484 {
485  mNoDataGroupBox->setEnabled( checked && mDataProvider->bandCount() == 1 );
486 }
487 
488 void QgsRasterLayerSaveAsDialog::on_mAddNoDataManuallyToolButton_clicked()
489 {
490  addNoDataRow( std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN() );
491 }
492 
493 void QgsRasterLayerSaveAsDialog::on_mLoadTransparentNoDataToolButton_clicked()
494 {
495  if ( !mRasterLayer->renderer() ) return;
496  const QgsRasterTransparency* rasterTransparency = mRasterLayer->renderer()->rasterTransparency();
497  if ( !rasterTransparency ) return;
498 
499  foreach ( QgsRasterTransparency::TransparentSingleValuePixel transparencyPixel, rasterTransparency->transparentSingleValuePixelList() )
500  {
501  if ( transparencyPixel.percentTransparent == 100 )
502  {
503  addNoDataRow( transparencyPixel.min, transparencyPixel.max );
504  if ( transparencyPixel.min != transparencyPixel.max )
505  {
506  setNoDataToEdited( mNoDataTableWidget->rowCount() - 1 );
507  }
508  }
509  }
510 }
511 
512 void QgsRasterLayerSaveAsDialog::on_mRemoveSelectedNoDataToolButton_clicked()
513 {
514  mNoDataTableWidget->removeRow( mNoDataTableWidget->currentRow() );
515 }
516 
517 void QgsRasterLayerSaveAsDialog::on_mRemoveAllNoDataToolButton_clicked()
518 {
519  while ( mNoDataTableWidget->rowCount() > 0 )
520  {
521  mNoDataTableWidget->removeRow( 0 );
522  }
523 }
524 
525 void QgsRasterLayerSaveAsDialog::addNoDataRow( double min, double max )
526 {
527  mNoDataTableWidget->insertRow( mNoDataTableWidget->rowCount() );
528  for ( int i = 0; i < 2; i++ )
529  {
530  double value = i == 0 ? min : max;
531  QLineEdit *lineEdit = new QLineEdit();
532  lineEdit->setFrame( false );
533  lineEdit->setContentsMargins( 1, 1, 1, 1 );
534  QString valueString;
535  switch ( mRasterLayer->dataProvider()->srcDataType( 1 ) )
536  {
537  case QGis::Float32:
538  case QGis::Float64:
539  lineEdit->setValidator( new QDoubleValidator( 0 ) );
540  if ( !qIsNaN( value ) )
541  {
542  valueString = QgsRasterBlock::printValue( value );
543  }
544  break;
545  default:
546  lineEdit->setValidator( new QIntValidator( 0 ) );
547  if ( !qIsNaN( value ) )
548  {
549  valueString = QString::number( static_cast<int>( value ) );
550  }
551  break;
552  }
553  lineEdit->setText( valueString );
554  mNoDataTableWidget->setCellWidget( mNoDataTableWidget->rowCount() - 1, i, lineEdit );
555 
556  adjustNoDataCellWidth( mNoDataTableWidget->rowCount() - 1, i );
557 
558  connect( lineEdit, SIGNAL( textEdited( const QString & ) ), this, SLOT( noDataCellTextEdited( const QString & ) ) );
559  }
560  mNoDataTableWidget->resizeColumnsToContents();
561  mNoDataTableWidget->resizeRowsToContents();
562 }
563 
564 void QgsRasterLayerSaveAsDialog::noDataCellTextEdited( const QString & text )
565 {
566  Q_UNUSED( text );
567 
568  QLineEdit *lineEdit = dynamic_cast<QLineEdit *>( sender() );
569  if ( !lineEdit ) return;
570  int row = -1;
571  int column = -1;
572  for ( int r = 0 ; r < mNoDataTableWidget->rowCount(); r++ )
573  {
574  for ( int c = 0 ; c < mNoDataTableWidget->columnCount(); c++ )
575  {
576  if ( mNoDataTableWidget->cellWidget( r, c ) == sender() )
577  {
578  row = r;
579  column = c;
580  break;
581  }
582  }
583  if ( row != -1 ) break;
584  }
585  QgsDebugMsg( QString( "row = %1 column =%2" ).arg( row ).arg( column ) );
586 
587  if ( column == 0 )
588  {
589  QLineEdit *toLineEdit = dynamic_cast<QLineEdit *>( mNoDataTableWidget->cellWidget( row, 1 ) );
590  if ( !toLineEdit ) return;
591  bool toChanged = mNoDataToEdited.value( row );
592  QgsDebugMsg( QString( "toChanged = %1" ).arg( toChanged ) );
593  if ( !toChanged )
594  {
595  toLineEdit->setText( lineEdit->text() );
596  }
597  }
598  else if ( column == 1 )
599  {
600  setNoDataToEdited( row );
601  }
602 }
603 
604 void QgsRasterLayerSaveAsDialog::on_mTileModeCheckBox_toggled( bool toggled )
605 {
606  if ( toggled )
607  {
608  // enable pyramids
609 
610  // Disabled (Radim), auto enabling of pyramids was making impression that
611  // we (programmers) know better what you (user) want to do,
612  // certainly auto expaning was bad experience
613 
614  //if ( ! mPyramidsGroupBox->isChecked() )
615  // mPyramidsGroupBox->setChecked( true );
616 
617  // Auto expanding mPyramidsGroupBox is bad - it auto crolls content of dialog
618  //if ( mPyramidsGroupBox->isCollapsed() )
619  // mPyramidsGroupBox->setCollapsed( false );
620  //mPyramidsOptionsWidget->checkAllLevels( true );
621 
622  // Show / hide tile options
623  mTilesGroupBox->show();
624  }
625  else
626  {
627  mTilesGroupBox->hide();
628  }
629 }
630 
631 void QgsRasterLayerSaveAsDialog::on_mPyramidsGroupBox_toggled( bool toggled )
632 {
633  Q_UNUSED( toggled );
634  populatePyramidsLevels();
635 }
636 
637 void QgsRasterLayerSaveAsDialog::populatePyramidsLevels()
638 {
639  QString text;
640 
641  if ( mPyramidsGroupBox->isChecked() )
642  {
643  QList<QgsRasterPyramid> myPyramidList;
644  // if use existing, get pyramids from actual layer
645  // but that's not available yet
646  if ( mPyramidsUseExistingCheckBox->isChecked() )
647  {
648  myPyramidList = mDataProvider->buildPyramidList();
649  }
650  else
651  {
652  if ( ! mPyramidsOptionsWidget->overviewList().isEmpty() )
653  myPyramidList = mDataProvider->buildPyramidList( mPyramidsOptionsWidget->overviewList() );
654  }
655  QList<QgsRasterPyramid>::iterator myRasterPyramidIterator;
656  for ( myRasterPyramidIterator = myPyramidList.begin();
657  myRasterPyramidIterator != myPyramidList.end();
658  ++myRasterPyramidIterator )
659  {
660  if ( ! mPyramidsUseExistingCheckBox->isChecked() || myRasterPyramidIterator->exists )
661  {
662  text += QString::number( myRasterPyramidIterator->xDim ) + QString( "x" ) +
663  QString::number( myRasterPyramidIterator->yDim ) + " ";
664  }
665  }
666  }
667 
668  mPyramidResolutionsLineEdit->setText( text.trimmed() );
669 }
670 
671 void QgsRasterLayerSaveAsDialog::setNoDataToEdited( int row )
672 {
673  if ( row >= mNoDataToEdited.size() )
674  {
675  mNoDataToEdited.resize( row + 1 );
676  }
677  mNoDataToEdited[row] = true;
678 }
679 
680 double QgsRasterLayerSaveAsDialog::noDataCellValue( int row, int column ) const
681 {
682  QLineEdit *lineEdit = dynamic_cast<QLineEdit *>( mNoDataTableWidget->cellWidget( row, column ) );
683  if ( !lineEdit || lineEdit->text().isEmpty() )
684  {
685  std::numeric_limits<double>::quiet_NaN();
686  }
687  return lineEdit->text().toDouble();
688 }
689 
690 void QgsRasterLayerSaveAsDialog::adjustNoDataCellWidth( int row, int column )
691 {
692  QLineEdit *lineEdit = dynamic_cast<QLineEdit *>( mNoDataTableWidget->cellWidget( row, column ) );
693  if ( !lineEdit ) return;
694 
695  int width = qMax( lineEdit->fontMetrics().width( lineEdit->text() ) + 10, 100 );
696  width = qMax( width, mNoDataTableWidget->columnWidth( column ) );
697 
698  lineEdit->setFixedWidth( width );
699 }
700 
702 {
703  QgsRasterRangeList noDataList;
704  if ( ! mNoDataGroupBox->isChecked() )
705  return noDataList;
706 
707  for ( int r = 0 ; r < mNoDataTableWidget->rowCount(); r++ )
708  {
709  QgsRasterRange noData( noDataCellValue( r, 0 ), noDataCellValue( r, 1 ) );
710  noDataList.append( noData );
711 
712  }
713  return noDataList;
714 }
715 
717 {
718  return mPyramidsGroupBox->isChecked() ? mPyramidsOptionsWidget->overviewList() : QList<int>();
719 }
720 
722 {
723  if ( ! mPyramidsGroupBox->isChecked() )
725  else if ( mPyramidsUseExistingCheckBox->isChecked() )
727  else
729 }
730 
731 bool QgsRasterLayerSaveAsDialog::validate() const
732 {
733  if ( mCreateOptionsGroupBox->isChecked() )
734  {
735  QString message = mCreateOptionsWidget->validateOptions( true, false );
736  if ( !message.isNull() )
737  return false;
738  }
739  if ( mPyramidsGroupBox->isChecked() )
740  {
741  QString message = mPyramidsOptionsWidget->createOptionsWidget()->validateOptions( true, false );
742  if ( !message.isNull() )
743  return false;
744  }
745  return true;
746 }
747 
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:198
int max(int a, int b)
Definition: util.h:87
QgsPoint center() const
Center point of the rectangle.
Definition: qgsrectangle.h:208
double height() const
Height of the rectangle.
Definition: qgsrectangle.h:203
Base class for raster data providers.
#define tr(sourceText)