Skip to content
Permalink
Browse files
Fix raster load min/max from extent in style dock (fix #15171)
  • Loading branch information
nyalldawson committed Jun 30, 2016
1 parent b49ada2 commit 19564672c20db414d5dcfa7294e67c12c7db1844
@@ -10,6 +10,7 @@ class QgsMultiBandColorRendererWidget: QgsRasterRendererWidget
~QgsMultiBandColorRendererWidget();

QgsRasterRenderer* renderer();
void setMapCanvas( QgsMapCanvas* canvas );

void setFromRenderer( const QgsRasterRenderer* r );

@@ -7,7 +7,28 @@ class QgsRasterMinMaxWidget: QWidget
QgsRasterMinMaxWidget( QgsRasterLayer* theLayer, QWidget *parent /TransferThis/ = 0 );
~QgsRasterMinMaxWidget();

void setExtent( const QgsRectangle & theExtent );
/** Sets the extent to use for minimum and maximum value calculation.
* @param theExtent extent in raster layer's CRS
* @note if a map canvas is set using setMapCanvas(), its extent will take
* precedence over any extent set using this method.
*/
void setExtent( const QgsRectangle& theExtent );

/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
* map extent from the canvas. If a canvas is set it will take precedence over any extent
* set from calling setExtent().
* @param canvas map canvas
* @see mapCanvas()
* @note added in QGIS 2.16
*/
void setMapCanvas( QgsMapCanvas* canvas );

/** Returns the map canvas associated with the widget.
* @see setMapCanvas()
* @see canvasExtent()
* @note added in QGIS 2.16
*/
QgsMapCanvas* mapCanvas();

void setBands( const QList<int> & theBands );
/** Return the extent selected by the user.
@@ -20,6 +20,21 @@ class QgsRasterRendererWidget: QWidget
void setRasterLayer( QgsRasterLayer* layer );
const QgsRasterLayer* rasterLayer() const;

/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
* map extent and other properties from the canvas.
* @param canvas map canvas
* @see mapCanvas()
* @note added in QGIS 2.16
*/
virtual void setMapCanvas( QgsMapCanvas* canvas );

/** Returns the map canvas associated with the widget.
* @see setMapCanvas()
* @see canvasExtent()
* @note added in QGIS 2.16
*/
QgsMapCanvas* mapCanvas();

virtual QString min( int index = 0 );
virtual QString max( int index = 0 );
virtual void setMin( const QString& value, int index = 0 );
@@ -10,6 +10,7 @@ class QgsSingleBandGrayRendererWidget: QgsRasterRendererWidget
static QgsRasterRendererWidget* create( QgsRasterLayer* layer, const QgsRectangle &theExtent ) /Factory/;

QgsRasterRenderer* renderer();
void setMapCanvas( QgsMapCanvas* canvas );

void setFromRenderer( const QgsRasterRenderer* r );

@@ -17,6 +17,7 @@ class QgsSingleBandPseudoColorRendererWidget : QgsRasterRendererWidget

static QgsRasterRendererWidget* create( QgsRasterLayer* layer, const QgsRectangle &theExtent ) /Factory/;
QgsRasterRenderer* renderer();
void setMapCanvas( QgsMapCanvas* canvas );

void setFromRenderer( const QgsRasterRenderer* r );

@@ -44,4 +45,4 @@ class QgsTreeWidgetItem: QObject, QTreeWidgetItem
signals:
/** This signal is emitted when the contents of the column in the specified item has been edited by the user. */
void itemEdited( QTreeWidgetItem* item, int column );
};
};
@@ -549,6 +549,7 @@ void QgsRasterLayerProperties::setRendererWidget( const QString& rendererName )
// Current canvas extent (used to calc min/max) in layer CRS
QgsRectangle myExtent = mMapCanvas->mapSettings().outputExtentToLayerExtent( mRasterLayer, mMapCanvas->extent() );
mRendererWidget = rendererEntry.widgetCreateFunction( mRasterLayer, myExtent );
mRendererWidget->setMapCanvas( mMapCanvas );
mRendererStackedWidget->addWidget( mRendererWidget );
if ( oldWidget )
{
@@ -29,9 +29,11 @@

QgsRasterRendererRegistryEntry::QgsRasterRendererRegistryEntry( const QString& theName, const QString& theVisibleName,
QgsRasterRendererCreateFunc rendererFunction,
QgsRasterRendererWidgetCreateFunc widgetFunction ):
name( theName ), visibleName( theVisibleName ), rendererCreateFunction( rendererFunction ),
widgetCreateFunction( widgetFunction )
QgsRasterRendererWidgetCreateFunc widgetFunction )
: name( theName )
, visibleName( theVisibleName )
, rendererCreateFunction( rendererFunction )
, widgetCreateFunction( widgetFunction )
{
}

