29#include "moc_qgspointcloudattributebyramprendererwidget.cpp"
31using namespace Qt::StringLiterals;
35QgsPointCloudAttributeByRampRendererWidget::QgsPointCloudAttributeByRampRendererWidget(
QgsPointCloudLayer *layer,
QgsStyle *style )
40 mAttributeComboBox->setAllowEmptyAttributeName(
false );
43 mMinSpin->setShowClearButton(
false );
44 mMaxSpin->setShowClearButton(
false );
48 mAttributeComboBox->setLayer( layer );
50 setFromRenderer( layer->
renderer() );
54 connect( mMinSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsPointCloudAttributeByRampRendererWidget::minMaxChanged );
55 connect( mMaxSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsPointCloudAttributeByRampRendererWidget::minMaxChanged );
58 connect( mScalarRecalculateMinMaxButton, &QPushButton::clicked,
this, &QgsPointCloudAttributeByRampRendererWidget::setMinMaxFromLayer );
63 return new QgsPointCloudAttributeByRampRendererWidget( layer, style );
73 auto renderer = std::make_unique<QgsPointCloudAttributeByRampRenderer>();
74 renderer->setAttribute( mAttributeComboBox->currentAttribute() );
76 renderer->setMinimum( mMinSpin->value() );
77 renderer->setMaximum( mMaxSpin->value() );
79 renderer->setColorRampShader( mScalarColorRampShaderWidget->shader() );
81 return renderer.release();
84void QgsPointCloudAttributeByRampRendererWidget::emitWidgetChanged()
86 if ( !mBlockChangedSignal )
90void QgsPointCloudAttributeByRampRendererWidget::minMaxChanged()
92 if ( mBlockMinMaxChanged )
95 mScalarColorRampShaderWidget->setMinimumMaximumAndClassify( mMinSpin->value(), mMaxSpin->value() );
98void QgsPointCloudAttributeByRampRendererWidget::attributeChanged()
100 if ( mLayer && mLayer->dataProvider() )
103 const double min = stats.
minimum( mAttributeComboBox->currentAttribute() );
104 const double max = stats.
maximum( mAttributeComboBox->currentAttribute() );
105 if ( !std::isnan( min ) && !std::isnan( max ) )
112 mProviderMin = std::numeric_limits<double>::quiet_NaN();
113 mProviderMax = std::numeric_limits<double>::quiet_NaN();
116 if ( mAttributeComboBox->currentAttribute().compare(
'z'_L1, Qt::CaseInsensitive ) == 0 )
120 mProviderMin = mProviderMin * zScale + zOffset;
121 mProviderMax = mProviderMax * zScale + zOffset;
124 if ( !mBlockSetMinMaxFromLayer )
125 setMinMaxFromLayer();
127 mScalarRecalculateMinMaxButton->setEnabled( !std::isnan( mProviderMin ) && !std::isnan( mProviderMax ) );
131void QgsPointCloudAttributeByRampRendererWidget::setMinMaxFromLayer()
133 if ( std::isnan( mProviderMin ) || std::isnan( mProviderMax ) )
136 mBlockMinMaxChanged =
true;
137 mMinSpin->setValue( mProviderMin );
138 mMaxSpin->setValue( mProviderMax );
139 mBlockMinMaxChanged =
false;
146 mBlockChangedSignal =
true;
151 mBlockSetMinMaxFromLayer =
true;
153 mAttributeComboBox->setAttribute( mbcr->
attribute() );
155 mMinSpin->setValue( mbcr->
minimum() );
156 mMaxSpin->setValue( mbcr->
maximum() );
163 if ( mAttributeComboBox->findText( u
"Intensity"_s ) > -1 )
165 mAttributeComboBox->setAttribute( u
"Intensity"_s );
169 mAttributeComboBox->setCurrentIndex( mAttributeComboBox->count() > 1 ? 1 : 0 );
173 mBlockChangedSignal =
false;
174 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.