Skip to content
Permalink
Browse files

[raster calc] use active layer to setup dialog to harmonize

the behavior with that of processing
  • Loading branch information
nirvn committed Feb 8, 2018
1 parent 50a103f commit a29d6d27d2353373488e3aebabb5b687e01f9b7c
Showing with 29 additions and 20 deletions.
  1. +1 −1 src/app/qgisapp.cpp
  2. +21 −17 src/app/qgsrastercalcdialog.cpp
  3. +7 −2 src/app/qgsrastercalcdialog.h
@@ -5320,7 +5320,7 @@ void QgisApp::newGeoPackageLayer()

void QgisApp::showRasterCalculator()
{
QgsRasterCalcDialog d( this );
QgsRasterCalcDialog d( dynamic_cast<QgsRasterLayer *>( activeLayer() ), this );
if ( d.exec() == QDialog::Accepted )
{
//invoke analysis library
@@ -29,7 +29,7 @@
#include <QFileDialog>
#include <QFontDatabase>

QgsRasterCalcDialog::QgsRasterCalcDialog( QWidget *parent, Qt::WindowFlags f ): QDialog( parent, f )
QgsRasterCalcDialog::QgsRasterCalcDialog( QgsRasterLayer *rasterLayer, QWidget *parent, Qt::WindowFlags f ): QDialog( parent, f )
{
setupUi( this );
QgsGui::instance()->enableAutoGeometryRestore( this );
@@ -66,16 +66,16 @@ QgsRasterCalcDialog::QgsRasterCalcDialog( QWidget *parent, Qt::WindowFlags f ):
connect( mOrButton, &QPushButton::clicked, this, &QgsRasterCalcDialog::mOrButton_clicked );
connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsRasterCalcDialog::showHelp );

if ( rasterLayer && rasterLayer->dataProvider() && rasterLayer->dataProvider()->name() == QLatin1String( "gdal" ) )
{
setExtentSize( rasterLayer->width(), rasterLayer->height(), rasterLayer->extent() );
mCrsSelector->setCrs( rasterLayer->crs() );
}

//add supported output formats
insertAvailableOutputFormats();
insertAvailableRasterBands();

if ( !mAvailableRasterBands.isEmpty() )
{
//grab default crs from first raster
mCrsSelector->setCrs( mAvailableRasterBands.at( 0 ).raster->crs() );
}

mExpressionTextEdit->setCurrentFont( QFontDatabase::systemFont( QFontDatabase::FixedFont ) );
}

@@ -148,27 +148,31 @@ QVector<QgsRasterCalculatorEntry> QgsRasterCalcDialog::rasterEntries() const
return entries;
}

void QgsRasterCalcDialog::setExtentSize( int width, int height, QgsRectangle bbox )
{
mNColumnsSpinBox->setValue( width );
mNRowsSpinBox->setValue( height );
mXMinSpinBox->setValue( bbox.xMinimum() );
mXMaxSpinBox->setValue( bbox.xMaximum() );
mYMinSpinBox->setValue( bbox.yMinimum() );
mYMaxSpinBox->setValue( bbox.yMaximum() );
mExtentSizeSet = true;
}

void QgsRasterCalcDialog::insertAvailableRasterBands()
{
const QMap<QString, QgsMapLayer *> &layers = QgsProject::instance()->mapLayers();
QMap<QString, QgsMapLayer *>::const_iterator layerIt = layers.constBegin();

bool firstLayer = true;
for ( ; layerIt != layers.constEnd(); ++layerIt )
{
QgsRasterLayer *rlayer = dynamic_cast<QgsRasterLayer *>( layerIt.value() );
if ( rlayer && rlayer->dataProvider() && rlayer->dataProvider()->name() == QLatin1String( "gdal" ) )
{
if ( firstLayer ) //set bounding box / resolution of output to the values of the first possible input layer
if ( !mExtentSizeSet ) //set bounding box / resolution of output to the values of the first possible input layer
{
mNColumnsSpinBox->setValue( rlayer->width() );
mNRowsSpinBox->setValue( rlayer->height() );
QgsRectangle bbox = rlayer->extent();
mXMinSpinBox->setValue( bbox.xMinimum() );
mXMaxSpinBox->setValue( bbox.xMaximum() );
mYMinSpinBox->setValue( bbox.yMinimum() );
mYMaxSpinBox->setValue( bbox.yMaximum() );
firstLayer = false;
setExtentSize( rlayer->width(), rlayer->height(), rlayer->extent() );
mCrsSelector->setCrs( rlayer->crs() );
}
//get number of bands
for ( int i = 0; i < rlayer->bandCount(); ++i )
@@ -28,7 +28,7 @@ class APP_EXPORT QgsRasterCalcDialog: public QDialog, private Ui::QgsRasterCalcD
{
Q_OBJECT
public:
QgsRasterCalcDialog( QWidget *parent = nullptr, Qt::WindowFlags f = nullptr );
QgsRasterCalcDialog( QgsRasterLayer *rasterLayer = nullptr, QWidget *parent = nullptr, Qt::WindowFlags f = nullptr );

QString formulaString() const;
QString outputFile() const;
@@ -83,7 +83,10 @@ class APP_EXPORT QgsRasterCalcDialog: public QDialog, private Ui::QgsRasterCalcD
void mOrButton_clicked();

private:
//insert available GDAL drivers that support the create() option
//! Sets the extent and size of the output
void setExtentSize( int width, int height, QgsRectangle bbox );

// Insert available GDAL drivers that support the create() option
void insertAvailableOutputFormats();
//! Accesses the available raster layers/bands from the layer registry
void insertAvailableRasterBands();
@@ -99,6 +102,8 @@ class APP_EXPORT QgsRasterCalcDialog: public QDialog, private Ui::QgsRasterCalcD
QMap<QString, QString> mDriverExtensionMap;

QList<QgsRasterCalculatorEntry> mAvailableRasterBands;

bool mExtentSizeSet = false;
};

#endif // QGSRASTERCALCDIALOG_H

0 comments on commit a29d6d2

Please sign in to comment.
You can’t perform that action at this time.