24 #include <QFileDialog>
25 #include <QMessageBox>
31 QWidget* parent, Qt::WindowFlags f ) :
33 , mRasterLayer( rasterLayer ), mDataProvider( sourceProvider )
34 , mCurrentExtent( currentExtent ), mLayerCrs( layerCrs )
35 , mCurrentCrs( currentCrs ), mExtentState( OriginalExtent )
36 , mResolutionState( OriginalResolution )
44 mNoDataTableWidget->setColumnCount( 2 );
45 mNoDataTableWidget->setHorizontalHeaderItem( 0,
new QTableWidgetItem(
tr(
"From" ) ) );
46 mNoDataTableWidget->setHorizontalHeaderItem( 1,
new QTableWidgetItem(
tr(
"To" ) ) );
53 mCrsComboBox->addItem(
"Project",
CurrentCrs );
54 mCrsComboBox->addItem(
"Selected",
UserCrs );
60 QStringList myFormats;
62 foreach ( QString myFormat, myFormats )
64 mFormatComboBox->addItem( myFormat );
78 mMaximumSizeXLineEdit->setText( QString::number( xSize ) );
79 mMaximumSizeYLineEdit->setText( QString::number( ySize ) );
83 mTileModeCheckBox->setChecked(
true );
84 mMaximumSizeXLineEdit->setText( QString::number( 2000 ) );
85 mMaximumSizeYLineEdit->setText( QString::number( 2000 ) );
92 mCreateOptionsWidget->setFormat( myFormats[0] );
95 mCreateOptionsWidget->update();
103 mPyramidsOptionsWidget->createOptionsWidget()->setRasterLayer(
mRasterLayer );
108 mPyramidsUseExistingCheckBox->setEnabled(
false );
109 mPyramidsUseExistingCheckBox->setVisible(
false );
112 connect( mPyramidsOptionsWidget, SIGNAL( overviewListChanged() ),
117 mPyramidsGroupBox->setEnabled(
false );
122 mCreateOptionsGroupBox->setSaveCheckedState(
true );
127 mTilesGroupBox->hide();
131 QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
134 okButton->setEnabled(
false );
140 mXResolutionLineEdit->setValidator(
new QDoubleValidator(
this ) );
141 mYResolutionLineEdit->setValidator(
new QDoubleValidator(
this ) );
142 mColumnsLineEdit->setValidator(
new QIntValidator(
this ) );
143 mRowsLineEdit->setValidator(
new QIntValidator(
this ) );
144 mMaximumSizeXLineEdit->setValidator(
new QIntValidator(
this ) );
145 mMaximumSizeYLineEdit->setValidator(
new QIntValidator(
this ) );
146 mXMinLineEdit->setValidator(
new QDoubleValidator(
this ) );
147 mXMaxLineEdit->setValidator(
new QDoubleValidator(
this ) );
148 mYMinLineEdit->setValidator(
new QDoubleValidator(
this ) );
149 mYMaxLineEdit->setValidator(
new QDoubleValidator(
this ) );
159 if ( mTileModeCheckBox->isChecked() )
164 fileName = QFileDialog::getExistingDirectory(
this,
tr(
"Select output directory" ) );
167 if ( fileName.isEmpty() )
break;
170 QDir dir( fileName );
171 QString baseName = QFileInfo( fileName ).baseName();
173 filters << QString(
"%1.*" ).arg( baseName );
174 QStringList files = dir.entryList( filters );
175 if ( !files.isEmpty() )
177 QMessageBox::StandardButton button = QMessageBox::warning(
this,
tr(
"Warning" ),
178 tr(
"The directory %1 contains files which will be overwritten: %2" ).arg( dir.absolutePath() ).arg( files.join(
", " ) ),
179 QMessageBox::Ok | QMessageBox::Cancel );
181 if ( button == QMessageBox::Ok )
198 fileName = QFileDialog::getSaveFileName(
this,
tr(
"Select output file" ), QString(),
tr(
"GeoTIFF" ) +
" (*.tif *.tiff *.TIF *.TIFF)" );
201 if ( !fileName.isEmpty() )
203 mSaveAsLineEdit->setText( fileName );
209 QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
215 okButton->setEnabled( QFileInfo( text ).absoluteDir().exists() );
236 mCreateOptionsWidget->setFormat( text );
237 mCreateOptionsWidget->update();
243 return mColumnsLineEdit->text().toInt();
248 return mRowsLineEdit->text().toInt();
253 return mXResolutionLineEdit->text().toDouble();
258 return mYResolutionLineEdit->text().toDouble();
263 return mMaximumSizeXLineEdit->text().toInt();
268 return mMaximumSizeYLineEdit->text().toInt();
273 return mTileModeCheckBox->isChecked();
278 return mSaveAsLineEdit->text();
283 return mFormatComboBox->currentText();
288 return mCreateOptionsGroupBox->isChecked() ? mCreateOptionsWidget->options() : QStringList();
293 return QgsRectangle( mXMinLineEdit->text().toDouble(), mYMinLineEdit->text().toDouble(), mXMaxLineEdit->text().toDouble(), mYMaxLineEdit->text().toDouble() );
320 mFormatLabel->hide();
321 mFormatComboBox->hide();
326 mSaveAsLabel->hide();
327 mSaveAsLineEdit->hide();
328 mBrowseButton->hide();
329 QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
332 okButton->setEnabled(
true );
340 bool on = mResolutionRadioButton->isChecked();
341 mXResolutionLineEdit->setEnabled( on );
342 mYResolutionLineEdit->setEnabled( on );
343 mOriginalResolutionPushButton->setEnabled( on && hasResolution );
344 mColumnsLineEdit->setEnabled( !on );
345 mRowsLineEdit->setEnabled( !on );
346 mOriginalSizePushButton->setEnabled( !on && hasResolution );
381 QgsRectangle srcExtent( srsCenter.
x() - xRes / 2, srsCenter.
y() - yRes / 2, srsCenter.
x() + xRes / 2, srsCenter.
y() + yRes / 2 );
384 xRes = extent.width();
385 yRes = extent.height();
387 mXResolutionLineEdit->setText( QString::number( xRes ) );
388 mYResolutionLineEdit->setText( QString::number( yRes ) );
397 mColumnsLineEdit->setText( QString::number( xSize ) );
398 mRowsLineEdit->setText( QString::number( ySize ) );
415 mXResolutionLineEdit->setText( QString::number( xRes ) );
416 mYResolutionLineEdit->setText( QString::number( yRes ) );
423 if ( mResolutionRadioButton->isChecked() )
443 msg =
tr(
"user defined" );
448 msg =
tr(
"Resolution (current: %1)" ).arg( msg );
449 mResolutionGroupBox->setTitle( msg );
456 if ( mSizeRadioButton->isChecked() )
472 msg =
tr(
"map view" );
475 msg =
tr(
"user defined" );
480 msg =
tr(
"Extent (current: %1)" ).arg( msg );
481 mExtentGroupBox->setTitle( msg );
489 if ( selector->exec() )
492 mCrsComboBox->setCurrentIndex( mCrsComboBox->findData(
UserCrs ) );
526 if ( mResolutionRadioButton->isChecked() )
552 mCrsComboBox->setItemText( mCrsComboBox->findData(
OriginalCrs ),
555 mCrsComboBox->setItemText( mCrsComboBox->findData(
CurrentCrs ),
558 mCrsComboBox->setItemText( mCrsComboBox->findData(
UserCrs ),
564 int state = mCrsComboBox->itemData( mCrsComboBox->currentIndex() ).toInt();
589 addNoDataRow( std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN() );
596 if ( !rasterTransparency )
return;
603 if ( transparencyPixel.
min != transparencyPixel.
max )
613 mNoDataTableWidget->removeRow( mNoDataTableWidget->currentRow() );
618 while ( mNoDataTableWidget->rowCount() > 0 )
620 mNoDataTableWidget->removeRow( 0 );
626 mNoDataTableWidget->insertRow( mNoDataTableWidget->rowCount() );
627 for (
int i = 0; i < 2; i++ )
629 double value = i == 0 ? min :
max;
630 QLineEdit *lineEdit =
new QLineEdit();
631 lineEdit->setFrame(
false );
632 lineEdit->setContentsMargins( 1, 1, 1, 1 );
638 lineEdit->setValidator(
new QDoubleValidator( 0 ) );
639 if ( !qIsNaN( value ) )
645 lineEdit->setValidator(
new QIntValidator( 0 ) );
646 if ( !qIsNaN( value ) )
648 valueString = QString::number( static_cast<int>( value ) );
652 lineEdit->setText( valueString );
653 mNoDataTableWidget->setCellWidget( mNoDataTableWidget->rowCount() - 1, i, lineEdit );
657 connect( lineEdit, SIGNAL( textEdited(
const QString & ) ),
this, SLOT(
noDataCellTextEdited(
const QString & ) ) );
659 mNoDataTableWidget->resizeColumnsToContents();
660 mNoDataTableWidget->resizeRowsToContents();
667 QLineEdit *lineEdit =
dynamic_cast<QLineEdit *
>( sender() );
668 if ( !lineEdit )
return;
671 for (
int r = 0 ; r < mNoDataTableWidget->rowCount(); r++ )
673 for (
int c = 0 ; c < mNoDataTableWidget->columnCount(); c++ )
675 if ( mNoDataTableWidget->cellWidget( r, c ) == sender() )
682 if ( row != -1 )
break;
684 QgsDebugMsg( QString(
"row = %1 column =%2" ).arg( row ).arg( column ) );
688 QLineEdit *toLineEdit =
dynamic_cast<QLineEdit *
>( mNoDataTableWidget->cellWidget( row, 1 ) );
689 if ( !toLineEdit )
return;
691 QgsDebugMsg( QString(
"toChanged = %1" ).arg( toChanged ) );
694 toLineEdit->setText( lineEdit->text() );
697 else if ( column == 1 )
722 mTilesGroupBox->show();
726 mTilesGroupBox->hide();
740 if ( mPyramidsGroupBox->isChecked() )
742 QList<QgsRasterPyramid> myPyramidList;
745 if ( mPyramidsUseExistingCheckBox->isChecked() )
751 if ( ! mPyramidsOptionsWidget->overviewList().isEmpty() )
754 QList<QgsRasterPyramid>::iterator myRasterPyramidIterator;
755 for ( myRasterPyramidIterator = myPyramidList.begin();
756 myRasterPyramidIterator != myPyramidList.end();
757 ++myRasterPyramidIterator )
759 if ( ! mPyramidsUseExistingCheckBox->isChecked() || myRasterPyramidIterator->exists )
761 text += QString::number( myRasterPyramidIterator->xDim ) + QString(
"x" ) +
762 QString::number( myRasterPyramidIterator->yDim ) +
" ";
767 mPyramidResolutionsLineEdit->setText( text.trimmed() );
781 QLineEdit *lineEdit =
dynamic_cast<QLineEdit *
>( mNoDataTableWidget->cellWidget( row, column ) );
782 if ( !lineEdit || lineEdit->text().isEmpty() )
784 std::numeric_limits<double>::quiet_NaN();
786 return lineEdit->text().toDouble();
791 QLineEdit *lineEdit =
dynamic_cast<QLineEdit *
>( mNoDataTableWidget->cellWidget( row, column ) );
792 if ( !lineEdit )
return;
794 int width = qMax( lineEdit->fontMetrics().width( lineEdit->text() ) + 10, 100 );
795 width = qMax( width, mNoDataTableWidget->columnWidth( column ) );
797 lineEdit->setFixedWidth( width );
803 if ( ! mNoDataGroupBox->isChecked() )
806 for (
int r = 0 ; r < mNoDataTableWidget->rowCount(); r++ )
809 noDataList.append( noData );
817 return mPyramidsGroupBox->isChecked() ? mPyramidsOptionsWidget->overviewList() : QList<int>();
822 if ( ! mPyramidsGroupBox->isChecked() )
824 else if ( mPyramidsUseExistingCheckBox->isChecked() )
832 if ( mCreateOptionsGroupBox->isChecked() )
834 QString message = mCreateOptionsWidget->validateOptions(
true,
false );
835 if ( !message.isNull() )
838 if ( mPyramidsGroupBox->isChecked() )
840 QString message = mPyramidsOptionsWidget->createOptionsWidget()->validateOptions(
true,
false );
841 if ( !message.isNull() )