27#include "moc_qgspointcloudattributebyramprendererwidget.cpp"
31QgsPointCloudAttributeByRampRendererWidget::QgsPointCloudAttributeByRampRendererWidget(
QgsPointCloudLayer *layer,
QgsStyle *style )
36 mAttributeComboBox->setAllowEmptyAttributeName(
false );
39 mMinSpin->setShowClearButton(
false );
40 mMaxSpin->setShowClearButton(
false );
44 mAttributeComboBox->setLayer( layer );
46 setFromRenderer( layer->
renderer() );
50 connect( mMinSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsPointCloudAttributeByRampRendererWidget::minMaxChanged );
51 connect( mMaxSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsPointCloudAttributeByRampRendererWidget::minMaxChanged );
54 connect( mScalarRecalculateMinMaxButton, &QPushButton::clicked,
this, &QgsPointCloudAttributeByRampRendererWidget::setMinMaxFromLayer );
59 return new QgsPointCloudAttributeByRampRendererWidget( layer, style );
69 auto renderer = std::make_unique<QgsPointCloudAttributeByRampRenderer>();
70 renderer->setAttribute( mAttributeComboBox->currentAttribute() );
72 renderer->setMinimum( mMinSpin->value() );
73 renderer->setMaximum( mMaxSpin->value() );
75 renderer->setColorRampShader( mScalarColorRampShaderWidget->shader() );
77 return renderer.release();
80void QgsPointCloudAttributeByRampRendererWidget::emitWidgetChanged()
82 if ( !mBlockChangedSignal )
86void QgsPointCloudAttributeByRampRendererWidget::minMaxChanged()
88 if ( mBlockMinMaxChanged )
91 mScalarColorRampShaderWidget->setMinimumMaximumAndClassify( mMinSpin->value(), mMaxSpin->value() );
94void QgsPointCloudAttributeByRampRendererWidget::attributeChanged()
96 if ( mLayer && mLayer->dataProvider() )
99 const double min = stats.
minimum( mAttributeComboBox->currentAttribute() );
100 const double max = stats.
maximum( mAttributeComboBox->currentAttribute() );
101 if ( !std::isnan( min ) && !std::isnan( max ) )
108 mProviderMin = std::numeric_limits<double>::quiet_NaN();
109 mProviderMax = std::numeric_limits<double>::quiet_NaN();
112 if ( mAttributeComboBox->currentAttribute().compare( QLatin1String(
"z" ), Qt::CaseInsensitive ) == 0 )
116 mProviderMin = mProviderMin * zScale + zOffset;
117 mProviderMax = mProviderMax * zScale + zOffset;
120 if ( !mBlockSetMinMaxFromLayer )
121 setMinMaxFromLayer();
123 mScalarRecalculateMinMaxButton->setEnabled( !std::isnan( mProviderMin ) && !std::isnan( mProviderMax ) );
127void QgsPointCloudAttributeByRampRendererWidget::setMinMaxFromLayer()
129 if ( std::isnan( mProviderMin ) || std::isnan( mProviderMax ) )
132 mBlockMinMaxChanged =
true;
133 mMinSpin->setValue( mProviderMin );
134 mMaxSpin->setValue( mProviderMax );
135 mBlockMinMaxChanged =
false;
142 mBlockChangedSignal =
true;
147 mBlockSetMinMaxFromLayer =
true;
149 mAttributeComboBox->setAttribute( mbcr->
attribute() );
151 mMinSpin->setValue( mbcr->
minimum() );
152 mMaxSpin->setValue( mbcr->
maximum() );
159 if ( mAttributeComboBox->findText( QStringLiteral(
"Intensity" ) ) > -1 )
161 mAttributeComboBox->setAttribute( QStringLiteral(
"Intensity" ) );
165 mAttributeComboBox->setCurrentIndex( mAttributeComboBox->count() > 1 ? 1 : 0 );
169 mBlockChangedSignal =
false;
170 mBlockSetMinMaxFromLayer =
false;
double zScale() const
Returns the z scale, which is a scaling factor which should be applied to z values from the layer.
double zOffset() const
Returns the z offset, which is a fixed offset amount which should be added to z values from the layer...
An RGB renderer for 2d visualisation of point clouds using embedded red, green and blue attributes.
double maximum() const
Returns the maximum value for attributes which will be used by the color ramp shader.
QgsColorRampShader colorRampShader() const
Returns the color ramp shader function used to visualize the attribute.
double minimum() const
Returns the minimum value for attributes which will be used by the color ramp shader.
QString attribute() const
Returns the attribute to use for the renderer.
void attributeChanged(const QString &name)
Emitted when the currently selected attribute changes.
@ AllTypes
All attribute types.
Point cloud layer specific subclass of QgsMapLayerElevationProperties.
Represents a map layer supporting display of point clouds.
QgsPointCloudRenderer * renderer()
Returns the 2D renderer for the point cloud.
Abstract base class for 2d point cloud renderers.
Used to store statistics of a point cloud dataset.
double maximum(const QString &attribute) const
Returns the maximum value for the attribute attribute If no matching statistic is available then NaN ...
double minimum(const QString &attribute) const
Returns the minimum value for the attribute attribute If no matching statistic is available then NaN ...
A database of saved style entities, including symbols, color ramps, text formats and others.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.