|
29 | 29 | #include <QFileDialog>
|
30 | 30 | #include <QFontDatabase>
|
31 | 31 |
|
32 |
| -QgsRasterCalcDialog::QgsRasterCalcDialog( QWidget *parent, Qt::WindowFlags f ): QDialog( parent, f ) |
| 32 | +QgsRasterCalcDialog::QgsRasterCalcDialog( QgsRasterLayer *rasterLayer, QWidget *parent, Qt::WindowFlags f ): QDialog( parent, f ) |
33 | 33 | {
|
34 | 34 | setupUi( this );
|
35 | 35 | QgsGui::instance()->enableAutoGeometryRestore( this );
|
@@ -66,16 +66,16 @@ QgsRasterCalcDialog::QgsRasterCalcDialog( QWidget *parent, Qt::WindowFlags f ):
|
66 | 66 | connect( mOrButton, &QPushButton::clicked, this, &QgsRasterCalcDialog::mOrButton_clicked );
|
67 | 67 | connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsRasterCalcDialog::showHelp );
|
68 | 68 |
|
| 69 | + if ( rasterLayer && rasterLayer->dataProvider() && rasterLayer->dataProvider()->name() == QLatin1String( "gdal" ) ) |
| 70 | + { |
| 71 | + setExtentSize( rasterLayer->width(), rasterLayer->height(), rasterLayer->extent() ); |
| 72 | + mCrsSelector->setCrs( rasterLayer->crs() ); |
| 73 | + } |
| 74 | + |
69 | 75 | //add supported output formats
|
70 | 76 | insertAvailableOutputFormats();
|
71 | 77 | insertAvailableRasterBands();
|
72 | 78 |
|
73 |
| - if ( !mAvailableRasterBands.isEmpty() ) |
74 |
| - { |
75 |
| - //grab default crs from first raster |
76 |
| - mCrsSelector->setCrs( mAvailableRasterBands.at( 0 ).raster->crs() ); |
77 |
| - } |
78 |
| - |
79 | 79 | mExpressionTextEdit->setCurrentFont( QFontDatabase::systemFont( QFontDatabase::FixedFont ) );
|
80 | 80 | }
|
81 | 81 |
|
@@ -148,27 +148,31 @@ QVector<QgsRasterCalculatorEntry> QgsRasterCalcDialog::rasterEntries() const
|
148 | 148 | return entries;
|
149 | 149 | }
|
150 | 150 |
|
| 151 | +void QgsRasterCalcDialog::setExtentSize( int width, int height, QgsRectangle bbox ) |
| 152 | +{ |
| 153 | + mNColumnsSpinBox->setValue( width ); |
| 154 | + mNRowsSpinBox->setValue( height ); |
| 155 | + mXMinSpinBox->setValue( bbox.xMinimum() ); |
| 156 | + mXMaxSpinBox->setValue( bbox.xMaximum() ); |
| 157 | + mYMinSpinBox->setValue( bbox.yMinimum() ); |
| 158 | + mYMaxSpinBox->setValue( bbox.yMaximum() ); |
| 159 | + mExtentSizeSet = true; |
| 160 | +} |
| 161 | + |
151 | 162 | void QgsRasterCalcDialog::insertAvailableRasterBands()
|
152 | 163 | {
|
153 | 164 | const QMap<QString, QgsMapLayer *> &layers = QgsProject::instance()->mapLayers();
|
154 | 165 | QMap<QString, QgsMapLayer *>::const_iterator layerIt = layers.constBegin();
|
155 | 166 |
|
156 |
| - bool firstLayer = true; |
157 | 167 | for ( ; layerIt != layers.constEnd(); ++layerIt )
|
158 | 168 | {
|
159 | 169 | QgsRasterLayer *rlayer = dynamic_cast<QgsRasterLayer *>( layerIt.value() );
|
160 | 170 | if ( rlayer && rlayer->dataProvider() && rlayer->dataProvider()->name() == QLatin1String( "gdal" ) )
|
161 | 171 | {
|
162 |
| - if ( firstLayer ) //set bounding box / resolution of output to the values of the first possible input layer |
| 172 | + if ( !mExtentSizeSet ) //set bounding box / resolution of output to the values of the first possible input layer |
163 | 173 | {
|
164 |
| - mNColumnsSpinBox->setValue( rlayer->width() ); |
165 |
| - mNRowsSpinBox->setValue( rlayer->height() ); |
166 |
| - QgsRectangle bbox = rlayer->extent(); |
167 |
| - mXMinSpinBox->setValue( bbox.xMinimum() ); |
168 |
| - mXMaxSpinBox->setValue( bbox.xMaximum() ); |
169 |
| - mYMinSpinBox->setValue( bbox.yMinimum() ); |
170 |
| - mYMaxSpinBox->setValue( bbox.yMaximum() ); |
171 |
| - firstLayer = false; |
| 174 | + setExtentSize( rlayer->width(), rlayer->height(), rlayer->extent() ); |
| 175 | + mCrsSelector->setCrs( rlayer->crs() ); |
172 | 176 | }
|
173 | 177 | //get number of bands
|
174 | 178 | for ( int i = 0; i < rlayer->bandCount(); ++i )
|
|
0 commit comments