Skip to content

Commit

Permalink
[pointclouds] Don't regenerate ramp classes automatically when
Browse files Browse the repository at this point in the history
restoring previous renderer settings in point cloud attribute
by ramp widgets

Otherwise we lose the previously set user classes and always
reset to autogenerated ones.
  • Loading branch information
nyalldawson committed Feb 4, 2021
1 parent 0d857d2 commit 9fe1c17
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/app/3d/qgspointcloud3dsymbolwidget.cpp
Expand Up @@ -91,7 +91,6 @@ QgsPointCloud3DSymbolWidget::QgsPointCloud3DSymbolWidget( QgsPointCloudLayer *la
if ( symbol )
setSymbol( symbol );


connect( mPointSizeSpinBox, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, &QgsPointCloud3DSymbolWidget::emitChangedSignal );
connect( mRenderingStyleComboBox, qgis::overload< int >::of( &QComboBox::currentIndexChanged ), this, &QgsPointCloud3DSymbolWidget::onRenderingStyleChanged );
connect( mScalarRecalculateMinMaxButton, &QPushButton::clicked, this, &QgsPointCloud3DSymbolWidget::setMinMaxFromLayer );
Expand All @@ -104,7 +103,8 @@ QgsPointCloud3DSymbolWidget::QgsPointCloud3DSymbolWidget( QgsPointCloudLayer *la
connect( mMaxScreenErrorSpinBox, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, [&]() { emitChangedSignal(); } );
connect( mShowBoundingBoxesCheckBox, &QCheckBox::stateChanged, [&]() { emitChangedSignal(); } );

rampAttributeChanged();
if ( !symbol ) // if we have a symbol, this was already handled in setSymbol above
rampAttributeChanged();

mClassifiedRendererWidget = new QgsPointCloudClassifiedRendererWidget( layer, nullptr );
mClassifiedRendererWidget->setParent( this );
Expand Down Expand Up @@ -138,13 +138,16 @@ void QgsPointCloud3DSymbolWidget::setSymbol( QgsPointCloud3DSymbol *symbol )
mStackedWidget->setCurrentIndex( 2 );
QgsColorRampPointCloud3DSymbol *symb = dynamic_cast<QgsColorRampPointCloud3DSymbol *>( symbol );

// we will be restoring the existing ramp classes -- we don't want to regenerate any automatically!
mBlockSetMinMaxFromLayer = true;
mRenderingParameterComboBox->setAttribute( symb->attribute() );

mColorRampShaderMinEdit->setValue( symb->colorRampShaderMin() );
mColorRampShaderMaxEdit->setValue( symb->colorRampShaderMax() );

whileBlocking( mColorRampShaderWidget )->setFromShader( symb->colorRampShader() );
whileBlocking( mColorRampShaderWidget )->setMinimumMaximum( symb->colorRampShaderMin(), symb->colorRampShaderMax() );
mBlockSetMinMaxFromLayer = false;
}
else if ( symbol->symbolType() == QLatin1String( "rgb" ) )
{
Expand Down Expand Up @@ -472,7 +475,8 @@ void QgsPointCloud3DSymbolWidget::rampAttributeChanged()
mProviderMax = mProviderMax * zScale + zOffset;
}
}
setMinMaxFromLayer();
if ( !mBlockSetMinMaxFromLayer )
setMinMaxFromLayer();
mScalarRecalculateMinMaxButton->setEnabled( !std::isnan( mProviderMin ) && !std::isnan( mProviderMax ) );
emitChangedSignal();
}
Expand Down
1 change: 1 addition & 0 deletions src/app/3d/qgspointcloud3dsymbolwidget.h
Expand Up @@ -74,6 +74,7 @@ class QgsPointCloud3DSymbolWidget : public QWidget, private Ui::QgsPointCloud3DS
QgsPointCloudLayer *mLayer = nullptr;

bool mBlockMinMaxChanged = false;
bool mBlockSetMinMaxFromLayer = false;

double mProviderMin = std::numeric_limits< double >::quiet_NaN();
double mProviderMax = std::numeric_limits< double >::quiet_NaN();
Expand Down
Expand Up @@ -50,8 +50,6 @@ QgsPointCloudAttributeByRampRendererWidget::QgsPointCloudAttributeByRampRenderer

connect( mScalarColorRampShaderWidget, &QgsColorRampShaderWidget::widgetChanged, this, &QgsPointCloudAttributeByRampRendererWidget::emitWidgetChanged );
connect( mScalarRecalculateMinMaxButton, &QPushButton::clicked, this, &QgsPointCloudAttributeByRampRendererWidget::setMinMaxFromLayer );

attributeChanged();
}

QgsPointCloudRendererWidget *QgsPointCloudAttributeByRampRendererWidget::create( QgsPointCloudLayer *layer, QgsStyle *style, QgsPointCloudRenderer * )
Expand Down Expand Up @@ -117,7 +115,9 @@ void QgsPointCloudAttributeByRampRendererWidget::attributeChanged()
}

}
setMinMaxFromLayer();
if ( !mBlockSetMinMaxFromLayer )
setMinMaxFromLayer();

mScalarRecalculateMinMaxButton->setEnabled( !std::isnan( mProviderMin ) && !std::isnan( mProviderMax ) );
emitWidgetChanged();
}
Expand All @@ -141,6 +141,9 @@ void QgsPointCloudAttributeByRampRendererWidget::setFromRenderer( const QgsPoint
const QgsPointCloudAttributeByRampRenderer *mbcr = dynamic_cast<const QgsPointCloudAttributeByRampRenderer *>( r );
if ( mbcr )
{
// we will be restoring the existing ramp classes -- we don't want to regenerate any automatically!
mBlockSetMinMaxFromLayer = true;

mAttributeComboBox->setAttribute( mbcr->attribute() );

mMinSpin->setValue( mbcr->minimum() );
Expand All @@ -162,6 +165,7 @@ void QgsPointCloudAttributeByRampRendererWidget::setFromRenderer( const QgsPoint
}
attributeChanged();
mBlockChangedSignal = false;
mBlockSetMinMaxFromLayer = false;
}

///@endcond
Expand Up @@ -52,6 +52,7 @@ class GUI_EXPORT QgsPointCloudAttributeByRampRendererWidget: public QgsPointClou

bool mBlockChangedSignal = false;
bool mBlockMinMaxChanged = false;
bool mBlockSetMinMaxFromLayer = false;

double mProviderMin = std::numeric_limits< double >::quiet_NaN();
double mProviderMax = std::numeric_limits< double >::quiet_NaN();
Expand Down

0 comments on commit 9fe1c17

Please sign in to comment.