@@ -36,6 +36,7 @@ QgsMultiBandColorRendererWidget::QgsMultiBandColorRendererWidget( QgsRasterLayer

mMinMaxWidget = new QgsRasterMinMaxWidget( layer, this );
mMinMaxWidget->setExtent( extent );
mMinMaxWidget->setMapCanvas( mCanvas );
layout()->addWidget( mMinMaxWidget );
connect( mMinMaxWidget, SIGNAL( load( int, double, double, int ) ),
this, SLOT( loadMinMax( int, double, double, int ) ) );
@@ -105,6 +106,12 @@ QgsRasterRenderer* QgsMultiBandColorRendererWidget::renderer()
return r;
}

void QgsMultiBandColorRendererWidget::setMapCanvas( QgsMapCanvas* canvas )
{
QgsRasterRendererWidget::setMapCanvas( canvas );
mMinMaxWidget->setMapCanvas( canvas );
}

void QgsMultiBandColorRendererWidget::createValidators()
{
mRedMinLineEdit->setValidator( new QDoubleValidator( mRedMinLineEdit ) );
@@ -38,6 +38,7 @@ class GUI_EXPORT QgsMultiBandColorRendererWidget: public QgsRasterRendererWidget
~QgsMultiBandColorRendererWidget();

QgsRasterRenderer* renderer() override;
void setMapCanvas( QgsMapCanvas* canvas ) override;

void setFromRenderer( const QgsRasterRenderer* r );

@@ -20,10 +20,12 @@

#include "qgsrasterlayer.h"
#include "qgsrasterminmaxwidget.h"
#include "qgsmapcanvas.h"

QgsRasterMinMaxWidget::QgsRasterMinMaxWidget( QgsRasterLayer* theLayer, QWidget *parent ):
QWidget( parent )
QgsRasterMinMaxWidget::QgsRasterMinMaxWidget( QgsRasterLayer* theLayer, QWidget *parent )
: QWidget( parent )
, mLayer( theLayer )
, mCanvas( nullptr )
{
QgsDebugMsg( "Entered." );
setupUi( this );
@@ -50,6 +52,29 @@ QgsRasterMinMaxWidget::~QgsRasterMinMaxWidget()
{
}

void QgsRasterMinMaxWidget::setMapCanvas( QgsMapCanvas* canvas )
{
mCanvas = canvas;
}

QgsMapCanvas* QgsRasterMinMaxWidget::mapCanvas()
{
return mCanvas;
}

QgsRectangle QgsRasterMinMaxWidget::extent()
{
if ( !mCurrentExtentRadioButton->isChecked() )
return QgsRectangle();

if ( mLayer && mCanvas )
return mCanvas->mapSettings().outputExtentToLayerExtent( mLayer, mCanvas->extent() );
else if ( mCanvas )
return mCanvas->extent();
else
return QgsRectangle();
}

void QgsRasterMinMaxWidget::on_mLoadPushButton_clicked()
{
QgsDebugMsg( "Entered." );
@@ -22,19 +22,45 @@
#include "qgsrasterlayer.h"
#include "qgsrectangle.h"

class QgsMapCanvas;

class GUI_EXPORT QgsRasterMinMaxWidget: public QWidget, private Ui::QgsRasterMinMaxWidgetBase
{
Q_OBJECT
public:
QgsRasterMinMaxWidget( QgsRasterLayer* theLayer, QWidget *parent = nullptr );
~QgsRasterMinMaxWidget();

/** Sets the extent to use for minimum and maximum value calculation.
* @param theExtent extent in raster layer's CRS
* @note if a map canvas is set using setMapCanvas(), its extent will take
* precedence over any extent set using this method.
*/
void setExtent( const QgsRectangle & theExtent ) { mExtent = theExtent; }

/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
* map extent from the canvas. If a canvas is set it will take precedence over any extent
* set from calling setExtent().
* @param canvas map canvas
* @see mapCanvas()
* @note added in QGIS 2.16
*/
void setMapCanvas( QgsMapCanvas* canvas );

/** Returns the map canvas associated with the widget.
* @see setMapCanvas()
* @see canvasExtent()
* @note added in QGIS 2.16
*/
QgsMapCanvas* mapCanvas();

void setBands( const QList<int> & theBands ) { mBands = theBands; }

/** Return the extent selected by the user.
Either an empty extent for 'full' or the current visible extent. */
QgsRectangle extent() { return mCurrentExtentRadioButton->isChecked() ? mExtent : QgsRectangle(); }
* Either an empty extent for 'full' or the current visible extent.
*/
QgsRectangle extent();

/** Return the selected sample size. */
int sampleSize() { return mEstimateRadioButton->isChecked() ? 250000 : 0; }

@@ -51,6 +77,9 @@ class GUI_EXPORT QgsRasterMinMaxWidget: public QWidget, private Ui::QgsRasterMin
QgsRasterLayer* mLayer;
QList<int> mBands;
QgsRectangle mExtent;

QgsMapCanvas* mCanvas;
QgsRasterLayer* mRasterLayer;
};

#endif // QGSRASTERMINMAXWIDGET_H
@@ -18,7 +18,17 @@
#include "qgsrasterrendererwidget.h"
#include "qgsrasterdataprovider.h"
#include "qgsrasterlayer.h"
#include "qgsmapcanvas.h"

void QgsRasterRendererWidget::setMapCanvas( QgsMapCanvas* canvas )
{
mCanvas = canvas;
}

QgsMapCanvas* QgsRasterRendererWidget::mapCanvas()
{
return mCanvas;
}

QString QgsRasterRendererWidget::displayBandName( int band ) const
{
@@ -24,15 +24,19 @@

class QgsRasterLayer;
class QgsRasterRenderer;
class QgsMapCanvas;

class GUI_EXPORT QgsRasterRendererWidget: public QWidget
{
Q_OBJECT

public:
QgsRasterRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent ):
mRasterLayer( layer )

//TODO QGIS 3.0 - remove extent parameter, replace with map canvas parameter
QgsRasterRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent )
: mRasterLayer( layer )
, mExtent( extent )
, mCanvas( nullptr )
{}

virtual ~QgsRasterRendererWidget() {}
@@ -50,6 +54,21 @@ class GUI_EXPORT QgsRasterRendererWidget: public QWidget
void setRasterLayer( QgsRasterLayer* layer ) { mRasterLayer = layer; }
const QgsRasterLayer* rasterLayer() const { return mRasterLayer; }

/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
* map extent and other properties from the canvas.
* @param canvas map canvas
* @see mapCanvas()
* @note added in QGIS 2.16
*/
virtual void setMapCanvas( QgsMapCanvas* canvas );

/** Returns the map canvas associated with the widget.
* @see setMapCanvas()
* @see canvasExtent()
* @note added in QGIS 2.16
*/
QgsMapCanvas* mapCanvas();

virtual QString min( int index = 0 ) { Q_UNUSED( index ); return QString(); }
virtual QString max( int index = 0 ) { Q_UNUSED( index ); return QString(); }
virtual void setMin( const QString& value, int index = 0 ) { Q_UNUSED( index ); Q_UNUSED( value ); }
@@ -73,6 +92,9 @@ class GUI_EXPORT QgsRasterRendererWidget: public QWidget

/** Current extent */
QgsRectangle mExtent;

//! Associated map canvas
QgsMapCanvas* mCanvas;
};

#endif // QGSRASTERRENDERERWIDGET_H
@@ -324,6 +324,7 @@ void QgsRendererRasterPropertiesWidget::setRendererWidget( const QString &render
// Current canvas extent (used to calc min/max) in layer CRS
QgsRectangle myExtent = mMapCanvas->mapSettings().outputExtentToLayerExtent( mRasterLayer, mMapCanvas->extent() );
mRendererWidget = rendererEntry.widgetCreateFunction( mRasterLayer, myExtent );
mRendererWidget->setMapCanvas( mMapCanvas );
connect( mRendererWidget, SIGNAL( widgetChanged() ), this, SIGNAL( widgetChanged() ) );
stackedWidget->addWidget( mRendererWidget );
stackedWidget->setCurrentWidget( mRendererWidget );
@@ -41,6 +41,7 @@ QgsSingleBandGrayRendererWidget::QgsSingleBandGrayRendererWidget( QgsRasterLayer

mMinMaxWidget = new QgsRasterMinMaxWidget( layer, this );
mMinMaxWidget->setExtent( extent );
mMinMaxWidget->setMapCanvas( mCanvas );

QHBoxLayout *layout = new QHBoxLayout();
layout->setContentsMargins( 0, 0, 0, 0 );
@@ -105,6 +106,12 @@ QgsRasterRenderer* QgsSingleBandGrayRendererWidget::renderer()
return renderer;
}

void QgsSingleBandGrayRendererWidget::setMapCanvas( QgsMapCanvas* canvas )
{
QgsRasterRendererWidget::setMapCanvas( canvas );
mMinMaxWidget->setMapCanvas( canvas );
}

void QgsSingleBandGrayRendererWidget::loadMinMax( int theBandNo, double theMin, double theMax, int theOrigin )
{
Q_UNUSED( theBandNo );
@@ -33,6 +33,7 @@ class GUI_EXPORT QgsSingleBandGrayRendererWidget: public QgsRasterRendererWidget
static QgsRasterRendererWidget* create( QgsRasterLayer* layer, const QgsRectangle &theExtent ) { return new QgsSingleBandGrayRendererWidget( layer, theExtent ); }

QgsRasterRenderer* renderer() override;
void setMapCanvas( QgsMapCanvas* canvas ) override;

void setFromRenderer( const QgsRasterRenderer* r );

@@ -100,6 +100,8 @@ QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget(

mMinMaxWidget = new QgsRasterMinMaxWidget( layer, this );
mMinMaxWidget->setExtent( extent );
mMinMaxWidget->setMapCanvas( mCanvas );

QHBoxLayout *layout = new QHBoxLayout();
layout->setContentsMargins( 0, 0, 0, 0 );
mMinMaxContainerWidget->setLayout( layout );
@@ -191,6 +193,12 @@ QgsRasterRenderer* QgsSingleBandPseudoColorRendererWidget::renderer()
return renderer;
}

void QgsSingleBandPseudoColorRendererWidget::setMapCanvas( QgsMapCanvas* canvas )
{
QgsRasterRendererWidget::setMapCanvas( canvas );
mMinMaxWidget->setMapCanvas( canvas );
}

/** Generate labels from the values in the color map.
* Skip labels which were manually edited (black text).
* Text of generated labels is made gray
@@ -40,6 +40,7 @@ class GUI_EXPORT QgsSingleBandPseudoColorRendererWidget: public QgsRasterRendere

static QgsRasterRendererWidget* create( QgsRasterLayer* layer, const QgsRectangle &theExtent ) { return new QgsSingleBandPseudoColorRendererWidget( layer, theExtent ); }
QgsRasterRenderer* renderer() override;
void setMapCanvas( QgsMapCanvas* canvas ) override;

void setFromRenderer( const QgsRasterRenderer* r );

1 comment on commit 1956467

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn commented on 1956467 Jun 30, 2016

@nyalldawson , yay!

Please sign in to comment.