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