Skip to content
Permalink
Browse files

[mesh] [feature] add opacity slider to mesh contours settings

  • Loading branch information
PeterPetrik authored and wonder-sk committed Aug 27, 2018
1 parent 304033c commit d7afb710d72ad5a65262400030419beb5b48ea16
@@ -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;
@@ -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
@@ -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 )
@@ -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;
}

@@ -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
@@ -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();
@@ -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;
@@ -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 );
}
@@ -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
@@ -98,6 +103,7 @@ class CORE_EXPORT QgsMeshRendererScalarSettings
QgsColorRampShader mColorRampShader;
double mClassificationMinimum = 0;
double mClassificationMaximum = 0;
double mOpacity = 1;
};

/**
@@ -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,
@@ -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>
@@ -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>

0 comments on commit d7afb71

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