Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 4f8c9e1
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 1,083 deletions.
34 changes: 27 additions & 7 deletions python/gui/auto_generated/raster/qgscolorrampshaderwidget.sip.in
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand Down
Expand Up @@ -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 *
* *
Expand Down
6 changes: 3 additions & 3 deletions src/app/mesh/qgsmeshrendererscalarsettingswidget.cpp
Expand Up @@ -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()
Expand All @@ -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 )
Expand Down
58 changes: 39 additions & 19 deletions src/gui/raster/qgscolorrampshaderwidget.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -265,7 +275,7 @@ void QgsColorRampShaderWidget::mAddEntryButton_clicked()
mColormapTreeWidget->sortItems( ValueColumn, Qt::AscendingOrder );
autoLabel();

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

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

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

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

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

loadMinMaxFromTree();
loadMinimumMaximumFromTree();

emit widgetChanged();
}
Expand Down Expand Up @@ -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 )
Expand All @@ -712,7 +732,7 @@ void QgsColorRampShaderWidget::loadMinMaxFromTree()
{
mMin = min;
mMax = max;
emit minMaxChangedFromTree( min, max );
emit minimumMaximumChangedFromTree( min, max );
}
}

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

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

loadMinMaxFromTree();
loadMinimumMaximumFromTree();
emit widgetChanged();
}
}
30 changes: 21 additions & 9 deletions src/gui/raster/qgscolorrampshaderwidget.h
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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
Expand All @@ -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();

Expand Down

0 comments on commit 4f8c9e1

Please sign in to comment.