Skip to content

Commit

Permalink
[mesh] [feature] add opacity slider to mesh contours settings
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik authored and wonder-sk committed Aug 28, 2018
1 parent 304033c commit d7afb71
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 5 deletions.
Expand Up @@ -103,6 +103,15 @@ Returns max value used for creation of the color ramp shader
void setClassificationMinimumMaximum( double minimum, double maximum );
%Docstring
Sets min/max values used for creation of the color ramp shader
%End

double opacity() const;
%Docstring
Returns opacity
%End
void setOpacity( double opacity );
%Docstring
Sets opacity
%End

QDomElement writeXml( QDomDocument &doc ) const;
Expand Down
Expand Up @@ -62,7 +62,7 @@ Generates an new RGBA value based on one input ``value``.
:param returnRedValue: The red component of the new RGBA value
:param returnGreenValue: The green component of the new RGBA value
:param returnBlueValue: The blue component of the new RGBA value
:param returnAlpha: The blue component of the new RGBA value
:param returnAlpha: The alpha component of the new RGBA value

:return: True if the return values are valid otherwise false
%End
Expand Down
4 changes: 3 additions & 1 deletion src/app/mesh/qgsmeshrendererscalarsettingswidget.cpp
Expand Up @@ -33,7 +33,7 @@ QgsMeshRendererScalarSettingsWidget::QgsMeshRendererScalarSettingsWidget( QWidge
connect( mScalarMinLineEdit, &QLineEdit::textEdited, this, &QgsMeshRendererScalarSettingsWidget::minMaxEdited );
connect( mScalarMaxLineEdit, &QLineEdit::textEdited, this, &QgsMeshRendererScalarSettingsWidget::minMaxEdited );
connect( mScalarColorRampShaderWidget, &QgsColorRampShaderWidget::widgetChanged, this, &QgsMeshRendererScalarSettingsWidget::widgetChanged );

connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsMeshRendererScalarSettingsWidget::widgetChanged );
}

void QgsMeshRendererScalarSettingsWidget::setLayer( QgsMeshLayer *layer )
Expand All @@ -46,6 +46,7 @@ QgsMeshRendererScalarSettings QgsMeshRendererScalarSettingsWidget::settings() co
QgsMeshRendererScalarSettings settings;
settings.setColorRampShader( mScalarColorRampShaderWidget->shader() );
settings.setClassificationMinimumMaximum( lineEditValue( mScalarMinLineEdit ), lineEditValue( mScalarMaxLineEdit ) );
settings.setOpacity( mOpacityWidget->opacity() );
return settings;
}

Expand All @@ -63,6 +64,7 @@ void QgsMeshRendererScalarSettingsWidget::syncToLayer( )
whileBlocking( mScalarMinLineEdit )->setText( QString::number( settings.classificationMinimum() ) );
whileBlocking( mScalarMaxLineEdit )->setText( QString::number( settings.classificationMaximum() ) );
whileBlocking( mScalarColorRampShaderWidget )->setFromShader( shader );
whileBlocking( mOpacityWidget )->setOpacity( settings.opacity() );
}

double QgsMeshRendererScalarSettingsWidget::lineEditValue( const QLineEdit *lineEdit ) const
Expand Down
1 change: 1 addition & 0 deletions src/core/mesh/qgsmeshlayerrenderer.cpp
Expand Up @@ -222,6 +222,7 @@ void QgsMeshLayerRenderer::renderScalarDataset()
QgsSingleBandPseudoColorRenderer renderer( &interpolator, 0, sh ); // takes ownership of sh
renderer.setClassificationMin( scalarSettings.classificationMinimum() );
renderer.setClassificationMax( scalarSettings.classificationMaximum() );
renderer.setOpacity( scalarSettings.opacity() );

std::unique_ptr<QgsRasterBlock> bl( renderer.block( 0, mContext.extent(), mOutputSize.width(), mOutputSize.height(), mFeedback.get() ) );
QImage img = bl->image();
Expand Down
10 changes: 10 additions & 0 deletions src/core/mesh/qgsmeshrenderersettings.cpp
Expand Up @@ -78,17 +78,26 @@ void QgsMeshRendererScalarSettings::setColorRampShader( const QgsColorRampShader
mColorRampShader = shader;
}

