Skip to content

Commit

Permalink
Align behavior and appearance of 2d point cloud ramp widget to 2d widget
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 4, 2020
1 parent 2f14a53 commit 5e062d1
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 143 deletions.
59 changes: 57 additions & 2 deletions src/app/3d/qgspointcloud3dsymbolwidget.cpp
Expand Up @@ -29,31 +29,44 @@ QgsPointCloud3DSymbolWidget::QgsPointCloud3DSymbolWidget( QgsPointCloudLayer *la
mPointSizeSpinBox->setClearValue( 2.0 );

mRenderingParameterComboBox->setLayer( layer );
mRenderingParameterComboBox->setFilters( QgsPointCloudAttributeProxyModel::Numeric );
mRenderingParameterComboBox->setAllowEmptyAttributeName( false );

mSingleColorBtn->setAllowOpacity( false );
mSingleColorBtn->setColorDialogTitle( tr( "Select Point Color" ) );
mSingleColorBtn->setColor( QColor( 0, 0, 255 ) ); // default color

mRenderingStyleComboBox->addItem( tr( "No Rendering" ), QString() );
mRenderingStyleComboBox->addItem( tr( "Single Color" ), QStringLiteral( "single-color" ) );
mRenderingStyleComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "styleicons/singlebandpseudocolor.svg" ) ), tr( "Attribute by Ramp" ), QStringLiteral( "color-ramp" ) );
mRenderingStyleComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "styleicons/multibandcolor.svg" ) ), tr( "RGB" ), QStringLiteral( "rgb" ) );

mRenderingStyleComboBox->setCurrentIndex( 0 );
mStackedWidget->setCurrentIndex( 0 );

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( mColorRampShaderMinMaxReloadButton, &QPushButton::clicked, this, &QgsPointCloud3DSymbolWidget::reloadColorRampShaderMinMax );
connect( mScalarRecalculateMinMaxButton, &QPushButton::clicked, this, &QgsPointCloud3DSymbolWidget::setMinMaxFromLayer );
connect( mColorRampShaderWidget, &QgsColorRampShaderWidget::widgetChanged, this, &QgsPointCloud3DSymbolWidget::emitChangedSignal );
connect( mSingleColorBtn, &QgsColorButton::colorChanged, this, &QgsPointCloud3DSymbolWidget::emitChangedSignal );
connect( mRenderingParameterComboBox, &QgsPointCloudAttributeComboBox::attributeChanged,
this, &QgsPointCloud3DSymbolWidget::rampAttributeChanged );
connect( mColorRampShaderMinEdit, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, &QgsPointCloud3DSymbolWidget::minMaxChanged );
connect( mColorRampShaderMaxEdit, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, &QgsPointCloud3DSymbolWidget::minMaxChanged );

rampAttributeChanged();
}

void QgsPointCloud3DSymbolWidget::setSymbol( QgsPointCloud3DSymbol *symbol )
{
mBlockChangedSignals++;
if ( !symbol )
{
mRenderingStyleComboBox->setCurrentIndex( mRenderingStyleComboBox->findData( QgsPointCloud3DSymbol::NoRendering ) );
mRenderingStyleComboBox->setCurrentIndex( 0 );
mStackedWidget->setCurrentIndex( 0 );
mBlockChangedSignals--;
return;
}
Expand Down Expand Up @@ -151,3 +164,45 @@ void QgsPointCloud3DSymbolWidget::emitChangedSignal()

emit changed();
}

void QgsPointCloud3DSymbolWidget::rampAttributeChanged()
{
if ( mLayer && mLayer->dataProvider() )
{
const QVariant min = mLayer->dataProvider()->metadataStatistic( mRenderingParameterComboBox->currentAttribute(), QgsStatisticalSummary::Min );
const QVariant max = mLayer->dataProvider()->metadataStatistic( mRenderingParameterComboBox->currentAttribute(), QgsStatisticalSummary::Max );
if ( min.isValid() && max.isValid() )
{
mProviderMin = min.toDouble();
mProviderMax = max.toDouble();
}
else
{
mProviderMin = std::numeric_limits< double >::quiet_NaN();
mProviderMax = std::numeric_limits< double >::quiet_NaN();
}
}
mScalarRecalculateMinMaxButton->setEnabled( !std::isnan( mProviderMin ) && !std::isnan( mProviderMax ) );
emitChangedSignal();
}

void QgsPointCloud3DSymbolWidget::setMinMaxFromLayer()
{
if ( std::isnan( mProviderMin ) || std::isnan( mProviderMax ) )
return;

mBlockMinMaxChanged = true;
mColorRampShaderMinEdit->setValue( mProviderMin );
mColorRampShaderMaxEdit->setValue( mProviderMax );
mBlockMinMaxChanged = false;

minMaxChanged();
}

void QgsPointCloud3DSymbolWidget::minMaxChanged()
{
if ( mBlockMinMaxChanged )
return;

mColorRampShaderWidget->setMinimumMaximumAndClassify( mColorRampShaderMinEdit->value(), mColorRampShaderMaxEdit->value() );
}
8 changes: 8 additions & 0 deletions src/app/3d/qgspointcloud3dsymbolwidget.h
Expand Up @@ -37,6 +37,9 @@ class QgsPointCloud3DSymbolWidget : public QWidget, private Ui::QgsPointCloud3DS
void reloadColorRampShaderMinMax();
void onRenderingStyleChanged();
void emitChangedSignal();
void rampAttributeChanged();
void setMinMaxFromLayer();
void minMaxChanged();

signals:
void changed();
Expand All @@ -48,6 +51,11 @@ class QgsPointCloud3DSymbolWidget : public QWidget, private Ui::QgsPointCloud3DS
int mBlockChangedSignals = 0;
QgsPointCloudLayer *mLayer = nullptr;

bool mBlockMinMaxChanged = false;

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

};

#endif // QGSPOINTCLOUD3DSYMBOLWIDGET_H
Expand Up @@ -29,7 +29,7 @@ QgsPointCloudAttributeByRampRendererWidget::QgsPointCloudAttributeByRampRenderer
{
setupUi( this );

mAttributeComboBox->setAllowEmptyAttributeName( true );
mAttributeComboBox->setAllowEmptyAttributeName( false );
mAttributeComboBox->setFilters( QgsPointCloudAttributeProxyModel::Numeric );

if ( layer )
Expand Down Expand Up @@ -105,6 +105,7 @@ void QgsPointCloudAttributeByRampRendererWidget::attributeChanged()
}
}
mScalarRecalculateMinMaxButton->setEnabled( !std::isnan( mProviderMin ) && !std::isnan( mProviderMax ) );
emitWidgetChanged();
}

void QgsPointCloudAttributeByRampRendererWidget::setMinMaxFromLayer()
Expand Down

0 comments on commit 5e062d1

Please sign in to comment.