28 QgsPointCloudAttributeByRampRendererWidget::QgsPointCloudAttributeByRampRendererWidget(
QgsPointCloudLayer *layer,
QgsStyle *style )
33 mAttributeComboBox->setAllowEmptyAttributeName(
false );
36 mMinSpin->setShowClearButton(
false );
37 mMaxSpin->setShowClearButton(
false );
41 mAttributeComboBox->setLayer( layer );
43 setFromRenderer( layer->
renderer() );
47 this, &QgsPointCloudAttributeByRampRendererWidget::attributeChanged );
48 connect( mMinSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsPointCloudAttributeByRampRendererWidget::minMaxChanged );
49 connect( mMaxSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsPointCloudAttributeByRampRendererWidget::minMaxChanged );
52 connect( mScalarRecalculateMinMaxButton, &QPushButton::clicked,
this, &QgsPointCloudAttributeByRampRendererWidget::setMinMaxFromLayer );
57 return new QgsPointCloudAttributeByRampRendererWidget( layer, style );
67 std::unique_ptr< QgsPointCloudAttributeByRampRenderer > renderer = std::make_unique< QgsPointCloudAttributeByRampRenderer >();
68 renderer->setAttribute( mAttributeComboBox->currentAttribute() );
70 renderer->setMinimum( mMinSpin->value() );
71 renderer->setMaximum( mMaxSpin->value() );
73 renderer->setColorRampShader( mScalarColorRampShaderWidget->shader() );
75 return renderer.release();
78 void QgsPointCloudAttributeByRampRendererWidget::emitWidgetChanged()
80 if ( !mBlockChangedSignal )
84 void QgsPointCloudAttributeByRampRendererWidget::minMaxChanged()
86 if ( mBlockMinMaxChanged )
89 mScalarColorRampShaderWidget->setMinimumMaximumAndClassify( mMinSpin->value(), mMaxSpin->value() );
92 void QgsPointCloudAttributeByRampRendererWidget::attributeChanged()
94 if ( mLayer && mLayer->dataProvider() )
97 const double min = stats.
minimum( mAttributeComboBox->currentAttribute() );
98 const double max = stats.
maximum( mAttributeComboBox->currentAttribute() );
99 if ( !std::isnan( min ) && !std::isnan( max ) )
106 mProviderMin = std::numeric_limits< double >::quiet_NaN();
107 mProviderMax = std::numeric_limits< double >::quiet_NaN();
110 if ( mAttributeComboBox->currentAttribute().compare( QLatin1String(
"z" ), Qt::CaseInsensitive ) == 0 )
114 mProviderMin = mProviderMin * zScale + zOffset;
115 mProviderMax = mProviderMax * zScale + zOffset;
119 if ( !mBlockSetMinMaxFromLayer )
120 setMinMaxFromLayer();
122 mScalarRecalculateMinMaxButton->setEnabled( !std::isnan( mProviderMin ) && !std::isnan( mProviderMax ) );
126 void QgsPointCloudAttributeByRampRendererWidget::setMinMaxFromLayer()
128 if ( std::isnan( mProviderMin ) || std::isnan( mProviderMax ) )
131 mBlockMinMaxChanged =
true;
132 mMinSpin->setValue( mProviderMin );
133 mMaxSpin->setValue( mProviderMax );
134 mBlockMinMaxChanged =
false;
141 mBlockChangedSignal =
true;
146 mBlockSetMinMaxFromLayer =
true;
150 mMinSpin->setValue( mbcr->
minimum() );
151 mMaxSpin->setValue( mbcr->
maximum() );
158 if ( mAttributeComboBox->findText( QStringLiteral(
"Intensity" ) ) > -1 )
160 mAttributeComboBox->setAttribute( QStringLiteral(
"Intensity" ) );
164 mAttributeComboBox->setCurrentIndex( mAttributeComboBox->count() > 1 ? 1 : 0 );
168 mBlockChangedSignal =
false;
169 mBlockSetMinMaxFromLayer =
false;