double QgsMeshRendererScalarSettings::classificationMinimum() const { return mClassificationMinimum; }

double QgsMeshRendererScalarSettings::classificationMaximum() const { return mClassificationMaximum; }

void QgsMeshRendererScalarSettings::setClassificationMinimumMaximum( double minimum, double maximum )
{
mClassificationMinimum = minimum;
mClassificationMaximum = maximum;
}

double QgsMeshRendererScalarSettings::opacity() const { return mOpacity; }

void QgsMeshRendererScalarSettings::setOpacity( double opacity ) { mOpacity = opacity; }

QDomElement QgsMeshRendererScalarSettings::writeXml( QDomDocument &doc ) const
{
QDomElement elem = doc.createElement( "scalar-settings" );
elem.setAttribute( "min-val", mClassificationMinimum );
elem.setAttribute( "max-val", mClassificationMaximum );
elem.setAttribute( "opacity", mOpacity );
QDomElement elemShader = mColorRampShader.writeXml( doc );
elem.appendChild( elemShader );
return elem;
Expand All @@ -98,6 +107,7 @@ void QgsMeshRendererScalarSettings::readXml( const QDomElement &elem )
{
mClassificationMinimum = elem.attribute( "min-val" ).toDouble();
mClassificationMaximum = elem.attribute( "max-val" ).toDouble();
mOpacity = elem.attribute( "opacity" ).toDouble();
QDomElement elemShader = elem.firstChildElement( QStringLiteral( "colorrampshader" ) );
mColorRampShader.readXml( elemShader );
}
Expand Down
10 changes: 8 additions & 2 deletions src/core/mesh/qgsmeshrenderersettings.h
Expand Up @@ -83,12 +83,17 @@ class CORE_EXPORT QgsMeshRendererScalarSettings
void setColorRampShader( const QgsColorRampShader &shader );

//! Returns min value used for creation of the color ramp shader
double classificationMinimum() const { return mClassificationMinimum; }
double classificationMinimum() const;
//! Returns max value used for creation of the color ramp shader
double classificationMaximum() const { return mClassificationMaximum; }
double classificationMaximum() const;
//! Sets min/max values used for creation of the color ramp shader
void setClassificationMinimumMaximum( double minimum, double maximum );

//! Returns opacity
double opacity() const;
//! Sets opacity
void setOpacity( double opacity );

//! Writes configuration to a new DOM element
QDomElement writeXml( QDomDocument &doc ) const;
//! Reads configuration from the given DOM element
Expand All @@ -98,6 +103,7 @@ class CORE_EXPORT QgsMeshRendererScalarSettings
QgsColorRampShader mColorRampShader;
double mClassificationMinimum = 0;
double mClassificationMaximum = 0;
double mOpacity = 1;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgsrastershaderfunction.h
Expand Up @@ -71,7 +71,7 @@ class CORE_EXPORT QgsRasterShaderFunction
* \param returnRedValue The red component of the new RGBA value
* \param returnGreenValue The green component of the new RGBA value
* \param returnBlueValue The blue component of the new RGBA value
* \param returnAlpha The blue component of the new RGBA value
* \param returnAlpha The alpha component of the new RGBA value
* \return True if the return values are valid otherwise false
*/
virtual bool shade( double value,
Expand Down
24 changes: 24 additions & 0 deletions src/ui/mesh/qgsmeshrendererscalarsettingswidgetbase.ui
Expand Up @@ -14,6 +14,24 @@
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="mOpacityLabel">
<property name="text">
<string>Opacity</string>
</property>
</widget>
</item>
<item>
<widget class="QgsOpacityWidget" name="mOpacityWidget" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
Expand Down Expand Up @@ -66,6 +84,12 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsOpacityWidget</class>
<extends>QWidget</extends>
<header>qgsopacitywidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorRampShaderWidget</class>
<extends>QWidget</extends>
Expand Down

0 comments on commit d7afb71

Please sign in to comment.