QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 "gdal.h"
25 
26 #include <QFileDialog>
27 #include <QMessageBox>
28 #include <QSettings>
29 
31  QgsRasterDataProvider* sourceProvider, const QgsRectangle& currentExtent,
32  const QgsCoordinateReferenceSystem& layerCrs, const QgsCoordinateReferenceSystem& currentCrs,
33  QWidget* parent, const Qt::WindowFlags& f )
34  : QDialog( parent, f )
35  , mRasterLayer( rasterLayer )
36  , mDataProvider( sourceProvider )
37  , mCurrentExtent( currentExtent )
38  , mLayerCrs( layerCrs )
39  , mCurrentCrs( currentCrs )
40  , mResolutionState( OriginalResolution )
41 {
42  setupUi( this );
43  mAddNoDataManuallyToolButton->setIcon( QgsApplication::getThemeIcon( "/mActionNewAttribute.svg" ) );
44  mLoadTransparentNoDataToolButton->setIcon( QgsApplication::getThemeIcon( "/mActionCopySelected.png" ) );
45  mRemoveSelectedNoDataToolButton->setIcon( QgsApplication::getThemeIcon( "/mActionDeleteAttribute.svg" ) );
46  mRemoveAllNoDataToolButton->setIcon( QgsApplication::getThemeIcon( "/mActionRemove.svg" ) );
47 
48  mNoDataTableWidget->setColumnCount( 2 );
49  mNoDataTableWidget->setHorizontalHeaderItem( 0, new QTableWidgetItem( tr( "From" ) ) );
50  mNoDataTableWidget->setHorizontalHeaderItem( 1, new QTableWidgetItem( tr( "To" ) ) );
51 
52  on_mRawModeRadioButton_toggled( true );
53 
54  setValidators();
55 
56  toggleResolutionSize();
57 
58  //only one hardcoded format at the moment
59  QStringList myFormats;
60  myFormats << "GTiff";
61  Q_FOREACH ( const QString& myFormat, myFormats )
62  {
63  mFormatComboBox->addItem( myFormat );
64  }
65 
66  //fill reasonable default values depending on the provider
67  if ( mDataProvider )
68  {
69  if ( mDataProvider->capabilities() & QgsRasterDataProvider::Size )
70  {
71  setOriginalResolution();
72  int xSize = mDataProvider->xSize();
73  int ySize = mDataProvider->ySize();
74  mMaximumSizeXLineEdit->setText( QString::number( xSize ) );
75  mMaximumSizeYLineEdit->setText( QString::number( ySize ) );
76  }
77  else //wms, sometimes wcs
78  {
79  mTileModeCheckBox->setChecked( true );
80  mMaximumSizeXLineEdit->setText( QString::number( 2000 ) );
81  mMaximumSizeYLineEdit->setText( QString::number( 2000 ) );
82  }
83 
84  // setup creation option widget
85  mCreateOptionsWidget->setProvider( mDataProvider->name() );
86  if ( mDataProvider->name() == "gdal" )
87  {
88  mCreateOptionsWidget->setFormat( myFormats[0] );
89  }
90  mCreateOptionsWidget->setRasterLayer( mRasterLayer );
91  mCreateOptionsWidget->update();
92  }
93 
94  // Only do pyramids if dealing directly with GDAL.
95  if ( mDataProvider && mDataProvider->capabilities() & QgsRasterDataProvider::BuildPyramids )
96  {
97  // setup pyramids option widget
98  // mPyramidsOptionsWidget->createOptionsWidget()->setType( QgsRasterFormatSaveOptionsWidget::ProfileLineEdit );
99  mPyramidsOptionsWidget->createOptionsWidget()->setRasterLayer( mRasterLayer );
100 
101  // TODO enable "use existing", has no effect for now, because using Create() in gdal provider
102  // if ( ! mDataProvider->hasPyramids() )
103  // mPyramidsButtonGroup->button( QgsRaster::PyramidsCopyExisting )->setEnabled( false );
104  mPyramidsUseExistingCheckBox->setEnabled( false );
105  mPyramidsUseExistingCheckBox->setVisible( false );
106 
107  populatePyramidsLevels();
108  connect( mPyramidsOptionsWidget, SIGNAL( overviewListChanged() ),
109  this, SLOT( populatePyramidsLevels() ) );
110  }
111  else
112  {
113  mPyramidsGroupBox->setEnabled( false );
114  }
115 
116  // restore checked state for most groupboxes (default is to restore collapsed state)
117  // create options and pyramids will be preset, if user has selected defaults in the gdal options dlg
118  mCreateOptionsGroupBox->setSaveCheckedState( true );
119  //mTilesGroupBox->setSaveCheckedState( true );
120  // don't restore nodata, it needs user input
121  // pyramids are not necessarily built every time
122 
123  mTilesGroupBox->hide();
124 
125  mCrsSelector->setLayerCrs( mLayerCrs );
126  //default to layer CRS - see http://hub.qgis.org/issues/14209 for discussion
127  mCrsSelector->setCrs( mLayerCrs );
128 
129  connect( mCrsSelector, SIGNAL( crsChanged( QgsCoordinateReferenceSystem ) ),
130  this, SLOT( crsChanged() ) );
131 
132  QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
133  if ( okButton )
134  {
135  okButton->setEnabled( false );
136  }
137 
138  mExtentGroupBox->setOutputCrs( outputCrs() );
139  mExtentGroupBox->setOriginalExtent( mDataProvider->extent(), mLayerCrs );
140  mExtentGroupBox->setCurrentExtent( mCurrentExtent, mCurrentCrs );
141  mExtentGroupBox->setOutputExtentFromOriginal();
142  connect( mExtentGroupBox, SIGNAL( extentChanged( QgsRectangle ) ), this, SLOT( extentChanged() ) );
143 
144  recalcResolutionSize();
145 }
146 
147 void QgsRasterLayerSaveAsDialog::setValidators()
148 {
149  mXResolutionLineEdit->setValidator( new QDoubleValidator( this ) );
150  mYResolutionLineEdit->setValidator( new QDoubleValidator( this ) );
151  mColumnsLineEdit->setValidator( new QIntValidator( this ) );
152  mRowsLineEdit->setValidator( new QIntValidator( this ) );
153  mMaximumSizeXLineEdit->setValidator( new QIntValidator( this ) );
154  mMaximumSizeYLineEdit->setValidator( new QIntValidator( this ) );
155 }
156 
158 {
159 }
160 
161 void QgsRasterLayerSaveAsDialog::on_mBrowseButton_clicked()
162 {
163  QString fileName;
164 
165  QSettings settings;
166  QString dirName = mSaveAsLineEdit->text().isEmpty() ? settings.value( "/UI/lastRasterFileDir", QDir::homePath() ).toString() : mSaveAsLineEdit->text();
167 
168  if ( mTileModeCheckBox->isChecked() )
169  {
170  Q_FOREVER
171  {
172  // TODO: would not it be better to select .vrt file instead of directory?
173  fileName = QFileDialog::getExistingDirectory( this, tr( "Select output directory" ), dirName );
174  //fileName = QFileDialog::getSaveFileName( this, tr( "Select output file" ), QString(), tr( "VRT" ) + " (*.vrt *.VRT)" );
175 
176  if ( fileName.isEmpty() )
177  break; // canceled
178 
179  // Check if directory is empty
180  QDir dir( fileName );
181  QString baseName = QFileInfo( fileName ).baseName();
182  QStringList filters;
183  filters << QString( "%1.*" ).arg( baseName );
184  QStringList files = dir.entryList( filters );
185  if ( files.isEmpty() )
186  break;
187 
188  if ( QMessageBox::warning( this, tr( "Warning" ),
189  tr( "The directory %1 contains files which will be overwritten: %2" ).arg( dir.absolutePath(), files.join( ", " ) ),
190  QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Ok )
191  break;
192 
193  fileName = "";
194  }
195  }
196  else
197  {
198  fileName = QFileDialog::getSaveFileName( this, tr( "Select output file" ), dirName, tr( "GeoTIFF" ) + " (*.tif *.tiff *.TIF *.TIFF)" );
199 
200  // ensure the user never omits the extension from the file name
201  if ( !fileName.isEmpty() && !fileName.endsWith( ".tif", Qt::CaseInsensitive ) && !fileName.endsWith( ".tiff", Qt::CaseInsensitive ) )
202  {
203  fileName += ".tif";
204  }
205  }
206 
207  if ( !fileName.isEmpty() )
208  {
209  mSaveAsLineEdit->setText( fileName );
210  }
211 }
212 
213 void QgsRasterLayerSaveAsDialog::on_mSaveAsLineEdit_textChanged( const QString& text )
214 {
215  QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
216  if ( !okButton )
217  {
218  return;
219  }
220 
221  okButton->setEnabled( QFileInfo( text ).absoluteDir().exists() );
222 }
223 
224 
225 void QgsRasterLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( const QString & text )
226 {
227  //gdal-specific
228  if ( mDataProvider && mDataProvider->name() == "gdal" )
229  {
230  mCreateOptionsWidget->setFormat( text );
231  mCreateOptionsWidget->update();
232  }
233 }
234 
236 {
237  return mColumnsLineEdit->text().toInt();
238 }
239 
241 {
242  return mRowsLineEdit->text().toInt();
243 }
244 
246 {
247  return mXResolutionLineEdit->text().toDouble();
248 }
249 
251 {
252  return mYResolutionLineEdit->text().toDouble();
253 }
254 
256 {
257  return mMaximumSizeXLineEdit->text().toInt();
258 }
259 
261 {
262  return mMaximumSizeYLineEdit->text().toInt();
263 }
264 
266 {
267  return mTileModeCheckBox->isChecked();
268 }
269 
271 {
272  return mAddToCanvas->isChecked();
273 }
274 
276 {
277  return mSaveAsLineEdit->text();
278 }
279 
281 {
282  return mFormatComboBox->currentText();
283 }
284 
286 {
287  return mCreateOptionsGroupBox->isChecked() ? mCreateOptionsWidget->options() : QStringList();
288 }
289 
291 {
292  return mExtentGroupBox->outputExtent();
293 }
294 
296 {
297  mFormatLabel->hide();
298  mFormatComboBox->hide();
299 }
300 
302 {
303  mSaveAsLabel->hide();
304  mSaveAsLineEdit->hide();
305  mBrowseButton->hide();
306  QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
307  if ( okButton )
308  {
309  okButton->setEnabled( true );
310  }
311 }
312 
313 void QgsRasterLayerSaveAsDialog::toggleResolutionSize()
314 {
315  bool hasResolution = mDataProvider && mDataProvider->capabilities() & QgsRasterDataProvider::Size;
316 
317  bool on = mResolutionRadioButton->isChecked();
318  mXResolutionLineEdit->setEnabled( on );
319  mYResolutionLineEdit->setEnabled( on );
320  mOriginalResolutionPushButton->setEnabled( on && hasResolution );
321  mColumnsLineEdit->setEnabled( !on );
322  mRowsLineEdit->setEnabled( !on );
323  mOriginalSizePushButton->setEnabled( !on && hasResolution );
324 }
325 
326 void QgsRasterLayerSaveAsDialog::setOriginalResolution()
327 {
328  double xRes, yRes;
329 
330  if ( mDataProvider->capabilities() & QgsRasterDataProvider::Size )
331  {
332  xRes = mDataProvider->extent().width() / mDataProvider->xSize();
333  yRes = mDataProvider->extent().height() / mDataProvider->ySize();
334  }
335  else
336  {
337  // Init to something if no original resolution is available
338  xRes = yRes = mDataProvider->extent().width() / 100;
339  }
340  setResolution( xRes, yRes, mLayerCrs );
341  mResolutionState = OriginalResolution;
342  recalcSize();
343 }
344 
345 void QgsRasterLayerSaveAsDialog::setResolution( double xRes, double yRes, const QgsCoordinateReferenceSystem& srcCrs )
346 {
347  if ( srcCrs != outputCrs() )
348  {
349  // We reproject pixel rectangle from center of selected extent, of course, it gives
350  // bigger xRes,yRes than reprojected edges (envelope), it may also be that
351  // close to margins are higher resolutions (even very, too high)
352  // TODO: consider more precise resolution calculation
353 
354  QgsPoint center = outputRectangle().center();
355  QgsCoordinateTransform ct( srcCrs, outputCrs() );
357 
358  QgsRectangle srcExtent( srsCenter.x() - xRes / 2, srsCenter.y() - yRes / 2, srsCenter.x() + xRes / 2, srsCenter.y() + yRes / 2 );
359 
360  QgsRectangle extent = ct.transform( srcExtent );
361  xRes = extent.width();
362  yRes = extent.height();
363  }
364  mXResolutionLineEdit->setText( QString::number( xRes ) );
365  mYResolutionLineEdit->setText( QString::number( yRes ) );
366 }
367 
368 void QgsRasterLayerSaveAsDialog::recalcSize()
369 {
370  QgsRectangle extent = outputRectangle();
371  int xSize = xResolution() != 0 ? static_cast<int>( qRound( extent.width() / xResolution() ) ) : 0;
372  int ySize = yResolution() != 0 ? static_cast<int>( qRound( extent.height() / yResolution() ) ) : 0;
373  mColumnsLineEdit->setText( QString::number( xSize ) );
374  mRowsLineEdit->setText( QString::number( ySize ) );
375  updateResolutionStateMsg();
376 }
377 
378 void QgsRasterLayerSaveAsDialog::setOriginalSize()
379 {
380  mColumnsLineEdit->setText( QString::number( mDataProvider->xSize() ) );
381  mRowsLineEdit->setText( QString::number( mDataProvider->ySize() ) );
382  recalcResolution();
383 }
384 
385 void QgsRasterLayerSaveAsDialog::recalcResolution()
386 {
387  QgsRectangle extent = outputRectangle();
388  double xRes = nColumns() != 0 ? extent.width() / nColumns() : 0;
389  double yRes = nRows() != 0 ? extent.height() / nRows() : 0;
390  mXResolutionLineEdit->setText( QString::number( xRes ) );
391  mYResolutionLineEdit->setText( QString::number( yRes ) );
392  updateResolutionStateMsg();
393 }
394 
395 void QgsRasterLayerSaveAsDialog::recalcResolutionSize()
396 {
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  Q_FOREACH ( const 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( nullptr ) );
549  if ( !qIsNaN( value ) )
550  {
551  valueString = QgsRasterBlock::printValue( value );
552  }
553  break;
554  default:
555  lineEdit->setValidator( new QIntValidator( nullptr ) );
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 ) + QLatin1String( "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  int rows = mNoDataTableWidget->rowCount();
717  noDataList.reserve( rows );
718  for ( int r = 0 ; r < rows; r++ )
719  {
720  QgsRasterRange noData( noDataCellValue( r, 0 ), noDataCellValue( r, 1 ) );
721  noDataList.append( noData );
722 
723  }
724  return noDataList;
725 }
726 
728 {
729  return mPyramidsGroupBox->isChecked() ? mPyramidsOptionsWidget->overviewList() : QList<int>();
730 }
731 
733 {
734  if ( ! mPyramidsGroupBox->isChecked() )
736  else if ( mPyramidsUseExistingCheckBox->isChecked() )
738  else
740 }
741 
742 bool QgsRasterLayerSaveAsDialog::validate() const
743 {
744  if ( mCreateOptionsGroupBox->isChecked() )
745  {
746  QString message = mCreateOptionsWidget->validateOptions( true, false );
747  if ( !message.isNull() )
748  return false;
749  }
750  if ( mPyramidsGroupBox->isChecked() )
751  {
752  QString message = mPyramidsOptionsWidget->createOptionsWidget()->validateOptions( true, false );
753  if ( !message.isNull() )
754  return false;
755  }
756  return true;
757 }
758 
QgsPoint transform(const QgsPoint &p, TransformDirection direction=ForwardTransform) const
Transform the point from Source Coordinate System to Destination Coordinate System If the direction i...
virtual int bandCount() const =0
Get number of bands.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
QgsPoint center() const
Center point of the rectangle.
Definition: qgsrectangle.h:217
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.
QgsRaster::RasterBuildPyramids buildPyramidsFlag() const
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.
virtual int ySize() const
Thirty two bit floating point (float)
Definition: qgis.h:141
Raster values range container.
QgsCoordinateReferenceSystem outputCrs()
QgsRasterRenderer * renderer() const
QString join(const QString &separator) const
QString homePath()
QString tr(const char *sourceText, const char *disambiguation, int n)
const QgsRasterTransparency * rasterTransparency() const
virtual QString name() const =0
Return a provider name.
double y() const
Get the y value of the point.
Definition: qgspoint.h:193
bool isNull() const
T value(int i) 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:142
void resize(int size)
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.
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
double width() const
Width of the rectangle.
Definition: qgsrectangle.h:207
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:117
iterator end()
QList< QgsRasterTransparency::TransparentSingleValuePixel > transparentSingleValuePixelList() const
Accessor for transparentSingleValuePixelList.
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)
QVariant value(const QString &key, const QVariant &defaultValue) const
void setFrame(bool)
QFontMetrics fontMetrics() const
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.
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.
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)
virtual int xSize() const
Get raster size.
QString baseName() const
iterator begin()
double x() const
Get the x value of the point.
Definition: qgspoint.h:185
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.