19#include "moc_qgspointcloudattributebyramprendererwidget.cpp"
29QgsPointCloudAttributeByRampRendererWidget::QgsPointCloudAttributeByRampRendererWidget(
QgsPointCloudLayer *layer,
QgsStyle *style )
34 mAttributeComboBox->setAllowEmptyAttributeName(
false );
37 mMinSpin->setShowClearButton(
false );
38 mMaxSpin->setShowClearButton(
false );
42 mAttributeComboBox->setLayer( layer );
44 setFromRenderer( layer->
renderer() );
48 this, &QgsPointCloudAttributeByRampRendererWidget::attributeChanged );
49 connect( mMinSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsPointCloudAttributeByRampRendererWidget::minMaxChanged );
50 connect( mMaxSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsPointCloudAttributeByRampRendererWidget::minMaxChanged );
53 connect( mScalarRecalculateMinMaxButton, &QPushButton::clicked,
this, &QgsPointCloudAttributeByRampRendererWidget::setMinMaxFromLayer );
58 return new QgsPointCloudAttributeByRampRendererWidget( layer, style );
68 std::unique_ptr< QgsPointCloudAttributeByRampRenderer > renderer = std::make_unique< QgsPointCloudAttributeByRampRenderer >();
69 renderer->setAttribute( mAttributeComboBox->currentAttribute() );
71 renderer->setMinimum( mMinSpin->value() );
72 renderer->setMaximum( mMaxSpin->value() );
74 renderer->setColorRampShader( mScalarColorRampShaderWidget->shader() );
76 return renderer.release();
79void QgsPointCloudAttributeByRampRendererWidget::emitWidgetChanged()
81 if ( !mBlockChangedSignal )
85void QgsPointCloudAttributeByRampRendererWidget::minMaxChanged()
87 if ( mBlockMinMaxChanged )
90 mScalarColorRampShaderWidget->setMinimumMaximumAndClassify( mMinSpin->value(), mMaxSpin->value() );
93void QgsPointCloudAttributeByRampRendererWidget::attributeChanged()
95 if ( mLayer && mLayer->dataProvider() )
98 const double min = stats.
minimum( mAttributeComboBox->currentAttribute() );
99 const double max = stats.
maximum( mAttributeComboBox->currentAttribute() );
100 if ( !std::isnan( min ) && !std::isnan( max ) )
107 mProviderMin = std::numeric_limits< double >::quiet_NaN();
108 mProviderMax = std::numeric_limits< double >::quiet_NaN();
111 if ( mAttributeComboBox->currentAttribute().compare( QLatin1String(
"z" ), Qt::CaseInsensitive ) == 0 )
115 mProviderMin = mProviderMin * zScale + zOffset;
116 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;
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;
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 setAttribute(const QString &attribute)
Sets 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.
Class 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 ...
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.