Skip to content

Commit

Permalink
Allow loading min/max values direct from provider metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 2, 2020
1 parent 3df0469 commit 9822fe0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Expand Up @@ -40,12 +40,14 @@ QgsPointCloudAttributeByRampRendererWidget::QgsPointCloudAttributeByRampRenderer
}

connect( mAttributeComboBox, &QgsPointCloudAttributeComboBox::attributeChanged,
this, &QgsPointCloudAttributeByRampRendererWidget::emitWidgetChanged );
this, &QgsPointCloudAttributeByRampRendererWidget::attributeChanged );
connect( mMinSpin, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, &QgsPointCloudAttributeByRampRendererWidget::minMaxChanged );
connect( mMaxSpin, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, &QgsPointCloudAttributeByRampRendererWidget::minMaxChanged );

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 @@ -79,9 +81,45 @@ void QgsPointCloudAttributeByRampRendererWidget::emitWidgetChanged()

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

mScalarColorRampShaderWidget->setMinimumMaximumAndClassify( mMinSpin->value(), mMaxSpin->value() );
}

void QgsPointCloudAttributeByRampRendererWidget::attributeChanged()
{
if ( mLayer && mLayer->dataProvider() )
{
const QVariant min = mLayer->dataProvider()->metadataStatistic( mAttributeComboBox->currentAttribute(), QgsStatisticalSummary::Min );
const QVariant max = mLayer->dataProvider()->metadataStatistic( mAttributeComboBox->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 ) );
}

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

mBlockMinMaxChanged = true;
mMinSpin->setValue( mProviderMin );
mMaxSpin->setValue( mProviderMax );
mBlockMinMaxChanged = false;

minMaxChanged();
}

void QgsPointCloudAttributeByRampRendererWidget::setFromRenderer( const QgsPointCloudRenderer *r )
{
mBlockChangedSignal = true;
Expand All @@ -107,6 +145,7 @@ void QgsPointCloudAttributeByRampRendererWidget::setFromRenderer( const QgsPoint
mAttributeComboBox->setCurrentIndex( mAttributeComboBox->count() > 1 ? 1 : 0 );
}
}
attributeChanged();
mBlockChangedSignal = false;
}

Expand Down
Expand Up @@ -44,11 +44,17 @@ class GUI_EXPORT QgsPointCloudAttributeByRampRendererWidget: public QgsPointClou

void emitWidgetChanged();
void minMaxChanged();
void attributeChanged();
void setMinMaxFromLayer();

private:
void setFromRenderer( const QgsPointCloudRenderer *r );

bool mBlockChangedSignal = false;
bool mBlockMinMaxChanged = false;

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

///@endcond
Expand Down

0 comments on commit 9822fe0

Please sign in to comment.