26 #include <QFileDialog> 27 #include <QMessageBox> 35 , mRasterLayer( rasterLayer )
36 , mDataProvider( sourceProvider )
37 , mCurrentExtent( currentExtent )
38 , mLayerCrs( layerCrs )
39 , mCurrentCrs( currentCrs )
40 , mResolutionState( OriginalResolution )
48 mNoDataTableWidget->setColumnCount( 2 );
49 mNoDataTableWidget->setHorizontalHeaderItem( 0,
new QTableWidgetItem(
tr(
"From" ) ) );
52 on_mRawModeRadioButton_toggled(
true );
56 toggleResolutionSize();
61 Q_FOREACH (
const QString& myFormat, myFormats )
63 mFormatComboBox->addItem( myFormat );
71 setOriginalResolution();
72 int xSize = mDataProvider->
xSize();
73 int ySize = mDataProvider->
ySize();
79 mTileModeCheckBox->setChecked(
true );
85 mCreateOptionsWidget->setProvider( mDataProvider->
name() );
86 if ( mDataProvider->
name() ==
"gdal" )
88 mCreateOptionsWidget->setFormat( myFormats[0] );
90 mCreateOptionsWidget->setRasterLayer( mRasterLayer );
91 mCreateOptionsWidget->update();
99 mPyramidsOptionsWidget->createOptionsWidget()->setRasterLayer( mRasterLayer );
104 mPyramidsUseExistingCheckBox->setEnabled(
false );
105 mPyramidsUseExistingCheckBox->setVisible(
false );
107 populatePyramidsLevels();
108 connect( mPyramidsOptionsWidget, SIGNAL( overviewListChanged() ),
109 this, SLOT( populatePyramidsLevels() ) );
113 mPyramidsGroupBox->setEnabled(
false );
118 mCreateOptionsGroupBox->setSaveCheckedState(
true );
123 mTilesGroupBox->hide();
125 mCrsSelector->setLayerCrs( mLayerCrs );
127 mCrsSelector->setCrs( mLayerCrs );
130 this, SLOT( crsChanged() ) );
132 QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
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() ) );
144 recalcResolutionSize();
147 void QgsRasterLayerSaveAsDialog::setValidators()
153 mMaximumSizeXLineEdit->setValidator(
new QIntValidator(
this ) );
154 mMaximumSizeYLineEdit->setValidator(
new QIntValidator(
this ) );
161 void QgsRasterLayerSaveAsDialog::on_mBrowseButton_clicked()
168 if ( mTileModeCheckBox->isChecked() )
180 QDir dir( fileName );
189 tr(
"The directory %1 contains files which will be overwritten: %2" ).arg( dir.
absolutePath(), files.
join(
", " ) ),
190 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Ok )
201 if ( !fileName.
isEmpty() && !fileName.
endsWith(
".tif", Qt::CaseInsensitive ) && !fileName.
endsWith(
".tiff", Qt::CaseInsensitive ) )
209 mSaveAsLineEdit->setText( fileName );
213 void QgsRasterLayerSaveAsDialog::on_mSaveAsLineEdit_textChanged(
const QString& text )
215 QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
225 void QgsRasterLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged(
const QString & text )
228 if ( mDataProvider && mDataProvider->
name() ==
"gdal" )
230 mCreateOptionsWidget->setFormat( text );
231 mCreateOptionsWidget->update();
237 return mColumnsLineEdit->text().toInt();
242 return mRowsLineEdit->text().toInt();
247 return mXResolutionLineEdit->text().toDouble();
252 return mYResolutionLineEdit->text().toDouble();
257 return mMaximumSizeXLineEdit->text().toInt();
262 return mMaximumSizeYLineEdit->text().toInt();
267 return mTileModeCheckBox->isChecked();
272 return mAddToCanvas->isChecked();
277 return mSaveAsLineEdit->text();
282 return mFormatComboBox->currentText();
287 return mCreateOptionsGroupBox->isChecked() ? mCreateOptionsWidget->options() :
QStringList();
292 return mExtentGroupBox->outputExtent();
297 mFormatLabel->hide();
298 mFormatComboBox->hide();
303 mSaveAsLabel->hide();
304 mSaveAsLineEdit->hide();
305 mBrowseButton->hide();
306 QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
313 void QgsRasterLayerSaveAsDialog::toggleResolutionSize()
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 );
326 void QgsRasterLayerSaveAsDialog::setOriginalResolution()
338 xRes = yRes = mDataProvider->
extent().
width() / 100;
340 setResolution( xRes, yRes, mLayerCrs );
358 QgsRectangle srcExtent( srsCenter.
x() - xRes / 2, srsCenter.
y() - yRes / 2, srsCenter.
x() + xRes / 2, srsCenter.
y() + yRes / 2 );
361 xRes = extent.width();
362 yRes = extent.height();
368 void QgsRasterLayerSaveAsDialog::recalcSize()
375 updateResolutionStateMsg();
378 void QgsRasterLayerSaveAsDialog::setOriginalSize()
385 void QgsRasterLayerSaveAsDialog::recalcResolution()
392 updateResolutionStateMsg();
395 void QgsRasterLayerSaveAsDialog::recalcResolutionSize()
397 if ( mResolutionRadioButton->isChecked() )
408 void QgsRasterLayerSaveAsDialog::updateResolutionStateMsg()
411 switch ( mResolutionState )
417 msg =
tr(
"user defined" );
422 msg =
tr(
"Resolution (current: %1)" ).
arg( msg );
423 mResolutionGroupBox->setTitle( msg );
426 void QgsRasterLayerSaveAsDialog::extentChanged()
429 if ( mSizeRadioButton->isChecked() )
433 recalcResolutionSize();
436 void QgsRasterLayerSaveAsDialog::crsChanged()
440 mExtentGroupBox->setOutputCrs(
outputCrs() );
448 mExtentGroupBox->setOutputExtentFromOriginal();
452 mExtentGroupBox->setOutputExtentFromCurrent();
456 mExtentGroupBox->setOutputExtentFromUser( mExtentGroupBox->outputExtent(), mPreviousCrs );
460 if ( mResolutionRadioButton->isChecked() )
464 setOriginalResolution();
483 return mCrsSelector->crs();
492 void QgsRasterLayerSaveAsDialog::on_mRawModeRadioButton_toggled(
bool checked )
494 mNoDataGroupBox->setEnabled( checked && mDataProvider->
bandCount() == 1 );
497 void QgsRasterLayerSaveAsDialog::on_mAddNoDataManuallyToolButton_clicked()
499 addNoDataRow( std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN() );
502 void QgsRasterLayerSaveAsDialog::on_mLoadTransparentNoDataToolButton_clicked()
504 if ( !mRasterLayer->
renderer() )
return;
506 if ( !rasterTransparency )
return;
512 addNoDataRow( transparencyPixel.
min, transparencyPixel.
max );
513 if ( transparencyPixel.
min != transparencyPixel.
max )
515 setNoDataToEdited( mNoDataTableWidget->rowCount() - 1 );
521 void QgsRasterLayerSaveAsDialog::on_mRemoveSelectedNoDataToolButton_clicked()
523 mNoDataTableWidget->removeRow( mNoDataTableWidget->currentRow() );
526 void QgsRasterLayerSaveAsDialog::on_mRemoveAllNoDataToolButton_clicked()
528 while ( mNoDataTableWidget->rowCount() > 0 )
530 mNoDataTableWidget->removeRow( 0 );
534 void QgsRasterLayerSaveAsDialog::addNoDataRow(
double min,
double max )
536 mNoDataTableWidget->insertRow( mNoDataTableWidget->rowCount() );
537 for (
int i = 0; i < 2; i++ )
539 double value = i == 0 ?
min :
max;
549 if ( !qIsNaN( value ) )
556 if ( !qIsNaN( value ) )
562 lineEdit->
setText( valueString );
563 mNoDataTableWidget->setCellWidget( mNoDataTableWidget->rowCount() - 1, i, lineEdit );
565 adjustNoDataCellWidth( mNoDataTableWidget->rowCount() - 1, i );
567 connect( lineEdit, SIGNAL( textEdited(
const QString & ) ),
this, SLOT( noDataCellTextEdited(
const QString & ) ) );
569 mNoDataTableWidget->resizeColumnsToContents();
570 mNoDataTableWidget->resizeRowsToContents();
573 void QgsRasterLayerSaveAsDialog::noDataCellTextEdited(
const QString & text )
578 if ( !lineEdit )
return;
581 for (
int r = 0 ; r < mNoDataTableWidget->rowCount(); r++ )
583 for (
int c = 0 ; c < mNoDataTableWidget->columnCount(); c++ )
585 if ( mNoDataTableWidget->cellWidget( r, c ) ==
sender() )
592 if ( row != -1 )
break;
598 QLineEdit *toLineEdit =
dynamic_cast<QLineEdit *
>( mNoDataTableWidget->cellWidget( row, 1 ) );
599 if ( !toLineEdit )
return;
600 bool toChanged = mNoDataToEdited.
value( row );
607 else if ( column == 1 )
609 setNoDataToEdited( row );
613 void QgsRasterLayerSaveAsDialog::on_mTileModeCheckBox_toggled(
bool toggled )
632 mTilesGroupBox->show();
636 mTilesGroupBox->hide();
640 void QgsRasterLayerSaveAsDialog::on_mPyramidsGroupBox_toggled(
bool toggled )
643 populatePyramidsLevels();
646 void QgsRasterLayerSaveAsDialog::populatePyramidsLevels()
650 if ( mPyramidsGroupBox->isChecked() )
655 if ( mPyramidsUseExistingCheckBox->isChecked() )
661 if ( ! mPyramidsOptionsWidget->overviewList().isEmpty() )
662 myPyramidList = mDataProvider->
buildPyramidList( mPyramidsOptionsWidget->overviewList() );
665 for ( myRasterPyramidIterator = myPyramidList.
begin();
666 myRasterPyramidIterator != myPyramidList.
end();
667 ++myRasterPyramidIterator )
669 if ( ! mPyramidsUseExistingCheckBox->isChecked() || myRasterPyramidIterator->exists )
677 mPyramidResolutionsLineEdit->setText( text.
trimmed() );
680 void QgsRasterLayerSaveAsDialog::setNoDataToEdited(
int row )
682 if ( row >= mNoDataToEdited.
size() )
684 mNoDataToEdited.
resize( row + 1 );
686 mNoDataToEdited[row] =
true;
689 double QgsRasterLayerSaveAsDialog::noDataCellValue(
int row,
int column )
const 691 QLineEdit *lineEdit =
dynamic_cast<QLineEdit *
>( mNoDataTableWidget->cellWidget( row, column ) );
692 if ( !lineEdit || lineEdit->
text().isEmpty() )
694 std::numeric_limits<double>::quiet_NaN();
696 return lineEdit->
text().toDouble();
699 void QgsRasterLayerSaveAsDialog::adjustNoDataCellWidth(
int row,
int column )
701 QLineEdit *lineEdit =
dynamic_cast<QLineEdit *
>( mNoDataTableWidget->cellWidget( row, column ) );
702 if ( !lineEdit )
return;
705 width = qMax( width, mNoDataTableWidget->columnWidth( column ) );
713 if ( ! mNoDataGroupBox->isChecked() )
716 int rows = mNoDataTableWidget->rowCount();
718 for (
int r = 0 ; r < rows; r++ )
721 noDataList.
append( noData );
729 return mPyramidsGroupBox->isChecked() ? mPyramidsOptionsWidget->overviewList() :
QList<int>();
734 if ( ! mPyramidsGroupBox->isChecked() )
736 else if ( mPyramidsUseExistingCheckBox->isChecked() )
742 bool QgsRasterLayerSaveAsDialog::validate()
const 744 if ( mCreateOptionsGroupBox->isChecked() )
746 QString message = mCreateOptionsWidget->validateOptions(
true,
false );
750 if ( mPyramidsGroupBox->isChecked() )
752 QString message = mPyramidsOptionsWidget->createOptionsWidget()->validateOptions(
true,
false );
QList< int > pyramidsList() const
virtual int bandCount() const =0
Get number of bands.
A rectangle specified with double values.
QgsPoint center() const
Center point of the rectangle.
QString getExistingDirectory(QWidget *parent, const QString &caption, const QString &dir, QFlags< QFileDialog::Option > options)
static QString printValue(double value)
Print double value with all necessary significant digits.
QgsRaster::RasterBuildPyramids buildPyramidsFlag() const
void setText(const QString &)
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.
virtual int ySize() const
double yResolution() const
Thirty two bit floating point (float)
Raster values range container.
QgsCoordinateReferenceSystem outputCrs()
QgsRasterRenderer * renderer() const
QString join(const QString &separator) const
QString outputFileName() const
int maximumTileSizeY() const
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.
QgsRectangle outputRectangle() const
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
QString number(int n, int base)
void append(const T &value)
Sixty four bit floating point (double)
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.
QStringList createOptions() const
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
double percentTransparent
double width() const
Width of the rectangle.
~QgsRasterLayerSaveAsDialog()
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
double xResolution() const
A class to represent a point.
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 ¤tExtent, const QgsCoordinateReferenceSystem &layerCrs, const QgsCoordinateReferenceSystem ¤tCrs, QWidget *parent=nullptr, const Qt::WindowFlags &f=nullptr)
int maximumTileSizeX() const
QVariant value(const QString &key, const QVariant &defaultValue) 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)
QString outputFormat() const
StandardButton warning(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
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)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
void setValidator(const QValidator *v)
virtual int xSize() const
Get raster size.
QgsRasterRangeList noData() const
double x() const
Get the x value of the point.
double height() const
Height of the rectangle.
void setContentsMargins(int left, int top, int right, int bottom)
Base class for raster data providers.