Skip to content
Permalink
Browse files

also use color ramp shader widget for pseudo color renderer (#7358)

  • Loading branch information
PeterPetrik authored and nirvn committed Jul 6, 2018
1 parent a261a66 commit 4f8c9e18ab0656234aff907f362e541bf6d85af2
@@ -32,24 +32,44 @@ The other mode is used to style mesh layer contours (scalar datasets)
Creates new color ramp shader widget
%End

void initForUseWithRasterLayer();
void initializeForUseWithRasterLayer();
%Docstring
Allows quantile classification mode for raster layers
%End

void setRasterBand( QgsRasterDataProvider *dp, int band, const QgsRectangle &extent );
void setRasterDataProvider( QgsRasterDataProvider *dp );
%Docstring
Associates raster with the widget
Associates raster with the widget, only when used for raster layer
%End

void setMinMaxAndClassify( double min, double max );
void setRasterBand( int band );
%Docstring
Sets raster band, only when used for raster layer
%End

void setExtent( const QgsRectangle &extent );
%Docstring
Sets extent, only when used for raster layer
%End

void setMinimumMaximumAndClassify( double minimum, double maximum );
%Docstring
Sets min max and classify color tree
%End

void setMinMax( double min, double max );
void setMinimumMaximum( double minimum, double maximum );
%Docstring
Sets min max
%End

double minimum() const;
%Docstring
Gets min value
%End

double maximum() const;
%Docstring
Gets max value
%End

QgsColorRampShader shader() const;
@@ -63,7 +83,7 @@ Sets widget state from the color ramp shader
%End

signals:
void minMaxChangedFromTree( double min, double max );
void minimumMaximumChangedFromTree( double minimum, double maximum );
%Docstring
Color ramp tree has changed
%End
@@ -85,7 +105,7 @@ Classification mode changed
Executes the single band pseudo raster classification
%End

void loadMinMaxFromTree();
void loadMinimumMaximumFromTree();
%Docstring
Loads min and max values from color ramp tree
%End
@@ -12,53 +12,58 @@

class QgsSingleBandPseudoColorRendererWidget: QgsRasterRendererWidget
{
%Docstring

Single band pseudo color renderer widget consists of a color ramp shader widget,
a raster min max widget and a band selector.
%End

%TypeHeaderCode
#include "qgssinglebandpseudocolorrendererwidget.h"
%End
public:

QgsSingleBandPseudoColorRendererWidget( QgsRasterLayer *layer, const QgsRectangle &extent = QgsRectangle() );
%Docstring
Creates new raster renderer widget
%End

static QgsRasterRendererWidget *create( QgsRasterLayer *layer, const QgsRectangle &extent ) /Factory/;
virtual QgsRasterRenderer *renderer();


QgsColorRampShader *shaderFunction() const /Factory/;
%Docstring
Returns shader function used in the renderer. Caller takes ownership and deletes it.
Creates new raster renderer widget
%End

virtual QgsRasterRenderer *renderer();

virtual void setMapCanvas( QgsMapCanvas *canvas );

virtual void doComputations();

virtual QgsRasterMinMaxWidget *minMaxWidget();


int currentBand() const;
%Docstring
Returns the current raster band number
%End

void setFromRenderer( const QgsRasterRenderer *r );

public slots:

void classify();
%Docstring
Executes the single band pseudo raster classficiation
Set state of the widget from renderer settings
%End

public slots:
void loadMinMax( int bandNo, double min, double max );
%Docstring
called when new min/max values are loaded
%End
void loadMinMaxFromTree();
void loadMinMaxFromTree( double min, double max );
%Docstring
called when the color ramp tree has changed
%End

};


/************************************************************************
* This file has been generated automatically from *
* *
@@ -79,14 +79,14 @@ void QgsMeshRendererScalarSettingsWidget::minMaxChanged()
{
double min = lineEditValue( mScalarMinLineEdit );
double max = lineEditValue( mScalarMaxLineEdit );
mScalarColorRampShaderWidget->setMinMax( min, max );
mScalarColorRampShaderWidget->setMinimumMaximum( min, max );
}

void QgsMeshRendererScalarSettingsWidget::minMaxEdited()
{
double min = lineEditValue( mScalarMinLineEdit );
double max = lineEditValue( mScalarMaxLineEdit );
mScalarColorRampShaderWidget->setMinMaxAndClassify( min, max );
mScalarColorRampShaderWidget->setMinimumMaximumAndClassify( min, max );
}

void QgsMeshRendererScalarSettingsWidget::recalculateMinMaxButtonClicked()
@@ -95,7 +95,7 @@ void QgsMeshRendererScalarSettingsWidget::recalculateMinMaxButtonClicked()
calcMinMax( mActiveDataset, min, max );
whileBlocking( mScalarMinLineEdit )->setText( QString::number( min ) );
whileBlocking( mScalarMaxLineEdit )->setText( QString::number( max ) );
mScalarColorRampShaderWidget->setMinMaxAndClassify( min, max );
mScalarColorRampShaderWidget->setMinimumMaximumAndClassify( min, max );
}

void QgsMeshRendererScalarSettingsWidget::setActiveDataset( int activeDataset )
@@ -90,22 +90,32 @@ QgsColorRampShaderWidget::QgsColorRampShaderWidget( QWidget *parent )
connect( mClassifyButton, &QPushButton::clicked, this, &QgsColorRampShaderWidget::applyColorRamp );
connect( btnColorRamp, &QgsColorRampButton::colorRampChanged, this, &QgsColorRampShaderWidget::applyColorRamp );
connect( mNumberOfEntriesSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsColorRampShaderWidget::classify );
connect( mClipCheckBox, &QAbstractButton::toggled, this, &QgsColorRampShaderWidget::widgetChanged );
}

void QgsColorRampShaderWidget::initForUseWithRasterLayer()
void QgsColorRampShaderWidget::initializeForUseWithRasterLayer()
{
Q_ASSERT( mClassificationModeComboBox->findData( QgsColorRampShader::Quantile < 0 ) );
mClassificationModeComboBox->addItem( tr( "Quantile" ), QgsColorRampShader::Quantile );
mLoadFromBandButton->setVisible( bool( mRasterDataProvider ) ); // only for raster version
}

void QgsColorRampShaderWidget::setRasterBand( QgsRasterDataProvider *dp,
int band,
const QgsRectangle &extent )
void QgsColorRampShaderWidget::setRasterDataProvider( QgsRasterDataProvider *dp )
{
mRasterDataProvider = dp;
loadMinimumMaximumFromTree();
}

void QgsColorRampShaderWidget::setRasterBand( int band )
{
mBand = band;
loadMinimumMaximumFromTree();
}

void QgsColorRampShaderWidget::setExtent( const QgsRectangle &extent )
{
mExtent = extent;
loadMinimumMaximumFromTree();
}

QgsColorRampShader QgsColorRampShaderWidget::shader() const
@@ -265,7 +275,7 @@ void QgsColorRampShaderWidget::mAddEntryButton_clicked()
mColormapTreeWidget->sortItems( ValueColumn, Qt::AscendingOrder );
autoLabel();

loadMinMaxFromTree();
loadMinimumMaximumFromTree();
emit widgetChanged();
}

@@ -283,7 +293,7 @@ void QgsColorRampShaderWidget::mDeleteEntryButton_clicked()
delete item;
}

loadMinMaxFromTree();
loadMinimumMaximumFromTree();
emit widgetChanged();
}

@@ -400,7 +410,7 @@ void QgsColorRampShaderWidget::mLoadFromBandButton_clicked()
QMessageBox::warning( this, tr( "Load Color Map" ), tr( "The color map for band %1 has no entries." ).arg( mBand ) );
}

loadMinMaxFromTree();
loadMinimumMaximumFromTree();
emit widgetChanged();
}

@@ -492,7 +502,7 @@ void QgsColorRampShaderWidget::mLoadFromFileButton_clicked()
QMessageBox::warning( this, tr( "Load Color Map from File" ), tr( "Read access denied. Adjust the file permissions and try again.\n\n" ) );
}

loadMinMaxFromTree();
loadMinimumMaximumFromTree();
emit widgetChanged();
}

@@ -577,7 +587,7 @@ void QgsColorRampShaderWidget::mColormapTreeWidget_itemDoubleClicked( QTreeWidge
if ( newColor.isValid() )
{
item->setBackground( ColorColumn, QBrush( newColor ) );
loadMinMaxFromTree();
loadMinimumMaximumFromTree();
emit widgetChanged();
}
}
@@ -601,7 +611,7 @@ void QgsColorRampShaderWidget::mColormapTreeWidget_itemEdited( QTreeWidgetItem *
mColormapTreeWidget->sortItems( ValueColumn, Qt::AscendingOrder );
autoLabel();

loadMinMaxFromTree();
loadMinimumMaximumFromTree();

emit widgetChanged();
}
@@ -678,25 +688,35 @@ void QgsColorRampShaderWidget::mColorInterpolationComboBox_currentIndexChanged(
emit widgetChanged();
}

void QgsColorRampShaderWidget::setMinMaxAndClassify( double min, double max )
void QgsColorRampShaderWidget::setMinimumMaximumAndClassify( double min, double max )
{
if ( !qgsDoubleNear( mMin, min ) || !qgsDoubleNear( mMax, max ) )
{
mMin = min;
mMax = max;

setMinimumMaximum( min, max );
classify();
}
}

void QgsColorRampShaderWidget::setMinMax( double min, double max )
void QgsColorRampShaderWidget::setMinimumMaximum( double min, double max )
{
mMin = min;
mMax = max;
resetClassifyButton();
}

void QgsColorRampShaderWidget::loadMinMaxFromTree()
double QgsColorRampShaderWidget::minimum() const
{
return mMin;
}

double QgsColorRampShaderWidget::maximum() const
{
return mMax;
}



void QgsColorRampShaderWidget::loadMinimumMaximumFromTree()
{
QTreeWidgetItem *item = mColormapTreeWidget->topLevelItem( 0 );
if ( !item )
@@ -712,7 +732,7 @@ void QgsColorRampShaderWidget::loadMinMaxFromTree()
{
mMin = min;
mMax = max;
emit minMaxChangedFromTree( min, max );
emit minimumMaximumChangedFromTree( min, max );
}
}

@@ -744,7 +764,7 @@ void QgsColorRampShaderWidget::changeColor()
item->setBackground( ColorColumn, QBrush( newColor ) );
}

loadMinMaxFromTree();
loadMinimumMaximumFromTree();
emit widgetChanged();
}
}
@@ -772,7 +792,7 @@ void QgsColorRampShaderWidget::changeOpacity()
item->setBackground( ColorColumn, QBrush( newColor ) );
}

loadMinMaxFromTree();
loadMinimumMaximumFromTree();
emit widgetChanged();
}
}
@@ -49,16 +49,28 @@ class GUI_EXPORT QgsColorRampShaderWidget: public QWidget, protected Ui::QgsColo
QgsColorRampShaderWidget( QWidget *parent = nullptr );

//! Allows quantile classification mode for raster layers
void initForUseWithRasterLayer();
void initializeForUseWithRasterLayer();

//! Associates raster with the widget
void setRasterBand( QgsRasterDataProvider *dp, int band, const QgsRectangle &extent );
//! Associates raster with the widget, only when used for raster layer
void setRasterDataProvider( QgsRasterDataProvider *dp );

//! Sets raster band, only when used for raster layer
void setRasterBand( int band );

//! Sets extent, only when used for raster layer
void setExtent( const QgsRectangle &extent );

//! Sets min max and classify color tree
void setMinMaxAndClassify( double min, double max );
void setMinimumMaximumAndClassify( double minimum, double maximum );

//! Sets min max
void setMinMax( double min, double max );
void setMinimumMaximum( double minimum, double maximum );

//! Gets min value
double minimum() const;

//! Gets max value
double maximum() const;

//! Returns shared function used in the renderer
QgsColorRampShader shader() const;
@@ -68,7 +80,7 @@ class GUI_EXPORT QgsColorRampShaderWidget: public QWidget, protected Ui::QgsColo

signals:
//! Color ramp tree has changed
void minMaxChangedFromTree( double min, double max );
void minimumMaximumChangedFromTree( double minimum, double maximum );

//! Widget changed
void widgetChanged();
@@ -84,7 +96,7 @@ class GUI_EXPORT QgsColorRampShaderWidget: public QWidget, protected Ui::QgsColo
void classify();

//! Loads min and max values from color ramp tree
void loadMinMaxFromTree();
void loadMinimumMaximumFromTree();

protected:
//! Populates color ramp tree from ramp items
@@ -101,8 +113,8 @@ class GUI_EXPORT QgsColorRampShaderWidget: public QWidget, protected Ui::QgsColo

/**
* Generate labels from the values in the color map.
* Skip labels which were manually edited (black text).
* Text of generated labels is made gray
* Skip labels which were manually edited (black text).
* Text of generated labels is made gray
*/
void autoLabel();

0 comments on commit 4f8c9e1

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